forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PMM-12912 Add indicator for updates * PMM-12912 Update MegaMenuItem * PMM-12912 Update pmm updates url * PMM-12912 Replace badge with dot * PMM-12912 Show dot based on the update availability * PMM-12912 Adjust dot * PMM-12912 update betterrer * PMM-12912 Fix dot styling * PMM-12912 Reorder comments * PMM-12912 Update api response
- Loading branch information
1 parent
fe75a73
commit a63d331
Showing
19 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
public/app/percona/shared/components/Elements/Dot/Dot.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { css } from '@emotion/css'; | ||
|
||
import { GrafanaTheme2 } from '@grafana/data'; | ||
|
||
export const getStyles = (theme: GrafanaTheme2, top?: number, bottom?: number, right?: number, left?: number) => ({ | ||
dot: css({ | ||
position: 'absolute', | ||
width: 6, | ||
height: 6, | ||
top, | ||
bottom, | ||
right, | ||
left, | ||
borderRadius: theme.shape.radius.circle, | ||
backgroundColor: theme.colors.error.main, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import classNames from 'classnames'; | ||
import React, { FC } from 'react'; | ||
|
||
import { useStyles2 } from '@grafana/ui'; | ||
|
||
import { getStyles } from './Dot.styles'; | ||
import { DotProps } from './Dot.types'; | ||
|
||
export const Dot: FC<DotProps> = ({ top, bottom, right, left }) => { | ||
const styles = useStyles2(getStyles, top, bottom, right, left); | ||
|
||
return <div className={classNames(styles.dot)} />; | ||
}; |
6 changes: 6 additions & 0 deletions
6
public/app/percona/shared/components/Elements/Dot/Dot.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface DotProps { | ||
top?: number; | ||
bottom?: number; | ||
right?: number; | ||
left?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Dot } from './Dot'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import updatesReducer from './updates'; | ||
|
||
export * from './updates'; | ||
export * from './updates.types'; | ||
|
||
export default updatesReducer; |
45 changes: 45 additions & 0 deletions
45
public/app/percona/shared/core/reducers/updates/updates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; | ||
|
||
import { UpdatesService } from 'app/percona/shared/services/updates'; | ||
|
||
import { CheckUpdatesPayload, UpdatesState } from './updates.types'; | ||
import { responseToPayload } from './updates.utils'; | ||
|
||
const initialState: UpdatesState = { | ||
isLoading: false, | ||
}; | ||
|
||
export const updatesSlice = createSlice({ | ||
name: 'updates', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(checkUpdatesAction.pending, () => ({ | ||
...initialState, | ||
isLoading: true, | ||
})); | ||
|
||
builder.addCase(checkUpdatesAction.fulfilled, (state, { payload }) => ({ | ||
...state, | ||
...payload, | ||
isLoading: false, | ||
})); | ||
|
||
builder.addCase(checkUpdatesAction.rejected, () => ({ | ||
...initialState, | ||
isLoading: false, | ||
})); | ||
}, | ||
}); | ||
|
||
export const checkUpdatesAction = createAsyncThunk('percona/checkUpdates', async (): Promise<CheckUpdatesPayload> => { | ||
try { | ||
const res = await UpdatesService.getCurrentVersion({ force: true }); | ||
return responseToPayload(res); | ||
} catch (error) { | ||
const res = await UpdatesService.getCurrentVersion({ force: true, only_installed_version: true }); | ||
return responseToPayload(res); | ||
} | ||
}); | ||
|
||
export default updatesSlice.reducer; |
28 changes: 28 additions & 0 deletions
28
public/app/percona/shared/core/reducers/updates/updates.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export interface CurrentInformation { | ||
version?: string; | ||
fullVersion?: string; | ||
timestamp?: string; | ||
} | ||
|
||
export interface LatestInformation { | ||
version?: string; | ||
tag?: string; | ||
timestamp?: string; | ||
} | ||
|
||
export interface UpdatesState { | ||
isLoading: boolean; | ||
updateAvailable?: boolean; | ||
installed?: CurrentInformation; | ||
latest?: LatestInformation; | ||
latestNewsUrl?: string; | ||
lastChecked?: string; | ||
} | ||
|
||
export interface CheckUpdatesPayload { | ||
installed?: CurrentInformation; | ||
latest?: LatestInformation; | ||
latestNewsUrl?: string; | ||
lastChecked?: string; | ||
updateAvailable: boolean; | ||
} |
23 changes: 23 additions & 0 deletions
23
public/app/percona/shared/core/reducers/updates/updates.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CheckUpdatesResponse } from 'app/percona/shared/services/updates/Updates.types'; | ||
|
||
import { CheckUpdatesPayload } from './updates.types'; | ||
|
||
export const responseToPayload = (response: CheckUpdatesResponse): CheckUpdatesPayload => ({ | ||
installed: response.installed | ||
? { | ||
version: response.installed.version, | ||
fullVersion: response.installed.full_version, | ||
timestamp: response.installed.timestamp, | ||
} | ||
: undefined, | ||
latest: response.latest | ||
? { | ||
version: response.latest.version, | ||
tag: response.latest.tag, | ||
timestamp: response.latest.timestamp, | ||
} | ||
: undefined, | ||
lastChecked: response.last_check, | ||
latestNewsUrl: response.latest_news_url, | ||
updateAvailable: !!response.update_available, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
public/app/percona/shared/services/updates/Updates.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { api } from '../../helpers/api'; | ||
|
||
import { CheckUpdatesBody, CheckUpdatesResponse } from './Updates.types'; | ||
|
||
export const UpdatesService = { | ||
getCurrentVersion: (body: CheckUpdatesBody = { force: false }) => | ||
api.post<CheckUpdatesResponse, CheckUpdatesBody>('/v1/Updates/Check', body, true), | ||
}; |
24 changes: 24 additions & 0 deletions
24
public/app/percona/shared/services/updates/Updates.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export interface CheckUpdatesBody { | ||
force: boolean; | ||
only_installed_version?: boolean; | ||
} | ||
|
||
export interface CurrentInfo { | ||
version?: string; | ||
full_version?: string; | ||
timestamp?: string; | ||
} | ||
|
||
export interface LatestInfo { | ||
version?: string; | ||
tag?: string; | ||
timestamp?: string; | ||
} | ||
|
||
export interface CheckUpdatesResponse { | ||
installed?: CurrentInfo; | ||
latest?: LatestInfo; | ||
update_available?: boolean; | ||
latest_news_url?: string; | ||
last_check?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UpdatesService } from './Updates.service'; |