Skip to content

[FEATURE/BREAKINGCHANGE] DataQueriesProvider: use full queryDefinitions + remove QueryCountProvider + add edit query name in QueryEditorContainer#69

Open
Gladorme wants to merge 5 commits into
perses:mainfrom
Gladorme:named-queries

Conversation

@Gladorme

@Gladorme Gladorme commented Feb 26, 2026

Copy link
Copy Markdown
Member

Description

Depends on: perses/perses#3915

This PR is doing some breaking changes:

  • DataQueriesProvider: need full query definitions instead of just definition (Definition => QueryDefinition)
  • QueryCountProvider: removed, you can retrieve query count using DataQueriesProvider
  • useQueryType: removed containing hard coded plugin data

This PR allow user to edit query names, using a self edit/submit button in order to not spam rerender when updating it

Migration should be easy, because Definition is often calculated from QueryDefinition. Worst case:

Before:

export function TestComponent(props: TestComponentProps): ReactElement {
      ...

      const definitions = [
        {
          kind: 'PrometheusTimeSeriesQuery',
          spec: {
            datasource: datasource,
            query: expr,
          },
        },
      ];

  return (
      <DataQueriesProvider definitions={definitions}>
        {/* ... */}
      </DataQueriesProvider>
  )
}

After:

export function TestComponent(props: TestComponentProps): ReactElement {
      ...

      const queryDefinitions = [
        {
          kind: 'TimeSeriesQuery',
          spec: {
            plugin: {
              kind: 'PrometheusTimeSeriesQuery',
              spec: {
                datasource: datasource,
                query: expr,
              },
            },
          },
        },
      ];

  return (
      <DataQueriesProvider definitions={queryDefinitions}>
        {/* ... */}
      </DataQueriesProvider>
  )
}

Screenshots

image

On edit:
image

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.
  • E2E tests are stable and unlikely to be flaky.
    See e2e docs for more details. Common issues include:
    • Is the data inconsistent? You need to mock API requests.
    • Does the time change? You need to use consistent time values or mock time utilities.
    • Does it have loading states? You need to wait for loading to complete.

@celian-garcia

celian-garcia commented Jun 11, 2026

Copy link
Copy Markdown
Member

Counter proposal to be less polluting for the edit button
image

Gladorme added 5 commits June 15, 2026 09:48
…ns + remove QueryCountProvider + add edit query name in QueryEditorContainer

Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
@Gladorme

Copy link
Copy Markdown
Member Author

@jgbernalp If you have any opinion about this breaking change, else I proceed with merge :)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces breaking changes to the query runtime API by switching DataQueriesProvider to consume full QueryDefinition objects (instead of plugin Definitions), removing QueryCountProvider/useQueryType, and adds UI support for editing query names in QueryEditorContainer with an explicit edit/submit flow to avoid noisy re-renders.

Changes:

  • Update DataQueriesProvider to accept/store full QueryDefinitions and expose them via context (enabling query count retrieval without a separate provider).
  • Remove QueryCountProvider exports and related wiring.
  • Add query-name utilities and implement editable query names in QueryEditorContainer.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
plugin-system/src/runtime/QueryCountProvider.tsx Removes the QueryCount context/provider (breaking change).
plugin-system/src/runtime/index.ts Stops exporting QueryCountProvider.
plugin-system/src/runtime/DataQueriesProvider/model.ts Updates provider props/context types to use full QueryDefinitions; removes useQueryType.
plugin-system/src/runtime/DataQueriesProvider/DataQueriesProvider.tsx Uses full QueryDefinitions directly; exposes queryDefinitions in context and filters by query type.
plugin-system/src/runtime/DataQueriesProvider/DataQueriesProvider.test.tsx Updates tests to the new QueryDefinition shape and removes useQueryType tests.
plugin-system/src/components/PanelSpecEditor/PanelSpecEditor.tsx Removes QueryCountProvider wrapper usage.
plugin-system/src/components/PanelSpecEditor/PanelSpecEditor.test.tsx Updates mocked DataQueries context to include queryDefinitions.
plugin-system/src/components/MultiQueryEditor/utils.tsx Adds helpers for default/query names (new export).
plugin-system/src/components/MultiQueryEditor/QueryEditorContainer.tsx Adds UI/state for editing query names with save/cancel.
plugin-system/src/components/MultiQueryEditor/index.tsx Exports the new query-name utilities.
dashboards/src/components/PanelDrawer/PanelQueriesSharedControls.tsx Updates preview definitions to use full QueryDefinitions (no more mapping to plugin-only definitions).
dashboards/src/components/GridLayout/GridItemContent.tsx Passes full query definitions into DataQueriesProvider and QueryViewerDialog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugin-system/src/components/MultiQueryEditor/utils.tsx
Comment on lines +83 to +99
const [isEditingName, setIsEditingName] = useState(false);
const [name, setName] = useState(query.spec.name ?? defaultQueryName(index));

function handleNameChange(): void {
setIsEditingName(false);
onChange(
index,
produce(query, (draft) => {
draft.spec.name = name;
})
);
}

function handleNameCancel(): void {
setName(query.spec.name ?? defaultQueryName(index));
setIsEditingName(false);
}
Comment on lines +131 to +153
<TextField
size="small"
variant="outlined"
value={name}
onChange={(e) => setName(e.target.value)}
fullWidth={true}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton size="small" aria-label="cancel edit" onClick={handleNameCancel} edge="end">
<CloseIcon />
</IconButton>
<IconButton size="small" aria-label="save query name" onClick={handleNameChange} edge="end">
<CheckIcon />
</IconButton>
</InputAdornment>
),
}}
/>
) : (
<Typography variant="overline" component="h4">
{name}
</Typography>
@Nexucis

Nexucis commented Jun 18, 2026

Copy link
Copy Markdown
Member

if there is an assuming breaking change. Can you please provide the migration plan please @Gladorme ?

@Gladorme

Copy link
Copy Markdown
Member Author

DataQueriesProvider: need full query definitions instead of just definition (Definition => QueryDefinition)
QueryCountProvider: removed, you can retrieve query count using DataQueriesProvider

Migration should be easy, because Definition is often calculated from QueryDefinition. Worst case:

Before:

export function TestComponent(props: TestComponentProps): ReactElement {
      ...

      const definitions = [
        {
          kind: 'PrometheusTimeSeriesQuery',
          spec: {
            datasource: datasource,
            query: expr,
          },
        },
      ];

  return (
      <DataQueriesProvider definitions={definitions}>
        {/* ... */}
      </DataQueriesProvider>
  )
}

After:

export function TestComponent(props: TestComponentProps): ReactElement {
      ...

      const queryDefinitions = [
        {
          kind: 'TimeSeriesQuery',
          spec: {
            plugin: {
              kind: 'PrometheusTimeSeriesQuery',
              spec: {
                datasource: datasource,
                query: expr,
              },
            },
          },
        },
      ];

  return (
      <DataQueriesProvider definitions={queryDefinitions}>
        {/* ... */}
      </DataQueriesProvider>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants