@perses-dev/dashboards 0.9.0 → 0.11.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 +6 -11
- package/dist/cjs/components/DashboardToolbar.js +12 -6
- package/dist/cjs/components/GridLayout/GridItemContent.js +7 -15
- package/dist/cjs/components/GridLayout/GridLayout.js +27 -22
- package/dist/cjs/components/GridLayout/GridTitle.js +27 -7
- package/dist/cjs/components/Panel/DeletePanelDialog.js +95 -0
- package/dist/cjs/components/Panel/Panel.js +12 -10
- package/dist/cjs/components/Panel/Panel.test.js +15 -6
- package/dist/cjs/components/Panel/PanelContent.js +3 -2
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -13
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +87 -39
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +54 -0
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +88 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -118
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -36
- 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 +20 -11
- package/dist/cjs/components/Variables/VariableEditor.js +240 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
- package/dist/cjs/components/Variables/VariableList.js +49 -69
- package/dist/cjs/components/Variables/index.js +1 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +82 -0
- package/dist/cjs/context/DashboardProvider/common.js +18 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +164 -0
- package/dist/cjs/context/DashboardProvider/index.js +29 -0
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +175 -0
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +102 -0
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +208 -0
- package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
- package/dist/cjs/context/TemplateVariableProvider.js +8 -1
- package/dist/cjs/context/TimeRangeProvider.js +20 -44
- package/dist/cjs/context/index.js +1 -3
- package/dist/cjs/context/useDashboardSpec.js +61 -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 +24 -11
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/utils/time-range-params.js +145 -0
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +5 -8
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +114 -0
- package/dist/components/Dashboard.d.ts +1 -4
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +7 -12
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +14 -8
- 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 +7 -15
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -4
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +28 -23
- 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 +28 -8
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/Panel/DeletePanelDialog.js +84 -0
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
- 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 +13 -11
- 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 +10 -6
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelContent.d.ts +4 -1
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +3 -2
- package/dist/components/Panel/PanelContent.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +9 -13
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +89 -41
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelPreview.js +48 -0
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +3 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +77 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- 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 -119
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +20 -35
- 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 +22 -13
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +8 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditor.js +229 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js +15 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +47 -72
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/Variables/index.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 +25 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.js +64 -0
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
- package/dist/context/DashboardProvider/common.d.ts +5 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -0
- package/dist/context/DashboardProvider/common.js +17 -0
- package/dist/context/DashboardProvider/common.js.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +74 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js +163 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +5 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -0
- package/dist/context/DashboardProvider/index.js +16 -0
- package/dist/context/DashboardProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +85 -0
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-editor-slice.js +171 -0
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +40 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +96 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +80 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.js +204 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +10 -2
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +111 -9
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider.d.ts +2 -0
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +8 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -1
- 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 -3
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -3
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboardSpec.d.ts +3 -0
- package/dist/context/useDashboardSpec.d.ts.map +1 -0
- package/dist/context/useDashboardSpec.js +55 -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/plugin-registry.d.ts +2 -2
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.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 +24 -11
- 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 +137 -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 +6 -9
- 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.d.ts +2 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +107 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
- package/package.json +5 -4
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
- package/dist/cjs/context/DashboardAppSlice.js +0 -57
- package/dist/cjs/context/DashboardProvider.js +0 -128
- package/dist/cjs/context/LayoutsSlice.js +0 -55
- package/dist/cjs/context/QueryStringProvider.js +0 -89
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
- package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
- package/dist/context/DashboardAppSlice.d.ts +0 -26
- package/dist/context/DashboardAppSlice.d.ts.map +0 -1
- package/dist/context/DashboardAppSlice.js +0 -45
- package/dist/context/DashboardAppSlice.js.map +0 -1
- package/dist/context/DashboardProvider.d.ts +0 -36
- package/dist/context/DashboardProvider.d.ts.map +0 -1
- package/dist/context/DashboardProvider.js +0 -107
- package/dist/context/DashboardProvider.js.map +0 -1
- package/dist/context/LayoutsSlice.d.ts +0 -12
- package/dist/context/LayoutsSlice.d.ts.map +0 -1
- package/dist/context/LayoutsSlice.js +0 -43
- package/dist/context/LayoutsSlice.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
|
@@ -24,30 +24,98 @@ const _core = require("@perses-dev/core");
|
|
|
24
24
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
25
|
function DatasourceStoreProvider(props) {
|
|
26
26
|
const { dashboardResource , datasourceApi , children } = props;
|
|
27
|
-
const
|
|
27
|
+
const { project } = dashboardResource.metadata;
|
|
28
|
+
const { getPlugin , listPluginMetadata } = (0, _pluginSystem.usePluginRegistry)();
|
|
29
|
+
const findDatasource = (0, _core.useEvent)(async (selector)=>{
|
|
28
30
|
// Try to find it in dashboard spec
|
|
29
31
|
const { datasources } = dashboardResource.spec;
|
|
30
32
|
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
31
33
|
if (dashboardDatasource !== undefined) {
|
|
32
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
spec: dashboardDatasource,
|
|
36
|
+
proxyUrl: undefined
|
|
37
|
+
};
|
|
33
38
|
}
|
|
34
39
|
// Try to find it at the project level as a Datasource resource
|
|
35
|
-
const { project } = dashboardResource.metadata;
|
|
36
40
|
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
37
41
|
if (datasource !== undefined) {
|
|
38
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
spec: datasource.resource.spec,
|
|
44
|
+
proxyUrl: datasource.proxyUrl
|
|
45
|
+
};
|
|
39
46
|
}
|
|
40
47
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
41
48
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
42
49
|
if (globalDatasource !== undefined) {
|
|
43
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
spec: globalDatasource.resource.spec,
|
|
52
|
+
proxyUrl: globalDatasource.proxyUrl
|
|
53
|
+
};
|
|
44
54
|
}
|
|
45
55
|
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
46
56
|
});
|
|
57
|
+
// Gets a datasource spec for a given selector
|
|
58
|
+
const getDatasource = (0, _react.useCallback)(async (selector)=>{
|
|
59
|
+
const { spec } = await findDatasource(selector);
|
|
60
|
+
return spec;
|
|
61
|
+
}, [
|
|
62
|
+
findDatasource
|
|
63
|
+
]);
|
|
64
|
+
// Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
|
|
65
|
+
const getDatasourceClient = (0, _react.useCallback)(async function getClient(selector) {
|
|
66
|
+
const { kind } = selector;
|
|
67
|
+
const [{ spec , proxyUrl }, plugin] = await Promise.all([
|
|
68
|
+
findDatasource(selector),
|
|
69
|
+
getPlugin('Datasource', kind)
|
|
70
|
+
]);
|
|
71
|
+
return plugin.createClient(spec.plugin.spec, {
|
|
72
|
+
proxyUrl
|
|
73
|
+
});
|
|
74
|
+
}, [
|
|
75
|
+
findDatasource,
|
|
76
|
+
getPlugin
|
|
77
|
+
]);
|
|
78
|
+
const listDatasourceMetadata = (0, _core.useEvent)(async (datasourcePluginKind)=>{
|
|
79
|
+
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
80
|
+
listPluginMetadata('Datasource'),
|
|
81
|
+
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
82
|
+
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
83
|
+
]);
|
|
84
|
+
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
85
|
+
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
|
|
86
|
+
if (datasourcePluginMetadata === undefined) {
|
|
87
|
+
throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
|
|
88
|
+
}
|
|
89
|
+
// Get helper for de-duping results properly
|
|
90
|
+
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
91
|
+
// Start with dashboard datasources that have highest precedence
|
|
92
|
+
if (dashboardResource.spec.datasources !== undefined) {
|
|
93
|
+
for(const selectorName in dashboardResource.spec.datasources){
|
|
94
|
+
const spec = dashboardResource.spec.datasources[selectorName];
|
|
95
|
+
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
96
|
+
addResult(spec, selectorName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Now look at project-level datasources
|
|
100
|
+
for (const datasource of datasources){
|
|
101
|
+
const selectorName1 = datasource.metadata.name;
|
|
102
|
+
addResult(datasource.spec, selectorName1);
|
|
103
|
+
}
|
|
104
|
+
// And finally global datasources
|
|
105
|
+
for (const globalDatasource of globalDatasources){
|
|
106
|
+
const selectorName2 = globalDatasource.metadata.name;
|
|
107
|
+
addResult(globalDatasource.spec, selectorName2);
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
});
|
|
47
111
|
const ctxValue = (0, _react.useMemo)(()=>({
|
|
48
|
-
getDatasource
|
|
112
|
+
getDatasource,
|
|
113
|
+
getDatasourceClient,
|
|
114
|
+
listDatasourceMetadata
|
|
49
115
|
}), [
|
|
50
|
-
getDatasource
|
|
116
|
+
getDatasource,
|
|
117
|
+
getDatasourceClient,
|
|
118
|
+
listDatasourceMetadata
|
|
51
119
|
]);
|
|
52
120
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceStoreContext.Provider, {
|
|
53
121
|
value: ctxValue,
|
|
@@ -66,3 +134,37 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
66
134
|
// If only using a kind, try to find one with that kind that is the default
|
|
67
135
|
return Object.values(dashboardDatasources).find((ds)=>ds.plugin.kind === selector.kind && ds.default === true);
|
|
68
136
|
}
|
|
137
|
+
// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors
|
|
138
|
+
function buildListDatasourceMetadataResults(pluginDisplayName) {
|
|
139
|
+
const results = [];
|
|
140
|
+
const usedNames = new Set();
|
|
141
|
+
let defaultAdded = false;
|
|
142
|
+
const addResult = (spec, selectorName)=>{
|
|
143
|
+
var ref;
|
|
144
|
+
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
145
|
+
if (spec.default && defaultAdded === false) {
|
|
146
|
+
results.unshift({
|
|
147
|
+
name: `Default ${pluginDisplayName}`,
|
|
148
|
+
selector: {
|
|
149
|
+
kind: spec.plugin.kind
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
defaultAdded = true;
|
|
153
|
+
}
|
|
154
|
+
// If we already have a datasource with this selector name, ignore it, otherwise add to end of list
|
|
155
|
+
if (usedNames.has(selectorName)) return;
|
|
156
|
+
var ref1;
|
|
157
|
+
results.push({
|
|
158
|
+
name: (ref1 = (ref = spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : selectorName,
|
|
159
|
+
selector: {
|
|
160
|
+
kind: spec.plugin.kind,
|
|
161
|
+
name: selectorName
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
usedNames.add(selectorName);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
results,
|
|
168
|
+
addResult
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -77,7 +77,8 @@ function useTemplateVariableActions() {
|
|
|
77
77
|
return {
|
|
78
78
|
setVariableValue: s.setVariableValue,
|
|
79
79
|
setVariableLoading: s.setVariableLoading,
|
|
80
|
-
setVariableOptions: s.setVariableOptions
|
|
80
|
+
setVariableOptions: s.setVariableOptions,
|
|
81
|
+
setVariableDefinitions: s.setVariableDefinitions
|
|
81
82
|
};
|
|
82
83
|
});
|
|
83
84
|
}
|
|
@@ -122,6 +123,12 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
|
122
123
|
const store = (0, _zustand.createStore)()((0, _middleware.devtools)((0, _immer.immer)((set)=>({
|
|
123
124
|
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
124
125
|
variableDefinitions: initialVariableDefinitions,
|
|
126
|
+
setVariableDefinitions (definitions) {
|
|
127
|
+
set((state)=>{
|
|
128
|
+
state.variableDefinitions = definitions;
|
|
129
|
+
state.variableState = hydrateTemplateVariableStates(definitions);
|
|
130
|
+
});
|
|
131
|
+
},
|
|
125
132
|
setVariableOptions (name, options) {
|
|
126
133
|
set((state)=>{
|
|
127
134
|
const varState = state.variableState[name];
|
|
@@ -14,14 +14,18 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
TimeRangeProvider: ()=>TimeRangeProvider,
|
|
25
|
+
useDashboardTimeRange: ()=>useDashboardTimeRange
|
|
20
26
|
});
|
|
21
27
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
28
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
23
|
-
const _dateFns = require("date-fns");
|
|
24
|
-
const _core = require("@perses-dev/core");
|
|
25
29
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
26
30
|
function _getRequireWildcardCache(nodeInterop) {
|
|
27
31
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -63,47 +67,12 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
63
67
|
return newObj;
|
|
64
68
|
}
|
|
65
69
|
function TimeRangeProvider(props) {
|
|
66
|
-
const {
|
|
67
|
-
|
|
68
|
-
const defaultTimeRange = (0, _core.isRelativeTimeRange)(initialTimeRange) ? (0, _core.toAbsoluteTimeRange)(initialTimeRange) : initialTimeRange;
|
|
69
|
-
const [timeRange, setActiveTimeRange] = (0, _react.useState)(defaultTimeRange);
|
|
70
|
-
const setTimeRange = (0, _react.useCallback)((value)=>{
|
|
71
|
-
if (onTimeRangeChange !== undefined) {
|
|
72
|
-
// optional callback to override default behavior
|
|
73
|
-
onTimeRangeChange(value);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if ((0, _core.isRelativeTimeRange)(value)) {
|
|
77
|
-
if (setQueryString) {
|
|
78
|
-
queryString.set('start', value.pastDuration);
|
|
79
|
-
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
80
|
-
queryString.delete('end');
|
|
81
|
-
setQueryString(queryString);
|
|
82
|
-
} else {
|
|
83
|
-
setActiveTimeRange((0, _core.toAbsoluteTimeRange)(value));
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
// allows app to specify whether query params should be source of truth for active time range
|
|
88
|
-
if (setQueryString) {
|
|
89
|
-
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
90
|
-
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
91
|
-
const startUnixMs = (0, _dateFns.getUnixTime)(value.start) * 1000;
|
|
92
|
-
const endUnixMs = (0, _dateFns.getUnixTime)(value.end) * 1000;
|
|
93
|
-
queryString.set('start', startUnixMs.toString());
|
|
94
|
-
queryString.set('end', endUnixMs.toString());
|
|
95
|
-
setQueryString(queryString);
|
|
96
|
-
} else {
|
|
97
|
-
setActiveTimeRange(value);
|
|
98
|
-
}
|
|
99
|
-
}, [
|
|
100
|
-
queryString,
|
|
101
|
-
setQueryString,
|
|
102
|
-
onTimeRangeChange
|
|
103
|
-
]);
|
|
70
|
+
const { timeRange , children , setTimeRange } = props;
|
|
71
|
+
// TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround
|
|
104
72
|
const ctx = (0, _react.useMemo)(()=>({
|
|
105
73
|
timeRange,
|
|
106
|
-
setTimeRange
|
|
74
|
+
setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : ()=>{
|
|
75
|
+
/* no-op */ }
|
|
107
76
|
}), [
|
|
108
77
|
timeRange,
|
|
109
78
|
setTimeRange
|
|
@@ -113,3 +82,10 @@ function TimeRangeProvider(props) {
|
|
|
113
82
|
children: children
|
|
114
83
|
});
|
|
115
84
|
}
|
|
85
|
+
function useDashboardTimeRange() {
|
|
86
|
+
const { timeRange , setTimeRange } = (0, _pluginSystem.useTimeRangeContext)();
|
|
87
|
+
return {
|
|
88
|
+
timeRange,
|
|
89
|
+
setTimeRange
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -14,13 +14,11 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./DashboardAppSlice"), exports);
|
|
18
17
|
_exportStar(require("./DashboardProvider"), exports);
|
|
19
18
|
_exportStar(require("./DatasourceStoreProvider"), exports);
|
|
20
|
-
_exportStar(require("./LayoutsSlice"), exports);
|
|
21
|
-
_exportStar(require("./QueryStringProvider"), exports);
|
|
22
19
|
_exportStar(require("./TemplateVariableProvider"), exports);
|
|
23
20
|
_exportStar(require("./TimeRangeProvider"), exports);
|
|
21
|
+
_exportStar(require("./useDashboardSpec"), exports);
|
|
24
22
|
function _exportStar(from, to) {
|
|
25
23
|
Object.keys(from).forEach(function(k) {
|
|
26
24
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useDashboardSpec", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useDashboardSpec
|
|
20
|
+
});
|
|
21
|
+
const _dashboardProvider = require("./DashboardProvider");
|
|
22
|
+
const _templateVariableProvider = require("./TemplateVariableProvider");
|
|
23
|
+
function useDashboardSpec() {
|
|
24
|
+
const { panels , panelGroups , defaultTimeRange } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , defaultTimeRange })=>({
|
|
25
|
+
panels,
|
|
26
|
+
panelGroups,
|
|
27
|
+
defaultTimeRange
|
|
28
|
+
}));
|
|
29
|
+
const variables = (0, _templateVariableProvider.useTemplateVariableDefinitions)();
|
|
30
|
+
const layouts = convertPanelGroupsToLayouts(panelGroups);
|
|
31
|
+
return {
|
|
32
|
+
panels,
|
|
33
|
+
layouts,
|
|
34
|
+
variables,
|
|
35
|
+
duration: defaultTimeRange.pastDuration
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function convertPanelGroupsToLayouts(panelGroups) {
|
|
39
|
+
const layouts = [];
|
|
40
|
+
Object.values(panelGroups).forEach((group)=>{
|
|
41
|
+
const { title , isCollapsed , items } = group;
|
|
42
|
+
let display = undefined;
|
|
43
|
+
if (title) {
|
|
44
|
+
display = {
|
|
45
|
+
title,
|
|
46
|
+
collapse: {
|
|
47
|
+
open: !isCollapsed
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const layout = {
|
|
52
|
+
kind: 'Grid',
|
|
53
|
+
spec: {
|
|
54
|
+
display,
|
|
55
|
+
items
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
layouts.push(layout);
|
|
59
|
+
});
|
|
60
|
+
return layouts;
|
|
61
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./components"), exports);
|
|
18
18
|
_exportStar(require("./context"), exports);
|
|
19
|
+
_exportStar(require("./utils"), exports);
|
|
19
20
|
_exportStar(require("./views"), exports);
|
|
20
21
|
function _exportStar(from, to) {
|
|
21
22
|
Object.keys(from).forEach(function(k) {
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -20,8 +20,13 @@ Object.defineProperty(exports, "renderWithContext", {
|
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _react = require("@testing-library/react");
|
|
23
|
+
const _reactRouterDom = require("react-router-dom");
|
|
24
|
+
const _history = require("history");
|
|
25
|
+
const _useQueryParams = require("use-query-params");
|
|
26
|
+
const _reactRouter6 = require("use-query-params/adapters/react-router-6");
|
|
23
27
|
const _reactQuery = require("@tanstack/react-query");
|
|
24
|
-
|
|
28
|
+
const _components = require("@perses-dev/components");
|
|
29
|
+
function renderWithContext(ui, options, history) {
|
|
25
30
|
// Create a new QueryClient for each test to avoid caching issues
|
|
26
31
|
const queryClient = new _reactQuery.QueryClient({
|
|
27
32
|
defaultOptions: {
|
|
@@ -31,8 +36,23 @@ function renderWithContext(ui, options) {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
const BaseRender = ()=>{
|
|
40
|
+
const HistoryRouter = _reactRouterDom.unstable_HistoryRouter;
|
|
41
|
+
history = history !== null && history !== void 0 ? history : (0, _history.createMemoryHistory)();
|
|
42
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(HistoryRouter, {
|
|
43
|
+
history: history,
|
|
44
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
|
|
45
|
+
client: queryClient,
|
|
46
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_useQueryParams.QueryParamProvider, {
|
|
47
|
+
adapter: _reactRouter6.ReactRouter6Adapter,
|
|
48
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ChartsThemeProvider, {
|
|
49
|
+
themeName: "perses",
|
|
50
|
+
chartsTheme: _components.testChartsTheme,
|
|
51
|
+
children: ui
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(BaseRender, {}), options);
|
|
38
58
|
}
|
|
@@ -10,11 +10,14 @@
|
|
|
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
|
-
// Add testing library assertions
|
|
14
13
|
"use strict";
|
|
15
14
|
Object.defineProperty(exports, "__esModule", {
|
|
16
15
|
value: true
|
|
17
16
|
});
|
|
17
|
+
const _reactIntersectionObserver = require("react-intersection-observer");
|
|
18
18
|
require("@testing-library/jest-dom/extend-expect");
|
|
19
19
|
// Always mock e-charts during tests since we don't have a proper canvas in jsdom
|
|
20
20
|
jest.mock('echarts/core');
|
|
21
|
+
// Tell react-intersection-observer that everything should be considered in-view for tests (see package documentation
|
|
22
|
+
// for other options)
|
|
23
|
+
(0, _reactIntersectionObserver.defaultFallbackInView)(true);
|
|
@@ -28,7 +28,7 @@ const testDashboard = {
|
|
|
28
28
|
version: 0
|
|
29
29
|
},
|
|
30
30
|
spec: {
|
|
31
|
-
duration: '
|
|
31
|
+
duration: '5m',
|
|
32
32
|
variables: [
|
|
33
33
|
{
|
|
34
34
|
kind: 'TextVariable',
|
|
@@ -144,6 +144,7 @@ const testDashboard = {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
+
// This panel is referenced in more than one layout below
|
|
147
148
|
diskIO: {
|
|
148
149
|
kind: 'Panel',
|
|
149
150
|
spec: {
|
|
@@ -209,7 +210,10 @@ const testDashboard = {
|
|
|
209
210
|
kind: 'Grid',
|
|
210
211
|
spec: {
|
|
211
212
|
display: {
|
|
212
|
-
title: 'CPU Stats'
|
|
213
|
+
title: 'CPU Stats',
|
|
214
|
+
collapse: {
|
|
215
|
+
open: true
|
|
216
|
+
}
|
|
213
217
|
},
|
|
214
218
|
items: [
|
|
215
219
|
// First Row
|
|
@@ -221,6 +225,15 @@ const testDashboard = {
|
|
|
221
225
|
content: {
|
|
222
226
|
$ref: '#/spec/panels/cpu'
|
|
223
227
|
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
x: 0,
|
|
231
|
+
y: 5,
|
|
232
|
+
width: 6,
|
|
233
|
+
height: 2,
|
|
234
|
+
content: {
|
|
235
|
+
$ref: '#/spec/panels/diskIO'
|
|
236
|
+
}
|
|
224
237
|
}
|
|
225
238
|
]
|
|
226
239
|
}
|
|
@@ -230,6 +243,15 @@ const testDashboard = {
|
|
|
230
243
|
kind: 'Grid',
|
|
231
244
|
spec: {
|
|
232
245
|
items: [
|
|
246
|
+
{
|
|
247
|
+
x: 0,
|
|
248
|
+
y: 0,
|
|
249
|
+
width: 6,
|
|
250
|
+
height: 2,
|
|
251
|
+
content: {
|
|
252
|
+
$ref: '#/spec/panels/diskIO'
|
|
253
|
+
}
|
|
254
|
+
},
|
|
233
255
|
{
|
|
234
256
|
x: 8,
|
|
235
257
|
y: 0,
|
|
@@ -253,15 +275,6 @@ const testDashboard = {
|
|
|
253
275
|
}
|
|
254
276
|
},
|
|
255
277
|
items: [
|
|
256
|
-
{
|
|
257
|
-
x: 0,
|
|
258
|
-
y: 0,
|
|
259
|
-
width: 6,
|
|
260
|
-
height: 2,
|
|
261
|
-
content: {
|
|
262
|
-
$ref: '#/spec/panels/diskIO'
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
278
|
{
|
|
266
279
|
x: 18,
|
|
267
280
|
y: 0,
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./time-range-params"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
encodeTimeRangeValue: ()=>encodeTimeRangeValue,
|
|
25
|
+
decodeTimeRangeValue: ()=>decodeTimeRangeValue,
|
|
26
|
+
TimeRangeParam: ()=>TimeRangeParam,
|
|
27
|
+
timeRangeQueryConfig: ()=>timeRangeQueryConfig,
|
|
28
|
+
useInitialTimeRange: ()=>useInitialTimeRange,
|
|
29
|
+
useSetTimeRangeParams: ()=>useSetTimeRangeParams
|
|
30
|
+
});
|
|
31
|
+
const _react = require("react");
|
|
32
|
+
const _useQueryParams = require("use-query-params");
|
|
33
|
+
const _dateFns = require("date-fns");
|
|
34
|
+
const _core = require("@perses-dev/core");
|
|
35
|
+
/* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
|
|
36
|
+
if (input == null) {
|
|
37
|
+
return input;
|
|
38
|
+
}
|
|
39
|
+
// '' or []
|
|
40
|
+
if (input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const str = input instanceof Array ? input[0] : input;
|
|
44
|
+
if (str == null) {
|
|
45
|
+
return str;
|
|
46
|
+
}
|
|
47
|
+
if (!allowEmptyString && str === '') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return str;
|
|
51
|
+
}
|
|
52
|
+
function encodeTimeRangeValue(timeOptionValue) {
|
|
53
|
+
if (!timeOptionValue) {
|
|
54
|
+
return timeOptionValue;
|
|
55
|
+
}
|
|
56
|
+
if (typeof timeOptionValue === 'string') {
|
|
57
|
+
if ((0, _core.isDurationString)(timeOptionValue)) {
|
|
58
|
+
return timeOptionValue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return ((0, _dateFns.getUnixTime)(timeOptionValue) * 1000).toString();
|
|
62
|
+
}
|
|
63
|
+
function decodeTimeRangeValue(input) {
|
|
64
|
+
const paramString = getEncodedValue(input);
|
|
65
|
+
if (paramString == null) return paramString;
|
|
66
|
+
return (0, _core.isDurationString)(paramString) ? paramString : new Date(Number(paramString));
|
|
67
|
+
}
|
|
68
|
+
const TimeRangeParam = {
|
|
69
|
+
encode: encodeTimeRangeValue,
|
|
70
|
+
decode: decodeTimeRangeValue,
|
|
71
|
+
equals: (valueA, valueB)=>{
|
|
72
|
+
if (valueA === valueB) return true;
|
|
73
|
+
if (valueA == null || valueB == null) return valueA === valueB;
|
|
74
|
+
return valueA.valueOf() === valueB.valueOf();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const timeRangeQueryConfig = {
|
|
78
|
+
start: TimeRangeParam,
|
|
79
|
+
end: TimeRangeParam
|
|
80
|
+
};
|
|
81
|
+
function useInitialTimeRange(dashboardDuration) {
|
|
82
|
+
const [query] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig);
|
|
83
|
+
const { start , end } = query;
|
|
84
|
+
return (0, _react.useMemo)(()=>{
|
|
85
|
+
let initialTimeRange = {
|
|
86
|
+
pastDuration: dashboardDuration
|
|
87
|
+
};
|
|
88
|
+
if (!start) {
|
|
89
|
+
return initialTimeRange;
|
|
90
|
+
}
|
|
91
|
+
const startStr = start.toString();
|
|
92
|
+
if ((0, _core.isDurationString)(startStr)) {
|
|
93
|
+
initialTimeRange = {
|
|
94
|
+
pastDuration: startStr
|
|
95
|
+
};
|
|
96
|
+
} else if ((0, _dateFns.isDate)(start) && (0, _dateFns.isDate)(end)) {
|
|
97
|
+
initialTimeRange = {
|
|
98
|
+
start: start,
|
|
99
|
+
end: end
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return initialTimeRange;
|
|
103
|
+
}, [
|
|
104
|
+
start,
|
|
105
|
+
end,
|
|
106
|
+
dashboardDuration
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
function useSetTimeRangeParams(initialTimeRange, paramsEnabled = true) {
|
|
110
|
+
const [query, setQuery] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig);
|
|
111
|
+
// fallback when app does not want query string as source of truth
|
|
112
|
+
const [timeRangeState, setTimeRangeState] = (0, _react.useState)(initialTimeRange);
|
|
113
|
+
const { start } = query;
|
|
114
|
+
// set start param on page load if empty
|
|
115
|
+
if (paramsEnabled && !start) {
|
|
116
|
+
if ((0, _core.isRelativeTimeRange)(initialTimeRange)) {
|
|
117
|
+
setQuery({
|
|
118
|
+
start: initialTimeRange.pastDuration,
|
|
119
|
+
end: undefined
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const setTimeRange = (0, _react.useCallback)((value)=>{
|
|
124
|
+
if ((0, _core.isRelativeTimeRange)(value)) {
|
|
125
|
+
setQuery({
|
|
126
|
+
start: value.pastDuration,
|
|
127
|
+
end: undefined
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
setQuery(value);
|
|
131
|
+
}
|
|
132
|
+
}, [
|
|
133
|
+
setQuery
|
|
134
|
+
]);
|
|
135
|
+
if (!paramsEnabled) {
|
|
136
|
+
return {
|
|
137
|
+
timeRange: timeRangeState,
|
|
138
|
+
setTimeRange: setTimeRangeState
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
timeRange: initialTimeRange,
|
|
143
|
+
setTimeRange: setTimeRange
|
|
144
|
+
};
|
|
145
|
+
}
|