Skip to content
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

VizPanel: support collapsible props #808

Merged
merged 7 commits into from
Dec 5, 2024

Conversation

gtk-grafana
Copy link
Contributor

@gtk-grafana gtk-grafana commented Jul 1, 2024

Adding support to panel builders to allow passing PanelChrome collapsible props.
e.g. collapsible, collapsed, onToggleCollapse

Example usage:

// Get current state from local storage
const collapsed = getLocalStorageOption('panelCollapsed', [CollapsedType.collapsed, CollapsedType.open]) === CollapsedType.collapsed;

// Build collapsable panel
const panel = PanelBuilders.timeseries()
    .setData(collapsed ? undefined : getQueryRunner([]))
    .setCollapsible(true)
    .setCollapsed(collapsed)
    .build()

panel.subscribeToState((newState, prevState) => {
    if (newState.collapsed !== prevState.collapsed) {
        // Set updated state to local storage
        setLocalStorageOption('panelCollapsed', newState.collapsed ? CollapsedType.collapsed : CollapsedType.open);

        // Conditionally set DataProvider if panel is not collapsed
        panel.setState({
            $data: newState.collapsed
                ? undefined
                : getQueryRunner([]),
        });

        // Update the height of the panel
        const flexItem = sceneGraph.getAncestor(panel, SceneFlexItem);
        flexItem.setState({
            height: newState.collapsed ? 35 : 200,
        });
    }
})

Notes:

  • Looks like the height in scenes is defined differently then in core Grafana, so users must manually set collapsed and uncollapsed heights when scene is activated and onToggleCollapse. 35px works pretty well for the collapsed state.
  • Developers will need to manually add/remove query runners to prevent queries from running while collapsed, if desired.
📦 Published PR as canary version: 5.29.0--canary.808.12181324273.0

✨ Test out this PR locally via:

npm install @grafana/[email protected]
npm install @grafana/[email protected]
# or 
yarn add @grafana/[email protected]
yarn add @grafana/[email protected]

@gtk-grafana gtk-grafana added release Create a release when this pr is merged minor Increment the minor version when merged no-changelog labels Dec 4, 2024
@gtk-grafana gtk-grafana changed the title Allow passthru of panelchrome props VizPanel: allow any PanelChrome props Dec 4, 2024
@gtk-grafana gtk-grafana marked this pull request as ready for review December 4, 2024 14:33
@gtk-grafana gtk-grafana changed the title VizPanel: allow any PanelChrome props VizPanel: support collapsible props Dec 4, 2024
@gtk-grafana gtk-grafana requested a review from torkelo December 4, 2024 15:32
gtk-grafana added a commit to grafana/explore-logs that referenced this pull request Dec 5, 2024
@gtk-grafana gtk-grafana self-assigned this Dec 5, 2024
@gtk-grafana gtk-grafana requested a review from torkelo December 5, 2024 13:41
Comment on lines 87 to 88
collapsible?: PanelChromeProps['collapsible']
collapsed?: PanelChromeProps['collapsed']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just stick with simple boolean types here, this just obfuscates the simple types that these props really have.

@gtk-grafana gtk-grafana merged commit 9449e79 into main Dec 5, 2024
5 checks passed
@gtk-grafana gtk-grafana deleted the gtk-grafana/panel-chrome-overrides branch December 5, 2024 14:09
@gtk-grafana gtk-grafana mentioned this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged no-changelog release Create a release when this pr is merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants