@perses-dev/dashboards 0.26.1 → 0.28.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/GridLayout/GridItemContent.js +22 -4
- package/dist/cjs/components/GridLayout/GridLayout.js +31 -2
- package/dist/cjs/components/Panel/Panel.js +2 -2
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +41 -34
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +32 -18
- package/dist/cjs/components/PanelDrawer/usePanelEditor.js +87 -0
- package/dist/cjs/components/Variables/{Variable.js → TemplateVariable.js} +1 -1
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
- package/dist/cjs/components/Variables/VariableList.js +2 -2
- package/dist/cjs/components/Variables/index.js +1 -1
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +4 -4
- package/dist/cjs/context/DashboardProvider/common.js +26 -6
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +8 -32
- package/dist/cjs/stories/decorators/WithDataQueriesProvider.js +39 -0
- package/dist/cjs/stories/decorators/WithDatasourceStore.js +2 -47
- package/dist/cjs/stories/decorators/index.js +1 -0
- package/dist/cjs/test/datasource-provider.js +70 -0
- package/dist/cjs/test/index.js +1 -0
- package/dist/cjs/test/plugin-registry.js +11 -5
- package/dist/cjs/test/testDashboard.js +79 -79
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/time.js +27 -0
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +22 -4
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +31 -2
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +3 -3
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +42 -35
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +32 -18
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelDrawer/usePanelEditor.d.ts +15 -0
- package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/usePanelEditor.js +84 -0
- package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -0
- package/dist/components/Variables/{Variable.d.ts → TemplateVariable.d.ts} +1 -1
- package/dist/components/Variables/TemplateVariable.d.ts.map +1 -0
- package/dist/components/Variables/{Variable.js → TemplateVariable.js} +2 -2
- package/dist/components/Variables/TemplateVariable.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableList.js +1 -1
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -1
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -1
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +4 -4
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +2 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js +17 -2
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +3 -6
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +9 -33
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/stories/decorators/WithDataQueriesProvider.js +33 -0
- package/dist/stories/decorators/WithDataQueriesProvider.js.map +1 -0
- package/dist/stories/decorators/WithDatasourceStore.js +1 -46
- package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
- package/dist/stories/decorators/index.js +1 -0
- package/dist/stories/decorators/index.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +6 -0
- package/dist/test/datasource-provider.d.ts.map +1 -0
- package/dist/test/datasource-provider.js +60 -0
- package/dist/test/datasource-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +1 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +11 -5
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/testDashboard.js +79 -79
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/time.d.ts +5 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +23 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +10 -5
- package/dist/components/Variables/Variable.d.ts.map +0 -1
- package/dist/components/Variables/Variable.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils/panelUtils';\nimport { generateId, Middleware } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'kind' | 'spec'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupId: PanelGroupId;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupId: panelGroupItemId.panelGroupId,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((state) => {\n state.panels[panelKey] = panelDefinititon;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n kind: get().initialValues?.kind ?? '',\n spec: get().initialValues?.spec ?? {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = getValidPanelKey(next.name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = panelDef;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","name","spec","display","description","groupId","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","panelDef","group","toString","editorValues"],"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;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,wBAAwB,CAAC;AACzE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAClD,SAMEC,aAAa,EACbC,qBAAqB,QAChB,qBAAqB,CAAC;AA6D7B;;CAEC,GACD,OAAO,SAASC,sBAAsB,GAMpC;IACA,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG;QAAM,OAAA;YACpBC,WAAW,EAAEC,SAAS;YAEtBC,aAAa,EAACC,gBAAgB,EAAE;oBAKbC,GAAyB;gBAJ1C,MAAM,EAAEC,MAAM,CAAA,EAAED,WAAW,CAAA,EAAE,GAAGL,GAAG,EAAE,AAAC;gBAEtC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,CAAA,EAAEC,sBAAsB,EAAEC,kBAAkB,CAAA,EAAE,GAAGL,gBAAgB,AAAC;gBACtF,MAAMM,QAAQ,GAAGL,CAAAA,GAAyB,GAAzBA,WAAW,CAACE,YAAY,CAAC,cAAzB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B,WAAW,CAACQ,IAAI,CAACN,MAAM,CAAC,CAAC;4BAC/BiB,KAAK,CAACvC,aAAa,CAACsB,MAAM,CAACC,CAAC,CAAC,GAAGxB,QAAQ,CAAC;wBAC3C,CAAC,CAAC,CAAC;oBACL,CAAC;oBACDkC,KAAK,EAAE,IAAM;wBACX7C,GAAG,CAAC,CAAC6B,KAAK,GAAK;4BACbA,KAAK,CAAC3B,WAAW,GAAGC,SAAS,CAAC;wBAChC,CAAC,CAAC,CAAC;oBACL,CAAC;iBACF,AAAC;gBAEFH,GAAG,CAAC,CAAC6B,KAAK,GAAK;oBACb,2DAA2D;oBAC3D,IAAIU,QAAQ,KAAKpC,SAAS,EAAE;wBAC1BN,aAAa,CAACgC,KAAK,EAAEU,QAAQ,CAAC,CAAC;oBACjC,CAAC;oBAED,qCAAqC;oBACrCV,KAAK,CAAC3B,WAAW,GAAGa,WAAW,CAAC;gBAClC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA;KAAC,CAAC;AACL,CAAC;AAED,gDAAgD;AAChD,SAASa,qCAAqC,CAACyB,YAA+B,EAAmB;IAC/F,OAAO;QACL9B,IAAI,EAAE,OAAO;QACbJ,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEmC,YAAY,CAACnC,IAAI;gBACvBG,WAAW,EAAEgC,YAAY,CAAChC,WAAW,KAAK,EAAE,GAAGgC,YAAY,CAAChC,WAAW,GAAGlB,SAAS;aACpF;YACDqB,MAAM,EAAE;gBACND,IAAI,EAAE8B,YAAY,CAAC9B,IAAI;gBACvBJ,IAAI,EAAEkC,YAAY,CAAClC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils/panelUtils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n groupId: PanelGroupId;\n panelDefinition: PanelDefinition;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"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;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,wBAAwB,CAAC;AACzE,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,UAAU,CAAC;AACzE,SAMEC,aAAa,EACbC,qBAAqB,QAChB,qBAAqB,CAAC;AA0D7B;;CAEC,GACD,OAAO,SAASC,sBAAsB,GAMpC;IACA,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG;QAAM,OAAA;YACpBC,WAAW,EAAEC,SAAS;YAEtBC,aAAa,EAACC,gBAAgB,EAAE;oBAKbC,GAAyB;gBAJ1C,MAAM,EAAEC,MAAM,CAAA,EAAED,WAAW,CAAA,EAAE,GAAGL,GAAG,EAAE,AAAC;gBAEtC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,CAAA,EAAEC,sBAAsB,EAAEC,kBAAkB,CAAA,EAAE,GAAGL,gBAAgB,AAAC;gBACtF,MAAMM,QAAQ,GAAGL,CAAAA,GAAyB,GAAzBA,WAAW,CAACE,YAAY,CAAC,cAAzBF,GAAyB,WAAe,GAAxCA,KAAAA,CAAwC,GAAxCA,GAAyB,CAAEM,aAAa,CAACF,kBAAkB,CAAC,AAAC;gBAC9E,IAAIC,QAAQ,KAAKR,SAAS,EAAE;oBAC1B,MAAM,IAAIU,KAAK,CAAC,CAAC,gCAAgC,EAAER,gBAAgB,CAAC,CAAC,CAAC,CAAC;gBACzE,CAAC;gBAED,yBAAyB;gBACzB,MAAMS,WAAW,GAAGP,MAAM,CAACI,QAAQ,CAAC,AAAC;gBACrC,IAA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AAC;4BACzD,CAAC;4BACD,MAAMS,MAAM,GAAyB;gCACnCC,CAAC,EAAEjC,UAAU,EAAE,CAACoD,QAAQ,EAAE;gCAC1Bb,CAAC,EAAE,CAAC;gCACJC,CAAC,EAAE1C,aAAa,CAACqD,KAAK,CAAC;gCACvBV,CAAC,EAAE,EAAE;gCACLC,CAAC,EAAE,CAAC;6BACL,AAAC;4BACFS,KAAK,CAACrB,WAAW,CAACQ,IAAI,CAACN,MAAM,CAAC,CAAC;4BAC/BmB,KAAK,CAAClC,aAAa,CAACe,MAAM,CAACC,CAAC,CAAC,GAAGjB,QAAQ,CAAC;wBAC3C,CAAC,CAAC,CAAC;oBACL,CAAC;oBACD2B,KAAK,EAAE,IAAM;wBACXtC,GAAG,CAAC,CAACsB,KAAK,GAAK;4BACbA,KAAK,CAACpB,WAAW,GAAGC,SAAS,CAAC;wBAChC,CAAC,CAAC,CAAC;oBACL,CAAC;iBACF,AAAC;gBAEFH,GAAG,CAAC,CAACsB,KAAK,GAAK;oBACb,2DAA2D;oBAC3D,IAAIU,QAAQ,KAAK7B,SAAS,EAAE;wBAC1BN,aAAa,CAACyB,KAAK,EAAEU,QAAQ,CAAC,CAAC;oBACjC,CAAC;oBAED,qCAAqC;oBACrCV,KAAK,CAACpB,WAAW,GAAGa,WAAW,CAAC;gBAClC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA;KAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2023 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 { DataQueriesProvider } from '@perses-dev/plugin-system';
|
|
15
|
+
// Type guard because storybook types parameters as `any`
|
|
16
|
+
function isWithDataQueriesParameter(parameter) {
|
|
17
|
+
return !!parameter && typeof parameter === 'object' && 'props' in parameter;
|
|
18
|
+
}
|
|
19
|
+
export const WithDataQueries = (Story, context)=>{
|
|
20
|
+
const initParameter = context.parameters.WithDataQueries;
|
|
21
|
+
const parameter = isWithDataQueriesParameter(initParameter) ? initParameter : {
|
|
22
|
+
props: {
|
|
23
|
+
definitions: []
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
|
|
27
|
+
return /*#__PURE__*/ _jsx(DataQueriesProvider, {
|
|
28
|
+
...props,
|
|
29
|
+
children: /*#__PURE__*/ _jsx(Story, {})
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=WithDataQueriesProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/stories/decorators/WithDataQueriesProvider.tsx"],"sourcesContent":["// Copyright 2023 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 { Definition, UnknownSpec } from '@perses-dev/core';\nimport { DataQueriesProvider, DataQueriesProviderProps } from '@perses-dev/plugin-system';\nimport { StoryFn, StoryContext } from '@storybook/react';\n\nexport type WithDataQueriesProvideParameter = {\n props: DataQueriesProviderProps;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDataQueriesParameter(\n parameter: unknown | WithDataQueriesProvideParameter\n): parameter is WithDataQueriesProvideParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithDataQueries = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.WithDataQueries;\n const parameter = isWithDataQueriesParameter(initParameter)\n ? initParameter\n : { props: { definitions: [] as Array<Definition<UnknownSpec>> } };\n const props = parameter?.props;\n\n return (\n <DataQueriesProvider {...props}>\n <Story />\n </DataQueriesProvider>\n );\n};\n"],"names":["DataQueriesProvider","isWithDataQueriesParameter","parameter","WithDataQueries","Story","context","initParameter","parameters","props","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;AACA,SAASA,mBAAmB,QAAkC,2BAA2B,CAAC;AAO1F,yDAAyD;AACzD,SAASC,0BAA0B,CACjCC,SAAoD,EACN;IAC9C,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,eAAe,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IACjF,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACJ,eAAe,AAAC;IACzD,MAAMD,SAAS,GAAGD,0BAA0B,CAACK,aAAa,CAAC,GACvDA,aAAa,GACb;QAAEE,KAAK,EAAE;YAAEC,WAAW,EAAE,EAAE;SAAoC;KAAE,AAAC;IACrE,MAAMD,KAAK,GAAGN,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEM,KAAK,AAAC;IAE/B,qBACE,KAACR,mBAAmB;QAAE,GAAGQ,KAAK;kBAC5B,cAAA,KAACJ,KAAK,KAAG;MACW,CACtB;AACJ,CAAC,CAAC"}
|
|
@@ -12,60 +12,15 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { DatasourceStoreProvider } from '@perses-dev/dashboards';
|
|
15
|
-
import {
|
|
15
|
+
import { defaultDatasourceProps } from '../../test';
|
|
16
16
|
// Type guard because storybook types parameters as `any`
|
|
17
17
|
function isWithDatasourceStoreParameter(parameter) {
|
|
18
18
|
return !!parameter && typeof parameter === 'object' && 'props' in parameter;
|
|
19
19
|
}
|
|
20
|
-
const prometheusDemoUrl = 'https://prometheus.demo.do.prometheus.io';
|
|
21
|
-
const prometheusDemo = {
|
|
22
|
-
kind: 'GlobalDatasource',
|
|
23
|
-
metadata: {
|
|
24
|
-
name: 'PrometheusDemo',
|
|
25
|
-
created_at: '0001-01-01T00:00:00Z',
|
|
26
|
-
updated_at: '0001-01-01T00:00:00Z',
|
|
27
|
-
version: 0
|
|
28
|
-
},
|
|
29
|
-
spec: {
|
|
30
|
-
default: true,
|
|
31
|
-
plugin: {
|
|
32
|
-
kind: 'PrometheusDatasource',
|
|
33
|
-
spec: {
|
|
34
|
-
direct_url: prometheusDemoUrl
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
20
|
export const WithDatasourceStore = (Story, context)=>{
|
|
40
21
|
const initParameter = context.parameters.withDatasourceStore;
|
|
41
22
|
const parameter = isWithDatasourceStoreParameter(initParameter) ? initParameter : undefined;
|
|
42
23
|
const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
|
|
43
|
-
// This default currently defines the bare minimum to get a story working in
|
|
44
|
-
// the `Dashboard` storybook with the Prometheus demo api. We'll likely want
|
|
45
|
-
// to expand it to do more in the future.
|
|
46
|
-
const defaultDatasourceProps = {
|
|
47
|
-
dashboardResource: EMPTY_DASHBOARD_RESOURCE,
|
|
48
|
-
datasourceApi: {
|
|
49
|
-
getDatasource: ()=>{
|
|
50
|
-
return Promise.resolve(undefined);
|
|
51
|
-
},
|
|
52
|
-
getGlobalDatasource: (selector)=>{
|
|
53
|
-
if (selector.kind === 'PrometheusDatasource') {
|
|
54
|
-
return Promise.resolve({
|
|
55
|
-
resource: prometheusDemo,
|
|
56
|
-
proxyUrl: prometheusDemoUrl
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return Promise.resolve(undefined);
|
|
60
|
-
},
|
|
61
|
-
listDatasources: ()=>{
|
|
62
|
-
return Promise.resolve([]);
|
|
63
|
-
},
|
|
64
|
-
listGlobalDatasources: ()=>{
|
|
65
|
-
return Promise.resolve([]);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
24
|
return /*#__PURE__*/ _jsx(DatasourceStoreProvider, {
|
|
70
25
|
...defaultDatasourceProps,
|
|
71
26
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/stories/decorators/WithDatasourceStore.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { DatasourceStoreProvider, DatasourceStoreProviderProps } from '@perses-dev/dashboards';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/stories/decorators/WithDatasourceStore.tsx"],"sourcesContent":["// Copyright 2023 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 { StoryFn, StoryContext } from '@storybook/react';\nimport { DatasourceStoreProvider, DatasourceStoreProviderProps } from '@perses-dev/dashboards';\nimport { defaultDatasourceProps } from '../../test';\n\nexport type WithDatasourceStoreParameter = {\n props: Partial<DatasourceStoreProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithDatasourceStoreParameter(\n parameter: unknown | WithDatasourceStoreParameter\n): parameter is WithDatasourceStoreParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithDatasourceStore = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withDatasourceStore;\n const parameter = isWithDatasourceStoreParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <DatasourceStoreProvider {...defaultDatasourceProps} {...props}>\n <Story />\n </DatasourceStoreProvider>\n );\n};\n"],"names":["DatasourceStoreProvider","defaultDatasourceProps","isWithDatasourceStoreParameter","parameter","WithDatasourceStore","Story","context","initParameter","parameters","withDatasourceStore","undefined","props"],"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;AACA,SAASA,uBAAuB,QAAsC,wBAAwB,CAAC;AAC/F,SAASC,sBAAsB,QAAQ,YAAY,CAAC;AAMpD,yDAAyD;AACzD,SAASC,8BAA8B,CACrCC,SAAiD,EACN;IAC3C,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,mBAAmB,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IACrF,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,mBAAmB,AAAC;IAC7D,MAAMN,SAAS,GAAGD,8BAA8B,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IAC5F,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACX,uBAAuB;QAAE,GAAGC,sBAAsB;QAAG,GAAGU,KAAK;kBAC5D,cAAA,KAACN,KAAK,KAAG;MACe,CAC1B;AACJ,CAAC,CAAC"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './constants';
|
|
14
14
|
export * from './WithDashboard';
|
|
15
|
+
export * from './WithDataQueriesProvider';
|
|
15
16
|
export * from './WithDatasourceStore';
|
|
16
17
|
export * from './WithPluginRegistry';
|
|
17
18
|
export * from './WithQueryClient';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/stories/decorators/index.ts"],"sourcesContent":["// Copyright 2023 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 './constants';\nexport * from './WithDashboard';\nexport * from './WithDatasourceStore';\nexport * from './WithPluginRegistry';\nexport * from './WithQueryClient';\nexport * from './WithQueryParams';\nexport * from './WithTemplateVariables';\nexport * from './WithTimeRange';\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,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/stories/decorators/index.ts"],"sourcesContent":["// Copyright 2023 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 './constants';\nexport * from './WithDashboard';\nexport * from './WithDataQueriesProvider';\nexport * from './WithDatasourceStore';\nexport * from './WithPluginRegistry';\nexport * from './WithQueryClient';\nexport * from './WithQueryParams';\nexport * from './WithTemplateVariables';\nexport * from './WithTimeRange';\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,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GlobalDatasource } from '@perses-dev/core';
|
|
2
|
+
import { DatasourceStoreProviderProps } from '../context';
|
|
3
|
+
export declare const prometheusDemoUrl = "https://prometheus.demo.do.prometheus.io";
|
|
4
|
+
export declare const prometheusDemo: GlobalDatasource;
|
|
5
|
+
export declare const defaultDatasourceProps: Pick<DatasourceStoreProviderProps, 'datasourceApi' | 'dashboardResource'>;
|
|
6
|
+
//# sourceMappingURL=datasource-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-provider.d.ts","sourceRoot":"","sources":["../../src/test/datasource-provider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAG1D,eAAO,MAAM,iBAAiB,6CAA6C,CAAC;AAC5E,eAAO,MAAM,cAAc,EAAE,gBAenB,CAAC;AAKX,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,4BAA4B,EAAE,eAAe,GAAG,mBAAmB,CAoB5G,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2023 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 { getTestDashboard } from './dashboard-provider';
|
|
14
|
+
export const prometheusDemoUrl = 'https://prometheus.demo.do.prometheus.io';
|
|
15
|
+
export const prometheusDemo = {
|
|
16
|
+
kind: 'GlobalDatasource',
|
|
17
|
+
metadata: {
|
|
18
|
+
name: 'PrometheusDemo',
|
|
19
|
+
created_at: '0001-01-01T00:00:00Z',
|
|
20
|
+
updated_at: '0001-01-01T00:00:00Z',
|
|
21
|
+
version: 0
|
|
22
|
+
},
|
|
23
|
+
spec: {
|
|
24
|
+
default: true,
|
|
25
|
+
plugin: {
|
|
26
|
+
kind: 'PrometheusDatasource',
|
|
27
|
+
spec: {
|
|
28
|
+
direct_url: prometheusDemoUrl
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// This default currently defines the bare minimum to get a story working in
|
|
34
|
+
// the `Dashboard` storybook with the Prometheus demo api. We'll likely want
|
|
35
|
+
// to expand it to do more in the future.
|
|
36
|
+
export const defaultDatasourceProps = {
|
|
37
|
+
dashboardResource: getTestDashboard(),
|
|
38
|
+
datasourceApi: {
|
|
39
|
+
getDatasource: ()=>{
|
|
40
|
+
return Promise.resolve(undefined);
|
|
41
|
+
},
|
|
42
|
+
getGlobalDatasource: (selector)=>{
|
|
43
|
+
if (selector.kind === 'PrometheusDatasource') {
|
|
44
|
+
return Promise.resolve({
|
|
45
|
+
resource: prometheusDemo,
|
|
46
|
+
proxyUrl: prometheusDemoUrl
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return Promise.resolve(undefined);
|
|
50
|
+
},
|
|
51
|
+
listDatasources: ()=>{
|
|
52
|
+
return Promise.resolve([]);
|
|
53
|
+
},
|
|
54
|
+
listGlobalDatasources: ()=>{
|
|
55
|
+
return Promise.resolve([]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=datasource-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/test/datasource-provider.tsx"],"sourcesContent":["// Copyright 2023 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 { GlobalDatasource } from '@perses-dev/core';\nimport { DatasourceStoreProviderProps } from '../context';\nimport { getTestDashboard } from './dashboard-provider';\n\nexport const prometheusDemoUrl = 'https://prometheus.demo.do.prometheus.io';\nexport const prometheusDemo: GlobalDatasource = {\n kind: 'GlobalDatasource',\n metadata: {\n name: 'PrometheusDemo',\n created_at: '0001-01-01T00:00:00Z',\n updated_at: '0001-01-01T00:00:00Z',\n version: 0,\n },\n spec: {\n default: true,\n plugin: {\n kind: 'PrometheusDatasource',\n spec: { direct_url: prometheusDemoUrl },\n },\n },\n} as const;\n\n// This default currently defines the bare minimum to get a story working in\n// the `Dashboard` storybook with the Prometheus demo api. We'll likely want\n// to expand it to do more in the future.\nexport const defaultDatasourceProps: Pick<DatasourceStoreProviderProps, 'datasourceApi' | 'dashboardResource'> = {\n dashboardResource: getTestDashboard(),\n datasourceApi: {\n getDatasource: () => {\n return Promise.resolve(undefined);\n },\n getGlobalDatasource: (selector) => {\n if (selector.kind === 'PrometheusDatasource') {\n return Promise.resolve({ resource: prometheusDemo, proxyUrl: prometheusDemoUrl });\n }\n\n return Promise.resolve(undefined);\n },\n listDatasources: () => {\n return Promise.resolve([]);\n },\n listGlobalDatasources: () => {\n return Promise.resolve([]);\n },\n },\n};\n"],"names":["getTestDashboard","prometheusDemoUrl","prometheusDemo","kind","metadata","name","created_at","updated_at","version","spec","default","plugin","direct_url","defaultDatasourceProps","dashboardResource","datasourceApi","getDatasource","Promise","resolve","undefined","getGlobalDatasource","selector","resource","proxy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C,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;QACDO,qBAAqB,EAAE,IAAM;YAC3B,OAAOR,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;KACF;CACF,CAAC"}
|
package/dist/test/index.d.ts
CHANGED
package/dist/test/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
package/dist/test/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './dashboard-provider';
|
|
14
|
+
export * from './datasource-provider';
|
|
14
15
|
export * from './plugin-registry';
|
|
15
16
|
export * from './render';
|
|
16
17
|
|
package/dist/test/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/index.ts"],"sourcesContent":["// Copyright 2023 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 './dashboard-provider';\nexport * from './plugin-registry';\nexport * from './render';\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,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/test/index.ts"],"sourcesContent":["// Copyright 2023 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 './dashboard-provider';\nexport * from './datasource-provider';\nexport * from './plugin-registry';\nexport * from './render';\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,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/test/plugin-registry.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAe,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/test/plugin-registry.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAe,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA0BpE,eAAO,MAAM,YAAY,EAAE,UAAU,EAA6B,CAAC"}
|
|
@@ -11,17 +11,23 @@
|
|
|
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
|
+
const FakeTimeSeriesChartOptionEditor = ()=>{
|
|
15
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
16
|
+
children: "TimeSeriesChart options"
|
|
17
|
+
});
|
|
18
|
+
};
|
|
14
19
|
const FakeTimeSeriesPlugin = {
|
|
15
20
|
PanelComponent: ()=>{
|
|
16
21
|
return /*#__PURE__*/ _jsx("div", {
|
|
17
22
|
children: "TimeSeriesChart panel"
|
|
18
23
|
});
|
|
19
24
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
panelOptionsEditorComponents: [
|
|
26
|
+
{
|
|
27
|
+
label: 'Settings',
|
|
28
|
+
content: FakeTimeSeriesChartOptionEditor
|
|
29
|
+
}
|
|
30
|
+
],
|
|
25
31
|
createInitialOptions: ()=>({})
|
|
26
32
|
};
|
|
27
33
|
const MOCK_TIME_SERIES_PANEL = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/plugin-registry.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PanelPlugin, MockPlugin } from '@perses-dev/plugin-system';\n\nconst FakeTimeSeriesPlugin: PanelPlugin<UnknownSpec> = {\n PanelComponent: () => {\n return <div>TimeSeriesChart panel</div>;\n },\n
|
|
1
|
+
{"version":3,"sources":["../../src/test/plugin-registry.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PanelPlugin, MockPlugin } from '@perses-dev/plugin-system';\n\nconst FakeTimeSeriesChartOptionEditor = () => {\n return <div>TimeSeriesChart options</div>;\n};\n\nconst FakeTimeSeriesPlugin: PanelPlugin<UnknownSpec> = {\n PanelComponent: () => {\n return <div>TimeSeriesChart panel</div>;\n },\n panelOptionsEditorComponents: [\n {\n label: 'Settings',\n content: FakeTimeSeriesChartOptionEditor,\n },\n ],\n createInitialOptions: () => ({}),\n};\n\nconst MOCK_TIME_SERIES_PANEL: MockPlugin = {\n pluginType: 'Panel',\n kind: 'TimeSeriesChart',\n plugin: FakeTimeSeriesPlugin,\n};\n\n// Array of default mock plugins added to the PluginRegistry during test renders\nexport const MOCK_PLUGINS: MockPlugin[] = [MOCK_TIME_SERIES_PANEL];\n"],"names":["FakeTimeSeriesChartOptionEditor","div","FakeTimeSeriesPlugin","PanelComponent","panelOptionsEditorComponents","label","content","createInitialOptions","MOCK_TIME_SERIES_PANEL","pluginType","kind","plugin","MOCK_PLUGINS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAGA,MAAMA,+BAA+B,GAAG,IAAM;IAC5C,qBAAO,KAACC,KAAG;kBAAC,yBAAuB;MAAM,CAAC;AAC5C,CAAC,AAAC;AAEF,MAAMC,oBAAoB,GAA6B;IACrDC,cAAc,EAAE,IAAM;QACpB,qBAAO,KAACF,KAAG;sBAAC,uBAAqB;UAAM,CAAC;IAC1C,CAAC;IACDG,4BAA4B,EAAE;QAC5B;YACEC,KAAK,EAAE,UAAU;YACjBC,OAAO,EAAEN,+BAA+B;SACzC;KACF;IACDO,oBAAoB,EAAE,IAAO,CAAA,EAAE,CAAA,AAAC;CACjC,AAAC;AAEF,MAAMC,sBAAsB,GAAe;IACzCC,UAAU,EAAE,OAAO;IACnBC,IAAI,EAAE,iBAAiB;IACvBC,MAAM,EAAET,oBAAoB;CAC7B,AAAC;AAEF,gFAAgF;AAChF,OAAO,MAAMU,YAAY,GAAiB;IAACJ,sBAAsB;CAAC,CAAC"}
|
|
@@ -54,24 +54,24 @@ const testDashboard = {
|
|
|
54
54
|
plugin: {
|
|
55
55
|
kind: 'TimeSeriesChart',
|
|
56
56
|
spec: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
unit: {
|
|
58
|
+
kind: '%'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
queries: [
|
|
63
|
+
{
|
|
64
|
+
kind: 'TimeSeriesQuery',
|
|
65
|
+
spec: {
|
|
66
|
+
plugin: {
|
|
67
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
60
68
|
spec: {
|
|
61
|
-
|
|
62
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
63
|
-
spec: {
|
|
64
|
-
query: 'avg without (cpu)(rate(node_cpu_seconds_total{job="node",instance="$instance",mode!="idle"}[$interval]))'
|
|
65
|
-
}
|
|
66
|
-
}
|
|
69
|
+
query: 'avg without (cpu)(rate(node_cpu_seconds_total{job="node",instance="$instance",mode!="idle"}[$interval]))'
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
|
-
],
|
|
70
|
-
unit: {
|
|
71
|
-
kind: '%'
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
]
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
memory: {
|
|
@@ -83,57 +83,57 @@ const testDashboard = {
|
|
|
83
83
|
plugin: {
|
|
84
84
|
kind: 'TimeSeriesChart',
|
|
85
85
|
spec: {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
unit: {
|
|
87
|
+
kind: 'Bytes'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
queries: [
|
|
92
|
+
{
|
|
93
|
+
kind: 'TimeSeriesQuery',
|
|
94
|
+
spec: {
|
|
95
|
+
plugin: {
|
|
96
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
89
97
|
spec: {
|
|
90
|
-
|
|
91
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
92
|
-
spec: {
|
|
93
|
-
query: 'node_memory_MemTotal_bytes{job="node",instance="$instance"} - node_memory_MemFree_bytes{job="node",instance="$instance"} - node_memory_Buffers_bytes{job="node",instance="$instance"} - node_memory_Cached_bytes{job="node",instance="$instance"}'
|
|
94
|
-
}
|
|
95
|
-
}
|
|
98
|
+
query: 'node_memory_MemTotal_bytes{job="node",instance="$instance"} - node_memory_MemFree_bytes{job="node",instance="$instance"} - node_memory_Buffers_bytes{job="node",instance="$instance"} - node_memory_Cached_bytes{job="node",instance="$instance"}'
|
|
96
99
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
kind: 'TimeSeriesQuery',
|
|
105
|
+
spec: {
|
|
106
|
+
plugin: {
|
|
107
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
100
108
|
spec: {
|
|
101
|
-
|
|
102
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
103
|
-
spec: {
|
|
104
|
-
query: 'node_memory_Buffers_bytes{job="node",instance="$instance"}'
|
|
105
|
-
}
|
|
106
|
-
}
|
|
109
|
+
query: 'node_memory_Buffers_bytes{job="node",instance="$instance"}'
|
|
107
110
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
kind: 'TimeSeriesQuery',
|
|
116
|
+
spec: {
|
|
117
|
+
plugin: {
|
|
118
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
111
119
|
spec: {
|
|
112
|
-
|
|
113
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
114
|
-
spec: {
|
|
115
|
-
query: 'node_memory_Cached_bytes{job="node",instance="$instance"}'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
120
|
+
query: 'node_memory_Cached_bytes{job="node",instance="$instance"}'
|
|
118
121
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
kind: 'TimeSeriesQuery',
|
|
127
|
+
spec: {
|
|
128
|
+
plugin: {
|
|
129
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
122
130
|
spec: {
|
|
123
|
-
|
|
124
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
125
|
-
spec: {
|
|
126
|
-
query: 'node_memory_MemFree_bytes{job="node",instance="$instance"}'
|
|
127
|
-
}
|
|
128
|
-
}
|
|
131
|
+
query: 'node_memory_MemFree_bytes{job="node",instance="$instance"}'
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
],
|
|
132
|
-
unit: {
|
|
133
|
-
kind: 'Bytes'
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
]
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
// This panel is referenced in more than one layout below
|
|
@@ -146,24 +146,24 @@ const testDashboard = {
|
|
|
146
146
|
plugin: {
|
|
147
147
|
kind: 'TimeSeriesChart',
|
|
148
148
|
spec: {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
unit: {
|
|
150
|
+
kind: 'Percent'
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
queries: [
|
|
155
|
+
{
|
|
156
|
+
kind: 'TimeSeriesQuery',
|
|
157
|
+
spec: {
|
|
158
|
+
plugin: {
|
|
159
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
152
160
|
spec: {
|
|
153
|
-
|
|
154
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
155
|
-
spec: {
|
|
156
|
-
query: 'rate(node_disk_io_time_seconds_total{job="node",instance="$instance",device!~"^(md\\\\d+$|dm-)"}[$interval])'
|
|
157
|
-
}
|
|
158
|
-
}
|
|
161
|
+
query: 'rate(node_disk_io_time_seconds_total{job="node",instance="$instance",device!~"^(md\\\\d+$|dm-)"}[$interval])'
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
|
-
],
|
|
162
|
-
unit: {
|
|
163
|
-
kind: 'Percent'
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
]
|
|
167
167
|
}
|
|
168
168
|
},
|
|
169
169
|
filesystemFullness: {
|
|
@@ -175,24 +175,24 @@ const testDashboard = {
|
|
|
175
175
|
plugin: {
|
|
176
176
|
kind: 'TimeSeriesChart',
|
|
177
177
|
spec: {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
unit: {
|
|
179
|
+
kind: 'Percent'
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
queries: [
|
|
184
|
+
{
|
|
185
|
+
kind: 'TimeSeriesQuery',
|
|
186
|
+
spec: {
|
|
187
|
+
plugin: {
|
|
188
|
+
kind: 'PrometheusTimeSeriesQuery',
|
|
181
189
|
spec: {
|
|
182
|
-
|
|
183
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
184
|
-
spec: {
|
|
185
|
-
query: '1 - node_filesystem_free_bytes{job="node",instance="$instance",fstype!="rootfs",mountpoint!~"/(run|var).*",mountpoint!=""} / node_filesystem_size_bytes{job="node",instance="$instance"}'
|
|
186
|
-
}
|
|
187
|
-
}
|
|
190
|
+
query: '1 - node_filesystem_free_bytes{job="node",instance="$instance",fstype!="rootfs",mountpoint!~"/(run|var).*",mountpoint!=""} / node_filesystem_size_bytes{job="node",instance="$instance"}'
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
|
-
],
|
|
191
|
-
unit: {
|
|
192
|
-
kind: 'Percent'
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
|
|
195
|
+
]
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
},
|