@perses-dev/dashboards 0.11.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 -16
- package/dist/cjs/components/DashboardToolbar/index.js +28 -0
- package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +4 -7
- 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/GridLayout/GridLayout.js +14 -16
- package/dist/cjs/components/Panel/Panel.js +30 -90
- package/dist/cjs/components/Panel/Panel.test.js +93 -46
- package/dist/cjs/components/Panel/PanelHeader.js +116 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +21 -19
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
- 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/Variables/VariableEditor.js +7 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +32 -20
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +14 -16
- package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +70 -0
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +85 -0
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +54 -164
- package/dist/cjs/context/DashboardProvider/panel-slice.js +25 -0
- 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/useDashboard.js +94 -0
- 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/utils/time-range-params.js +14 -8
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -11
- 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 -12
- 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 +3 -6
- 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 +2 -2
- 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/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +16 -18
- package/dist/components/GridLayout/GridLayout.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 -92
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +95 -48
- 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/PanelDrawer/PanelDrawer.test.js +22 -20
- 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 +16 -16
- 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/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +7 -6
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.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 +8 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +34 -22
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +7 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +8 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +6 -6
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +14 -16
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js +64 -0
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +36 -0
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js +81 -0
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +3 -1
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +6 -35
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +74 -67
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -8
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -19
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +14 -44
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +46 -162
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +14 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +21 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- 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/useDashboard.js +88 -0
- 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/utils/time-range-params.d.ts.map +1 -1
- package/dist/utils/time-range-params.js +15 -9
- package/dist/utils/time-range-params.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +40 -6
- 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/cjs/context/useDashboardSpec.js +0 -61
- 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 -5
- 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 -3
- package/dist/context/useDashboardSpec.d.ts.map +0 -1
- package/dist/context/useDashboardSpec.js +0 -55
- package/dist/context/useDashboardSpec.js.map +0 -1
|
@@ -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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AC;AAEHR,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpC,MAAMM,SAAS,GAAsD;QACnE;YACEC,KAAK,EAAE,KAAK;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"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 { createPanelRef } from '@perses-dev/core';
|
|
14
|
+
import { useDashboardStore } from './DashboardProvider';
|
|
15
|
+
import { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';
|
|
16
|
+
export function useDashboard() {
|
|
17
|
+
const { panels , panelGroups , panelGroupOrder , defaultTimeRange , metadata , setDashboard: setDashboardResource , } = useDashboardStore(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata })=>({
|
|
18
|
+
panels,
|
|
19
|
+
panelGroups,
|
|
20
|
+
panelGroupOrder,
|
|
21
|
+
defaultTimeRange,
|
|
22
|
+
setDashboard,
|
|
23
|
+
metadata
|
|
24
|
+
}));
|
|
25
|
+
const { setVariableDefinitions } = useTemplateVariableActions();
|
|
26
|
+
const variables = useTemplateVariableDefinitions();
|
|
27
|
+
const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
|
|
28
|
+
const dashboard = {
|
|
29
|
+
kind: 'Dashboard',
|
|
30
|
+
metadata,
|
|
31
|
+
spec: {
|
|
32
|
+
panels,
|
|
33
|
+
layouts,
|
|
34
|
+
variables,
|
|
35
|
+
duration: defaultTimeRange.pastDuration
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const setDashboard = (dashboardResource)=>{
|
|
39
|
+
setVariableDefinitions(dashboardResource.spec.variables);
|
|
40
|
+
setDashboardResource(dashboardResource);
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
dashboard,
|
|
44
|
+
setDashboard
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
48
|
+
const layouts = [];
|
|
49
|
+
panelGroupOrder.map((groupOrderId)=>{
|
|
50
|
+
const group = panelGroups[groupOrderId];
|
|
51
|
+
if (group === undefined) {
|
|
52
|
+
throw new Error('panel group not found');
|
|
53
|
+
}
|
|
54
|
+
const { title , isCollapsed , itemLayouts , itemPanelKeys } = group;
|
|
55
|
+
let display = undefined;
|
|
56
|
+
if (title) {
|
|
57
|
+
display = {
|
|
58
|
+
title,
|
|
59
|
+
collapse: {
|
|
60
|
+
open: !isCollapsed
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const layout = {
|
|
65
|
+
kind: 'Grid',
|
|
66
|
+
spec: {
|
|
67
|
+
display,
|
|
68
|
+
items: itemLayouts.map((layout)=>{
|
|
69
|
+
const panelKey = itemPanelKeys[layout.i];
|
|
70
|
+
if (panelKey === undefined) {
|
|
71
|
+
throw new Error(`Missing panel key of layout ${layout.i}`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
x: layout.x,
|
|
75
|
+
y: layout.y,
|
|
76
|
+
width: layout.w,
|
|
77
|
+
height: layout.h,
|
|
78
|
+
content: createPanelRef(panelKey)
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
layouts.push(layout);
|
|
84
|
+
});
|
|
85
|
+
return layouts;
|
|
86
|
+
}
|
|
87
|
+
|
|
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,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B,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,mE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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,UA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cAAc,CAgBrF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,cAAc,EAAE,aAAa,UAAO,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"time-range-params.d.ts","sourceRoot":"","sources":["../../src/utils/time-range-params.ts"],"names":[],"mappings":"AAcA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EACL,cAAc,EAGd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,oBAAY,eAAe,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AA2BvE,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAWhG;AAGD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAI1C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAQ7E,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAgBrF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,cAAc,EAAE,aAAa,UAAO,GAAG,SAAS,CA+BvG"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { useMemo, useCallback, useState } from 'react';
|
|
13
|
+
import { useMemo, useCallback, useEffect, useState } from 'react';
|
|
14
14
|
import { useQueryParams } from 'use-query-params';
|
|
15
15
|
import { getUnixTime, isDate } from 'date-fns';
|
|
16
16
|
import { isRelativeTimeRange, isDurationString } from '@perses-dev/core';
|
|
@@ -101,15 +101,21 @@ export const timeRangeQueryConfig = {
|
|
|
101
101
|
// fallback when app does not want query string as source of truth
|
|
102
102
|
const [timeRangeState, setTimeRangeState] = useState(initialTimeRange);
|
|
103
103
|
const { start } = query;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
useEffect(()=>{
|
|
105
|
+
if (paramsEnabled && !start) {
|
|
106
|
+
if (isRelativeTimeRange(initialTimeRange)) {
|
|
107
|
+
setQuery({
|
|
108
|
+
start: initialTimeRange.pastDuration,
|
|
109
|
+
end: undefined
|
|
110
|
+
});
|
|
111
|
+
}
|
|
111
112
|
}
|
|
112
|
-
}
|
|
113
|
+
}, [
|
|
114
|
+
initialTimeRange,
|
|
115
|
+
paramsEnabled,
|
|
116
|
+
start,
|
|
117
|
+
setQuery
|
|
118
|
+
]);
|
|
113
119
|
const setTimeRange = useCallback((value)=>{
|
|
114
120
|
if (isRelativeTimeRange(value)) {
|
|
115
121
|
setQuery({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/time-range-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 { useMemo, useCallback, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { TimeRange } from '@perses-dev/plugin-system';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig);\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set paramsEnabled to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, paramsEnabled = true): TimeRange {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig);\n\n // fallback when app does not want query string as source of truth\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils/time-range-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 { useMemo, useCallback, useEffect, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { TimeRange } from '@perses-dev/plugin-system';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig);\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set paramsEnabled to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, paramsEnabled = true): TimeRange {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig);\n\n // fallback when app does not want query string as source of truth\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n useEffect(() => {\n if (paramsEnabled && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n }\n }\n }, [initialTimeRange, paramsEnabled, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!paramsEnabled) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","useInitialTimeRange","dashboardDuration","query","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","paramsEnabled","setQuery","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AAC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K;QACzB,IAAItC,mBAAmB,CAACsC,KAAK,CAAC,EAAE;YAC9BL,QAAQ,CAAC;gBAAEV,KAAK,EAAEe,KAAK,CAACT,YAAY;gBAAEL,GAAG,EAAEY,SAAS;aAAE,CAAC,CAAC;QAC1D,OAAO;YACLH,QAAQ,CAACK,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,EACD;QAACL,QAAQ;KAAC,CACX,AAAC;IAEF,IAAI,CAACD,aAAa,EAAE;QAClB,OAAO;YAAEO,SAAS,EAAEL,cAAc;YAAEG,YAAY,EAAEF,iBAAiB;SAAE,CAAC;IACxE,CAAC;IACD,OAAO;QAAEI,SAAS,EAAEX,gBAAgB;QAAES,YAAY,EAAEA,YAAY;KAAE,CAAC;AACrE,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"}
|