mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Filters: Introduce enrichFiltersRequest (#88913)
This commit is contained in:
parent
52fe19249e
commit
56ce88dea3
@ -258,7 +258,7 @@
|
|||||||
"@grafana/prometheus": "workspace:*",
|
"@grafana/prometheus": "workspace:*",
|
||||||
"@grafana/runtime": "workspace:*",
|
"@grafana/runtime": "workspace:*",
|
||||||
"@grafana/saga-icons": "workspace:*",
|
"@grafana/saga-icons": "workspace:*",
|
||||||
"@grafana/scenes": "4.27.0",
|
"@grafana/scenes": "4.29.0",
|
||||||
"@grafana/schema": "workspace:*",
|
"@grafana/schema": "workspace:*",
|
||||||
"@grafana/sql": "workspace:*",
|
"@grafana/sql": "workspace:*",
|
||||||
"@grafana/ui": "workspace:*",
|
"@grafana/ui": "workspace:*",
|
||||||
|
@ -375,6 +375,7 @@ export interface DataSourceGetTagKeysOptions<TQuery extends DataQuery = DataQuer
|
|||||||
*/
|
*/
|
||||||
timeRange?: TimeRange;
|
timeRange?: TimeRange;
|
||||||
queries?: TQuery[];
|
queries?: TQuery[];
|
||||||
|
scopes?: Scope[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -391,6 +392,7 @@ export interface DataSourceGetTagValuesOptions<TQuery extends DataQuery = DataQu
|
|||||||
*/
|
*/
|
||||||
timeRange?: TimeRange;
|
timeRange?: TimeRange;
|
||||||
queries?: TQuery[];
|
queries?: TQuery[];
|
||||||
|
scopes?: Scope[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MetadataInspectorProps<
|
export interface MetadataInspectorProps<
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import * as H from 'history';
|
import * as H from 'history';
|
||||||
|
|
||||||
import { AppEvents, CoreApp, DataQueryRequest, NavIndex, NavModelItem, locationUtil } from '@grafana/data';
|
import {
|
||||||
|
AppEvents,
|
||||||
|
CoreApp,
|
||||||
|
DataQueryRequest,
|
||||||
|
NavIndex,
|
||||||
|
NavModelItem,
|
||||||
|
locationUtil,
|
||||||
|
DataSourceGetTagKeysOptions,
|
||||||
|
DataSourceGetTagValuesOptions,
|
||||||
|
} from '@grafana/data';
|
||||||
import { config, locationService } from '@grafana/runtime';
|
import { config, locationService } from '@grafana/runtime';
|
||||||
import {
|
import {
|
||||||
getUrlSyncManager,
|
getUrlSyncManager,
|
||||||
@ -848,6 +857,12 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enrichFiltersRequest(): Partial<DataSourceGetTagKeysOptions | DataSourceGetTagValuesOptions> {
|
||||||
|
return {
|
||||||
|
scopes: this.state.scopes?.getSelectedScopes(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
canEditDashboard() {
|
canEditDashboard() {
|
||||||
const { meta } = this.state;
|
const { meta } = this.state;
|
||||||
|
|
||||||
|
@ -377,8 +377,8 @@ describe('ScopesScene', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Data requests', () => {
|
describe('Enrichers', () => {
|
||||||
it('Enriches data requests', async () => {
|
it('Data requests', async () => {
|
||||||
await userEvents.click(getBasicInput());
|
await userEvents.click(getBasicInput());
|
||||||
await userEvents.click(getApplicationsExpand());
|
await userEvents.click(getApplicationsExpand());
|
||||||
await userEvents.click(getApplicationsSlothPictureFactorySelect());
|
await userEvents.click(getApplicationsSlothPictureFactorySelect());
|
||||||
@ -412,6 +412,38 @@ describe('ScopesScene', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Filters requests', async () => {
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await userEvents.click(getApplicationsExpand());
|
||||||
|
await userEvents.click(getApplicationsSlothPictureFactorySelect());
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(dashboardScene.enrichFiltersRequest().scopes).toEqual(
|
||||||
|
mocksScopes.filter(({ metadata: { name } }) => name === 'slothPictureFactory')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await userEvents.click(getApplicationsSlothVoteTrackerSelect());
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(dashboardScene.enrichFiltersRequest().scopes).toEqual(
|
||||||
|
mocksScopes.filter(
|
||||||
|
({ metadata: { name } }) => name === 'slothPictureFactory' || name === 'slothVoteTracker'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await userEvents.click(getApplicationsSlothPictureFactorySelect());
|
||||||
|
await userEvents.click(getBasicInput());
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(dashboardScene.enrichFiltersRequest().scopes).toEqual(
|
||||||
|
mocksScopes.filter(({ metadata: { name } }) => name === 'slothVoteTracker')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,17 @@ import React from 'react';
|
|||||||
import { render } from 'test/test-utils';
|
import { render } from 'test/test-utils';
|
||||||
|
|
||||||
import { Scope, ScopeDashboardBinding, ScopeNode } from '@grafana/data';
|
import { Scope, ScopeDashboardBinding, ScopeNode } from '@grafana/data';
|
||||||
import { behaviors, SceneGridItem, SceneGridLayout, SceneQueryRunner, SceneTimeRange, VizPanel } from '@grafana/scenes';
|
import {
|
||||||
|
AdHocFiltersVariable,
|
||||||
|
behaviors,
|
||||||
|
GroupByVariable,
|
||||||
|
SceneGridItem,
|
||||||
|
SceneGridLayout,
|
||||||
|
SceneQueryRunner,
|
||||||
|
SceneTimeRange,
|
||||||
|
SceneVariableSet,
|
||||||
|
VizPanel,
|
||||||
|
} from '@grafana/scenes';
|
||||||
import { DashboardControls } from 'app/features/dashboard-scene/scene//DashboardControls';
|
import { DashboardControls } from 'app/features/dashboard-scene/scene//DashboardControls';
|
||||||
import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene';
|
import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene';
|
||||||
|
|
||||||
@ -304,6 +314,18 @@ export function buildTestScene(overrides: Partial<DashboardScene> = {}) {
|
|||||||
}),
|
}),
|
||||||
controls: new DashboardControls({}),
|
controls: new DashboardControls({}),
|
||||||
$behaviors: [new behaviors.CursorSync({})],
|
$behaviors: [new behaviors.CursorSync({})],
|
||||||
|
$variables: new SceneVariableSet({
|
||||||
|
variables: [
|
||||||
|
new AdHocFiltersVariable({
|
||||||
|
name: 'adhoc',
|
||||||
|
datasource: { uid: 'my-ds-uid' },
|
||||||
|
}),
|
||||||
|
new GroupByVariable({
|
||||||
|
name: 'groupby',
|
||||||
|
datasource: { uid: 'my-ds-uid' },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
body: new SceneGridLayout({
|
body: new SceneGridLayout({
|
||||||
children: [
|
children: [
|
||||||
new SceneGridItem({
|
new SceneGridItem({
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -3513,9 +3513,9 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@grafana/scenes@npm:4.27.0":
|
"@grafana/scenes@npm:4.29.0":
|
||||||
version: 4.27.0
|
version: 4.29.0
|
||||||
resolution: "@grafana/scenes@npm:4.27.0"
|
resolution: "@grafana/scenes@npm:4.29.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@grafana/e2e-selectors": "npm:^11.0.0"
|
"@grafana/e2e-selectors": "npm:^11.0.0"
|
||||||
"@leeoniya/ufuzzy": "npm:^1.0.14"
|
"@leeoniya/ufuzzy": "npm:^1.0.14"
|
||||||
@ -3530,7 +3530,7 @@ __metadata:
|
|||||||
"@grafana/ui": ^10.4.1
|
"@grafana/ui": ^10.4.1
|
||||||
react: ^18.0.0
|
react: ^18.0.0
|
||||||
react-dom: ^18.0.0
|
react-dom: ^18.0.0
|
||||||
checksum: 10/db072541da50cece2ccc2cd8965daa0ac83a77ab423aa576b9bfd08bb227727d5187bf4e27b0f8578d6fd1ba8fe38e2dafc73c0e74b627ff926915cf744830a2
|
checksum: 10/5da9b2ae9093f4c3ed012eeea58ce0dc66ddeabb02d2b0d4a87917f17463c857ccab5df23142cfc62323991e714a1a3f4d38d5956cdfe455ce57edcc82fe6893
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@ -16981,7 +16981,7 @@ __metadata:
|
|||||||
"@grafana/prometheus": "workspace:*"
|
"@grafana/prometheus": "workspace:*"
|
||||||
"@grafana/runtime": "workspace:*"
|
"@grafana/runtime": "workspace:*"
|
||||||
"@grafana/saga-icons": "workspace:*"
|
"@grafana/saga-icons": "workspace:*"
|
||||||
"@grafana/scenes": "npm:4.27.0"
|
"@grafana/scenes": "npm:4.29.0"
|
||||||
"@grafana/schema": "workspace:*"
|
"@grafana/schema": "workspace:*"
|
||||||
"@grafana/sql": "workspace:*"
|
"@grafana/sql": "workspace:*"
|
||||||
"@grafana/tsconfig": "npm:^1.3.0-rc1"
|
"@grafana/tsconfig": "npm:^1.3.0-rc1"
|
||||||
|
Loading…
Reference in New Issue
Block a user