-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: (scenes-react) - VizPanel add missing props and tests #998
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94381e9
feat: (scenes-react) - VizPanel add missing props and tests
L2D2Grafana a57f889
feat: (scenes-react) - VizPanel add newer props and remove failing tests
L2D2Grafana a51ca76
feat: (scenes-react) - remove VizPanelMenu
L2D2Grafana c2b2568
feat: (scenes-react) - restrict titleItems to react elements
L2D2Grafana 183c392
feat: (scenes-react) - remove unused type
L2D2Grafana 687436f
test: update unit tests
gtk-grafana f5eb180
feat: (scenes-react) - run prettier
L2D2Grafana 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import React, { useEffect, useId } from 'react'; | ||
import { | ||
SceneObject, | ||
VizPanelMenu, | ||
SceneDataProvider, | ||
VizPanel as VizPanelObject, | ||
VizPanelState, | ||
|
@@ -9,18 +11,47 @@ import { | |
} from '@grafana/scenes'; | ||
import { usePrevious } from 'react-use'; | ||
import { getPanelOptionsWithDefaults } from '@grafana/data'; | ||
import { PanelContext } from '@grafana/ui'; | ||
import { writeSceneLog } from '../utils'; | ||
import { useSceneContext } from '../hooks/hooks'; | ||
|
||
export interface VizPanelProps { | ||
title: string; | ||
description?: string; | ||
dataProvider?: SceneDataProvider; | ||
viz: VizConfig; | ||
displayMode?: 'default' | 'transparent'; | ||
hoverHeader?: boolean; | ||
hoverHeaderOffset?: number; | ||
menu?: VizPanelMenu; | ||
titleItems?: React.ReactNode | SceneObject | SceneObject[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we restrict this to only react elements? |
||
seriesLimit?: number; | ||
seriesLimitShowAll?: boolean; | ||
headerActions?: React.ReactNode; | ||
extendPanelContext?: (vizPanel: VizPanelObject, context: PanelContext) => void; | ||
collapsible?: boolean; | ||
collapsed?: boolean; | ||
} | ||
|
||
export function VizPanel(props: VizPanelProps) { | ||
const { title, viz, dataProvider, headerActions } = props; | ||
const { | ||
title, | ||
description, | ||
viz, | ||
dataProvider, | ||
displayMode, | ||
hoverHeader, | ||
hoverHeaderOffset, | ||
headerActions, | ||
menu, | ||
titleItems, | ||
extendPanelContext, | ||
seriesLimit, | ||
seriesLimitShowAll, | ||
collapsible, | ||
collapsed, | ||
} = props; | ||
|
||
const scene = useSceneContext(); | ||
const key = useId(); | ||
const prevProps = usePrevious(props); | ||
|
@@ -30,13 +61,24 @@ export function VizPanel(props: VizPanelProps) { | |
if (!panel) { | ||
panel = new VizPanelObject({ | ||
key: key, | ||
title: title, | ||
pluginId: viz.pluginId, | ||
pluginVersion: viz.pluginVersion, | ||
title: title, | ||
titleItems: titleItems, | ||
description: description, | ||
options: viz.options, | ||
fieldConfig: viz.fieldConfig, | ||
pluginVersion: viz.pluginVersion, | ||
$data: getDataProviderForVizPanel(dataProvider), | ||
displayMode: displayMode, | ||
hoverHeader: hoverHeader, | ||
hoverHeaderOffset: hoverHeaderOffset, | ||
headerActions: headerActions, | ||
menu: menu, | ||
extendPanelContext: extendPanelContext, | ||
collapsible: collapsible, | ||
collapsed: collapsed, | ||
seriesLimit: seriesLimit, | ||
seriesLimitShowAll: seriesLimitShowAll, | ||
}); | ||
} | ||
|
||
|
@@ -54,6 +96,30 @@ export function VizPanel(props: VizPanelProps) { | |
stateUpdate.title = title; | ||
} | ||
|
||
if (description !== prevProps.description) { | ||
stateUpdate.description = description; | ||
} | ||
|
||
if (displayMode !== prevProps.displayMode) { | ||
stateUpdate.displayMode = displayMode; | ||
} | ||
|
||
if (hoverHeader !== prevProps.hoverHeader) { | ||
stateUpdate.hoverHeader = hoverHeader; | ||
} | ||
|
||
if (hoverHeaderOffset !== prevProps.hoverHeaderOffset) { | ||
stateUpdate.hoverHeaderOffset = hoverHeaderOffset; | ||
} | ||
|
||
if (menu !== prevProps.menu) { | ||
stateUpdate.menu = menu; | ||
} | ||
|
||
if (titleItems !== prevProps.titleItems) { | ||
stateUpdate.titleItems = titleItems; | ||
} | ||
|
||
if (headerActions !== prevProps.headerActions) { | ||
stateUpdate.headerActions = headerActions; | ||
} | ||
|
@@ -62,6 +128,22 @@ export function VizPanel(props: VizPanelProps) { | |
stateUpdate.$data = getDataProviderForVizPanel(dataProvider); | ||
} | ||
|
||
if (seriesLimit !== prevProps.seriesLimit) { | ||
stateUpdate.seriesLimit = seriesLimit; | ||
} | ||
|
||
if (seriesLimitShowAll !== prevProps.seriesLimitShowAll) { | ||
stateUpdate.seriesLimitShowAll = seriesLimitShowAll; | ||
} | ||
|
||
if (collapsible !== prevProps.collapsible) { | ||
stateUpdate.collapsible = collapsible; | ||
} | ||
|
||
if (collapsed !== prevProps.collapsed) { | ||
stateUpdate.collapsed = collapsed; | ||
} | ||
|
||
if (viz !== prevProps.viz) { | ||
if (viz.pluginId === prevProps.viz.pluginId) { | ||
const plugin = panel.getPlugin(); | ||
|
@@ -84,7 +166,24 @@ export function VizPanel(props: VizPanelProps) { | |
panel.setState(stateUpdate); | ||
writeSceneLog('VizPanel', 'Updating VizPanel state', stateUpdate); | ||
} | ||
}, [panel, title, headerActions, viz, dataProvider, prevProps]); | ||
}, [ | ||
panel, | ||
title, | ||
description, | ||
displayMode, | ||
hoverHeader, | ||
hoverHeaderOffset, | ||
headerActions, | ||
menu, | ||
titleItems, | ||
viz, | ||
dataProvider, | ||
seriesLimit, | ||
seriesLimitShowAll, | ||
collapsible, | ||
collapsed, | ||
prevProps, | ||
]); | ||
|
||
return <panel.Component model={panel} />; | ||
} | ||
|
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.
This comment was marked as outdated.
Sorry, something went wrong.
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.
Ignore the above, I got this working locally in the browser and everything works as expected, must be something in the test env that is keeping the panel from rendering