@perses-dev/dashboards 0.10.0 → 0.12.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 +4 -5
- package/dist/cjs/components/DashboardToolbar.js +18 -5
- package/dist/cjs/components/GridLayout/GridItemContent.js +3 -11
- package/dist/cjs/components/GridLayout/GridLayout.js +20 -20
- package/dist/cjs/components/GridLayout/GridTitle.js +9 -11
- package/dist/cjs/components/Panel/DeletePanelDialog.js +12 -10
- package/dist/cjs/components/Panel/Panel.js +12 -22
- package/dist/cjs/components/Panel/Panel.test.js +5 -3
- package/dist/cjs/components/Panel/index.js +1 -0
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +13 -5
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +21 -15
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +9 -3
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -111
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +22 -16
- package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +92 -0
- package/dist/cjs/components/PanelGroupDialog/index.js +29 -0
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +8 -11
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +20 -13
- package/dist/cjs/components/Variables/Variable.js +1 -0
- package/dist/cjs/components/Variables/VariableEditor.js +40 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
- package/dist/cjs/components/Variables/VariableList.js +0 -1
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +26 -8
- package/dist/cjs/context/DashboardProvider/common.js +10 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +122 -29
- 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 +182 -0
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +89 -0
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +83 -18
- package/dist/cjs/context/DashboardProvider/panel-slice.js +36 -0
- package/dist/cjs/context/TimeRangeProvider.js +20 -44
- package/dist/cjs/context/index.js +1 -1
- package/dist/cjs/context/useDashboardSpec.js +90 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/test/render.js +25 -5
- package/dist/cjs/test/setup-tests.js +4 -1
- package/dist/cjs/test/testDashboard.js +11 -10
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/utils/time-range-params.js +151 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -5
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +42 -93
- package/dist/components/Dashboard.js +5 -6
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +20 -7
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +2 -4
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +4 -12
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -3
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +22 -22
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +2 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +10 -12
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +0 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.js +13 -11
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +2 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +12 -22
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.d.ts +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +1 -1
- package/dist/components/Panel/Panel.test.js +5 -3
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/index.d.ts +1 -0
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +1 -0
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +2 -2
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +13 -5
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +22 -16
- package/dist/components/PanelDrawer/PanelEditorForm.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 +9 -3
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +1 -2
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -2
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +73 -112
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +12 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +82 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -0
- package/dist/components/PanelGroupDialog/index.d.ts +3 -0
- package/dist/components/PanelGroupDialog/index.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/index.js +16 -0
- package/dist/components/PanelGroupDialog/index.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +11 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +21 -14
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
- package/dist/components/Variables/Variable.js +1 -0
- 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 +40 -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/Variables/VariableList.js +0 -1
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +10 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +26 -8
- 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 +65 -22
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +133 -26
- 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 -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-editor-slice.d.ts +56 -0
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-editor-slice.js +178 -0
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +33 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +83 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +60 -11
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +85 -18
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-slice.d.ts +23 -0
- package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
- package/dist/context/TimeRangeProvider.d.ts +9 -2
- package/dist/context/TimeRangeProvider.d.ts.map +1 -1
- package/dist/context/TimeRangeProvider.js +15 -43
- package/dist/context/TimeRangeProvider.js.map +1 -1
- 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/useDashboardSpec.d.ts +11 -0
- package/dist/context/useDashboardSpec.d.ts.map +1 -0
- package/dist/context/useDashboardSpec.js +84 -0
- package/dist/context/useDashboardSpec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/test/render.d.ts +2 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +25 -5
- package/dist/test/render.js.map +1 -1
- package/dist/test/setup-tests.d.ts.map +1 -1
- package/dist/test/setup-tests.js +4 -0
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +11 -10
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/time-range-params.d.ts +25 -0
- package/dist/utils/time-range-params.d.ts.map +1 -0
- package/dist/utils/time-range-params.js +143 -0
- package/dist/utils/time-range-params.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +1 -4
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +45 -96
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/context/DashboardProvider/layout-slice.js +0 -200
- package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +0 -156
- package/dist/cjs/context/QueryStringProvider.js +0 -89
- package/dist/context/DashboardProvider/layout-slice.d.ts +0 -57
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/layout-slice.js +0 -196
- package/dist/context/DashboardProvider/layout-slice.js.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts +0 -70
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +0 -1
- package/dist/context/DashboardProvider/panel-editing-slice.js +0 -152
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +0 -1
- package/dist/context/QueryStringProvider.d.ts +0 -13
- package/dist/context/QueryStringProvider.d.ts.map +0 -1
- package/dist/context/QueryStringProvider.js +0 -40
- package/dist/context/QueryStringProvider.js.map +0 -1
|
@@ -1,15 +1,64 @@
|
|
|
1
|
+
import { LayoutDefinition } from '@perses-dev/core';
|
|
2
|
+
import { Layout } from 'react-grid-layout';
|
|
1
3
|
import { StateCreator } from 'zustand';
|
|
2
4
|
import { Middleware } from './common';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.
|
|
7
|
+
*/
|
|
6
8
|
export interface PanelGroupSlice {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Panel groups indexed by their ID.
|
|
11
|
+
*/
|
|
12
|
+
panelGroups: Record<PanelGroupId, PanelGroupDefinition>;
|
|
13
|
+
/**
|
|
14
|
+
* An array of panel group IDs, representing their order in the dashboard.
|
|
15
|
+
*/
|
|
16
|
+
panelGroupOrder: PanelGroupId[];
|
|
17
|
+
/**
|
|
18
|
+
* previous state
|
|
19
|
+
*/
|
|
20
|
+
previousPanelGroupState: {
|
|
21
|
+
panelGroups: PanelGroupSlice['panelGroups'];
|
|
22
|
+
panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Rearrange the order of panel groups by swapping the positions
|
|
26
|
+
*/
|
|
27
|
+
swapPanelGroups: (xIndex: number, yIndex: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Update the item layouts for a panel group when, for example, a panel is moved or resized.
|
|
30
|
+
*/
|
|
31
|
+
updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
|
|
32
|
+
/**
|
|
33
|
+
* save
|
|
34
|
+
*/
|
|
35
|
+
savePanelGroups: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* reset to previous panel group states
|
|
38
|
+
*/
|
|
39
|
+
resetPanelGroups: () => void;
|
|
40
|
+
}
|
|
41
|
+
export declare type PanelGroupId = number;
|
|
42
|
+
export interface PanelGroupDefinition {
|
|
43
|
+
id: PanelGroupId;
|
|
44
|
+
isCollapsed: boolean;
|
|
45
|
+
title?: string;
|
|
46
|
+
itemLayouts: PanelGroupItemLayout[];
|
|
47
|
+
itemPanelKeys: Record<PanelGroupItemLayoutId, string>;
|
|
48
|
+
}
|
|
49
|
+
export interface PanelGroupItemLayout extends Layout {
|
|
50
|
+
i: PanelGroupItemLayoutId;
|
|
51
|
+
}
|
|
52
|
+
export declare type PanelGroupItemLayoutId = string;
|
|
53
|
+
/**
|
|
54
|
+
* Uniquely identifies an item in a PanelGroup.
|
|
55
|
+
*/
|
|
56
|
+
export interface PanelGroupItemId {
|
|
57
|
+
panelGroupId: PanelGroupId;
|
|
58
|
+
panelGroupItemLayoutId: PanelGroupItemLayoutId;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Curried function for creating a PanelGroupSlice.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
|
|
15
64
|
//# sourceMappingURL=panel-group-slice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.
|
|
1
|
+
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,uBAAuB,EAAE;QACvB,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC5C,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC;KACvD,CAAC;IAEF;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;IAEhH;;OAEG;IACH,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkFhE"}
|
|
@@ -10,23 +10,90 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
import { getPanelKeyFromRef } from '@perses-dev/core';
|
|
14
|
+
import { generateId } from './common';
|
|
15
|
+
/**
|
|
16
|
+
* Curried function for creating a PanelGroupSlice.
|
|
17
|
+
*/ export function createPanelGroupSlice(layouts) {
|
|
18
|
+
// Convert the initial layouts from the JSON
|
|
19
|
+
const panelGroups = {};
|
|
20
|
+
const panelGroupIdOrder = [];
|
|
21
|
+
for (const layout of layouts){
|
|
22
|
+
var ref, ref1, ref2;
|
|
23
|
+
const itemLayouts = [];
|
|
24
|
+
const itemPanelKeys = {};
|
|
25
|
+
// Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
|
|
26
|
+
for (const item of layout.spec.items){
|
|
27
|
+
const panelGroupLayoutId = generateId().toString();
|
|
28
|
+
itemLayouts.push({
|
|
29
|
+
i: panelGroupLayoutId,
|
|
30
|
+
w: item.width,
|
|
31
|
+
h: item.height,
|
|
32
|
+
x: item.x,
|
|
33
|
+
y: item.y
|
|
34
|
+
});
|
|
35
|
+
itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);
|
|
36
|
+
}
|
|
37
|
+
// Create the panel group and keep track of the ID order
|
|
38
|
+
const panelGroupId = generateId();
|
|
39
|
+
panelGroups[panelGroupId] = {
|
|
40
|
+
id: panelGroupId,
|
|
41
|
+
isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
|
|
42
|
+
title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
|
|
43
|
+
itemLayouts,
|
|
44
|
+
itemPanelKeys
|
|
45
|
+
};
|
|
46
|
+
panelGroupIdOrder.push(panelGroupId);
|
|
47
|
+
}
|
|
48
|
+
// Return the state creator function for Zustand
|
|
49
|
+
return (set)=>({
|
|
50
|
+
panelGroups,
|
|
51
|
+
panelGroupOrder: panelGroupIdOrder,
|
|
52
|
+
previousPanelGroupState: {
|
|
53
|
+
panelGroups,
|
|
54
|
+
panelGroupIdOrder
|
|
55
|
+
},
|
|
56
|
+
savePanelGroups () {
|
|
57
|
+
set((state)=>{
|
|
58
|
+
state.previousPanelGroupState = {
|
|
59
|
+
panelGroups: state.panelGroups,
|
|
60
|
+
panelGroupIdOrder: state.panelGroupOrder
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
resetPanelGroups () {
|
|
65
|
+
set((state)=>{
|
|
66
|
+
state.panelGroups = state.previousPanelGroupState.panelGroups;
|
|
67
|
+
state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
swapPanelGroups (x, y) {
|
|
71
|
+
set((state)=>{
|
|
72
|
+
if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
|
|
73
|
+
throw new Error('index out of bound');
|
|
74
|
+
}
|
|
75
|
+
const xPanelGroup = state.panelGroupOrder[x];
|
|
76
|
+
const yPanelGroup = state.panelGroupOrder[y];
|
|
77
|
+
if (xPanelGroup === undefined || yPanelGroup === undefined) {
|
|
78
|
+
throw new Error('panel group is undefined');
|
|
79
|
+
}
|
|
80
|
+
// assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
|
|
81
|
+
[state.panelGroupOrder[x], state.panelGroupOrder[y]] = [
|
|
82
|
+
yPanelGroup,
|
|
83
|
+
xPanelGroup
|
|
84
|
+
];
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
updatePanelGroupLayouts (panelGroupId, itemLayouts) {
|
|
88
|
+
set((state)=>{
|
|
89
|
+
const group = state.panelGroups[panelGroupId];
|
|
90
|
+
if (group === undefined) {
|
|
91
|
+
throw new Error(`Cannot find panel group ${panelGroupId}`);
|
|
92
|
+
}
|
|
93
|
+
group.itemLayouts = itemLayouts;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
31
98
|
|
|
32
99
|
//# sourceMappingURL=panel-group-slice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * previous state\n */\n previousPanelGroupState: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];\n };\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n\n previousPanelGroupState: { panelGroups, panelGroupIdOrder },\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupState = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupState.panelGroups;\n state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupIdOrder","layout","itemLayouts","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","x","y","content","panelGroupId","id","isCollapsed","display","collapse","open","title","set","panelGroupOrder","previousPanelGroupState","savePanelGroups","state","resetPanelGroups","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","group"],"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,kBAAkB,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAqElD;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACqC;IAChE,4CAA4C;IAC5C,MAAMC,WAAW,GAAmC,EAAE,AAAC;IACvD,MAAMC,iBAAiB,GAAuC,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A0B,CAAC,CAAC;oBAC9C,CAAC;oBACD,8FAA8F;oBAC9F,CAACJ,KAAK,CAACH,eAAe,CAACX,CAAC,CAAC,EAAEc,KAAK,CAACH,eAAe,CAACV,CAAC,CAAC,CAAC,GAAG;wBAACmB,WAAW;wBAAED,WAAW;qBAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;YACL,CAAC;YAEDG,uBAAuB,EAACnB,YAAY,EAAEhB,WAAW,EAAE;gBACjDuB,GAAG,CAAC,CAACI,KAAK,GAAK;oBACb,MAAMS,KAAK,GAAGT,KAAK,CAAC9B,WAAW,CAACmB,YAAY,CAAC,AAAC;oBAC9C,IAAIoB,KAAK,KAAKF,SAAS,EAAE;wBACvB,MAAM,IAAIH,KAAK,CAAC,CAAC,wBAAwB,EAAEf,YAAY,CAAC,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBACDoB,KAAK,CAACpC,WAAW,GAAGA,WAAW,CAAC;gBAClC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA,AAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PanelDefinition } from '@perses-dev/core';
|
|
2
|
+
import { StateCreator } from 'zustand';
|
|
3
|
+
import { Middleware } from './common';
|
|
4
|
+
/**
|
|
5
|
+
* Slice with the state of Panels, along with any actions that modify only the Panels state.
|
|
6
|
+
*/
|
|
7
|
+
export interface PanelSlice {
|
|
8
|
+
panels: Record<string, PanelDefinition>;
|
|
9
|
+
previousPanels: Record<string, PanelDefinition>;
|
|
10
|
+
/**
|
|
11
|
+
* Reset panels to previous state
|
|
12
|
+
*/
|
|
13
|
+
resetPanels: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Save panels
|
|
16
|
+
*/
|
|
17
|
+
savePanels: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Curried function for creating the PanelSlice.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice>;
|
|
23
|
+
//# sourceMappingURL=panel-slice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAEhD;;OAEG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,CAAC,CAiBnH"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Curried function for creating the PanelSlice.
|
|
15
|
+
*/ export function createPanelSlice(panels) {
|
|
16
|
+
return (set)=>({
|
|
17
|
+
panels,
|
|
18
|
+
previousPanels: panels,
|
|
19
|
+
resetPanels () {
|
|
20
|
+
set((state)=>{
|
|
21
|
+
state.panels = state.previousPanels;
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
savePanels () {
|
|
25
|
+
set((state)=>{
|
|
26
|
+
state.previousPanels = state.panels;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=panel-slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-slice.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 { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n previousPanels: Record<string, PanelDefinition>;\n\n /**\n * Reset panels to previous state\n */\n resetPanels: () => void;\n\n /**\n * Save panels\n */\n savePanels: () => void;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return (set) => ({\n panels,\n previousPanels: panels,\n\n resetPanels() {\n set((state) => {\n state.panels = state.previousPanels;\n });\n },\n\n savePanels() {\n set((state) => {\n state.previousPanels = state.panels;\n });\n },\n });\n}\n"],"names":["createPanelSlice","panels","set","previousPanels","resetPanels","state","savePanels"],"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;AAwBjC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,CAACC,GAAG,GAAM,CAAA;YACfD,MAAM;YACNE,cAAc,EAAEF,MAAM;YAEtBG,WAAW,IAAG;gBACZF,GAAG,CAAC,CAACG,KAAK,GAAK;oBACbA,KAAK,CAACJ,MAAM,GAAGI,KAAK,CAACF,cAAc,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;YAEDG,UAAU,IAAG;gBACXJ,GAAG,CAAC,CAACG,KAAK,GAAK;oBACbA,KAAK,CAACF,cAAc,GAAGE,KAAK,CAACJ,MAAM,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA,AAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TimeRangeValue } from '@perses-dev/core';
|
|
3
3
|
export interface TimeRangeProviderProps {
|
|
4
|
-
|
|
4
|
+
timeRange: TimeRangeValue;
|
|
5
|
+
setTimeRange?: (value: TimeRangeValue) => void;
|
|
5
6
|
children?: React.ReactNode;
|
|
6
|
-
onTimeRangeChange?: (e: TimeRangeValue) => void;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Provider implementation that supplies the time range state at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export declare function TimeRangeProvider(props: TimeRangeProviderProps): JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Internal version of time range hook to get all supported values
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDashboardTimeRange(): {
|
|
16
|
+
timeRange: TimeRangeValue;
|
|
17
|
+
setTimeRange: (value: TimeRangeValue) => void;
|
|
18
|
+
};
|
|
12
19
|
//# sourceMappingURL=TimeRangeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAiB9D;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;;EAGpC"}
|
|
@@ -11,54 +11,17 @@
|
|
|
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
|
-
import React, {
|
|
15
|
-
import {
|
|
16
|
-
import { toAbsoluteTimeRange, isRelativeTimeRange } from '@perses-dev/core';
|
|
17
|
-
import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
14
|
+
import React, { useMemo } from 'react';
|
|
15
|
+
import { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';
|
|
18
16
|
/**
|
|
19
17
|
* Provider implementation that supplies the time range state at runtime.
|
|
20
18
|
*/ export function TimeRangeProvider(props) {
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
const defaultTimeRange = isRelativeTimeRange(initialTimeRange) ? toAbsoluteTimeRange(initialTimeRange) : initialTimeRange;
|
|
24
|
-
const [timeRange, setActiveTimeRange] = useState(defaultTimeRange);
|
|
25
|
-
const setTimeRange = useCallback((value)=>{
|
|
26
|
-
if (onTimeRangeChange !== undefined) {
|
|
27
|
-
// optional callback to override default behavior
|
|
28
|
-
onTimeRangeChange(value);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (isRelativeTimeRange(value)) {
|
|
32
|
-
if (setQueryString) {
|
|
33
|
-
queryString.set('start', value.pastDuration);
|
|
34
|
-
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
35
|
-
queryString.delete('end');
|
|
36
|
-
setQueryString(queryString);
|
|
37
|
-
} else {
|
|
38
|
-
setActiveTimeRange(toAbsoluteTimeRange(value));
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// allows app to specify whether query params should be source of truth for active time range
|
|
43
|
-
if (setQueryString) {
|
|
44
|
-
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
45
|
-
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
46
|
-
const startUnixMs = getUnixTime(value.start) * 1000;
|
|
47
|
-
const endUnixMs = getUnixTime(value.end) * 1000;
|
|
48
|
-
queryString.set('start', startUnixMs.toString());
|
|
49
|
-
queryString.set('end', endUnixMs.toString());
|
|
50
|
-
setQueryString(queryString);
|
|
51
|
-
} else {
|
|
52
|
-
setActiveTimeRange(value);
|
|
53
|
-
}
|
|
54
|
-
}, [
|
|
55
|
-
queryString,
|
|
56
|
-
setQueryString,
|
|
57
|
-
onTimeRangeChange
|
|
58
|
-
]);
|
|
19
|
+
const { timeRange , children , setTimeRange } = props;
|
|
20
|
+
// TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround
|
|
59
21
|
const ctx = useMemo(()=>({
|
|
60
22
|
timeRange,
|
|
61
|
-
setTimeRange
|
|
23
|
+
setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : ()=>{
|
|
24
|
+
/* no-op */ }
|
|
62
25
|
}), [
|
|
63
26
|
timeRange,
|
|
64
27
|
setTimeRange
|
|
@@ -68,5 +31,14 @@ import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
|
68
31
|
children: children
|
|
69
32
|
});
|
|
70
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Internal version of time range hook to get all supported values
|
|
36
|
+
*/ export function useDashboardTimeRange() {
|
|
37
|
+
const { timeRange , setTimeRange } = useTimeRangeContext();
|
|
38
|
+
return {
|
|
39
|
+
timeRange,
|
|
40
|
+
setTimeRange
|
|
41
|
+
};
|
|
42
|
+
}
|
|
71
43
|
|
|
72
44
|
//# sourceMappingURL=TimeRangeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TimeRangeProvider.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 React, {
|
|
1
|
+
{"version":3,"sources":["../../src/context/TimeRangeProvider.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 React, { useMemo } from 'react';\nimport { TimeRangeValue } from '@perses-dev/core';\nimport { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n setTimeRange?: (value: TimeRangeValue) => void;\n children?: React.ReactNode;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { timeRange, children, setTimeRange } = props;\n\n // TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround\n const ctx = useMemo(\n () => ({\n timeRange,\n setTimeRange:\n setTimeRange ??\n (() => {\n /* no-op */\n }),\n }),\n [timeRange, setTimeRange]\n );\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n\n/**\n * Internal version of time range hook to get all supported values\n */\nexport function useDashboardTimeRange() {\n const { timeRange, setTimeRange } = useTimeRangeContext();\n return { timeRange, setTimeRange };\n}\n"],"names":["React","useMemo","TimeRangeContext","useTimeRangeContext","TimeRangeProvider","props","timeRange","children","setTimeRange","ctx","Provider","value","useDashboardTimeRange"],"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,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AAEvC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AAQlF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAACC,KAA6B,EAAE;IAC/D,MAAM,EAAEC,SAAS,CAAA,EAAEC,QAAQ,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGH,KAAK,AAAC;IAEpD,sFAAsF;IACtF,MAAMI,GAAG,GAAGR,OAAO,CACjB,IAAO,CAAA;YACLK,SAAS;YACTE,YAAY,EACVA,YAAY,aAAZA,YAAY,cAAZA,YAAY,GACX,IAAM;YACL,SAAS,GACX,CAAC,AAAC;SACL,CAAA,AAAC,EACF;QAACF,SAAS;QAAEE,YAAY;KAAC,CAC1B,AAAC;IAEF,qBAAO,KAACN,gBAAgB,CAACQ,QAAQ;QAACC,KAAK,EAAEF,GAAG;kBAAGF,QAAQ;MAA6B,CAAC;AACvF,CAAC;AAED;;CAEC,GACD,OAAO,SAASK,qBAAqB,GAAG;IACtC,MAAM,EAAEN,SAAS,CAAA,EAAEE,YAAY,CAAA,EAAE,GAAGL,mBAAmB,EAAE,AAAC;IAC1D,OAAO;QAAEG,SAAS;QAAEE,YAAY;KAAE,CAAC;AACrC,CAAC"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './DashboardProvider';
|
|
2
2
|
export * from './DatasourceStoreProvider';
|
|
3
|
-
export * from './QueryStringProvider';
|
|
4
3
|
export * from './TemplateVariableProvider';
|
|
5
4
|
export * from './TimeRangeProvider';
|
|
5
|
+
export * from './useDashboardSpec';
|
|
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,
|
|
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,oBAAoB,CAAC"}
|
package/dist/context/index.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './DashboardProvider';
|
|
14
14
|
export * from './DatasourceStoreProvider';
|
|
15
|
-
export * from './QueryStringProvider';
|
|
16
15
|
export * from './TemplateVariableProvider';
|
|
17
16
|
export * from './TimeRangeProvider';
|
|
17
|
+
export * from './useDashboardSpec';
|
|
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 './
|
|
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 './useDashboardSpec';\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,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DashboardSpec, GridDefinition } from '@perses-dev/core';
|
|
2
|
+
export declare function useDashboardSpec(): {
|
|
3
|
+
spec: {
|
|
4
|
+
panels: Record<string, import("@perses-dev/core").PanelDefinition<import("@perses-dev/core").UnknownSpec>>;
|
|
5
|
+
layouts: GridDefinition[];
|
|
6
|
+
variables: import("@perses-dev/core").VariableDefinition[];
|
|
7
|
+
duration: import("@perses-dev/core").DurationString;
|
|
8
|
+
};
|
|
9
|
+
resetSpec: (spec: DashboardSpec) => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useDashboardSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDashboardSpec.d.ts","sourceRoot":"","sources":["../../src/context/useDashboardSpec.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIjF,wBAAgB,gBAAgB;;;;;;;sBAyBL,aAAa;EAUvC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 useDashboardSpec() {
|
|
17
|
+
const { panels , panelGroups , panelGroupOrder , defaultTimeRange , reset: resetDashboardStore , } = useDashboardStore(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , reset })=>({
|
|
18
|
+
panels,
|
|
19
|
+
panelGroups,
|
|
20
|
+
panelGroupOrder,
|
|
21
|
+
defaultTimeRange,
|
|
22
|
+
reset
|
|
23
|
+
}));
|
|
24
|
+
const { setVariableDefinitions } = useTemplateVariableActions();
|
|
25
|
+
const variables = useTemplateVariableDefinitions();
|
|
26
|
+
const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
|
|
27
|
+
const spec = {
|
|
28
|
+
panels,
|
|
29
|
+
layouts,
|
|
30
|
+
variables,
|
|
31
|
+
duration: defaultTimeRange.pastDuration
|
|
32
|
+
};
|
|
33
|
+
const resetSpec = (spec)=>{
|
|
34
|
+
setVariableDefinitions(spec.variables);
|
|
35
|
+
// TODO: Should we call reset on the dashboard store with the spec?
|
|
36
|
+
resetDashboardStore();
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
spec,
|
|
40
|
+
resetSpec
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function convertPanelGroupsToLayouts(panelGroups, panelGroupOrder) {
|
|
44
|
+
const layouts = [];
|
|
45
|
+
panelGroupOrder.map((groupOrderId)=>{
|
|
46
|
+
const group = panelGroups[groupOrderId];
|
|
47
|
+
if (group === undefined) {
|
|
48
|
+
throw new Error('panel group not found');
|
|
49
|
+
}
|
|
50
|
+
const { title , isCollapsed , itemLayouts , itemPanelKeys } = group;
|
|
51
|
+
let display = undefined;
|
|
52
|
+
if (title) {
|
|
53
|
+
display = {
|
|
54
|
+
title,
|
|
55
|
+
collapse: {
|
|
56
|
+
open: !isCollapsed
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const layout = {
|
|
61
|
+
kind: 'Grid',
|
|
62
|
+
spec: {
|
|
63
|
+
display,
|
|
64
|
+
items: itemLayouts.map((layout)=>{
|
|
65
|
+
const panelKey = itemPanelKeys[layout.i];
|
|
66
|
+
if (panelKey === undefined) {
|
|
67
|
+
throw new Error(`Missing panel key of layout ${layout.i}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
x: layout.x,
|
|
71
|
+
y: layout.y,
|
|
72
|
+
width: layout.w,
|
|
73
|
+
height: layout.h,
|
|
74
|
+
content: createPanelRef(panelKey)
|
|
75
|
+
};
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
layouts.push(layout);
|
|
80
|
+
});
|
|
81
|
+
return layouts;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=useDashboardSpec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/useDashboardSpec.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, DashboardSpec, GridDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupId, useDashboardStore } from './DashboardProvider';\nimport { useTemplateVariableActions, useTemplateVariableDefinitions } from './TemplateVariableProvider';\n\nexport function useDashboardSpec() {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n reset: resetDashboardStore,\n } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, defaultTimeRange, reset }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n defaultTimeRange,\n reset,\n }));\n const { setVariableDefinitions } = useTemplateVariableActions();\n const variables = useTemplateVariableDefinitions();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const spec = {\n panels,\n layouts,\n variables,\n duration: defaultTimeRange.pastDuration,\n };\n\n const resetSpec = (spec: DashboardSpec) => {\n setVariableDefinitions(spec.variables);\n // TODO: Should we call reset on the dashboard store with the spec?\n resetDashboardStore();\n };\n\n return {\n spec,\n resetSpec,\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","useDashboardSpec","panels","panelGroups","panelGroupOrder","defaultTimeRange","reset","resetDashboardStore","setVariableDefinitions","variables","layouts","convertPanelGroupsToLayouts","spec","duration","pastDuration","resetSpec","map","groupOrderId","group","undefined","Error","title","isCollapsed","itemLayouts","itemPanelKeys","display","collapse","open","layout","kind","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,iCA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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/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 './components';\nexport * from './context';\nexport * from './views';\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,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/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 './components';\nexport * from './context';\nexport * from './utils';\nexport * from './views';\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,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|