@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/time-range-params.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo, useCallback, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { TimeRange } from '@perses-dev/plugin-system';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig);\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set paramsEnabled to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, paramsEnabled = true): TimeRange {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig);\n\n // fallback when app does not want query string as source of truth\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n // set start param on page load if empty\n if (paramsEnabled && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n }\n }\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!paramsEnabled) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n"],"names":["useMemo","useCallback","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","useInitialTimeRange","dashboardDuration","query","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","paramsEnabled","setQuery","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACvD,SAASC,cAAc,QAA0B,kBAAkB,CAAC;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,UAAU,CAAC;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,QAGX,kBAAkB,CAAC;AAK1B,iGAAiG,GACjG,SAASC,eAAe,CACtBC,KAAuD,EACvDC,gBAA0B,EACC;IAC3B,IAAID,KAAK,IAAI,IAAI,EAAE;QACjB,OAAOA,KAAK,CAAC;IACf,CAAC;IACD,WAAW;IACX,IAAIA,KAAK,CAACE,MAAM,KAAK,CAAC,IAAK,CAAA,CAACD,gBAAgB,IAAKA,gBAAgB,IAAID,KAAK,KAAK,EAAE,AAAC,CAAA,AAAC,EAAE;QACnF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAMG,GAAG,GAAGH,KAAK,YAAYI,KAAK,GAAGJ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EAAkE;IAClE,MAAM,CAACY,cAAc,EAAEC,iBAAiB,CAAC,GAAGvC,QAAQ,CAAiBgC,gBAAgB,CAAC,AAAC;IAEvF,MAAM,EAAEL,KAAK,CAAA,EAAE,GAAGI,KAAK,AAAC;IAExB,wCAAwC;IACxC,IAAIK,aAAa,IAAI,CAACT,KAAK,EAAE;QAC3B,IAAIvB,mBAAmB,CAAC4B,gBAAgB,CAAC,EAAE;YACzCK,QAAQ,CAAC;gBAAEV,KAAK,EAAEK,gBAAgB,CAACC,YAAY;gBAAEL,GAAG,EAAEY,SAAS;aAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED,MAAMC,YAAY,GAA8B1C,WAAW,CACzD,CAAC2C,KAAqB,GAAK;QACzB,IAAItC,mBAAmB,CAACsC,KAAK,CAAC,EAAE;YAC9BL,QAAQ,CAAC;gBAAEV,KAAK,EAAEe,KAAK,CAACT,YAAY;gBAAEL,GAAG,EAAEY,SAAS;aAAE,CAAC,CAAC;QAC1D,OAAO;YACLH,QAAQ,CAACK,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,EACD;QAACL,QAAQ;KAAC,CACX,AAAC;IAEF,IAAI,CAACD,aAAa,EAAE;QAClB,OAAO;YAAEO,SAAS,EAAEL,cAAc;YAAEG,YAAY,EAAEF,iBAAiB;SAAE,CAAC;IACxE,CAAC;IACD,OAAO;QAAEI,SAAS,EAAEX,gBAAgB;QAAES,YAAY,EAAEA,YAAY;KAAE,CAAC;AACrE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,gBAyBpD,CAAC"}
|
|
@@ -13,14 +13,11 @@
|
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Box } from '@mui/material';
|
|
15
15
|
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
16
|
-
import { PanelDrawer, Dashboard } from '../../components';
|
|
17
|
-
import PanelGroupDialog from '../../components/PanelGroupDialog/PanelGroupDialog';
|
|
16
|
+
import { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog } from '../../components';
|
|
18
17
|
import { DashboardToolbar } from '../../components/DashboardToolbar';
|
|
19
|
-
import
|
|
18
|
+
import DeletePanelDialog from '../../components/Panel/DeletePanelDialog';
|
|
20
19
|
export const DashboardApp = (props)=>{
|
|
21
20
|
const { dashboardResource } = props;
|
|
22
|
-
const { dashboard } = useDashboard();
|
|
23
|
-
const { panelGroupDialog } = useDashboardApp();
|
|
24
21
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
25
22
|
sx: {
|
|
26
23
|
padding: (theme)=>theme.spacing(1, 0),
|
|
@@ -41,12 +38,12 @@ export const DashboardApp = (props)=>{
|
|
|
41
38
|
children: [
|
|
42
39
|
/*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
43
40
|
FallbackComponent: ErrorAlert,
|
|
44
|
-
children: /*#__PURE__*/ _jsx(Dashboard, {
|
|
45
|
-
spec: dashboard
|
|
46
|
-
})
|
|
41
|
+
children: /*#__PURE__*/ _jsx(Dashboard, {})
|
|
47
42
|
}),
|
|
48
43
|
/*#__PURE__*/ _jsx(PanelDrawer, {}),
|
|
49
|
-
|
|
44
|
+
/*#__PURE__*/ _jsx(PanelGroupDialog, {}),
|
|
45
|
+
/*#__PURE__*/ _jsx(DeletePanelGroupDialog, {}),
|
|
46
|
+
/*#__PURE__*/ _jsx(DeletePanelDialog, {})
|
|
50
47
|
]
|
|
51
48
|
})
|
|
52
49
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport { PanelDrawer, Dashboard
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport { PanelDrawer, Dashboard, PanelGroupDialog, DeletePanelGroupDialog } from '../../components';\nimport { DashboardToolbar } from '../../components/DashboardToolbar';\nimport DeletePanelDialog from '../../components/Panel/DeletePanelDialog';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n}\n\nexport const DashboardApp = (props: DashboardAppProps) => {\n const { dashboardResource } = props;\n return (\n <Box\n sx={{\n padding: (theme) => theme.spacing(1, 0),\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar dashboardName={dashboardResource.metadata.name} />\n <Box sx={{ padding: (theme) => theme.spacing(2) }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard />\n </ErrorBoundary>\n <PanelDrawer />\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n </Box>\n </Box>\n );\n};\n"],"names":["Box","ErrorAlert","ErrorBoundary","PanelDrawer","Dashboard","PanelGroupDialog","DeletePanelGroupDialog","DashboardToolbar","DeletePanelDialog","DashboardApp","props","dashboardResource","sx","padding","theme","spacing","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","metadata","name","FallbackComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AAEnE,SAASC,WAAW,EAAEC,SAAS,EAAEC,gBAAgB,EAAEC,sBAAsB,QAAQ,kBAAkB,CAAC;AACpG,SAASC,gBAAgB,QAAQ,mCAAmC,CAAC;AACrE,OAAOC,iBAAiB,MAAM,0CAA0C,CAAC;AAMzE,OAAO,MAAMC,YAAY,GAAG,CAACC,KAAwB,GAAK;IACxD,MAAM,EAAEC,iBAAiB,CAAA,EAAE,GAAGD,KAAK,AAAC;IACpC,qBACE,MAACV,GAAG;QACFY,EAAE,EAAE;YACFC,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;YACvCC,QAAQ,EAAE,CAAC;YACXC,SAAS,EAAE,QAAQ;YACnBC,SAAS,EAAE,MAAM;YACjBC,OAAO,EAAE,MAAM;YACfC,aAAa,EAAE,QAAQ;SACxB;;0BAED,KAACb,gBAAgB;gBAACc,aAAa,EAAEV,iBAAiB,CAACW,QAAQ,CAACC,IAAI;cAAI;0BACpE,MAACvB,GAAG;gBAACY,EAAE,EAAE;oBAAEC,OAAO,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;iBAAE;;kCAC/C,KAACb,aAAa;wBAACsB,iBAAiB,EAAEvB,UAAU;kCAC1C,cAAA,KAACG,SAAS,KAAG;sBACC;kCAChB,KAACD,WAAW,KAAG;kCACf,KAACE,gBAAgB,KAAG;kCACpB,KAACC,sBAAsB,KAAG;kCAC1B,KAACE,iBAAiB,KAAG;;cACjB;;MACF,CACN;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAIL,4BAA4B,EAE7B,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;IACpE,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAkCtD"}
|
|
@@ -11,38 +11,20 @@
|
|
|
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 { useEffect } from 'react';
|
|
15
14
|
import { Box } from '@mui/material';
|
|
16
|
-
import { getDefaultTimeRange } from '@perses-dev/core';
|
|
17
|
-
import { useQueryString } from '@perses-dev/plugin-system';
|
|
18
15
|
import { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';
|
|
19
16
|
import { TimeRangeProvider, TemplateVariableProvider, DashboardProvider, DatasourceStoreProvider } from '../../context';
|
|
17
|
+
import { useInitialTimeRange, useSetTimeRangeParams } from '../../utils';
|
|
20
18
|
import { DashboardApp } from './DashboardApp';
|
|
21
19
|
/**
|
|
22
20
|
* The View for displaying a Dashboard, along with the UI for selecting variable values.
|
|
23
21
|
*/ export function ViewDashboard(props) {
|
|
24
22
|
const { dashboardResource , datasourceApi , sx , ...others } = props;
|
|
25
23
|
const { spec } = dashboardResource;
|
|
26
|
-
const { queryString , setQueryString } = useQueryString();
|
|
27
24
|
var _duration;
|
|
28
25
|
const dashboardDuration = (_duration = spec.duration) !== null && _duration !== void 0 ? _duration : '1h';
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
useEffect(()=>{
|
|
32
|
-
const currentParams = Object.fromEntries([
|
|
33
|
-
...queryString
|
|
34
|
-
]);
|
|
35
|
-
// if app does not provide query string implementation, setTimeRange is used instead
|
|
36
|
-
if (!currentParams.start && setQueryString) {
|
|
37
|
-
// default to duration in dashboard definition if start param is not already set
|
|
38
|
-
queryString.set('start', dashboardDuration);
|
|
39
|
-
setQueryString(queryString);
|
|
40
|
-
}
|
|
41
|
-
}, [
|
|
42
|
-
dashboardDuration,
|
|
43
|
-
queryString,
|
|
44
|
-
setQueryString
|
|
45
|
-
]);
|
|
26
|
+
const initialTimeRange = useInitialTimeRange(dashboardDuration);
|
|
27
|
+
const { timeRange , setTimeRange } = useSetTimeRangeParams(initialTimeRange, true);
|
|
46
28
|
return /*#__PURE__*/ _jsx(DatasourceStoreProvider, {
|
|
47
29
|
dashboardResource: dashboardResource,
|
|
48
30
|
datasourceApi: datasourceApi,
|
|
@@ -51,7 +33,8 @@ import { DashboardApp } from './DashboardApp';
|
|
|
51
33
|
dashboardSpec: spec
|
|
52
34
|
},
|
|
53
35
|
children: /*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
54
|
-
|
|
36
|
+
timeRange: timeRange,
|
|
37
|
+
setTimeRange: setTimeRange,
|
|
55
38
|
children: /*#__PURE__*/ _jsx(TemplateVariableProvider, {
|
|
56
39
|
initialVariableDefinitions: spec.variables,
|
|
57
40
|
children: /*#__PURE__*/ _jsx(Box, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ViewDashboard/ViewDashboard.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, BoxProps } from '@mui/material';\nimport { DashboardResource } from '@perses-dev/core';\nimport { ErrorBoundary, ErrorAlert, combineSx } from '@perses-dev/components';\nimport {\n TimeRangeProvider,\n TemplateVariableProvider,\n DashboardProvider,\n DatasourceStoreProviderProps,\n DatasourceStoreProvider,\n} from '../../context';\nimport { useInitialTimeRange, useSetTimeRangeParams } from '../../utils';\nimport { DashboardApp } from './DashboardApp';\n\nexport interface ViewDashboardProps extends Omit<BoxProps, 'children'> {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceStoreProviderProps['datasourceApi'];\n}\n\n/**\n * The View for displaying a Dashboard, along with the UI for selecting variable values.\n */\nexport function ViewDashboard(props: ViewDashboardProps) {\n const { dashboardResource, datasourceApi, sx, ...others } = props;\n const { spec } = dashboardResource;\n const dashboardDuration = spec.duration ?? '1h';\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, true);\n\n return (\n <DatasourceStoreProvider dashboardResource={dashboardResource} datasourceApi={datasourceApi}>\n <DashboardProvider initialState={{ dashboardSpec: spec }}>\n <TimeRangeProvider timeRange={timeRange} setTimeRange={setTimeRange}>\n <TemplateVariableProvider initialVariableDefinitions={spec.variables}>\n <Box\n sx={combineSx(\n {\n display: 'flex',\n width: '100%',\n height: '100%',\n position: 'relative',\n overflow: 'hidden',\n },\n sx\n )}\n {...others}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardApp dashboardResource={dashboardResource} />\n </ErrorBoundary>\n </Box>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n </DashboardProvider>\n </DatasourceStoreProvider>\n );\n}\n"],"names":["Box","ErrorBoundary","ErrorAlert","combineSx","TimeRangeProvider","TemplateVariableProvider","DashboardProvider","DatasourceStoreProvider","useInitialTimeRange","useSetTimeRangeParams","DashboardApp","ViewDashboard","props","dashboardResource","datasourceApi","sx","others","spec","dashboardDuration","duration","initialTimeRange","timeRange","setTimeRange","initialState","dashboardSpec","initialVariableDefinitions","variables","display","width","height","position","overflow","FallbackComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CA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0BAA0B,EAAER,IAAI,CAACS,SAAS;8BAClE,cAAA,KAAC1B,GAAG;wBACFe,EAAE,EAAEZ,SAAS,CACX;4BACEwB,OAAO,EAAE,MAAM;4BACfC,KAAK,EAAE,MAAM;4BACbC,MAAM,EAAE,MAAM;4BACdC,QAAQ,EAAE,UAAU;4BACpBC,QAAQ,EAAE,QAAQ;yBACnB,EACDhB,EAAE,CACH;wBACA,GAAGC,MAAM;kCAEV,cAAA,KAACf,aAAa;4BAAC+B,iBAAiB,EAAE9B,UAAU;sCAC1C,cAAA,KAACQ,YAAY;gCAACG,iBAAiB,EAAEA,iBAAiB;8BAAI;0BACxC;sBACZ;kBACmB;cACT;UACF;MACI,CAC1B;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panelGroups.test.d.ts","sourceRoot":"","sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { screen } from '@testing-library/react';
|
|
15
|
+
import userEvent from '@testing-library/user-event';
|
|
16
|
+
import { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';
|
|
17
|
+
import { getTestDashboard, renderWithContext } from '../../../test';
|
|
18
|
+
import { DashboardApp } from '../DashboardApp';
|
|
19
|
+
describe('Panel Groups', ()=>{
|
|
20
|
+
const renderDashboard = ()=>{
|
|
21
|
+
renderWithContext(/*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
22
|
+
timeRange: {
|
|
23
|
+
pastDuration: '30m'
|
|
24
|
+
},
|
|
25
|
+
children: /*#__PURE__*/ _jsx(TemplateVariableProvider, {
|
|
26
|
+
children: /*#__PURE__*/ _jsx(DashboardProvider, {
|
|
27
|
+
initialState: {
|
|
28
|
+
dashboardSpec: getTestDashboard().spec,
|
|
29
|
+
isEditMode: true
|
|
30
|
+
},
|
|
31
|
+
children: /*#__PURE__*/ _jsx(DashboardApp, {
|
|
32
|
+
dashboardResource: getTestDashboard()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
38
|
+
it('should delete panel', ()=>{
|
|
39
|
+
renderDashboard();
|
|
40
|
+
const panel = screen.getByText('CPU');
|
|
41
|
+
userEvent.hover(panel);
|
|
42
|
+
const deletePanelButton = screen.getByLabelText('delete panel');
|
|
43
|
+
userEvent.click(deletePanelButton);
|
|
44
|
+
screen.getByText('Delete Panel');
|
|
45
|
+
const deleteButton = screen.getByText('Delete');
|
|
46
|
+
userEvent.click(deleteButton);
|
|
47
|
+
// The panel should disappear
|
|
48
|
+
const deletedPanel = screen.queryByText('CPU');
|
|
49
|
+
expect(deletedPanel).not.toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
|
|
52
|
+
renderDashboard();
|
|
53
|
+
const panels = screen.getAllByText('Disk I/O Utilization');
|
|
54
|
+
expect(panels).toHaveLength(2);
|
|
55
|
+
const panel = panels[0];
|
|
56
|
+
if (panel === undefined) throw new Error('Missing panel');
|
|
57
|
+
userEvent.hover(panel);
|
|
58
|
+
const deletePanelButton = screen.getByLabelText('delete panel');
|
|
59
|
+
userEvent.click(deletePanelButton);
|
|
60
|
+
screen.getByText('Delete Panel');
|
|
61
|
+
const deleteButton = screen.getByText('Delete');
|
|
62
|
+
userEvent.click(deleteButton);
|
|
63
|
+
// The deleted panel should still be on screen in the other group
|
|
64
|
+
const deletedPanel = screen.queryByText('Disk I/O Utilization');
|
|
65
|
+
expect(deletedPanel).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
it('should swap panels', ()=>{
|
|
68
|
+
renderDashboard();
|
|
69
|
+
// should move panel down
|
|
70
|
+
const group1 = screen.getByText('CPU Stats');
|
|
71
|
+
userEvent.hover(group1);
|
|
72
|
+
const moveGroupDownBtn = screen.getByLabelText('move group down');
|
|
73
|
+
userEvent.click(moveGroupDownBtn);
|
|
74
|
+
userEvent.unhover(moveGroupDownBtn);
|
|
75
|
+
// should move panel up
|
|
76
|
+
const group2 = screen.getByText('Disk Stats');
|
|
77
|
+
userEvent.hover(group2);
|
|
78
|
+
const moveGroupUpBtn = screen.getByLabelText('move group up');
|
|
79
|
+
userEvent.click(moveGroupUpBtn);
|
|
80
|
+
/* TODO: Figure out how to test this visually without coupling to the store
|
|
81
|
+
const layouts = storeApi.getState().layouts;
|
|
82
|
+
expect(layouts[0]?.title).toBe(undefined);
|
|
83
|
+
expect(layouts[1]?.title).toBe('Disk Stats');
|
|
84
|
+
expect(layouts[2]?.title).toBe('CPU Stats');
|
|
85
|
+
*/ });
|
|
86
|
+
it('should delete a panel group', ()=>{
|
|
87
|
+
renderDashboard();
|
|
88
|
+
const group = screen.getByText('CPU Stats');
|
|
89
|
+
userEvent.hover(group);
|
|
90
|
+
const deleteGroupIcon = screen.getByLabelText('delete group');
|
|
91
|
+
userEvent.click(deleteGroupIcon);
|
|
92
|
+
screen.getByText('Delete Panel Group');
|
|
93
|
+
const deleteButton = screen.getByText('Delete');
|
|
94
|
+
userEvent.click(deleteButton);
|
|
95
|
+
// should remove group
|
|
96
|
+
const deletedGroup = screen.queryByText('CPU Stats');
|
|
97
|
+
expect(deletedGroup).not.toBeInTheDocument();
|
|
98
|
+
// CPU panel should be completely gone since it wasn't in any other group
|
|
99
|
+
let panel = screen.queryByText('CPU');
|
|
100
|
+
expect(panel).not.toBeInTheDocument();
|
|
101
|
+
// A DiskIO panel should still be present in the other group that wasn't deleted
|
|
102
|
+
panel = screen.queryByText('Disk I/O Utilization');
|
|
103
|
+
expect(panel).toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=panelGroups.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/ViewDashboard/tests/panelGroups.test.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 { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { DashboardProvider, TemplateVariableProvider, TimeRangeProvider } from '../../../context';\nimport { getTestDashboard, renderWithContext } from '../../../test';\nimport { DashboardApp } from '../DashboardApp';\n\ndescribe('Panel Groups', () => {\n const renderDashboard = () => {\n renderWithContext(\n <TimeRangeProvider timeRange={{ pastDuration: '30m' }}>\n <TemplateVariableProvider>\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode: true }}>\n <DashboardApp dashboardResource={getTestDashboard()} />\n </DashboardProvider>\n </TemplateVariableProvider>\n </TimeRangeProvider>\n );\n };\n it('should delete panel', () => {\n renderDashboard();\n const panel = screen.getByText('CPU');\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The panel should disappear\n const deletedPanel = screen.queryByText('CPU');\n expect(deletedPanel).not.toBeInTheDocument();\n });\n\n it('should only delete panel from panel group if panel is not referenced more than once', () => {\n renderDashboard();\n\n const panels = screen.getAllByText('Disk I/O Utilization');\n expect(panels).toHaveLength(2);\n\n const panel = panels[0];\n if (panel === undefined) throw new Error('Missing panel');\n\n userEvent.hover(panel);\n const deletePanelButton = screen.getByLabelText('delete panel');\n userEvent.click(deletePanelButton);\n screen.getByText('Delete Panel');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // The deleted panel should still be on screen in the other group\n const deletedPanel = screen.queryByText('Disk I/O Utilization');\n expect(deletedPanel).toBeInTheDocument();\n });\n\n it('should swap panels', () => {\n renderDashboard();\n\n // should move panel down\n const group1 = screen.getByText('CPU Stats');\n userEvent.hover(group1);\n const moveGroupDownBtn = screen.getByLabelText('move group down');\n userEvent.click(moveGroupDownBtn);\n userEvent.unhover(moveGroupDownBtn);\n\n // should move panel up\n const group2 = screen.getByText('Disk Stats');\n userEvent.hover(group2);\n const moveGroupUpBtn = screen.getByLabelText('move group up');\n userEvent.click(moveGroupUpBtn);\n\n /* TODO: Figure out how to test this visually without coupling to the store\n const layouts = storeApi.getState().layouts;\n expect(layouts[0]?.title).toBe(undefined);\n expect(layouts[1]?.title).toBe('Disk Stats');\n expect(layouts[2]?.title).toBe('CPU Stats');\n */\n });\n\n it('should delete a panel group', () => {\n renderDashboard();\n const group = screen.getByText('CPU Stats');\n userEvent.hover(group);\n const deleteGroupIcon = screen.getByLabelText('delete group');\n userEvent.click(deleteGroupIcon);\n screen.getByText('Delete Panel Group');\n const deleteButton = screen.getByText('Delete');\n userEvent.click(deleteButton);\n\n // should remove group\n const deletedGroup = screen.queryByText('CPU Stats');\n expect(deletedGroup).not.toBeInTheDocument();\n\n // CPU panel should be completely gone since it wasn't in any other group\n let panel = screen.queryByText('CPU');\n expect(panel).not.toBeInTheDocument();\n\n // A DiskIO panel should still be present in the other group that wasn't deleted\n panel = screen.queryByText('Disk I/O Utilization');\n expect(panel).toBeInTheDocument();\n });\n});\n"],"names":["screen","userEvent","DashboardProvider","TemplateVariableProvider","TimeRangeProvider","getTestDashboard","renderWithContext","DashboardApp","describe","renderDashboard","timeRange","pastDuration","initialState","dashboardSpec","spec","isEditMode","dashboardResource","it","panel","getByText","hover","deletePanelButton","getByLabelText","click","deleteButton","deletedPanel","queryByText","expect","not","toBeInTheDocument","panels","getAllByText","toHaveLength","undefined","Error","group1","moveGroupDownBtn","unhover","group2","moveGroupUpBtn","group","deleteGroupIcon","deletedGroup"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,iBAAiB,EAAEC,wBAAwB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAClG,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AACpE,SAASC,YAAY,QAAQ,iBAAiB,CAAC;AAE/CC,QAAQ,CAAC,cAAc,EAAE,IAAM;IAC7B,MAAMC,eAAe,GAAG,IAAM;QAC5BH,iBAAiB,eACf,KAACF,iBAAiB;YAACM,SAAS,EAAE;gBAAEC,YAAY,EAAE,KAAK;aAAE;sBACnD,cAAA,KAACR,wBAAwB;0BACvB,cAAA,KAACD,iBAAiB;oBAACU,YAAY,EAAE;wBAAEC,aAAa,EAAER,gBAAgB,EAAE,CAACS,IAAI;wBAAEC,UAAU,EAAE,IAAI;qBAAE;8BAC3F,cAAA,KAACR,YAAY;wBAACS,iBAAiB,EAAEX,gBAAgB,EAAE;sBAAI;kBACrC;cACK;UACT,CACrB,CAAC;I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B,MAAMC,eAAe,GAAGzC,MAAM,CAACsB,cAAc,CAAC,cAAc,CAAC,AAAC;QAC9DrB,SAAS,CAACsB,KAAK,CAACkB,eAAe,CAAC,CAAC;QACjCzC,MAAM,CAACmB,SAAS,CAAC,oBAAoB,CAAC,CAAC;QACvC,MAAMK,YAAY,GAAGxB,MAAM,CAACmB,SAAS,CAAC,QAAQ,CAAC,AAAC;QAChDlB,SAAS,CAACsB,KAAK,CAACC,YAAY,CAAC,CAAC;QAE9B,sBAAsB;QACtB,MAAMkB,YAAY,GAAG1C,MAAM,CAAC0B,WAAW,CAAC,WAAW,CAAC,AAAC;QACrDC,MAAM,CAACe,YAAY,CAAC,CAACd,GAAG,CAACC,iBAAiB,EAAE,CAAC;QAE7C,yEAAyE;QACzE,IAAIX,KAAK,GAAGlB,MAAM,CAAC0B,WAAW,CAAC,KAAK,CAAC,AAAC;QACtCC,MAAM,CAACT,KAAK,CAAC,CAACU,GAAG,CAACC,iBAAiB,EAAE,CAAC;QAEtC,gFAAgF;QAChFX,KAAK,GAAGlB,MAAM,CAAC0B,WAAW,CAAC,sBAAsB,CAAC,CAAC;QACnDC,MAAM,CAACT,KAAK,CAAC,CAACW,iBAAiB,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/dashboards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "The dashboards feature in Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@perses-dev/components": "^0.
|
|
31
|
-
"@perses-dev/core": "^0.
|
|
32
|
-
"@perses-dev/plugin-system": "^0.
|
|
30
|
+
"@perses-dev/components": "^0.11.0",
|
|
31
|
+
"@perses-dev/core": "^0.11.0",
|
|
32
|
+
"@perses-dev/plugin-system": "^0.11.0",
|
|
33
33
|
"@types/react-grid-layout": "^1.3.2",
|
|
34
34
|
"date-fns": "^2.28.0",
|
|
35
35
|
"immer": "^9.0.15",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"react-grid-layout": "^1.3.4",
|
|
38
38
|
"react-intersection-observer": "^9.4.0",
|
|
39
39
|
"use-immer": "^0.7.0",
|
|
40
|
+
"use-query-params": "^2.1.1",
|
|
40
41
|
"use-resize-observer": "^9.0.0",
|
|
41
42
|
"zustand": "^4.1.1"
|
|
42
43
|
},
|
|
@@ -1,40 +0,0 @@
|
|
|
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, "PanelSpecEditor", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: ()=>PanelSpecEditor
|
|
20
|
-
});
|
|
21
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
23
|
-
function PanelSpecEditor(props) {
|
|
24
|
-
const { panelPluginKind , ...others } = props;
|
|
25
|
-
const { data: plugin , isLoading } = (0, _pluginSystem.usePlugin)('Panel', panelPluginKind, {
|
|
26
|
-
useErrorBoundary: true,
|
|
27
|
-
enabled: panelPluginKind !== ''
|
|
28
|
-
});
|
|
29
|
-
// TODO: Proper loading indicator
|
|
30
|
-
if (isLoading) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
if (plugin === undefined) {
|
|
34
|
-
throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);
|
|
35
|
-
}
|
|
36
|
-
const { OptionsEditorComponent } = plugin;
|
|
37
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(OptionsEditorComponent, {
|
|
38
|
-
...others
|
|
39
|
-
});
|
|
40
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
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, "PanelTypeSelect", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: ()=>PanelTypeSelect
|
|
20
|
-
});
|
|
21
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _material = require("@mui/material");
|
|
23
|
-
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
24
|
-
function PanelTypeSelect(props) {
|
|
25
|
-
const { value: propValue , ...others } = props;
|
|
26
|
-
const { data , isLoading } = (0, _pluginSystem.useListPluginMetadata)('Panel');
|
|
27
|
-
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
28
|
-
const value = propValue !== '' && isLoading ? '' : propValue;
|
|
29
|
-
// TODO: Does this need a loading indicator of some kind?
|
|
30
|
-
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
|
|
31
|
-
...others,
|
|
32
|
-
value: value,
|
|
33
|
-
children: data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
34
|
-
value: metadata.kind,
|
|
35
|
-
children: metadata.display.name
|
|
36
|
-
}, metadata.kind))
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
usePanelDrawerModel: ()=>usePanelDrawerModel,
|
|
25
|
-
usePanelSpecState: ()=>usePanelSpecState
|
|
26
|
-
});
|
|
27
|
-
const _react = require("react");
|
|
28
|
-
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
29
|
-
const _useImmer = require("use-immer");
|
|
30
|
-
const _context = require("../../context");
|
|
31
|
-
const _functions = require("../../utils/functions");
|
|
32
|
-
function usePanelDrawerModel() {
|
|
33
|
-
const { panelDrawer } = (0, _context.useDashboardApp)();
|
|
34
|
-
const { panels , updatePanel } = (0, _context.usePanels)();
|
|
35
|
-
// If we're closed, no model to return
|
|
36
|
-
if (panelDrawer === undefined) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
// If we don't have a panel key, we're adding a new panel
|
|
40
|
-
const { panelKey , groupIndex } = panelDrawer;
|
|
41
|
-
if (panelKey === undefined) {
|
|
42
|
-
return {
|
|
43
|
-
drawerTitle: 'Add Panel',
|
|
44
|
-
submitButtonText: 'Add',
|
|
45
|
-
initialValues: {
|
|
46
|
-
name: '',
|
|
47
|
-
description: '',
|
|
48
|
-
group: groupIndex !== null && groupIndex !== void 0 ? groupIndex : 0,
|
|
49
|
-
kind: '',
|
|
50
|
-
spec: {}
|
|
51
|
-
},
|
|
52
|
-
applyChanges: (values)=>{
|
|
53
|
-
const { name , description , group , kind , spec } = values;
|
|
54
|
-
const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(name);
|
|
55
|
-
updatePanel(panelKey, {
|
|
56
|
-
kind: 'Panel',
|
|
57
|
-
spec: {
|
|
58
|
-
display: {
|
|
59
|
-
name,
|
|
60
|
-
description
|
|
61
|
-
},
|
|
62
|
-
plugin: {
|
|
63
|
-
kind,
|
|
64
|
-
spec
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, group);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
// Otherwise we have a panel key, so we're trying to edit an existing panel
|
|
72
|
-
const existingPanel = panels[panelKey];
|
|
73
|
-
// TODO: Can we better express this via the type system on the dashboard store to avoid these states?
|
|
74
|
-
if (existingPanel === undefined) {
|
|
75
|
-
throw new Error(`Cannot find existing panel '${panelKey}' to edit`);
|
|
76
|
-
}
|
|
77
|
-
if (groupIndex === undefined) {
|
|
78
|
-
throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);
|
|
79
|
-
}
|
|
80
|
-
var _description;
|
|
81
|
-
return {
|
|
82
|
-
drawerTitle: 'Edit Panel',
|
|
83
|
-
submitButtonText: 'Apply',
|
|
84
|
-
initialValues: {
|
|
85
|
-
name: existingPanel.spec.display.name,
|
|
86
|
-
description: (_description = existingPanel.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
87
|
-
group: groupIndex,
|
|
88
|
-
kind: existingPanel.spec.plugin.kind,
|
|
89
|
-
spec: existingPanel.spec.plugin.spec
|
|
90
|
-
},
|
|
91
|
-
applyChanges: (values)=>{
|
|
92
|
-
const { name , description , group , kind , spec } = values;
|
|
93
|
-
updatePanel(panelKey, {
|
|
94
|
-
kind: 'Panel',
|
|
95
|
-
spec: {
|
|
96
|
-
display: {
|
|
97
|
-
name,
|
|
98
|
-
description
|
|
99
|
-
},
|
|
100
|
-
plugin: {
|
|
101
|
-
kind,
|
|
102
|
-
spec
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
if (group !== groupIndex) {
|
|
107
|
-
// TO DO: need to move panel if panel group changes
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function usePanelSpecState(panelPluginKind, initialState) {
|
|
113
|
-
// Keeping track of spec values by kind allows users to switch between panel types and come back with their old
|
|
114
|
-
// values intact from before the switch
|
|
115
|
-
const [specByKind, setSpecByKind] = (0, _useImmer.useImmer)({
|
|
116
|
-
[panelPluginKind]: initialState
|
|
117
|
-
});
|
|
118
|
-
const { data: plugin } = (0, _pluginSystem.usePlugin)('Panel', panelPluginKind, {
|
|
119
|
-
enabled: panelPluginKind !== ''
|
|
120
|
-
});
|
|
121
|
-
const pluginInitialSpec = (0, _react.useMemo)(()=>{
|
|
122
|
-
return plugin === null || plugin === void 0 ? void 0 : plugin.createInitialOptions();
|
|
123
|
-
}, [
|
|
124
|
-
plugin
|
|
125
|
-
]);
|
|
126
|
-
var _panelPluginKind;
|
|
127
|
-
// Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)
|
|
128
|
-
const spec = (_panelPluginKind = specByKind[panelPluginKind]) !== null && _panelPluginKind !== void 0 ? _panelPluginKind : pluginInitialSpec;
|
|
129
|
-
// TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the
|
|
130
|
-
// current "onChange" API?
|
|
131
|
-
const onSpecChange = (next)=>{
|
|
132
|
-
setSpecByKind((draft)=>{
|
|
133
|
-
draft[panelPluginKind] = next;
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
return {
|
|
137
|
-
spec,
|
|
138
|
-
onSpecChange
|
|
139
|
-
};
|
|
140
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
createDashboardAppSlice: ()=>createDashboardAppSlice,
|
|
25
|
-
useDashboardApp: ()=>useDashboardApp
|
|
26
|
-
});
|
|
27
|
-
const _immer = require("zustand/middleware/immer");
|
|
28
|
-
const _dashboardProvider = require("./DashboardProvider");
|
|
29
|
-
const createDashboardAppSlice = (0, _immer.immer)((set)=>({
|
|
30
|
-
openPanelDrawer: ({ groupIndex , panelKey })=>set((state)=>{
|
|
31
|
-
state.panelDrawer = {
|
|
32
|
-
groupIndex,
|
|
33
|
-
panelKey
|
|
34
|
-
};
|
|
35
|
-
}),
|
|
36
|
-
closePanelDrawer: ()=>set((state)=>{
|
|
37
|
-
state.panelDrawer = undefined;
|
|
38
|
-
}),
|
|
39
|
-
openPanelGroupDialog: (groupIndex)=>set((state)=>{
|
|
40
|
-
state.panelGroupDialog = {
|
|
41
|
-
groupIndex
|
|
42
|
-
};
|
|
43
|
-
}),
|
|
44
|
-
closePanelGroupDialog: ()=>set((state)=>{
|
|
45
|
-
state.panelGroupDialog = undefined;
|
|
46
|
-
})
|
|
47
|
-
}));
|
|
48
|
-
function useDashboardApp() {
|
|
49
|
-
return (0, _dashboardProvider.useDashboardStore)(({ panelDrawer , openPanelDrawer , closePanelDrawer , panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , })=>({
|
|
50
|
-
panelDrawer,
|
|
51
|
-
openPanelDrawer,
|
|
52
|
-
closePanelDrawer,
|
|
53
|
-
panelGroupDialog,
|
|
54
|
-
openPanelGroupDialog,
|
|
55
|
-
closePanelGroupDialog
|
|
56
|
-
}));
|
|
57
|
-
}
|