-
Notifications
You must be signed in to change notification settings - Fork 37
[FEATURE] Add plugin versioning support + dashboard lock mode #243
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
Open
Gladorme
wants to merge
11
commits into
perses:main
Choose a base branch
from
Gladorme:versioning-lock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a242467
[FEATURE] Add dashboard versioning
Gladorme 290f519
Enforce version selected
Gladorme 832995d
Add versioning to panel type
Gladorme e7f7ba2
Add update drawer
Gladorme bc38d10
Handle dev plugin
Gladorme d9906b6
Reviewing
Gladorme 5162805
Apply review changes
Gladorme e5dab68
Fix unlock + lock button
Gladorme d7496e4
Apply Gabriel feedbacks
Gladorme 3ec838d
Only show update button if lock mode is available
Gladorme ff71233
Separate update button in its own prop
Gladorme 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 hidden or 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 hidden or 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
112 changes: 112 additions & 0 deletions
112
dashboards/src/components/LockDashboardButton/LockDashboardButton.tsx
This file contains hidden or 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,112 @@ | ||
| // Copyright The Perses Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import { Button, Tooltip } from '@mui/material'; | ||
| import { Dialog } from '@perses-dev/components'; | ||
| import { useListPluginMetadata } from '@perses-dev/plugin-system'; | ||
| import LockOpenOutline from 'mdi-material-ui/LockOpenOutline'; | ||
| import LockOutline from 'mdi-material-ui/LockOutline'; | ||
| import type { ReactElement } from 'react'; | ||
| import { useCallback, useMemo, useState } from 'react'; | ||
|
|
||
| import { useDashboard } from '../../context/useDashboard'; | ||
| import { | ||
| applyPluginVersions, | ||
| buildLatestPluginVersions, | ||
| isDashboardLocked, | ||
| removePluginVersions, | ||
| } from '../../utils/pluginVersioning'; | ||
|
|
||
| /** | ||
| * Toolbar button that "locks" or "unlocks" the dashboard. | ||
| * | ||
| * Locking pins every plugin definition (panels, queries, variables, datasources, annotations) to the latest version | ||
| * currently available in the Perses instance, by setting `plugin.metadata.version`. Unlocking removes that pinned | ||
| * version so the plugins float on the latest available version again. | ||
| * | ||
| * A dashboard can also be versioned partially (a single panel pinned from the panel editor, for instance). In that case | ||
| * both actions are offered: locking completes the pinning, unlocking clears it. | ||
| * | ||
| * Both actions are confirmed through a dialog explaining their consequences before the dashboard is updated. | ||
| */ | ||
| export function LockDashboardButton(): ReactElement { | ||
| const { dashboard, setDashboard } = useDashboard(); | ||
| const { data: pluginMetadata, isLoading } = useListPluginMetadata(); | ||
| const [pendingAction, setPendingAction] = useState<'lock' | 'unlock' | undefined>(undefined); | ||
|
|
||
| const isLocked = useMemo(() => isDashboardLocked(dashboard), [dashboard]); | ||
|
|
||
| const closeConfirmation = useCallback((): void => setPendingAction(undefined), []); | ||
|
|
||
| const handleConfirm = useCallback((): void => { | ||
| if (pendingAction === 'unlock') { | ||
| setDashboard(removePluginVersions(dashboard)); | ||
| } else if (pendingAction === 'lock') { | ||
| setDashboard(applyPluginVersions(dashboard, buildLatestPluginVersions(pluginMetadata ?? []))); | ||
| } | ||
| setPendingAction(undefined); | ||
| }, [dashboard, pendingAction, pluginMetadata, setDashboard]); | ||
|
|
||
| const isUnlockAction = pendingAction === 'unlock'; | ||
| const confirmLabel = isUnlockAction ? 'Unlock' : 'Lock'; | ||
|
|
||
| return ( | ||
| <> | ||
| {isLocked ? ( | ||
| <Tooltip title="Remove the pinned plugin versions" placement="bottom"> | ||
| <span> | ||
| <Button | ||
| onClick={() => setPendingAction('unlock')} | ||
| startIcon={<LockOpenOutline />} | ||
| variant="outlined" | ||
| color="secondary" | ||
| sx={{ whiteSpace: 'nowrap', minWidth: 'auto' }} | ||
| > | ||
| Unlock | ||
| </Button> | ||
| </span> | ||
| </Tooltip> | ||
| ) : ( | ||
| <Tooltip title="Pin every plugin to its latest version" placement="bottom"> | ||
| <span> | ||
| <Button | ||
| onClick={() => setPendingAction('lock')} | ||
| disabled={isLoading} | ||
| startIcon={<LockOutline />} | ||
| variant="outlined" | ||
| color="secondary" | ||
| sx={{ whiteSpace: 'nowrap', minWidth: 'auto' }} | ||
| > | ||
| Lock | ||
| </Button> | ||
| </span> | ||
| </Tooltip> | ||
| )} | ||
| <Dialog open={pendingAction !== undefined} onClose={closeConfirmation} aria-labelledby="lock-dashboard-dialog"> | ||
| <Dialog.Header id="lock-dashboard-dialog" onClose={closeConfirmation}> | ||
| {isUnlockAction ? 'Unlock Dashboard' : 'Lock Dashboard'} | ||
| </Dialog.Header> | ||
| <Dialog.Content> | ||
| {isUnlockAction | ||
| ? 'Unlocking removes the plugin versions pinned on this dashboard. Its panels, queries, variables, datasources and annotations will use the latest plugin versions available in this Perses instance, so their behavior may change when those plugins are updated.' | ||
| : 'Locking pins every plugin used by this dashboard (panels, queries, variables, datasources and annotations) to the latest version currently available in this Perses instance. The dashboard keeps using those exact versions, even after the plugins are updated. Plugins that are not installed in this instance cannot be pinned.'} | ||
| {' The change only applies once you save the dashboard.'} | ||
| </Dialog.Content> | ||
| <Dialog.Actions> | ||
| <Dialog.PrimaryButton onClick={handleConfirm}>{confirmLabel}</Dialog.PrimaryButton> | ||
| <Dialog.SecondaryButton onClick={closeConfirmation}>Cancel</Dialog.SecondaryButton> | ||
| </Dialog.Actions> | ||
| </Dialog> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or 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,14 @@ | ||
| // Copyright The Perses Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| export * from './LockDashboardButton'; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
75 changes: 75 additions & 0 deletions
75
dashboards/src/components/UpdatePluginsButton/UpdatePluginsButton.tsx
This file contains hidden or 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,75 @@ | ||
| // Copyright The Perses Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import { Badge, Button, Tooltip } from '@mui/material'; | ||
| import { useListPluginMetadata } from '@perses-dev/plugin-system'; | ||
| import UpdateIcon from 'mdi-material-ui/Update'; | ||
| import type { ReactElement } from 'react'; | ||
| import { useMemo, useState } from 'react'; | ||
|
|
||
| import { useDashboard } from '../../context/useDashboard'; | ||
| import type { OutdatedPlugin } from '../../utils/pluginVersioning'; | ||
| import { buildLatestPluginVersions, findOutdatedPlugins, updatePluginVersions } from '../../utils/pluginVersioning'; | ||
| import { UpdatePluginsDrawer } from '../UpdatePluginsDrawer'; | ||
|
|
||
| /** | ||
| * Toolbar button shown when at least one plugin pinned by the dashboard has a newer version installed. Opens a drawer to | ||
| * review and select which plugins to update. | ||
| * | ||
| * This is not reserved to fully locked dashboards: versioning can be enforced partially (a single panel pinned from the | ||
| * panel editor, for instance) and those pins are just as worth updating. | ||
| */ | ||
| export function UpdatePluginsButton(): ReactElement | null { | ||
| const { dashboard, setDashboard } = useDashboard(); | ||
| const { data: pluginMetadata } = useListPluginMetadata(); | ||
| const [isDrawerOpen, setDrawerOpen] = useState(false); | ||
|
|
||
| const outdatedPlugins = useMemo( | ||
| () => findOutdatedPlugins(dashboard, buildLatestPluginVersions(pluginMetadata ?? [])), | ||
| [dashboard, pluginMetadata], | ||
| ); | ||
|
|
||
| const handleUpdate = (plugins: OutdatedPlugin[]): void => { | ||
| setDashboard(updatePluginVersions(dashboard, plugins)); | ||
| setDrawerOpen(false); | ||
| }; | ||
|
|
||
| // Nothing to update: don't render the button at all. | ||
| if (outdatedPlugins.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Tooltip title="Update plugins to their latest version" placement="bottom"> | ||
| <Badge badgeContent={outdatedPlugins.length} color="primary"> | ||
| <Button | ||
| onClick={() => setDrawerOpen(true)} | ||
| startIcon={<UpdateIcon />} | ||
| variant="outlined" | ||
| color="secondary" | ||
| sx={{ whiteSpace: 'nowrap', minWidth: 'auto' }} | ||
| > | ||
| Update | ||
| </Button> | ||
| </Badge> | ||
| </Tooltip> | ||
| <UpdatePluginsDrawer | ||
| isOpen={isDrawerOpen} | ||
| outdatedPlugins={outdatedPlugins} | ||
| onUpdate={handleUpdate} | ||
| onClose={() => setDrawerOpen(false)} | ||
| /> | ||
| </> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I got lost on this comment, it says a lot of things but it seems contradictory in
the button that updates already-pinned plugins is shown regardless of this flag.as the button is gated behind theisUpdateButtonAvailable.