mirror of https://github.com/grafana/grafana.git
Bump scenes and fix types (#105167)
* bump scenes and fix types * bump scenes * refactor * refactor + test * naming
This commit is contained in:
parent
c92ff0ca75
commit
c6428dfc74
|
|
@ -282,8 +282,8 @@
|
|||
"@grafana/plugin-ui": "0.10.5",
|
||||
"@grafana/prometheus": "workspace:*",
|
||||
"@grafana/runtime": "workspace:*",
|
||||
"@grafana/scenes": "6.10.2",
|
||||
"@grafana/scenes-react": "6.10.2",
|
||||
"@grafana/scenes": "6.10.4",
|
||||
"@grafana/scenes-react": "6.10.4",
|
||||
"@grafana/schema": "workspace:*",
|
||||
"@grafana/sql": "workspace:*",
|
||||
"@grafana/ui": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -552,6 +552,132 @@ describe('sceneVariablesSetToVariables', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
describe('should adapt AdHocFiltersVariable filters', () => {
|
||||
it('should remove origin from filter if its not dashboard or scope', () => {
|
||||
const variable = new AdHocFiltersVariable({
|
||||
name: 'test',
|
||||
allowCustomValue: true,
|
||||
label: 'test-label',
|
||||
description: 'test-desc',
|
||||
datasource: { uid: 'fake-std', type: 'fake-std' },
|
||||
filters: [
|
||||
{
|
||||
key: 'filterTest',
|
||||
operator: '=',
|
||||
value: 'test',
|
||||
origin: 'asserts',
|
||||
},
|
||||
],
|
||||
baseFilters: [
|
||||
{
|
||||
key: 'baseFilterTest',
|
||||
operator: '=',
|
||||
value: 'test',
|
||||
origin: 'asserts',
|
||||
},
|
||||
],
|
||||
});
|
||||
const set = new SceneVariableSet({
|
||||
variables: [variable],
|
||||
});
|
||||
|
||||
const result = sceneVariablesSetToVariables(set);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toMatchInlineSnapshot(`
|
||||
{
|
||||
"allowCustomValue": true,
|
||||
"baseFilters": [
|
||||
{
|
||||
"key": "baseFilterTest",
|
||||
"operator": "=",
|
||||
"value": "test",
|
||||
},
|
||||
],
|
||||
"datasource": {
|
||||
"type": "fake-std",
|
||||
"uid": "fake-std",
|
||||
},
|
||||
"defaultKeys": undefined,
|
||||
"description": "test-desc",
|
||||
"filters": [
|
||||
{
|
||||
"key": "filterTest",
|
||||
"operator": "=",
|
||||
"value": "test",
|
||||
},
|
||||
],
|
||||
"label": "test-label",
|
||||
"name": "test",
|
||||
"type": "adhoc",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should maintain dashboard or scope origin', () => {
|
||||
const variable = new AdHocFiltersVariable({
|
||||
name: 'test',
|
||||
allowCustomValue: true,
|
||||
label: 'test-label',
|
||||
description: 'test-desc',
|
||||
datasource: { uid: 'fake-std', type: 'fake-std' },
|
||||
filters: [
|
||||
{
|
||||
key: 'filterTest',
|
||||
operator: '=',
|
||||
value: 'test',
|
||||
origin: 'dashboard',
|
||||
},
|
||||
],
|
||||
baseFilters: [
|
||||
{
|
||||
key: 'baseFilterTest',
|
||||
operator: '=',
|
||||
value: 'test',
|
||||
origin: 'scope',
|
||||
},
|
||||
],
|
||||
});
|
||||
const set = new SceneVariableSet({
|
||||
variables: [variable],
|
||||
});
|
||||
|
||||
const result = sceneVariablesSetToVariables(set);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toMatchInlineSnapshot(`
|
||||
{
|
||||
"allowCustomValue": true,
|
||||
"baseFilters": [
|
||||
{
|
||||
"key": "baseFilterTest",
|
||||
"operator": "=",
|
||||
"origin": "scope",
|
||||
"value": "test",
|
||||
},
|
||||
],
|
||||
"datasource": {
|
||||
"type": "fake-std",
|
||||
"uid": "fake-std",
|
||||
},
|
||||
"defaultKeys": undefined,
|
||||
"description": "test-desc",
|
||||
"filters": [
|
||||
{
|
||||
"key": "filterTest",
|
||||
"operator": "=",
|
||||
"origin": "dashboard",
|
||||
"value": "test",
|
||||
},
|
||||
],
|
||||
"label": "test-label",
|
||||
"name": "test",
|
||||
"type": "adhoc",
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle AdHocFiltersVariable with defaultKeys', () => {
|
||||
const variable = new AdHocFiltersVariable({
|
||||
name: 'test',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import { config } from '@grafana/runtime';
|
||||
import { MultiValueVariable, SceneVariables, sceneUtils } from '@grafana/scenes';
|
||||
import {
|
||||
AdHocFilterWithLabels as SceneAdHocFilterWithLabels,
|
||||
MultiValueVariable,
|
||||
SceneVariables,
|
||||
sceneUtils,
|
||||
} from '@grafana/scenes';
|
||||
import {
|
||||
VariableModel,
|
||||
VariableRefresh as OldVariableRefresh,
|
||||
|
|
@ -18,6 +23,7 @@ import {
|
|||
GroupByVariableKind,
|
||||
defaultVariableHide,
|
||||
VariableOption,
|
||||
AdHocFilterWithLabels,
|
||||
} from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen';
|
||||
|
||||
import { getIntervalsQueryFromNewIntervalModel } from '../utils/utils';
|
||||
|
|
@ -181,8 +187,8 @@ export function sceneVariablesSetToVariables(set: SceneVariables, keepQueryOptio
|
|||
datasource: variable.state.datasource,
|
||||
allowCustomValue: variable.state.allowCustomValue,
|
||||
// @ts-expect-error
|
||||
baseFilters: variable.state.baseFilters,
|
||||
filters: variable.state.filters,
|
||||
baseFilters: validateFiltersOrigin(variable.state.baseFilters),
|
||||
filters: validateFiltersOrigin(variable.state.filters),
|
||||
defaultKeys: variable.state.defaultKeys,
|
||||
});
|
||||
} else {
|
||||
|
|
@ -423,8 +429,8 @@ export function sceneVariablesSetToSchemaV2Variables(
|
|||
...commonProperties,
|
||||
name: variable.state.name,
|
||||
datasource: variable.state.datasource || {}, //FIXME what is the default value?
|
||||
baseFilters: variable.state.baseFilters || [],
|
||||
filters: variable.state.filters,
|
||||
baseFilters: validateFiltersOrigin(variable.state.baseFilters),
|
||||
filters: validateFiltersOrigin(variable.state.filters),
|
||||
defaultKeys: variable.state.defaultKeys || [], //FIXME what is the default value?
|
||||
},
|
||||
};
|
||||
|
|
@ -436,3 +442,20 @@ export function sceneVariablesSetToSchemaV2Variables(
|
|||
|
||||
return variables;
|
||||
}
|
||||
|
||||
function validateFiltersOrigin(filters?: SceneAdHocFilterWithLabels[]): AdHocFilterWithLabels[] {
|
||||
return (
|
||||
filters?.map((filter) => {
|
||||
const { origin: initialOrigin, ...restOfFilter } = filter;
|
||||
|
||||
if (initialOrigin === 'dashboard' || initialOrigin === 'scope') {
|
||||
return {
|
||||
...restOfFilter,
|
||||
origin: initialOrigin,
|
||||
};
|
||||
}
|
||||
|
||||
return restOfFilter;
|
||||
}) || []
|
||||
);
|
||||
}
|
||||
|
|
|
|||
22
yarn.lock
22
yarn.lock
|
|
@ -3469,11 +3469,11 @@ __metadata:
|
|||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@grafana/scenes-react@npm:6.10.2":
|
||||
version: 6.10.2
|
||||
resolution: "@grafana/scenes-react@npm:6.10.2"
|
||||
"@grafana/scenes-react@npm:6.10.4":
|
||||
version: 6.10.4
|
||||
resolution: "@grafana/scenes-react@npm:6.10.4"
|
||||
dependencies:
|
||||
"@grafana/scenes": "npm:6.10.2"
|
||||
"@grafana/scenes": "npm:6.10.4"
|
||||
lru-cache: "npm:^10.2.2"
|
||||
react-use: "npm:^17.4.0"
|
||||
peerDependencies:
|
||||
|
|
@ -3485,13 +3485,13 @@ __metadata:
|
|||
react: ^18.0.0
|
||||
react-dom: ^18.0.0
|
||||
react-router-dom: ^6.28.0
|
||||
checksum: 10/f87d51654becdbb9c703b04d60532413ccb3d963e6addb6577d4fe4b96a99d52e792cd12c6fed102b2a01c07266cac29061d1f38cb43e5929ea892c6093ea671
|
||||
checksum: 10/73aee4eca47a27e1fbb7a8f09ddf6a365b121cb361b01c7daabf698677f192c188de0dd64a424db4195139f625660f40371619abbb95a999e14c94e313e25755
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@grafana/scenes@npm:6.10.2":
|
||||
version: 6.10.2
|
||||
resolution: "@grafana/scenes@npm:6.10.2"
|
||||
"@grafana/scenes@npm:6.10.4":
|
||||
version: 6.10.4
|
||||
resolution: "@grafana/scenes@npm:6.10.4"
|
||||
dependencies:
|
||||
"@floating-ui/react": "npm:^0.26.16"
|
||||
"@leeoniya/ufuzzy": "npm:^1.0.16"
|
||||
|
|
@ -3509,7 +3509,7 @@ __metadata:
|
|||
react: ^18.0.0
|
||||
react-dom: ^18.0.0
|
||||
react-router-dom: ^6.28.0
|
||||
checksum: 10/4a6acc3e3f2ceb3316fcdb8cba79d54b3fca0130f05d480349bfc726ca6624cba6acf2333d96a292cc1a573f578274b1e85b7ba7c0096deda3fb02feb0179e3d
|
||||
checksum: 10/ffd51ad71fe3b89c3cd16bfaa0f11e003bf11e4a4fb7513c5c55fdc5e569f51dcf9fb70cb125e63b5b2269d68e86a961769e07a8078cad70163de2c2ed779ef7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
|
@ -17700,8 +17700,8 @@ __metadata:
|
|||
"@grafana/plugin-ui": "npm:0.10.5"
|
||||
"@grafana/prometheus": "workspace:*"
|
||||
"@grafana/runtime": "workspace:*"
|
||||
"@grafana/scenes": "npm:6.10.2"
|
||||
"@grafana/scenes-react": "npm:6.10.2"
|
||||
"@grafana/scenes": "npm:6.10.4"
|
||||
"@grafana/scenes-react": "npm:6.10.4"
|
||||
"@grafana/schema": "workspace:*"
|
||||
"@grafana/sql": "workspace:*"
|
||||
"@grafana/tsconfig": "npm:^2.0.0"
|
||||
|
|
|
|||
Loading…
Reference in New Issue