@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/context/DashboardProvider/panel-group-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, getPanelKeyFromRef, GridItemDefinition, LayoutDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelEditorSlice } from './panel-editor-slice';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupIdOrder: PanelGroupId[];\n\n /**\n * previous state\n */\n previousPanelGroupStates: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'];\n };\n\n // TODO: Remove this\n createPanelGroupId: () => PanelGroupId;\n\n /**\n * Given a LayoutItem location, returns the panel's unique key at that location.\n */\n getPanelKey: (layoutItem: PanelGroupItemId) => string;\n\n /**\n * Add a panel with the specified key to an existing group.\n */\n addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;\n\n /**\n * Move an existing Panel to a new panel group.\n */\n movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n\n /**\n * Delete panel in panel group\n */\n deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;\n\n /**\n * Map panel to panel groups\n */\n mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n items: GridItemDefinition[];\n isCollapsed: boolean;\n title?: string;\n}\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n itemIndex: number;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice & PanelEditorSlice, Middleware, [], PanelGroupSlice> {\n // Helper function for generating unique IDs for a PanelGroup\n let id: PanelGroupId = -1;\n function createPanelGroupId(): PanelGroupId {\n id++;\n return id;\n }\n\n // Convert the initial layouts from the JSON to panel groups and keep track of the order\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'] = [];\n for (const layout of layouts) {\n const id = createPanelGroupId();\n panelGroups[id] = {\n id,\n items: layout.spec.items,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n };\n panelGroupIdOrder.push(id);\n }\n\n // Return the state creator function for Zustand\n return (set, get) => ({\n panelGroups,\n panelGroupIdOrder,\n\n previousPanelGroupStates: { panelGroups, panelGroupIdOrder },\n\n // TODO: Reorder init logic so this isn't exposed\n createPanelGroupId,\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupStates = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupIdOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupStates.panelGroups;\n state.panelGroupIdOrder = state.previousPanelGroupStates.panelGroupIdOrder;\n });\n },\n\n getPanelKey({ panelGroupId, itemIndex }) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n return getPanelKeyFromRef(item.content);\n },\n\n addPanelToGroup(panelKey, panelGroupId) {\n const { panelGroups } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const gridItem: GridItemDefinition = {\n x: 0,\n y: getYForNewRow(group),\n width: 12,\n height: 6,\n content: createPanelRef(panelKey),\n };\n set((state) => {\n state.panelGroups[panelGroupId]?.items.push(gridItem);\n });\n },\n\n movePanelToGroup({ panelGroupId, itemIndex }, newPanelGroupId) {\n const { panelGroups } = get();\n\n // Find the existing item to make sure it exists\n const group = findGroup(panelGroups, panelGroupId);\n const item = findItem(group, itemIndex);\n\n // Find the new group and figure out where a new row should go\n const newGroup = findGroup(panelGroups, newPanelGroupId);\n const newGroupY = getYForNewRow(newGroup);\n\n set((state) => {\n // Remove the item from its current group\n state.panelGroups[panelGroupId]?.items.splice(itemIndex, 1);\n\n // Add a new item to the new group\n state.panelGroups[newPanelGroupId]?.items.push({\n x: 0,\n y: newGroupY,\n width: item.width,\n height: item.height,\n content: item.content,\n });\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupIdOrder.length || y < 0 || y >= state.panelGroupIdOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupIdOrder[x];\n const yPanelGroup = state.panelGroupIdOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupIdOrder[x], state.panelGroupIdOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n deletePanelInPanelGroup({ panelGroupId, itemIndex }) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`No panel group found: ${panelGroupId}`);\n }\n // remove panel from panel group\n group.items.splice(itemIndex, 1);\n });\n },\n\n deletePanelGroup(panelGroupId) {\n const { panelGroups, panelGroupIdOrder: panelGroupOrder, deletePanels } = get();\n const group = findGroup(panelGroups, panelGroupId);\n const orderIdx = panelGroupOrder.findIndex((id) => id === panelGroupId);\n if (orderIdx === -1) {\n throw new Error(`Could not find panel group Id ${panelGroupId} in order array`);\n }\n\n // remove panels from group first\n const panelsToBeDeleted: PanelGroupItemId[] = [];\n for (let i = 0; i < group.items.length; i++) {\n panelsToBeDeleted.push({ panelGroupId, itemIndex: i });\n }\n deletePanels(panelsToBeDeleted);\n\n // remove group from both panelGroups and panelGroupOrder\n set((state) => {\n state.panelGroupIdOrder.splice(orderIdx, 1);\n delete state.panelGroups[panelGroupId];\n });\n },\n\n // Return an object that maps each panel to the groups it belongs\n mapPanelToPanelGroups() {\n const map: Record<string, Array<PanelGroupDefinition['id']>> = {}; // { panel key: [group ids] }\n Object.values(get().panelGroups).forEach((group) => {\n // for each panel in a group, add the group id to map[panelKey]\n group.items.forEach((panel) => {\n const panelKey = getPanelKeyFromRef(panel.content);\n if (map[panelKey]) {\n map[panelKey]?.push(group.id);\n } else {\n map[panelKey] = [group.id];\n }\n });\n });\n return map;\n },\n });\n}\n\n// Helper to find a group and throw if not found\nfunction findGroup(panelGroups: PanelGroupSlice['panelGroups'], groupId: PanelGroupId) {\n const group = panelGroups[groupId];\n if (group === undefined) {\n throw new Error(`No panel group found for Id ${groupId}`);\n }\n return group;\n}\n\n// Helper to get an item in a group and throw if not found\nfunction findItem(group: PanelGroupDefinition, itemIndex: number) {\n const item = group.items[itemIndex];\n if (item === undefined) {\n throw new Error(`No grid item found at position ${itemIndex}`);\n }\n return item;\n}\n\n// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const item of group.items) {\n const itemMaxY = item.y + item.height;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["createPanelRef","getPanelKeyFromRef","createPanelGroupSlice","layouts","id","createPanelGroupId","panelGroups","panelGroupIdOrder","layout","items","spec","isCollapsed","display","collapse","open","title","push","set","get","previousPanelGroupStates","savePanelGroups","state","resetPanelGroups","getPanelKey","panelGroupId","itemIndex","group","findGroup","item","findItem","content","addPanelToGroup","panelKey","gridItem","x","y","getYForNewRow","width","height","movePanelToGroup","newPanelGroupId","newGroup","newGroupY","splice","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","deletePanelInPanelGroup","deletePanelGroup","panelGroupOrder","deletePanels","orderIdx","findIndex","panelsToBeDeleted","i","mapPanelToPanelGroups","map","Object","values","forEach","panel","groupId","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,EAAEC,kBAAkB,QAA8C,kBAAkB,CAAC;AA6F5G;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACwD;IACnF,6DAA6D;IAC7D,IAAIC,EAAE,GAAiB,CAAC,CAAC,AAAC;IAC1B,SAASC,kBAAkB,GAAiB;QAC1CD,EAAE,EAAE,CAAC;QACL,OAAOA,EAAE,CAAC;IACZ,CAAC;IAED,wFAAwF;IACxF,MAAME,WAAW,GAAmC,EAAE,AAAC;IACvD,MAAMC,iBAAiB,GAAyC,EAAE,AAAC;IACnE,KAAK,MAAMC,MAAM,IAAIL,OAAO,CAAE;YAKbK,GAAmB,QACzBA,IAAmB;QAL5B,MAAMJ,GAAE,GAAGC,kBAAkB,EAAE,AAAC;QAChCC,WAAW,CAACF,GAAE,CAAC,GAAG;YAChBA,EAAE,EAAFA,GAAE;YACFK,KAAK,EAAED,MAAM,CAACE,IAAI,CAACD,KAAK;YACxBE,WAAW,EAAEH,CAAAA,CAA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16 @@ export interface DatasourceStoreProviderProps {
|
|
|
6
6
|
children?: React.ReactNode;
|
|
7
7
|
}
|
|
8
8
|
export interface DatasourceApi {
|
|
9
|
-
getDatasource: (project: string, selector: DatasourceSelector) => Promise<
|
|
10
|
-
|
|
9
|
+
getDatasource: (project: string, selector: DatasourceSelector) => Promise<{
|
|
10
|
+
resource: Datasource;
|
|
11
|
+
proxyUrl: string;
|
|
12
|
+
} | undefined>;
|
|
13
|
+
getGlobalDatasource: (selector: DatasourceSelector) => Promise<{
|
|
14
|
+
resource: GlobalDatasource;
|
|
15
|
+
proxyUrl: string;
|
|
16
|
+
} | undefined>;
|
|
17
|
+
listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;
|
|
18
|
+
listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
21
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,EACL,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAElB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,EACL,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAElB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAGD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAErE,mBAAmB,EAAE,CACnB,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAE3E,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEjF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,eAkG1E"}
|
|
@@ -11,37 +11,105 @@
|
|
|
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 { useMemo } from 'react';
|
|
14
|
+
import { useCallback, useMemo } from 'react';
|
|
15
15
|
import { useEvent } from '@perses-dev/core';
|
|
16
|
-
import { DatasourceStoreContext } from '@perses-dev/plugin-system';
|
|
16
|
+
import { DatasourceStoreContext, usePluginRegistry } from '@perses-dev/plugin-system';
|
|
17
17
|
/**
|
|
18
18
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
19
19
|
*/ export function DatasourceStoreProvider(props) {
|
|
20
20
|
const { dashboardResource , datasourceApi , children } = props;
|
|
21
|
-
const
|
|
21
|
+
const { project } = dashboardResource.metadata;
|
|
22
|
+
const { getPlugin , listPluginMetadata } = usePluginRegistry();
|
|
23
|
+
const findDatasource = useEvent(async (selector)=>{
|
|
22
24
|
// Try to find it in dashboard spec
|
|
23
25
|
const { datasources } = dashboardResource.spec;
|
|
24
26
|
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
25
27
|
if (dashboardDatasource !== undefined) {
|
|
26
|
-
return
|
|
28
|
+
return {
|
|
29
|
+
spec: dashboardDatasource,
|
|
30
|
+
proxyUrl: undefined
|
|
31
|
+
};
|
|
27
32
|
}
|
|
28
33
|
// Try to find it at the project level as a Datasource resource
|
|
29
|
-
const { project } = dashboardResource.metadata;
|
|
30
34
|
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
31
35
|
if (datasource !== undefined) {
|
|
32
|
-
return
|
|
36
|
+
return {
|
|
37
|
+
spec: datasource.resource.spec,
|
|
38
|
+
proxyUrl: datasource.proxyUrl
|
|
39
|
+
};
|
|
33
40
|
}
|
|
34
41
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
35
42
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
36
43
|
if (globalDatasource !== undefined) {
|
|
37
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
spec: globalDatasource.resource.spec,
|
|
46
|
+
proxyUrl: globalDatasource.proxyUrl
|
|
47
|
+
};
|
|
38
48
|
}
|
|
39
49
|
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
40
50
|
});
|
|
51
|
+
// Gets a datasource spec for a given selector
|
|
52
|
+
const getDatasource = useCallback(async (selector)=>{
|
|
53
|
+
const { spec } = await findDatasource(selector);
|
|
54
|
+
return spec;
|
|
55
|
+
}, [
|
|
56
|
+
findDatasource
|
|
57
|
+
]);
|
|
58
|
+
// Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
|
|
59
|
+
const getDatasourceClient = useCallback(async function getClient(selector) {
|
|
60
|
+
const { kind } = selector;
|
|
61
|
+
const [{ spec , proxyUrl }, plugin] = await Promise.all([
|
|
62
|
+
findDatasource(selector),
|
|
63
|
+
getPlugin('Datasource', kind)
|
|
64
|
+
]);
|
|
65
|
+
return plugin.createClient(spec.plugin.spec, {
|
|
66
|
+
proxyUrl
|
|
67
|
+
});
|
|
68
|
+
}, [
|
|
69
|
+
findDatasource,
|
|
70
|
+
getPlugin
|
|
71
|
+
]);
|
|
72
|
+
const listDatasourceMetadata = useEvent(async (datasourcePluginKind)=>{
|
|
73
|
+
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
74
|
+
listPluginMetadata('Datasource'),
|
|
75
|
+
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
76
|
+
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
77
|
+
]);
|
|
78
|
+
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
79
|
+
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
|
|
80
|
+
if (datasourcePluginMetadata === undefined) {
|
|
81
|
+
throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
|
|
82
|
+
}
|
|
83
|
+
// Get helper for de-duping results properly
|
|
84
|
+
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
85
|
+
// Start with dashboard datasources that have highest precedence
|
|
86
|
+
if (dashboardResource.spec.datasources !== undefined) {
|
|
87
|
+
for(const selectorName in dashboardResource.spec.datasources){
|
|
88
|
+
const spec = dashboardResource.spec.datasources[selectorName];
|
|
89
|
+
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
90
|
+
addResult(spec, selectorName);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Now look at project-level datasources
|
|
94
|
+
for (const datasource of datasources){
|
|
95
|
+
const selectorName1 = datasource.metadata.name;
|
|
96
|
+
addResult(datasource.spec, selectorName1);
|
|
97
|
+
}
|
|
98
|
+
// And finally global datasources
|
|
99
|
+
for (const globalDatasource of globalDatasources){
|
|
100
|
+
const selectorName2 = globalDatasource.metadata.name;
|
|
101
|
+
addResult(globalDatasource.spec, selectorName2);
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
});
|
|
41
105
|
const ctxValue = useMemo(()=>({
|
|
42
|
-
getDatasource
|
|
106
|
+
getDatasource,
|
|
107
|
+
getDatasourceClient,
|
|
108
|
+
listDatasourceMetadata
|
|
43
109
|
}), [
|
|
44
|
-
getDatasource
|
|
110
|
+
getDatasource,
|
|
111
|
+
getDatasourceClient,
|
|
112
|
+
listDatasourceMetadata
|
|
45
113
|
]);
|
|
46
114
|
return /*#__PURE__*/ _jsx(DatasourceStoreContext.Provider, {
|
|
47
115
|
value: ctxValue,
|
|
@@ -60,5 +128,39 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
60
128
|
// If only using a kind, try to find one with that kind that is the default
|
|
61
129
|
return Object.values(dashboardDatasources).find((ds)=>ds.plugin.kind === selector.kind && ds.default === true);
|
|
62
130
|
}
|
|
131
|
+
// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors
|
|
132
|
+
function buildListDatasourceMetadataResults(pluginDisplayName) {
|
|
133
|
+
const results = [];
|
|
134
|
+
const usedNames = new Set();
|
|
135
|
+
let defaultAdded = false;
|
|
136
|
+
const addResult = (spec, selectorName)=>{
|
|
137
|
+
var ref;
|
|
138
|
+
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
139
|
+
if (spec.default && defaultAdded === false) {
|
|
140
|
+
results.unshift({
|
|
141
|
+
name: `Default ${pluginDisplayName}`,
|
|
142
|
+
selector: {
|
|
143
|
+
kind: spec.plugin.kind
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
defaultAdded = true;
|
|
147
|
+
}
|
|
148
|
+
// If we already have a datasource with this selector name, ignore it, otherwise add to end of list
|
|
149
|
+
if (usedNames.has(selectorName)) return;
|
|
150
|
+
var ref1;
|
|
151
|
+
results.push({
|
|
152
|
+
name: (ref1 = (ref = spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : selectorName,
|
|
153
|
+
selector: {
|
|
154
|
+
kind: spec.plugin.kind,
|
|
155
|
+
name: selectorName
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
usedNames.add(selectorName);
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
results,
|
|
162
|
+
addResult
|
|
163
|
+
};
|
|
164
|
+
}
|
|
63
165
|
|
|
64
166
|
//# sourceMappingURL=DatasourceStoreProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { useMemo } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n Datasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n} from '@perses-dev/core';\nimport { DatasourceStoreContext, DatasourceStore } from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<Datasource | undefined>;\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { dashboardResource, datasourceApi, children } = props;\n\n const getDatasource = useEvent(async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n // Try to find it in dashboard spec\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return dashboardDatasource;\n }\n\n // Try to find it at the project level as a Datasource resource\n const { project } = dashboardResource.metadata;\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return datasource.spec;\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return globalDatasource.spec;\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n const ctxValue: DatasourceStore = useMemo(\n () => ({\n getDatasource,\n }),\n [getDatasource]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(dashboardDatasources: DashboardSpec['datasources'], selector: DatasourceSelector) {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? named : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n return Object.values(dashboardDatasources).find((ds) => ds.plugin.kind === selector.kind && ds.default === true);\n}\n"],"names":["useMemo","useEvent","DatasourceStoreContext","DatasourceStoreProvider","props","dashboardResource","datasourceApi","children","getDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","project","metadata","datasource","globalDatasource","getGlobalDatasource","Error","kind","name","ctxValue","Provider","value","dashboardDatasources","named","plugin","Object","values","find","ds","default"],"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,OAAO,QAAQ,OAAO,CAAC;AAChC,SAOEC,QAAQ,QACH,kBAAkB,CAAC;AAC1B,SAASC,sBAAsB,QAAyB,2BAA2B,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ACN,sBAAsB,CAACsB,QAAQ;QAACC,KAAK,EAAEF,QAAQ;kBAAGhB,QAAQ;MAAmC,CAAC;AACxG,CAAC;AAED,uEAAuE;AACvE,SAASM,uBAAuB,CAACa,oBAAkD,EAAEjB,QAA4B,EAAE;IACjH,IAAIiB,oBAAoB,KAAKZ,SAAS,EAAE,OAAOA,SAAS,CAAC;IAEzD,qCAAqC;IACrC,IAAIL,QAAQ,CAACa,IAAI,KAAKR,SAAS,EAAE;QAC/B,MAAMa,KAAK,GAAGD,oBAAoB,CAACjB,QAAQ,CAACa,IAAI,CAAC,AAAC;QAClD,IAAIK,KAAK,KAAKb,SAAS,EAAE,OAAOA,SAAS,CAAC;QAC1C,OAAOa,KAAK,CAACC,MAAM,CAACP,IAAI,KAAKZ,QAAQ,CAACY,IAAI,GAAGM,KAAK,GAAGb,SAAS,CAAC;IACjE,CAAC;IAED,2EAA2E;IAC3E,OAAOe,MAAM,CAACC,MAAM,CAACJ,oBAAoB,CAAC,CAACK,IAAI,CAAC,CAACC,EAAE,GAAKA,EAAE,CAACJ,MAAM,CAACP,IAAI,KAAKZ,QAAQ,CAACY,IAAI,IAAIW,EAAE,CAACC,OAAO,KAAK,IAAI,CAAC,CAAC;AACnH,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { useCallback, useMemo } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n Datasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n usePluginRegistry,\n DatasourceMetadata,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource: DashboardResource;\n datasourceApi: DatasourceApi;\n children?: React.ReactNode;\n}\n\n// The external API for fetching datasource resources\nexport interface DatasourceApi {\n getDatasource: (\n project: string,\n selector: DatasourceSelector\n ) => Promise<{ resource: Datasource; proxyUrl: string } | undefined>;\n\n getGlobalDatasource: (\n selector: DatasourceSelector\n ) => Promise<{ resource: GlobalDatasource; proxyUrl: string } | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { dashboardResource, datasourceApi, children } = props;\n const { project } = dashboardResource.metadata;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return { spec: dashboardDatasource, proxyUrl: undefined };\n }\n\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return { spec: datasource.resource.spec, proxyUrl: datasource.proxyUrl };\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return { spec: globalDatasource.resource.spec, proxyUrl: globalDatasource.proxyUrl };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n return plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n },\n [findDatasource, getPlugin]\n );\n\n const listDatasourceMetadata = useEvent(async (datasourcePluginKind: string): Promise<DatasourceMetadata[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n datasourceApi.listDatasources(project, datasourcePluginKind),\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for de-duping results properly\n const { results, addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources that have highest precedence\n if (dashboardResource.spec.datasources !== undefined) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n addResult(spec, selectorName);\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addResult(datasource.spec, selectorName);\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addResult(globalDatasource.spec, selectorName);\n }\n\n return results;\n });\n\n const ctxValue: DatasourceStore = useMemo(\n () => ({\n getDatasource,\n getDatasourceClient,\n listDatasourceMetadata,\n }),\n [getDatasource, getDatasourceClient, listDatasourceMetadata]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(dashboardDatasources: DashboardSpec['datasources'], selector: DatasourceSelector) {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? named : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n return Object.values(dashboardDatasources).find((ds) => ds.plugin.kind === selector.kind && ds.default === true);\n}\n\n// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors\nfunction buildListDatasourceMetadataResults(pluginDisplayName: string) {\n const results: DatasourceMetadata[] = [];\n const usedNames = new Set<string>();\n let defaultAdded = false;\n const addResult = (spec: DatasourceSpec, selectorName: string) => {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n if (spec.default && defaultAdded === false) {\n results.unshift({\n name: `Default ${pluginDisplayName}`,\n selector: {\n kind: spec.plugin.kind,\n },\n });\n defaultAdded = true;\n }\n\n // If we already have a datasource with this selector name, ignore it, otherwise add to end of list\n if (usedNames.has(selectorName)) return;\n\n results.push({\n name: spec.display?.name ?? selectorName,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n },\n });\n usedNames.add(selectorName);\n };\n\n return { results, addResult };\n}\n"],"names":["useCallback","useMemo","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","dashboardResource","datasourceApi","children","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","datasource","getDatasource","resource","globalDatasource","getGlobalDatasource","Error","kind","name","getDatasourceClient","getClient","plugin","Promise","all","createClient","listDatasourceMetadata","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addResult","buildListDatasourceMetadataResults","display","selectorName","ctxValue","Provider","value","dashboardDatasources","named","Object","values","ds","default","p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,IAAI;gBACtBC,IAAI,EAAEmB,YAAY;aACnB;SACF,CAAC,CAAC;QACHW,SAAS,CAACM,GAAG,CAACjB,YAAY,CAAC,CAAC;IAC9B,CAAC,AAAC;IAEF,OAAO;QAAEJ,OAAO;QAAEC,SAAS;KAAE,CAAC;AAChC,CAAC"}
|
|
@@ -7,6 +7,7 @@ declare type TemplateVariableStore = {
|
|
|
7
7
|
setVariableValue: (variableName: VariableName, value: VariableValue) => void;
|
|
8
8
|
setVariableOptions: (name: VariableName, options: VariableOption[]) => void;
|
|
9
9
|
setVariableLoading: (name: VariableName, loading: boolean) => void;
|
|
10
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
10
11
|
};
|
|
11
12
|
export declare function useTemplateVariableValues(variableNames?: string[]): VariableStateMap;
|
|
12
13
|
export declare function useTemplateVariable(name: string): {
|
|
@@ -17,6 +18,7 @@ export declare function useTemplateVariableActions(): {
|
|
|
17
18
|
setVariableValue: (variableName: string, value: VariableValue) => void;
|
|
18
19
|
setVariableLoading: (name: string, loading: boolean) => void;
|
|
19
20
|
setVariableOptions: (name: string, options: VariableOption[]) => void;
|
|
21
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
20
22
|
};
|
|
21
23
|
export declare function useTemplateVariableDefinitions(): VariableDefinition[];
|
|
22
24
|
export declare function useTemplateVariableStore(): TemplateVariableStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../src/context/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,cAAc,EAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEnF,aAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,EAAE,gBAAgB,CA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C,QAAQ,EACR,0BAA+B,GAChC,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACnD,eAQA"}
|
|
@@ -59,7 +59,8 @@ export function useTemplateVariableActions() {
|
|
|
59
59
|
return {
|
|
60
60
|
setVariableValue: s.setVariableValue,
|
|
61
61
|
setVariableLoading: s.setVariableLoading,
|
|
62
|
-
setVariableOptions: s.setVariableOptions
|
|
62
|
+
setVariableOptions: s.setVariableOptions,
|
|
63
|
+
setVariableDefinitions: s.setVariableDefinitions
|
|
63
64
|
};
|
|
64
65
|
});
|
|
65
66
|
}
|
|
@@ -104,6 +105,12 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
|
104
105
|
const store = createStore()(devtools(immer((set)=>({
|
|
105
106
|
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
106
107
|
variableDefinitions: initialVariableDefinitions,
|
|
108
|
+
setVariableDefinitions (definitions) {
|
|
109
|
+
set((state)=>{
|
|
110
|
+
state.variableDefinitions = definitions;
|
|
111
|
+
state.variableState = hydrateTemplateVariableStates(definitions);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
107
114
|
setVariableOptions (name, options) {
|
|
108
115
|
set((state)=>{
|
|
109
116
|
const varState = state.variableState[name];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TemplateVariableProvider.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 { createContext, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [] }: TemplateVariableSrvArgs) {\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions),\n variableDefinitions: initialVariableDefinitions,\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n varState.value = val;\n }),\n }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(definition: VariableDefinition) {\n const v = definition;\n const varState: VariableState = {\n value: v.spec.default_value ?? null,\n loading: false,\n };\n switch (v.kind) {\n case 'TextVariable':\n varState.value = v.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = v.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(definitions: VariableDefinition[]): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n state[v.spec.name] = hydrateTemplateVariableState(v);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","set","hydrateTemplateVariableStates","loading","val","Array","isArray","includes","at","filter","TemplateVariableProvider","hydrateTemplateVariableState","default_value","kind","length","firstOptionValue","allow_multiple","definitions"],"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,aAAa,EAAEC,UAA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AAAA,GAAmB,GAAnBA,QAAQ,CAACuB,OAAO,CAAC,CAAC,CAAC,cAAnBvB,GAAmB,WAAO,GAA1BA,KAAAA,CAA0B,GAA1BA,GAAmB,CAAEsB,KAAK,cAA1BtB,IAA0B,cAA1BA,IAA0B,GAAI,IAAI,AAAC;gBAC5D,IAAI2C,gBAAgB,KAAK,IAAI,EAAE;oBAC7B3C,QAAQ,CAACsB,KAAK,GAAGb,CAAC,CAACC,IAAI,CAACkC,cAAc,GAAG;wBAACD,gBAAgB;qBAAC,GAAGA,gBAAgB,CAAC;gBACjF,CAAC;YACH,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAO3C,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS8B,6BAA6B,CAACe,WAAiC,EAAoB;IAC1F,MAAMtD,KAAK,GAAqB,EAAE,AAAC;IACnCsD,WAAW,CAAC/C,OAAO,CAAC,CAACW,CAAC,GAAK;QACzBlB,KAAK,CAACkB,CAAC,CAACC,IAAI,CAACX,IAAI,CAAC,GAAGwC,4BAA4B,CAAC9B,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,OAAOlB,KAAK,CAAC;AACf,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/context/TemplateVariableProvider.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 { createContext, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\nimport {\n TemplateVariableContext,\n VariableStateMap,\n VariableState,\n VariableOption,\n DEFAULT_ALL_VALUE as ALL_VALUE,\n} from '@perses-dev/plugin-system';\nimport { VariableName, VariableValue, VariableDefinition } from '@perses-dev/core';\n\ntype TemplateVariableStore = {\n variableDefinitions: VariableDefinition[];\n variableState: VariableStateMap;\n setVariableValue: (variableName: VariableName, value: VariableValue) => void;\n setVariableOptions: (name: VariableName, options: VariableOption[]) => void;\n setVariableLoading: (name: VariableName, loading: boolean) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n};\n\nconst TemplateVariableStoreContext = createContext<ReturnType<typeof createTemplateVariableSrvStore> | undefined>(\n undefined\n);\nfunction useTemplateVariableStoreCtx() {\n const context = useContext(TemplateVariableStoreContext);\n if (!context) {\n throw new Error('TemplateVariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useTemplateVariableValues(variableNames?: string[]) {\n const store = useTemplateVariableStoreCtx();\n const state = useStore(\n store,\n (s) => {\n const names = variableNames ?? Object.keys(s.variableState);\n const vars: VariableStateMap = {};\n names.forEach((name) => {\n const varState = s.variableState[name];\n if (!varState) {\n return;\n }\n vars[name] = varState;\n });\n return vars;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n return state;\n}\n\nexport function useTemplateVariable(name: string) {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n const variableState = s.variableState[name];\n const definition = s.variableDefinitions.find((v) => v.spec.name === name);\n return {\n state: variableState,\n definition,\n };\n });\n}\n\nexport function useTemplateVariableActions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n };\n });\n}\n\nexport function useTemplateVariableDefinitions() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useTemplateVariableStore() {\n const store = useTemplateVariableStoreCtx();\n return useStore(store);\n}\n\nfunction PluginProvider({ children }: { children: React.ReactNode }) {\n const originalValues = useTemplateVariableValues();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n if (v.value === ALL_VALUE) {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues]);\n\n return <TemplateVariableContext.Provider value={{ state: values }}>{children}</TemplateVariableContext.Provider>;\n}\n\ninterface TemplateVariableSrvArgs {\n initialVariableDefinitions?: VariableDefinition[];\n}\n\nfunction createTemplateVariableSrvStore({ initialVariableDefinitions = [] }: TemplateVariableSrvArgs) {\n const store = createStore<TemplateVariableStore>()(\n devtools(\n immer((set) => ({\n variableState: hydrateTemplateVariableStates(initialVariableDefinitions),\n variableDefinitions: initialVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set((state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateTemplateVariableStates(definitions);\n });\n },\n setVariableOptions(name, options) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.options = options;\n });\n },\n setVariableLoading(name, loading) {\n set((state) => {\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n varState.loading = loading;\n });\n },\n\n setVariableValue: (name, value) =>\n set((state) => {\n let val = value;\n const varState = state.variableState[name];\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n varState.value = val;\n }),\n }))\n )\n );\n\n return store;\n}\n\nexport function TemplateVariableProvider({\n children,\n initialVariableDefinitions = [],\n}: {\n children: React.ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n}) {\n const [store] = useState(createTemplateVariableSrvStore({ initialVariableDefinitions }));\n\n return (\n <TemplateVariableStoreContext.Provider value={store}>\n <PluginProvider>{children}</PluginProvider>\n </TemplateVariableStoreContext.Provider>\n );\n}\n\n/** Helpers */\n\nfunction hydrateTemplateVariableState(definition: VariableDefinition) {\n const v = definition;\n const varState: VariableState = {\n value: v.spec.default_value ?? null,\n loading: false,\n };\n switch (v.kind) {\n case 'TextVariable':\n varState.value = v.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = v.spec.allow_multiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n break;\n default:\n break;\n }\n return varState;\n}\n\nfunction hydrateTemplateVariableStates(definitions: VariableDefinition[]): VariableStateMap {\n const state: VariableStateMap = {};\n definitions.forEach((v) => {\n state[v.spec.name] = hydrateTemplateVariableState(v);\n });\n return state;\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","immer","devtools","TemplateVariableContext","DEFAULT_ALL_VALUE","ALL_VALUE","TemplateVariableStoreContext","undefined","useTemplateVariableStoreCtx","context","Error","useTemplateVariableValues","variableNames","store","state","s","names","Object","keys","variableState","vars","forEach","name","varState","left","right","JSON","stringify","useTemplateVariable","definition","variableDefinitions","find","v","spec","useTemplateVariableActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","useTemplateVariableDefinitions","useTemplateVariableStore","PluginProvider","children","originalValues","values","contextValues","value","options","map","o","Provider","createTemplateVariableSrvStore","initialVariableDefinitions","set","hydrateTemplateVariableStates","definitions","loading","val","Array","isArray","includes","at","filter","TemplateVariableProvider","hydrateTemplateVariableState","default_value","kind","length","firstOptionValue","allow_multiple"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3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C,QAAQ,CAACuB,KAAK,GAAGd,CAAC,CAACC,IAAI,CAACa,KAAK,CAAC;YAC9B,MAAM;QACR,KAAK,cAAc;YACjBvB,QAAQ,CAACwB,OAAO,GAAG,EAAE,CAAC;YACtB,IAAIxB,QAAQ,CAACwB,OAAO,CAACoB,MAAM,GAAG,CAAC,IAAI,CAAC5C,QAAQ,CAACuB,KAAK,EAAE;oBACzBvB,GAAmB;oBAAnBA,IAA0B;gBAAnD,MAAM6C,gBAAgB,GAAG7C,CAAAA,IAA0B,GAA1BA,CAAAA,GAAmB,GAAnBA,QAAQ,CAACwB,OAAO,CAAC,CAAC,CAAC,cAAnBxB,GAAmB,WAAO,GAA1BA,KAAAA,CAA0B,GAA1BA,GAAmB,CAAEuB,KAAK,cAA1BvB,IAA0B,cAA1BA,IAA0B,GAAI,IAAI,AAAC;gBAC5D,IAAI6C,gBAAgB,KAAK,IAAI,EAAE;oBAC7B7C,QAAQ,CAACuB,KAAK,GAAGd,CAAC,CAACC,IAAI,CAACoC,cAAc,GAAG;wBAACD,gBAAgB;qBAAC,GAAGA,gBAAgB,CAAC;gBACjF,CAAC;YACH,CAAC;YACD,MAAM;QACR;YACE,MAAM;KACT;IACD,OAAO7C,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS+B,6BAA6B,CAACC,WAAiC,EAAoB;IAC1F,MAAMzC,KAAK,GAAqB,EAAE,AAAC;IACnCyC,WAAW,CAAClC,OAAO,CAAC,CAACW,CAAC,GAAK;QACzBlB,KAAK,CAACkB,CAAC,CAACC,IAAI,CAACX,IAAI,CAAC,GAAG0C,4BAA4B,CAAChC,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,OAAOlB,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TimeRangeValue } from '@perses-dev/core';
|
|
3
3
|
export interface TimeRangeProviderProps {
|
|
4
|
-
|
|
4
|
+
timeRange: TimeRangeValue;
|
|
5
|
+
setTimeRange?: (value: TimeRangeValue) => void;
|
|
5
6
|
children?: React.ReactNode;
|
|
6
|
-
onTimeRangeChange?: (e: TimeRangeValue) => void;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Provider implementation that supplies the time range state at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export declare function TimeRangeProvider(props: TimeRangeProviderProps): JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* Internal version of time range hook to get all supported values
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDashboardTimeRange(): {
|
|
16
|
+
timeRange: TimeRangeValue;
|
|
17
|
+
setTimeRange: (value: TimeRangeValue) => void;
|
|
18
|
+
};
|
|
12
19
|
//# sourceMappingURL=TimeRangeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAiB9D;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;;EAGpC"}
|
|
@@ -11,54 +11,17 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import React, {
|
|
15
|
-
import {
|
|
16
|
-
import { toAbsoluteTimeRange, isRelativeTimeRange } from '@perses-dev/core';
|
|
17
|
-
import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
14
|
+
import React, { useMemo } from 'react';
|
|
15
|
+
import { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';
|
|
18
16
|
/**
|
|
19
17
|
* Provider implementation that supplies the time range state at runtime.
|
|
20
18
|
*/ export function TimeRangeProvider(props) {
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
const defaultTimeRange = isRelativeTimeRange(initialTimeRange) ? toAbsoluteTimeRange(initialTimeRange) : initialTimeRange;
|
|
24
|
-
const [timeRange, setActiveTimeRange] = useState(defaultTimeRange);
|
|
25
|
-
const setTimeRange = useCallback((value)=>{
|
|
26
|
-
if (onTimeRangeChange !== undefined) {
|
|
27
|
-
// optional callback to override default behavior
|
|
28
|
-
onTimeRangeChange(value);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (isRelativeTimeRange(value)) {
|
|
32
|
-
if (setQueryString) {
|
|
33
|
-
queryString.set('start', value.pastDuration);
|
|
34
|
-
// end not required for relative time but may have been set by AbsoluteTimePicker or zoom
|
|
35
|
-
queryString.delete('end');
|
|
36
|
-
setQueryString(queryString);
|
|
37
|
-
} else {
|
|
38
|
-
setActiveTimeRange(toAbsoluteTimeRange(value));
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// allows app to specify whether query params should be source of truth for active time range
|
|
43
|
-
if (setQueryString) {
|
|
44
|
-
// Absolute URL example) ?start=1663707045000&end=1663713330000
|
|
45
|
-
// currently set from ViewDashboard initial queryString, AbsoluteTimePicker, or LineChart panel onDataZoom
|
|
46
|
-
const startUnixMs = getUnixTime(value.start) * 1000;
|
|
47
|
-
const endUnixMs = getUnixTime(value.end) * 1000;
|
|
48
|
-
queryString.set('start', startUnixMs.toString());
|
|
49
|
-
queryString.set('end', endUnixMs.toString());
|
|
50
|
-
setQueryString(queryString);
|
|
51
|
-
} else {
|
|
52
|
-
setActiveTimeRange(value);
|
|
53
|
-
}
|
|
54
|
-
}, [
|
|
55
|
-
queryString,
|
|
56
|
-
setQueryString,
|
|
57
|
-
onTimeRangeChange
|
|
58
|
-
]);
|
|
19
|
+
const { timeRange , children , setTimeRange } = props;
|
|
20
|
+
// TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround
|
|
59
21
|
const ctx = useMemo(()=>({
|
|
60
22
|
timeRange,
|
|
61
|
-
setTimeRange
|
|
23
|
+
setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : ()=>{
|
|
24
|
+
/* no-op */ }
|
|
62
25
|
}), [
|
|
63
26
|
timeRange,
|
|
64
27
|
setTimeRange
|
|
@@ -68,5 +31,14 @@ import { TimeRangeContext, useQueryString } from '@perses-dev/plugin-system';
|
|
|
68
31
|
children: children
|
|
69
32
|
});
|
|
70
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Internal version of time range hook to get all supported values
|
|
36
|
+
*/ export function useDashboardTimeRange() {
|
|
37
|
+
const { timeRange , setTimeRange } = useTimeRangeContext();
|
|
38
|
+
return {
|
|
39
|
+
timeRange,
|
|
40
|
+
setTimeRange
|
|
41
|
+
};
|
|
42
|
+
}
|
|
71
43
|
|
|
72
44
|
//# sourceMappingURL=TimeRangeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, {
|
|
1
|
+
{"version":3,"sources":["../../src/context/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useMemo } from 'react';\nimport { TimeRangeValue } from '@perses-dev/core';\nimport { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n setTimeRange?: (value: TimeRangeValue) => void;\n children?: React.ReactNode;\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { timeRange, children, setTimeRange } = props;\n\n // TODO: fix no-op, pass paramsEnabled as false in useSetTimeRangeParams as workaround\n const ctx = useMemo(\n () => ({\n timeRange,\n setTimeRange:\n setTimeRange ??\n (() => {\n /* no-op */\n }),\n }),\n [timeRange, setTimeRange]\n );\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n\n/**\n * Internal version of time range hook to get all supported values\n */\nexport function useDashboardTimeRange() {\n const { timeRange, setTimeRange } = useTimeRangeContext();\n return { timeRange, setTimeRange };\n}\n"],"names":["React","useMemo","TimeRangeContext","useTimeRangeContext","TimeRangeProvider","props","timeRange","children","setTimeRange","ctx","Provider","value","useDashboardTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AAEvC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AAQlF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAACC,KAA6B,EAAE;IAC/D,MAAM,EAAEC,SAAS,CAAA,EAAEC,QAAQ,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGH,KAAK,AAAC;IAEpD,sFAAsF;IACtF,MAAMI,GAAG,GAAGR,OAAO,CACjB,IAAO,CAAA;YACLK,SAAS;YACTE,YAAY,EACVA,YAAY,aAAZA,YAAY,cAAZA,YAAY,GACX,IAAM;YACL,SAAS,GACX,CAAC,AAAC;SACL,CAAA,AAAC,EACF;QAACF,SAAS;QAAEE,YAAY;KAAC,CAC1B,AAAC;IAEF,qBAAO,KAACN,gBAAgB,CAACQ,QAAQ;QAACC,KAAK,EAAEF,GAAG;kBAAGF,QAAQ;MAA6B,CAAC;AACvF,CAAC;AAED;;CAEC,GACD,OAAO,SAASK,qBAAqB,GAAG;IACtC,MAAM,EAAEN,SAAS,CAAA,EAAEE,YAAY,CAAA,EAAE,GAAGL,mBAAmB,EAAE,AAAC;IAC1D,OAAO;QAAEG,SAAS;QAAEE,YAAY;KAAE,CAAC;AACrC,CAAC"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from './DashboardAppSlice';
|
|
2
1
|
export * from './DashboardProvider';
|
|
3
2
|
export * from './DatasourceStoreProvider';
|
|
4
|
-
export * from './LayoutsSlice';
|
|
5
|
-
export * from './QueryStringProvider';
|
|
6
3
|
export * from './TemplateVariableProvider';
|
|
7
4
|
export * from './TimeRangeProvider';
|
|
5
|
+
export * from './useDashboardSpec';
|
|
8
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
package/dist/context/index.js
CHANGED
|
@@ -10,12 +10,10 @@
|
|
|
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
|
-
export * from './DashboardAppSlice';
|
|
14
13
|
export * from './DashboardProvider';
|
|
15
14
|
export * from './DatasourceStoreProvider';
|
|
16
|
-
export * from './LayoutsSlice';
|
|
17
|
-
export * from './QueryStringProvider';
|
|
18
15
|
export * from './TemplateVariableProvider';
|
|
19
16
|
export * from './TimeRangeProvider';
|
|
17
|
+
export * from './useDashboardSpec';
|
|
20
18
|
|
|
21
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './TemplateVariableProvider';\nexport * from './TimeRangeProvider';\nexport * from './useDashboardSpec';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDashboardSpec.d.ts","sourceRoot":"","sources":["../../src/context/useDashboardSpec.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAIjE,wBAAgB,gBAAgB,IAAI,aAAa,CAehD"}
|