forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PMM-12912 Add indicator for updates #723
Merged
matejkubinec
merged 13 commits into
PMM-11231-pmm-updates-ui
from
PMM-12912-updates-menu-indicator
Jul 12, 2024
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34a8adf
PMM-12912 Add indicator for updates
matejkubinec 9b364d4
Merge branch 'PMM-11231-pmm-updates-ui'
matejkubinec 94600c0
PMM-12912 Update MegaMenuItem
matejkubinec e939a02
Merge branch 'v3' into PMM-12912-updates-menu-indicator
matejkubinec bf3f8e5
PMM-12912 Update pmm updates url
matejkubinec d092f6a
PMM-12912 Replace badge with dot
matejkubinec 66ca5db
PMM-12912 Show dot based on the update availability
matejkubinec 515d822
PMM-12912 Adjust dot
matejkubinec 3e8b731
PMM-12912 update betterrer
matejkubinec ee8432d
PMM-12912 Fix dot styling
matejkubinec df7214d
PMM-12912 Reorder comments
matejkubinec 0875d2c
Merge branch 'v3' into PMM-12912-updates-menu-indicator
matejkubinec 1d92966
PMM-12912 Update api response
matejkubinec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
export interface UpdateInformation { | ||
version?: string; | ||
fullVersion?: string; | ||
timestamp?: string; | ||
} | ||
|
||
export interface UpdatesState { | ||
isLoading: boolean; | ||
updateAvailable?: boolean; | ||
installed?: UpdateInformation; | ||
latest?: UpdateInformation; | ||
latestNewsUrl?: string; | ||
lastChecked?: string; | ||
} | ||
|
||
export interface CheckUpdatesPayload { | ||
installed?: UpdateInformation; | ||
latest?: UpdateInformation; | ||
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, | ||
fullVersion: response.latest.full_version, | ||
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), | ||
}; |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
export interface CheckUpdatesBody { | ||
force: boolean; | ||
only_installed_version?: boolean; | ||
} | ||
|
||
export interface VersionInfo { | ||
version?: string; | ||
full_version?: string; | ||
timestamp: string; | ||
} | ||
|
||
export interface CheckUpdatesResponse { | ||
installed?: VersionInfo; | ||
latest?: VersionInfo; | ||
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'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will impact the "API breaking changes" , https://github.com/percona/pmm/blob/PMM-12913-migrate-api-endpoints-to-restful/api/MIGRATION_TO_V3.md?plain=1
POST /v1/updates/Check was replaced by GET /v1/server/updates
Depending on what branch will be merged first, we need to make changes. To keep that in mind.