@perses-dev/dashboards 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/cjs/components/Dashboard/index.js +28 -0
- package/dist/cjs/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +9 -23
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +2 -3
- package/dist/cjs/components/DeletePanelDialog/index.js +28 -0
- package/dist/cjs/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/cjs/components/DeletePanelGroupDialog/index.js +28 -0
- package/dist/cjs/components/GridLayout/GridItemContent.js +11 -1
- package/dist/cjs/components/Panel/Panel.js +30 -89
- package/dist/cjs/components/Panel/Panel.test.js +93 -47
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/Panel/index.js +0 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -15
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
- package/dist/cjs/components/PanelGroupDialog/index.js +0 -1
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +67 -0
- package/dist/cjs/components/UnsavedChangesConfirmationDialog/index.js +28 -0
- package/dist/cjs/components/Variables/Variable.js +18 -11
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -18
- package/dist/cjs/context/DashboardProvider/common.js +3 -3
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +2 -4
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +47 -52
- package/dist/cjs/context/DashboardProvider/panel-slice.js +2 -13
- package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
- package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/{useDashboardSpec.js → useDashboard.js} +20 -16
- package/dist/cjs/test/plugin-registry.js +14 -54
- package/dist/cjs/test/render.js +6 -1
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -10
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
- package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
- package/dist/components/Dashboard/Dashboard.js.map +1 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/index.d.ts.map +1 -0
- package/dist/components/Dashboard/index.js +15 -0
- package/dist/components/Dashboard/index.js.map +1 -0
- package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +2 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
- package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +5 -19
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
- package/dist/components/DashboardToolbar/index.d.ts +2 -0
- package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
- package/dist/components/DashboardToolbar/index.js +15 -0
- package/dist/components/DashboardToolbar/index.js.map +1 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
- package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +1 -2
- package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
- package/dist/components/DeletePanelDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelDialog/index.js +15 -0
- package/dist/components/DeletePanelDialog/index.js.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
- package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/DeletePanelGroupDialog/index.js +15 -0
- package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +12 -2
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +3 -3
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +32 -91
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -49
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +16 -0
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
- package/dist/components/Panel/PanelHeader.js +105 -0
- package/dist/components/Panel/PanelHeader.js.map +1 -0
- package/dist/components/Panel/index.d.ts +0 -1
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +0 -1
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +10 -16
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/index.d.ts +0 -1
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/index.js +0 -1
- package/dist/components/PanelGroupDialog/index.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
- package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
- package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +19 -12
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -4
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +26 -20
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +4 -4
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +2 -4
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -15
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +38 -49
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +0 -9
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.js +2 -13
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
- package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/index.js +15 -0
- package/dist/context/TemplateVariableProvider/index.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.js +64 -0
- package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
- package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
- package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts +6 -0
- package/dist/context/useDashboard.d.ts.map +1 -0
- package/dist/context/{useDashboardSpec.js → useDashboard.js} +19 -15
- package/dist/context/useDashboard.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -11
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +12 -49
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +6 -1
- package/dist/test/render.js.map +1 -1
- package/dist/utils/component-ids.d.ts +8 -0
- package/dist/utils/component-ids.d.ts.map +1 -0
- package/dist/utils/component-ids.js +27 -0
- package/dist/utils/component-ids.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +40 -5
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/components/Dashboard.d.ts.map +0 -1
- package/dist/components/Dashboard.js.map +0 -1
- package/dist/components/DashboardToolbar.d.ts.map +0 -1
- package/dist/components/DashboardToolbar.js.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +0 -4
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
- package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
- package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider.js.map +0 -1
- package/dist/context/useDashboardSpec.d.ts +0 -11
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useQueryParams } from 'use-query-params';
|
|
14
|
+
const variableQueryParameterPrefix = 'var-';
|
|
15
|
+
export function getURLQueryParamName(name) {
|
|
16
|
+
return `${variableQueryParameterPrefix}${name}`;
|
|
17
|
+
}
|
|
18
|
+
export function encodeVariableValue(value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
return value.join(',');
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export function decodeVariableValue(value) {
|
|
25
|
+
if (!value) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const values = value.split(',');
|
|
29
|
+
if (values.length === 1) {
|
|
30
|
+
return values[0];
|
|
31
|
+
}
|
|
32
|
+
return values;
|
|
33
|
+
}
|
|
34
|
+
const VariableValueParam = {
|
|
35
|
+
encode: encodeVariableValue,
|
|
36
|
+
decode: (v)=>{
|
|
37
|
+
if (typeof v === 'string') {
|
|
38
|
+
return decodeVariableValue(v);
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export function useVariableQueryParams(defs) {
|
|
44
|
+
const config = {};
|
|
45
|
+
defs.forEach((def)=>{
|
|
46
|
+
const name = getURLQueryParamName(def.spec.name);
|
|
47
|
+
config[name] = VariableValueParam;
|
|
48
|
+
});
|
|
49
|
+
return useQueryParams(config);
|
|
50
|
+
}
|
|
51
|
+
export function getInitalValuesFromQueryParameters(queryParamValues) {
|
|
52
|
+
const values = {};
|
|
53
|
+
Object.keys(queryParamValues).forEach((key)=>{
|
|
54
|
+
const value = queryParamValues[key];
|
|
55
|
+
if (!value) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const name = key.replace(variableQueryParameterPrefix, '');
|
|
59
|
+
values[name] = value;
|
|
60
|
+
});
|
|
61
|
+
return values;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=query-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { QueryParamConfig, useQueryParams } from 'use-query-params';\n\nconst variableQueryParameterPrefix = 'var-';\n\nexport function getURLQueryParamName(name: string) {\n return `${variableQueryParameterPrefix}${name}`;\n}\n\nexport function encodeVariableValue(value: VariableValue) {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n return value;\n}\n\nexport function decodeVariableValue(value: string): VariableValue {\n if (!value) {\n return null;\n }\n const values = value.split(',');\n if (values.length === 1) {\n return values[0] as string;\n }\n return values;\n}\n\nconst VariableValueParam: QueryParamConfig<VariableValue> = {\n encode: encodeVariableValue,\n decode: (v) => {\n if (typeof v === 'string') {\n return decodeVariableValue(v);\n }\n return '';\n },\n};\n\nexport function useVariableQueryParams(defs: VariableDefinition[]) {\n const config: Record<string, typeof VariableValueParam> = {};\n defs.forEach((def) => {\n const name = getURLQueryParamName(def.spec.name);\n config[name] = VariableValueParam;\n });\n return useQueryParams(config);\n}\n\nexport function getInitalValuesFromQueryParameters(\n queryParamValues: Record<string, VariableValue>\n): Record<string, VariableValue> {\n const values: Record<string, VariableValue> = {};\n Object.keys(queryParamValues).forEach((key) => {\n const value = queryParamValues[key];\n if (!value) {\n return;\n }\n const name = key.replace(variableQueryParameterPrefix, '');\n values[name] = value;\n });\n return values;\n}\n"],"names":["useQueryParams","variableQueryParameterPrefix","getURLQueryParamName","name","encodeVariableValue","value","Array","isArray","join","decodeVariableValue","values","split","length","VariableValueParam","encode","decode","v","useVariableQueryParams","defs","config","forEach","def","spec","getInitalValuesFromQueryParameters","queryParamValues","Object","keys","key","replace"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA2BA,cAAc,QAAQ,kBAAkB,CAAC;AAEpE,MAAMC,4BAA4B,GAAG,MAAM,AAAC;AAE5C,OAAO,SAASC,oBAAoB,CAACC,IAAY,EAAE;IACjD,OAAO,CAAC,EAAEF,4BAA4B,CAAC,EAAEE,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,OA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AAgB,CAAC,CAACJ,OAAO,CAAC,CAACO,GAAG,GAAK;QAC7C,MAAMtB,KAAK,GAAGmB,gBAAgB,CAACG,GAAG,CAAC,AAAC;QACpC,IAAI,CAACtB,KAAK,EAAE;YACV,OAAO;QACT,CAAC;QACD,MAAMF,IAAI,GAAGwB,GAAG,CAACC,OAAO,CAAC3B,4BAA4B,EAAE,EAAE,CAAC,AAAC;QAC3DS,MAAM,CAACP,IAAI,CAAC,GAAGE,KAAK,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,OAAOK,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-params.test.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/query-params.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { getInitalValuesFromQueryParameters, decodeVariableValue, encodeVariableValue } from './query-params';
|
|
14
|
+
describe('getInitalValuesFromQueryParameters', ()=>{
|
|
15
|
+
test('base case', ()=>{
|
|
16
|
+
expect(getInitalValuesFromQueryParameters({
|
|
17
|
+
'var-foo': 'bar',
|
|
18
|
+
'var-baz': [
|
|
19
|
+
'qux',
|
|
20
|
+
'quux'
|
|
21
|
+
]
|
|
22
|
+
})).toEqual({
|
|
23
|
+
foo: 'bar',
|
|
24
|
+
baz: [
|
|
25
|
+
'qux',
|
|
26
|
+
'quux'
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('encodeVariableValue', ()=>{
|
|
32
|
+
const testCases = [
|
|
33
|
+
{
|
|
34
|
+
input: 'foo',
|
|
35
|
+
expected: 'foo'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
input: [
|
|
39
|
+
'foo',
|
|
40
|
+
'bar'
|
|
41
|
+
],
|
|
42
|
+
expected: 'foo,bar'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
input: '$__all',
|
|
46
|
+
expected: '$__all'
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
testCases.forEach(({ input , expected })=>{
|
|
50
|
+
test(`encodes ${input} as ${expected}`, ()=>{
|
|
51
|
+
expect(encodeVariableValue(input)).toEqual(expected);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('decodeVariableValue', ()=>{
|
|
56
|
+
const testCases = [
|
|
57
|
+
{
|
|
58
|
+
input: 'foo',
|
|
59
|
+
expected: 'foo'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
input: 'foo,bar',
|
|
63
|
+
expected: [
|
|
64
|
+
'foo',
|
|
65
|
+
'bar'
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
input: '$__all',
|
|
70
|
+
expected: '$__all'
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
testCases.forEach(({ input , expected })=>{
|
|
74
|
+
test(`encodes ${input} as ${expected}`, ()=>{
|
|
75
|
+
expect(decodeVariableValue(input)).toEqual(expected);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=query-params.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/TemplateVariableProvider/query-params.test.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue } from '@perses-dev/core';\nimport { getInitalValuesFromQueryParameters, decodeVariableValue, encodeVariableValue } from './query-params';\n\ndescribe('getInitalValuesFromQueryParameters', () => {\n test('base case', () => {\n expect(\n getInitalValuesFromQueryParameters({\n 'var-foo': 'bar',\n 'var-baz': ['qux', 'quux'],\n })\n ).toEqual({\n foo: 'bar',\n baz: ['qux', 'quux'],\n });\n });\n});\n\ndescribe('encodeVariableValue', () => {\n const testCases = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: ['foo', 'bar'],\n expected: 'foo,bar',\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(encodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n\ndescribe('decodeVariableValue', () => {\n const testCases: Array<{ input: string; expected: VariableValue }> = [\n {\n input: 'foo',\n expected: 'foo',\n },\n {\n input: 'foo,bar',\n expected: ['foo', 'bar'],\n },\n {\n input: '$__all',\n expected: '$__all',\n },\n ];\n\n testCases.forEach(({ input, expected }) => {\n test(`encodes ${input} as ${expected}`, () => {\n expect(decodeVariableValue(input)).toEqual(expected);\n });\n });\n});\n"],"names":["getInitalValuesFromQueryParameters","decodeVariableValue","encodeVariableValue","describe","test","expect","toEqual","foo","baz","testCases","input","expected","forEach"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF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AAK;YACZC,QAAQ,EAAE,KAAK;SAChB;QACD;YACED,KAAK,EAAE,SAAS;YAChBC,QAAQ,EAAE;gBAAC,KAAK;gBAAE,KAAK;aAAC;SACzB;QACD;YACED,KAAK,EAAE,QAAQ;YACfC,QAAQ,EAAE,QAAQ;SACnB;KACF,AAAC;IAEFF,SAAS,CAACG,OAAO,CAAC,CAAC,EAAEF,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAK;QACzCP,IAAI,CAAC,CAAC,QAAQ,EAAEM,KAAK,CAAC,IAAI,EAAEC,QAAQ,CAAC,CAAC,EAAE,IAAM;YAC5CN,MAAM,CAACJ,mBAAmB,CAACS,KAAK,CAAC,CAAC,CAACJ,OAAO,CAACK,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from './DashboardProvider';
|
|
|
2
2
|
export * from './DatasourceStoreProvider';
|
|
3
3
|
export * from './TemplateVariableProvider';
|
|
4
4
|
export * from './TimeRangeProvider';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './useDashboard';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
package/dist/context/index.js
CHANGED
|
@@ -14,6 +14,6 @@ export * from './DashboardProvider';
|
|
|
14
14
|
export * from './DatasourceStoreProvider';
|
|
15
15
|
export * from './TemplateVariableProvider';
|
|
16
16
|
export * from './TimeRangeProvider';
|
|
17
|
-
export * from './
|
|
17
|
+
export * from './useDashboard';
|
|
18
18
|
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './TemplateVariableProvider';\nexport * from './TimeRangeProvider';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './TemplateVariableProvider';\nexport * from './TimeRangeProvider';\nexport * from './useDashboard';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../src/context/useDashboard.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,iBAAiB,EAAkB,MAAM,kBAAkB,CAAC;AAIrF,wBAAgB,YAAY;;sCA+Be,iBAAiB;EAS3D"}
|
|
@@ -13,31 +13,35 @@
|
|
|
13
13
|
import { createPanelRef } from '@perses-dev/core';
|
|
14
14
|
import { useDashboardStore } from './DashboardProvider';
|
|
15
15
|
import { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';
|
|
16
|
-
export function
|
|
17
|
-
const { panels , panelGroups , panelGroupOrder , defaultTimeRange ,
|
|
16
|
+
export function useDashboard() {
|
|
17
|
+
const { panels , panelGroups , panelGroupOrder , defaultTimeRange , metadata , setDashboard: setDashboardResource , } = useDashboardStore(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata })=>({
|
|
18
18
|
panels,
|
|
19
19
|
panelGroups,
|
|
20
20
|
panelGroupOrder,
|
|
21
21
|
defaultTimeRange,
|
|
22
|
-
|
|
22
|
+
setDashboard,
|
|
23
|
+
metadata
|
|
23
24
|
}));
|
|
24
25
|
const { setVariableDefinitions } = useTemplateVariableActions();
|
|
25
26
|
const variables = useTemplateVariableDefinitions();
|
|
26
27
|
const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const dashboard = {
|
|
29
|
+
kind: 'Dashboard',
|
|
30
|
+
metadata,
|
|
31
|
+
spec: {
|
|
32
|
+
panels,
|
|
33
|
+
layouts,
|
|
34
|
+
variables,
|
|
35
|
+
duration: defaultTimeRange.pastDuration
|
|
36
|
+
}
|
|
32
37
|
};
|
|
33
|
-
const
|
|
34
|
-
setVariableDefinitions(spec.variables);
|
|
35
|
-
|
|
36
|
-
resetDashboardStore();
|
|
38
|
+
const setDashboard = (dashboardResource)=>{
|
|
39
|
+
setVariableDefinitions(dashboardResource.spec.variables);
|
|
40
|
+
setDashboardResource(dashboardResource);
|
|
37
41
|
};
|
|
38
42
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
dashboard,
|
|
44
|
+
setDashboard
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
@@ -81,4 +85,4 @@ function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
|
81
85
|
return layouts;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
//# sourceMappingURL=
|
|
88
|
+
//# sourceMappingURL=useDashboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardResource, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboard() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n metadata,\n setDashboard: setDashboardResource,\n } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, defaultTimeRange, setDashboard, metadata }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n setDashboard,\n metadata,\n }));\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardResource = {\n kind: 'Dashboard',\n metadata,\n spec: {\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource) => {\n setVariableDefinitions(dashboardResource.spec.variables);\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title) {\n display = {\n title,\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useTemplateVariableActions","useTemplateVariableDefinitions","useDashboard","panels","panelGroups","panelGroupOrder","defaultTimeRange","metadata","setDashboard","setDashboardResource","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","dashboard","kind","spec","duration","pastDuration","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","display","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAA2C,kBAAkB,CAAC;AACrF,SAA6CC,iBAAiB,QAAQ,qBAAqB,CAAC;AAC5F,SAASC,0BAA0B,EAAEC,8BAA8B,QAAQ,4BAA4B,CAAC;AAExG,OAAO,SAASC,YAAY,GAAG;IAC7B,MAAM,EACJC,MAAM,CAAA,EACNC,WAAW,CAAA,EACXC,eAAe,CAAA,EACfC,gBAAgB,CAAA,EAChBC,QAAQ,CAAA,EACRC,YAAY,EAAEC,oBAAoB,CAAA,IACnC,GAAGV,iBAAiB,CAAC,CAAC,EAAEI,MAAM,CAAA,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAEC,gBAAgB,CAAA,EAAEE,YAAY,CAAA,EAAED,QAAQ,CAAA,EAAE,GAAM,CAAA;YAC7GJ,MAAM;YACNC,WAAW;YACXC,eAAe;YACfC,gBAAgB;YAChBE,YAAY;YACZD,QAAQ;SACT,CAAA,AAAC,CAAC,AAAC;IACJ,MAAM,EAAEG,sBAAsB,CAAA,EAAE,GAAGV,0BAA0B,EAAE,AAAC;IAChE,MAAMW,SAAS,GAAGV,8BAA8B,EAAE,AAAC;IACnD,MAAMW,OAAO,GAAGC,2BAA2B,CAACT,WAAW,EAAEC,eAAe,CAAC,AAAC;IAE1E,MAAMS,SAAS,GAAsB;QACnCC,IAAI,EAAE,WAAW;QACjBR,QAAQ;QACRS,IAAI,EAAE;YACJb,MAAM;YACNS,OAAO;YACPD,SAAS;YACTM,QAAQ,EAAEX,gBAAgB,CAACY,YAAY;SACxC;KACF,AAAC;IAEF,MAAMV,YAAY,GAAG,CAACW,iBAAo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MAAM,CAACK,CAAC;wBACXC,KAAK,EAAEN,MAAM,CAACO,CAAC;wBACfC,MAAM,EAAER,MAAM,CAACS,CAAC;wBAChBC,OAAO,EAAE5C,cAAc,CAACoC,QAAQ,CAAC;qBAClC,CAAC;gBACJ,CAAC,CAAC;aACH;SACF,AAAC;QACFtB,OAAO,CAAC+B,IAAI,CAACX,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAOpB,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Helper for mocking `PluginRegistry` data during tests. Returns props that can be spread on the `PluginRegistry`
|
|
4
|
-
* component so that it will load the mock plugins you setup. You can use the `addMockPlugin` function that's returned
|
|
5
|
-
* to add mock plugins before rendering components that use them.
|
|
6
|
-
*/
|
|
7
|
-
export declare function mockPluginRegistryProps(): {
|
|
8
|
-
pluginRegistryProps: Omit<PluginRegistryProps, "children">;
|
|
9
|
-
addMockPlugin: <T extends PluginType>(pluginType: T, kind: string, plugin: PluginImplementation<T>) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare const FAKE_PANEL_PLUGIN: PanelPlugin;
|
|
1
|
+
import { MockPlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
export declare const MOCK_PLUGINS: MockPlugin[];
|
|
12
3
|
//# sourceMappingURL=plugin-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/test/plugin-registry.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/test/plugin-registry.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAe,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAmBpE,eAAO,MAAM,YAAY,EAAE,UAAU,EAA6B,CAAC"}
|
|
@@ -11,64 +11,27 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
|
|
15
|
-
* Helper for mocking `PluginRegistry` data during tests. Returns props that can be spread on the `PluginRegistry`
|
|
16
|
-
* component so that it will load the mock plugins you setup. You can use the `addMockPlugin` function that's returned
|
|
17
|
-
* to add mock plugins before rendering components that use them.
|
|
18
|
-
*/ export function mockPluginRegistryProps() {
|
|
19
|
-
const mockPluginResource = {
|
|
20
|
-
kind: 'PluginModule',
|
|
21
|
-
metadata: {
|
|
22
|
-
name: 'Fake Plugin Module for Tests',
|
|
23
|
-
created_at: '',
|
|
24
|
-
updated_at: '',
|
|
25
|
-
version: 0
|
|
26
|
-
},
|
|
27
|
-
spec: {
|
|
28
|
-
plugins: []
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const mockPluginModule = {};
|
|
32
|
-
// Allow adding mock plugins in tests
|
|
33
|
-
const addMockPlugin = (pluginType, kind, plugin)=>{
|
|
34
|
-
mockPluginResource.spec.plugins.push({
|
|
35
|
-
pluginType,
|
|
36
|
-
kind,
|
|
37
|
-
display: {
|
|
38
|
-
name: `Fake ${pluginType} Plugin for ${kind}`
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
// "Export" on the module under the same name as the kind the plugin handles
|
|
42
|
-
mockPluginModule[kind] = plugin;
|
|
43
|
-
};
|
|
44
|
-
const pluginRegistryProps = {
|
|
45
|
-
getInstalledPlugins () {
|
|
46
|
-
return Promise.resolve([
|
|
47
|
-
mockPluginResource
|
|
48
|
-
]);
|
|
49
|
-
},
|
|
50
|
-
importPluginModule () {
|
|
51
|
-
return Promise.resolve(mockPluginModule);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
pluginRegistryProps,
|
|
56
|
-
addMockPlugin
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export const FAKE_PANEL_PLUGIN = {
|
|
14
|
+
const FakeTimeSeriesPlugin = {
|
|
60
15
|
PanelComponent: ()=>{
|
|
61
16
|
return /*#__PURE__*/ _jsx("div", {
|
|
62
|
-
|
|
63
|
-
children: "FakePanel chart"
|
|
17
|
+
children: "TimeSeriesChart panel"
|
|
64
18
|
});
|
|
65
19
|
},
|
|
66
20
|
OptionsEditorComponent: ()=>{
|
|
67
21
|
return /*#__PURE__*/ _jsx("div", {
|
|
68
|
-
children: "
|
|
22
|
+
children: "TimeSeriesChart options"
|
|
69
23
|
});
|
|
70
24
|
},
|
|
71
25
|
createInitialOptions: ()=>({})
|
|
72
26
|
};
|
|
27
|
+
const MOCK_TIME_SERIES_PANEL = {
|
|
28
|
+
pluginType: 'Panel',
|
|
29
|
+
kind: 'TimeSeriesChart',
|
|
30
|
+
plugin: FakeTimeSeriesPlugin
|
|
31
|
+
};
|
|
32
|
+
// Array of default mock plugins added to the PluginRegistry during test renders
|
|
33
|
+
export const MOCK_PLUGINS = [
|
|
34
|
+
MOCK_TIME_SERIES_PANEL
|
|
35
|
+
];
|
|
73
36
|
|
|
74
37
|
//# sourceMappingURL=plugin-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/plugin-registry.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { UnknownSpec } from '@perses-dev/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/test/plugin-registry.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PanelPlugin, MockPlugin } from '@perses-dev/plugin-system';\n\nconst FakeTimeSeriesPlugin: PanelPlugin<UnknownSpec> = {\n PanelComponent: () => {\n return <div>TimeSeriesChart panel</div>;\n },\n OptionsEditorComponent: () => {\n return <div>TimeSeriesChart options</div>;\n },\n createInitialOptions: () => ({}),\n};\n\nconst MOCK_TIME_SERIES_PANEL: MockPlugin = {\n pluginType: 'Panel',\n kind: 'TimeSeriesChart',\n plugin: FakeTimeSeriesPlugin,\n};\n\n// Array of default mock plugins added to the PluginRegistry during test renders\nexport const MOCK_PLUGINS: MockPlugin[] = [MOCK_TIME_SERIES_PANEL];\n"],"names":["FakeTimeSeriesPlugin","PanelComponent","div","OptionsEditorComponent","createInitialOptions","MOCK_TIME_SERIES_PANEL","pluginType","kind","plugin","MOCK_PLUGINS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAGA,MAAMA,oBAAoB,GAA6B;IACrDC,cAAc,EAAE,IAAM;QACpB,qBAAO,KAACC,KAAG;sBAAC,uBAAqB;UAAM,CAAC;IAC1C,CAAC;IACDC,sBAAsB,EAAE,IAAM;QAC5B,qBAAO,KAACD,KAAG;sBAAC,yBAAuB;UAAM,CAAC;IAC5C,CAAC;IACDE,oBAAoB,EAAE,IAAO,CAAA,EAAE,CAAA,AAAC;CACjC,AAAC;AAEF,MAAMC,sBAAsB,GAAe;IACzCC,UAAU,EAAE,OAAO;IACnBC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAER,oBAAoB;CAC7B,AAAC;AAEF,gFAAgF;AAChF,OAAO,MAAMS,YAAY,GAAiB;IAACJ,sBAAsB;CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/test/render.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAuB,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/test/render.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAuB,aAAa,EAAE,MAAM,SAAS,CAAC;AAQ7D;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,KAAK,CAAC,YAAY,EACtB,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EACxC,OAAO,CAAC,EAAE,aAAa,gIAsBxB"}
|
package/dist/test/render.js
CHANGED
|
@@ -18,6 +18,8 @@ import { QueryParamProvider } from 'use-query-params';
|
|
|
18
18
|
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
|
|
19
19
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
20
20
|
import { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';
|
|
21
|
+
import { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';
|
|
22
|
+
import { MOCK_PLUGINS } from './plugin-registry';
|
|
21
23
|
/**
|
|
22
24
|
* Test helper to render a React component with some common app-level providers wrapped around it.
|
|
23
25
|
*/ export function renderWithContext(ui, options, history) {
|
|
@@ -42,7 +44,10 @@ import { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';
|
|
|
42
44
|
children: /*#__PURE__*/ _jsx(ChartsThemeProvider, {
|
|
43
45
|
themeName: "perses",
|
|
44
46
|
chartsTheme: testChartsTheme,
|
|
45
|
-
children:
|
|
47
|
+
children: /*#__PURE__*/ _jsx(PluginRegistry, {
|
|
48
|
+
...mockPluginRegistry(...MOCK_PLUGINS),
|
|
49
|
+
children: ui
|
|
50
|
+
})
|
|
46
51
|
})
|
|
47
52
|
})
|
|
48
53
|
})
|
package/dist/test/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { render, RenderOptions } from '@testing-library/react';\nimport { unstable_HistoryRouter } from 'react-router-dom';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const BaseRender = () => {\n const HistoryRouter = unstable_HistoryRouter;\n history = history ?? createMemoryHistory();\n return (\n <HistoryRouter history={history}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <ChartsThemeProvider themeName=\"perses\" chartsTheme={testChartsTheme}>\n {ui}
|
|
1
|
+
{"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { render, RenderOptions } from '@testing-library/react';\nimport { unstable_HistoryRouter } from 'react-router-dom';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ChartsThemeProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const BaseRender = () => {\n const HistoryRouter = unstable_HistoryRouter;\n history = history ?? createMemoryHistory();\n return (\n <HistoryRouter history={history}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <ChartsThemeProvider themeName=\"perses\" chartsTheme={testChartsTheme}>\n <PluginRegistry {...mockPluginRegistry(...MOCK_PLUGINS)}>{ui}</PluginRegistry>\n </ChartsThemeProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </HistoryRouter>\n );\n };\n\n return render(<BaseRender />, options);\n}\n"],"names":["render","unstable_HistoryRouter","createMemoryHistory","QueryParamProvider","ReactRouter6Adapter","QueryClient","QueryClientProvider","ChartsThemeProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","MOCK_PLUGINS","renderWithContext","ui","options","history","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","BaseRender","HistoryRouter","client","adapter","themeName","chartsTheme"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,QAAuB,wBAAwB,CAAC;AAC/D,SAASC,sBAAsB,QAAQ,kBAAkB,CAAC;AAC1D,SAASC,mBAAmB,QAAuB,SAAS,CAAC;AAC7D,SAASC,kBAAkB,QAAQ,kBAAkB,CAAC;AACtD,SAASC,mBAAmB,QAAQ,0CAA0C,CAAC;AAC/E,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,uBAAuB,CAAC;AACzE,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,wBAAwB,CAAC;AAC9E,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,2BAA2B,CAAC;AAC/E,SAASC,YAAY,QAAQ,mBAAmB,CAAC;AAEjD;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAC/BC,EAAsB,EACtBC,OAAwC,EACxCC,OAAuB,EACvB;IACA,iEAAiE;IACjE,MAAMC,WAAW,GAAG,IAAIX,WAAW,CAAC;QAAEY,cAAc,EAAE;YAAEC,OAAO,EAAE;gBAAEC,oBAAoB,EAAE,KAAK;gBAAEC,KAAK,EAAE,KAAK;aAAE;SAAE;KAAE,CAAC,AAAC;IAEpH,MAAMC,UAAU,GAAG,IAAM;QACvB,MAAMC,aAAa,GAAGrB,sBAAsB,AAAC;QAC7Cc,OAAO,GAAGA,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAIb,mBAAmB,EAAE,CAAC;QAC3C,qBACE,KAACoB,aAAa;YAACP,OAAO,EAAEA,OAAO;sBAC7B,cAAA,KAACT,mBAAmB;gBAACiB,MAAM,EAAEP,WAAW;0BACtC,cAAA,KAACb,kBAAkB;oBAACqB,OAAO,EAAEpB,mBAAmB;8BAC9C,cAAA,KAACG,mBAAmB;wBAACkB,SAAS,EAAC,QAAQ;wBAACC,WAAW,EAAElB,eAAe;kCAClE,cAAA,KAACE,cAAc;4BAAE,GAAGD,kBAAkB,IAAIE,YAAY,CAAC;sCAAGE,EAAE;0BAAkB;sBAC1D;kBACH;cACD;UACR,CAChB;IACJ,CAAC,AAAC;IAEF,OAAOb,MAAM,eAAC,KAACqB,UAAU,KAAG,EAAEP,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
var useIdValue: number;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useId(prefix: string): string;
|
|
8
|
+
//# sourceMappingURL=component-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-ids.d.ts","sourceRoot":"","sources":["../../src/utils/component-ids.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,UAAU,EAAE,MAAM,CAAC;CACxB;AAMD;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,UAMnC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useRef } from 'react';
|
|
14
|
+
if (globalThis.useIdValue === undefined) {
|
|
15
|
+
globalThis.useIdValue = 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
|
|
19
|
+
*/ export function useId(prefix) {
|
|
20
|
+
const id = useRef(undefined);
|
|
21
|
+
if (id.current === undefined) {
|
|
22
|
+
id.current = `${prefix}-${globalThis.useIdValue++}`;
|
|
23
|
+
}
|
|
24
|
+
return id.current;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=component-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/component-ids.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef } from 'react';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var useIdValue: number;\n}\n\nif (globalThis.useIdValue === undefined) {\n globalThis.useIdValue = 0;\n}\n\n/**\n * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.\n */\nexport function useId(prefix: string) {\n const id = useRef<string | undefined>(undefined);\n if (id.current === undefined) {\n id.current = `${prefix}-${globalThis.useIdValue++}`;\n }\n return id.current;\n}\n"],"names":["useRef","globalThis","useIdValue","undefined","useId","prefix","id","current"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAQ,OAAO,CAAC;AAO/B,IAAIC,UAAU,CAACC,UAAU,KAAKC,SAAS,EAAE;IACvCF,UAAU,CAACC,UAAU,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,KAAK,CAACC,MAAc,EAAE;IACpC,MAAMC,EAAE,GAAGN,MAAM,CAAqBG,SAAS,CAAC,AAAC;IACjD,IAAIG,EAAE,CAACC,OAAO,KAAKJ,SAAS,EAAE;QAC5BG,EAAE,CAACC,OAAO,GAAG,CAAC,EAAEF,MAAM,CAAC,CAAC,EAAEJ,UAAU,CAACC,UAAU,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,OAAOI,EAAE,CAACC,OAAO,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAkEpD,CAAC"}
|
|
@@ -11,13 +11,41 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
14
15
|
import { Box } from '@mui/material';
|
|
15
16
|
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
16
|
-
import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog } from '../../components';
|
|
17
|
-
import {
|
|
18
|
-
import DeletePanelDialog from '../../components/Panel/DeletePanelDialog';
|
|
17
|
+
import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog, UnsavedChangesConfirmationDialog, DashboardToolbar, DeletePanelDialog } from '../../components';
|
|
18
|
+
import { useDashboard, useEditMode } from '../../context';
|
|
19
19
|
export const DashboardApp = (props)=>{
|
|
20
20
|
const { dashboardResource } = props;
|
|
21
|
+
const { setEditMode } = useEditMode();
|
|
22
|
+
const { dashboard , setDashboard } = useDashboard();
|
|
23
|
+
const [originalDashboard, setOriginalDashboard] = useState(undefined);
|
|
24
|
+
const [isUnsavedDashboardDialogOpen, setUnsavedDashboardDialogIsOpen] = useState(false);
|
|
25
|
+
const saveDashboard = async ()=>{
|
|
26
|
+
setEditMode(false);
|
|
27
|
+
setUnsavedDashboardDialogIsOpen(false);
|
|
28
|
+
};
|
|
29
|
+
const cancelDashboard = ()=>{
|
|
30
|
+
// Reset to the original spec and exit edit mode
|
|
31
|
+
if (originalDashboard) {
|
|
32
|
+
setDashboard(originalDashboard);
|
|
33
|
+
}
|
|
34
|
+
setUnsavedDashboardDialogIsOpen(false);
|
|
35
|
+
setEditMode(false);
|
|
36
|
+
};
|
|
37
|
+
const onEditButtonClick = ()=>{
|
|
38
|
+
setEditMode(true);
|
|
39
|
+
setOriginalDashboard(dashboard);
|
|
40
|
+
};
|
|
41
|
+
const onCancelButtonClick = ()=>{
|
|
42
|
+
// check if dashboard has been modified
|
|
43
|
+
if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {
|
|
44
|
+
setEditMode(false);
|
|
45
|
+
} else {
|
|
46
|
+
setUnsavedDashboardDialogIsOpen(true);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
21
49
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
22
50
|
sx: {
|
|
23
51
|
flexGrow: 1,
|
|
@@ -28,7 +56,9 @@ export const DashboardApp = (props)=>{
|
|
|
28
56
|
},
|
|
29
57
|
children: [
|
|
30
58
|
/*#__PURE__*/ _jsx(DashboardToolbar, {
|
|
31
|
-
dashboardName: dashboardResource.metadata.name
|
|
59
|
+
dashboardName: dashboardResource.metadata.name,
|
|
60
|
+
onEditButtonClick: onEditButtonClick,
|
|
61
|
+
onCancelButtonClick: onCancelButtonClick
|
|
32
62
|
}),
|
|
33
63
|
/*#__PURE__*/ _jsxs(Box, {
|
|
34
64
|
sx: {
|
|
@@ -42,7 +72,12 @@ export const DashboardApp = (props)=>{
|
|
|
42
72
|
/*#__PURE__*/ _jsx(PanelDrawer, {}),
|
|
43
73
|
/*#__PURE__*/ _jsx(PanelGroupDialog, {}),
|
|
44
74
|
/*#__PURE__*/ _jsx(DeletePanelGroupDialog, {}),
|
|
45
|
-
/*#__PURE__*/ _jsx(DeletePanelDialog, {})
|
|
75
|
+
/*#__PURE__*/ _jsx(DeletePanelDialog, {}),
|
|
76
|
+
/*#__PURE__*/ _jsx(UnsavedChangesConfirmationDialog, {
|
|
77
|
+
isOpen: isUnsavedDashboardDialogOpen,
|
|
78
|
+
onSave: saveDashboard,
|
|
79
|
+
onClose: cancelDashboard
|
|
80
|
+
})
|
|
46
81
|
]
|
|
47
82
|
})
|
|
48
83
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport {\n PanelDrawer,\n Dashboard,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n UnsavedChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n} from '../../components';\nimport { useDashboard, useEditMode } from '../../context';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const { dashboardResource } = props;\n const { setEditMode } = useEditMode();\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n const [isUnsavedDashboardDialogOpen, setUnsavedDashboardDialogIsOpen] = useState(false);\n\n const saveDashboard = async () => {\n setEditMode(false);\n setUnsavedDashboardDialogIsOpen(false);\n };\n\n const cancelDashboard = () => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setUnsavedDashboardDialogIsOpen(false);\n setEditMode(false);\n };\n\n const onEditButtonClick = () => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n };\n\n const onCancelButtonClick = () => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n setUnsavedDashboardDialogIsOpen(true);\n }\n };\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ padding: (theme) => theme.spacing(2) }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <UnsavedChangesConfirmationDialog\n isOpen={isUnsavedDashboardDialogOpen}\n onSave={saveDashboard}\n onClose={cancelDashboard}\n />\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","UnsavedChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","useDashboard","useEditMode","DashboardApp","props","dashboardResource","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","isUnsavedDashboardDialogOpen","setUnsavedDashboardDialogIsOpen","saveDashboard","cancelDashboard","onEditButtonClick","onCancelButtonClick","JSON","stringify","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","padding","theme","spacing","FallbackComponent","isOpen","onSave","onClose"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,UAAU,EAAEC,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