@perses-dev/dashboards 0.8.0 → 0.9.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 +29 -14
- package/dist/cjs/components/DashboardToolbar.js +148 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
- package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
- package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
- package/dist/cjs/components/GridLayout/index.js +18 -19
- package/dist/cjs/components/Panel/Panel.js +145 -55
- package/dist/cjs/components/Panel/Panel.test.js +50 -41
- package/dist/cjs/components/Panel/PanelContent.js +40 -12
- package/dist/cjs/components/Panel/index.js +16 -17
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
- package/dist/cjs/components/PanelDrawer/index.js +28 -0
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
- package/dist/cjs/components/TimeRangeControls/index.js +16 -17
- package/dist/cjs/components/Variables/Variable.js +186 -35
- package/dist/cjs/components/Variables/VariableList.js +100 -13
- package/dist/cjs/components/Variables/index.js +17 -18
- package/dist/cjs/components/index.js +21 -21
- package/dist/cjs/context/DashboardAppSlice.js +43 -31
- package/dist/cjs/context/DashboardProvider.js +88 -58
- package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
- package/dist/cjs/context/LayoutsSlice.js +40 -27
- package/dist/cjs/context/QueryStringProvider.js +69 -15
- package/dist/cjs/context/TemplateVariableProvider.js +128 -136
- package/dist/cjs/context/TimeRangeProvider.js +79 -30
- package/dist/cjs/context/index.js +22 -22
- package/dist/cjs/css/styles.js +43 -39
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/test/dashboard-provider.js +51 -0
- package/dist/cjs/test/index.js +18 -18
- package/dist/cjs/test/plugin-registry.js +52 -25
- package/dist/cjs/test/render.js +25 -22
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/test/testDashboard.js +193 -109
- package/dist/cjs/utils/functions.js +9 -5
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
- package/dist/cjs/views/ViewDashboard/index.js +28 -0
- package/dist/cjs/views/index.js +16 -17
- package/dist/components/Dashboard.js +38 -1
- package/dist/components/Dashboard.js.map +1 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +154 -1
- package/dist/components/DashboardToolbar.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.js +35 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -0
- package/dist/components/GridLayout/GridLayout.js +99 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.js +77 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -0
- package/dist/components/GridLayout/index.js +16 -1
- package/dist/components/GridLayout/index.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +170 -1
- package/dist/components/Panel/Panel.js.map +1 -0
- package/dist/components/Panel/Panel.test.js +71 -1
- package/dist/components/Panel/Panel.test.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +2 -4
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +40 -1
- package/dist/components/Panel/PanelContent.js.map +1 -0
- package/dist/components/Panel/index.js +15 -1
- package/dist/components/Panel/index.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
- package/dist/components/PanelDrawer/index.d.ts +2 -0
- package/dist/components/PanelDrawer/index.d.ts.map +1 -0
- package/dist/components/PanelDrawer/index.js +15 -0
- package/dist/components/PanelDrawer/index.js.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
- package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
- package/dist/components/TimeRangeControls/index.js +15 -1
- package/dist/components/TimeRangeControls/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +202 -1
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableList.js +108 -1
- package/dist/components/Variables/VariableList.js.map +1 -0
- package/dist/components/Variables/index.js +16 -1
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +20 -1
- package/dist/components/index.js.map +1 -0
- package/dist/context/DashboardAppSlice.js +45 -1
- package/dist/context/DashboardAppSlice.js.map +1 -0
- package/dist/context/DashboardProvider.d.ts +4 -2
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +107 -1
- package/dist/context/DashboardProvider.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +16 -0
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
- package/dist/context/DatasourceStoreProvider.js +64 -0
- package/dist/context/DatasourceStoreProvider.js.map +1 -0
- package/dist/context/LayoutsSlice.js +43 -1
- package/dist/context/LayoutsSlice.js.map +1 -0
- package/dist/context/QueryStringProvider.js +40 -1
- package/dist/context/QueryStringProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +6 -3
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +192 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider.js +72 -1
- package/dist/context/TimeRangeProvider.js.map +1 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +21 -1
- package/dist/context/index.js.map +1 -0
- package/dist/css/styles.js +186 -1
- package/dist/css/styles.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/test/dashboard-provider.d.ts +19 -0
- package/dist/test/dashboard-provider.d.ts.map +1 -0
- package/dist/test/dashboard-provider.js +40 -0
- package/dist/test/dashboard-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 +17 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -3
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +74 -1
- package/dist/test/plugin-registry.js.map +1 -0
- package/dist/test/render.d.ts +1 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +34 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +274 -1
- package/dist/test/testDashboard.js.map +1 -0
- package/dist/utils/functions.js +17 -1
- package/dist/utils/functions.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.js +56 -0
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
- package/dist/views/ViewDashboard/index.d.ts +2 -0
- package/dist/views/ViewDashboard/index.d.ts.map +1 -0
- package/dist/views/ViewDashboard/index.js +15 -0
- package/dist/views/ViewDashboard/index.js.map +1 -0
- package/dist/views/index.js +15 -1
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -43
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
- package/dist/views/DashboardApp.d.ts +0 -4
- package/dist/views/DashboardApp.d.ts.map +0 -1
- package/dist/views/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard.d.ts.map +0 -1
- package/dist/views/ViewDashboard.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelDrawer.test.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PluginRegistry } from '@perses-dev/plugin-system';\nimport { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { act } from 'react-dom/test-utils';\nimport {\n createDashboardProviderSpy,\n FAKE_PANEL_PLUGIN,\n getTestDashboard,\n mockPluginRegistryProps,\n renderWithContext,\n} from '../../test';\nimport { DashboardProvider } from '../../context/DashboardProvider';\nimport { PanelDrawer } from './PanelDrawer';\n\ndescribe('Panel Drawer', () => {\n const renderPanelDrawer = () => {\n const { addMockPlugin, pluginRegistryProps } = mockPluginRegistryProps();\n addMockPlugin('Panel', 'LineChart', FAKE_PANEL_PLUGIN);\n\n const { store, DashboardProviderSpy } = createDashboardProviderSpy();\n\n renderWithContext(\n <PluginRegistry {...pluginRegistryProps}>\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode: true }}>\n <DashboardProviderSpy />\n <PanelDrawer />\n </DashboardProvider>\n </PluginRegistry>\n );\n\n const { value: storeApi } = store;\n if (storeApi === undefined) {\n throw new Error('Expected dashboard store to be set after initial render');\n }\n\n return storeApi;\n };\n\n it('should add new panel', async () => {\n const storeApi = renderPanelDrawer();\n\n // Open the drawer for a new panel (i.e. no panel key)\n act(() => storeApi.getState().openPanelDrawer({ groupIndex: 0 }));\n\n const nameInput = await screen.findByLabelText(/Panel Name/);\n userEvent.type(nameInput, 'New Panel');\n userEvent.click(screen.getByText('Add'));\n\n // TODO: Assert drawer is closed?\n const panels = storeApi.getState().panels;\n expect(panels).toMatchObject({\n // Should have the new panel in the store\n NewPanel: {\n kind: 'Panel',\n spec: {\n display: { name: 'New Panel', description: '' },\n plugin: {\n kind: '',\n spec: {},\n },\n },\n },\n });\n });\n\n it('should edit an existing panel', async () => {\n const storeApi = renderPanelDrawer();\n\n // Open the drawer for an existing panel\n act(() => storeApi.getState().openPanelDrawer({ groupIndex: 0, panelKey: 'cpu' }));\n\n const nameInput = await screen.findByLabelText(/Panel Name/);\n userEvent.clear(nameInput);\n userEvent.type(nameInput, 'cpu usage');\n userEvent.click(screen.getByText('Apply'));\n\n const panels = storeApi.getState().panels;\n expect(panels).toMatchObject({\n cpu: {\n kind: 'Panel',\n spec: {\n display: { name: 'cpu usage', description: '' },\n plugin: {\n kind: 'TimeSeriesChart',\n spec: {},\n },\n },\n },\n });\n });\n});\n"],"names":["PluginRegistry","screen","userEvent","act","createDashboardProviderSpy","FAKE_PANEL_PLUGIN","getTestDashboard","mockPluginRegistryProps","renderWithContext","DashboardProvider","PanelDrawer","describe","renderPanelDrawer","addMockPlugin","pluginRegistryProps","store","DashboardProviderSpy","initialState","dashboardSpec","spec","isEditMode","value","storeApi","undefined","Error","it","getState","openPanelDrawer","groupIndex","nameInput","findByLabelText","type","click","getByText","panels","expect","toMatchObject","NewPanel","kind","display","name","description","plugin","panelKey","clear","cpu"],"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,cAAc,QAAQ,2BAA2B,CAAC;AAC3D,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,GAAG,QAAQ,sBAAsB,CAAC;AAC3C,SACEC,0BAA0B,EAC1BC,iBAAiB,EACjBC,gBAAgB,EAChBC,uBAAuB,EACvBC,iBAAiB,QACZ,YAAY,CAAC;AACpB,SAASC,iBAAiB,QAAQ,iCAAiC,CAAC;AACpE,SAASC,WAAW,QAAQ,eAAe,CAAC;AAE5CC,QAAQ,CAAC,cAAc,EAAE,IAAM;IAC7B,MAAMC,iBAAiB,GAAG,IAAM;QAC9B,MAAM,EAAEC,aAAa,CAAA,EAAEC,mBAAmB,CAAA,EAAE,GAAGP,uBAAuB,EAAE,AAAC;QACzEM,aAAa,CAAC,OAAO,EAAE,WAAW,EAAER,iBAAiB,CAAC,CAAC;QAEvD,MAAM,EAAEU,KAAK,CAAA,EAAEC,oBAAoB,CAAA,EAAE,GAAGZ,0BAA0B,EAAE,AAAC;QAErEI,iBAAiB,eACf,KAACR,cAAc;YAAE,GAAGc,mBAAmB;sBACrC,cAAA,MAACL,iBAAiB;gBAACQ,YAAY,EAAE;oBAAEC,aAAa,EAAEZ,gBAAgB,EAAE,CAACa,IAAI;oBAAEC,UAAU,EAAE,IAAI;iBAAE;;kCAC3F,KAACJ,oBAAoB,KAAG;kCACxB,KAACN,WAAW,KAAG;;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AG,CAAC,IAAMmB,QAAQ,CAACI,QAAQ,EAAE,CAACC,eAAe,CAAC;gBAAEC,UAAU,EAAE,CAAC;gBAAEe,QAAQ,EAAE,KAAK;aAAE,CAAC,CAAC,CAAC;QAEnF,MAAMd,SAAS,GAAG,MAAM5B,MAAM,CAAC6B,eAAe,cAAc,AAAC;QAC7D5B,SAAS,CAAC0C,KAAK,CAACf,SAAS,CAAC,CAAC;QAC3B3B,SAAS,CAAC6B,IAAI,CAACF,SAAS,EAAE,WAAW,CAAC,CAAC;QACvC3B,SAAS,CAAC8B,KAAK,CAAC/B,MAAM,CAACgC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAE3C,MAAMC,MAAM,GAAGZ,QAAQ,CAACI,QAAQ,EAAE,CAACQ,MAAM,AAAC;QAC1CC,MAAM,CAACD,MAAM,CAAC,CAACE,aAAa,CAAC;YAC3BS,GAAG,EAAE;gBACHP,IAAI,EAAE,OAAO;gBACbnB,IAAI,EAAE;oBACJoB,OAAO,EAAE;wBAAEC,IAAI,EAAE,WAAW;wBAAEC,WAAW,EAAE,EAAE;qBAAE;oBAC/CC,MAAM,EAAE;wBACNJ,IAAI,EAAE,iBAAiB;wBACvBnB,IAAI,EAAE,EAAE;qBACT;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PanelEditorFormValues } from './panel-editor-model';
|
|
3
|
+
export interface PanelEditorFormProps {
|
|
4
|
+
initialValues: PanelEditorFormValues;
|
|
5
|
+
onSubmit: (values: PanelEditorFormValues) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function PanelEditorForm(props: PanelEditorFormProps): JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.
|
|
10
|
+
*/
|
|
11
|
+
export declare const panelEditorFormId = "panel-editor-form";
|
|
12
|
+
//# sourceMappingURL=PanelEditorForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,qBAAqB,EAAqB,MAAM,sBAAsB,CAAC;AAIhF,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,qBAAqB,CAAC;IACrC,QAAQ,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACnD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eA+E1D;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
import { Grid, FormControl, InputLabel, Select, MenuItem, TextField } from '@mui/material';
|
|
16
|
+
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
17
|
+
import { useLayouts } from '../../context';
|
|
18
|
+
import { usePanelSpecState } from './panel-editor-model';
|
|
19
|
+
import { PanelTypeSelect } from './PanelTypeSelect';
|
|
20
|
+
import { PanelSpecEditor } from './PanelSpecEditor';
|
|
21
|
+
export function PanelEditorForm(props) {
|
|
22
|
+
const { initialValues , onSubmit } = props;
|
|
23
|
+
const { layouts } = useLayouts();
|
|
24
|
+
const [name, setName] = useState(initialValues.name);
|
|
25
|
+
const [description, setDescription] = useState(initialValues.description);
|
|
26
|
+
const [group, setGroup] = useState(initialValues.group);
|
|
27
|
+
const [kind, setKind] = useState(initialValues.kind);
|
|
28
|
+
const { spec , onSpecChange } = usePanelSpecState(kind, initialValues.spec);
|
|
29
|
+
// Ignore string values (which would be an "empty" value from the Select) since we don't allow them to unset it
|
|
30
|
+
const handleGroupChange = (e)=>{
|
|
31
|
+
const { value } = e.target;
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setGroup(value);
|
|
36
|
+
};
|
|
37
|
+
const handleSubmit = (e)=>{
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
const values = {
|
|
40
|
+
name,
|
|
41
|
+
description,
|
|
42
|
+
group,
|
|
43
|
+
kind,
|
|
44
|
+
spec
|
|
45
|
+
};
|
|
46
|
+
onSubmit(values);
|
|
47
|
+
};
|
|
48
|
+
var ref;
|
|
49
|
+
return /*#__PURE__*/ _jsx("form", {
|
|
50
|
+
id: panelEditorFormId,
|
|
51
|
+
onSubmit: handleSubmit,
|
|
52
|
+
children: /*#__PURE__*/ _jsxs(Grid, {
|
|
53
|
+
container: true,
|
|
54
|
+
spacing: 2,
|
|
55
|
+
children: [
|
|
56
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
57
|
+
item: true,
|
|
58
|
+
xs: 8,
|
|
59
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
60
|
+
required: true,
|
|
61
|
+
label: "Panel Name",
|
|
62
|
+
value: name,
|
|
63
|
+
variant: "outlined",
|
|
64
|
+
onChange: (e)=>setName(e.target.value)
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
68
|
+
item: true,
|
|
69
|
+
xs: 4,
|
|
70
|
+
children: /*#__PURE__*/ _jsxs(FormControl, {
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
73
|
+
id: "select-group",
|
|
74
|
+
children: "Group"
|
|
75
|
+
}),
|
|
76
|
+
/*#__PURE__*/ _jsx(Select, {
|
|
77
|
+
required: true,
|
|
78
|
+
labelId: "select-group",
|
|
79
|
+
label: "Group",
|
|
80
|
+
value: group !== null && group !== void 0 ? group : 0,
|
|
81
|
+
onChange: handleGroupChange,
|
|
82
|
+
children: layouts.map((layout, index)=>{
|
|
83
|
+
var ref1;
|
|
84
|
+
/*#__PURE__*/ return _jsx(MenuItem, {
|
|
85
|
+
value: index,
|
|
86
|
+
children: (ref = (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref !== void 0 ? ref : `Group ${index + 1}`
|
|
87
|
+
}, index);
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
}),
|
|
93
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
94
|
+
item: true,
|
|
95
|
+
xs: 8,
|
|
96
|
+
children: /*#__PURE__*/ _jsx(TextField, {
|
|
97
|
+
label: "Panel Description",
|
|
98
|
+
value: description,
|
|
99
|
+
variant: "outlined",
|
|
100
|
+
onChange: (e)=>setDescription(e.target.value)
|
|
101
|
+
})
|
|
102
|
+
}),
|
|
103
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
104
|
+
item: true,
|
|
105
|
+
xs: 4,
|
|
106
|
+
children: /*#__PURE__*/ _jsxs(FormControl, {
|
|
107
|
+
children: [
|
|
108
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
109
|
+
id: "panel-type-label",
|
|
110
|
+
children: "Panel Type"
|
|
111
|
+
}),
|
|
112
|
+
/*#__PURE__*/ _jsx(PanelTypeSelect, {
|
|
113
|
+
required: true,
|
|
114
|
+
labelId: "panel-type-label",
|
|
115
|
+
label: "Panel Type",
|
|
116
|
+
value: kind,
|
|
117
|
+
onChange: (e)=>setKind(e.target.value)
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
})
|
|
121
|
+
}),
|
|
122
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
123
|
+
item: true,
|
|
124
|
+
xs: 12,
|
|
125
|
+
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
126
|
+
FallbackComponent: ErrorAlert,
|
|
127
|
+
children: spec !== undefined && /*#__PURE__*/ _jsx(PanelSpecEditor, {
|
|
128
|
+
panelPluginKind: kind,
|
|
129
|
+
value: spec,
|
|
130
|
+
onChange: onSpecChange
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.
|
|
140
|
+
*/ export const panelEditorFormId = 'panel-editor-form';
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=PanelEditorForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.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 { FormEventHandler, useState } from 'react';\nimport { Grid, FormControl, InputLabel, Select, MenuItem, TextField, SelectProps } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { useLayouts } from '../../context';\nimport { PanelEditorFormValues, usePanelSpecState } from './panel-editor-model';\nimport { PanelTypeSelect } from './PanelTypeSelect';\nimport { PanelSpecEditor } from './PanelSpecEditor';\n\nexport interface PanelEditorFormProps {\n initialValues: PanelEditorFormValues;\n onSubmit: (values: PanelEditorFormValues) => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps) {\n const { initialValues, onSubmit } = props;\n\n const { layouts } = useLayouts();\n\n const [name, setName] = useState(initialValues.name);\n const [description, setDescription] = useState(initialValues.description);\n const [group, setGroup] = useState(initialValues.group);\n const [kind, setKind] = useState(initialValues.kind);\n const { spec, onSpecChange } = usePanelSpecState(kind, initialValues.spec);\n\n // Ignore string values (which would be an \"empty\" value from the Select) since we don't allow them to unset it\n const handleGroupChange: SelectProps<number>['onChange'] = (e) => {\n const { value } = e.target;\n if (typeof value === 'string') {\n return;\n }\n setGroup(value);\n };\n\n const handleSubmit: FormEventHandler = (e) => {\n e.preventDefault();\n const values: PanelEditorFormValues = { name, description, group, kind, spec };\n onSubmit(values);\n };\n\n return (\n <form id={panelEditorFormId} onSubmit={handleSubmit}>\n <Grid container spacing={2}>\n <Grid item xs={8}>\n <TextField\n required\n label=\"Panel Name\"\n value={name}\n variant=\"outlined\"\n onChange={(e) => setName(e.target.value)}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl>\n <InputLabel id=\"select-group\">Group</InputLabel>\n <Select required labelId=\"select-group\" label=\"Group\" value={group ?? 0} onChange={handleGroupChange}>\n {layouts.map((layout, index) => (\n <MenuItem key={index} value={index}>\n {layout.spec.display?.title ?? `Group ${index + 1}`}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n <Grid item xs={8}>\n <TextField\n label=\"Panel Description\"\n value={description}\n variant=\"outlined\"\n onChange={(e) => setDescription(e.target.value)}\n />\n </Grid>\n <Grid item xs={4}>\n <FormControl>\n <InputLabel id=\"panel-type-label\">Panel Type</InputLabel>\n <PanelTypeSelect\n required\n labelId=\"panel-type-label\"\n label=\"Panel Type\"\n value={kind}\n onChange={(e) => setKind(e.target.value)}\n />\n </FormControl>\n </Grid>\n <Grid item xs={12}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n {/* Wait until we have some proper initial spec values before rendering the editor */}\n {spec !== undefined && <PanelSpecEditor panelPluginKind={kind} value={spec} onChange={onSpecChange} />}\n </ErrorBoundary>\n </Grid>\n </Grid>\n </form>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelEditorFormId = 'panel-editor-form';\n"],"names":["useState","Grid","FormControl","InputLabel","Select","MenuItem","TextField","ErrorAlert","ErrorBoundary","useLayouts","usePanelSpecState","PanelTypeSelect","PanelSpecEditor","PanelEditorForm","props","initialValues","onSubmit","layouts","name","setName","description","setDescription","group","setGroup","kind","setKind","spec","onSpecChange","handleGroupChange","e","value","target","handleSubmit","preventDefault","values","layout","form","id","panelEditorFormId","container","spacing","item","xs","required","label","variant","onChange","labelId","map","index","display","title","FallbackComponent","undefined","panelPluginKind"],"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,SAA2BA,QAAQ,QAAQ,OAAO,CAAC;AACnD,SAASC,IAAI,EAAEC,WAAW,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,SAAS,QAAqB,eAAe,CAAC;AACxG,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAwB,CAAC;AACnE,SAASC,UAAU,QAAQ,eAAe,CAAC;AAC3C,SAAgCC,iBAAiB,QAAQ,sBAAsB,CAAC;AAChF,SAASC,eAAe,QAAQ,mBAAmB,CAAC;AACpD,SAASC,eAAe,QAAQ,mBAAmB,CAAC;AAOpD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,E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C,mBAAmB;wBACzBd,KAAK,EAAEV,WAAW;wBAClByB,OAAO,EAAC,UAAU;wBAClBC,QAAQ,EAAE,CAACjB,CAAC,GAAKR,cAAc,CAACQ,CAAC,CAACE,MAAM,CAACD,KAAK,CAAC;sBAC/C;kBACG;8BACP,KAAC7B,IAAI;oBAACwC,IAAI;oBAACC,EAAE,EAAE,CAAC;8BACd,cAAA,MAACxC,WAAW;;0CACV,KAACC,UAAU;gCAACkC,EAAE,EAAC,kBAAkB;0CAAC,YAAU;8BAAa;0CACzD,KAAC1B,eAAe;gCACdgC,QAAQ;gCACRI,OAAO,EAAC,kBAAkB;gCAC1BH,KAAK,EAAC,YAAY;gCAClBd,KAAK,EAAEN,IAAI;gCACXsB,QAAQ,EAAE,CAACjB,CAAC,GAAKJ,OAAO,CAACI,CAAC,CAACE,MAAM,CAACD,KAAK,CAAC;8BACxC;;sBACU;kBACT;8BACP,KAAC7B,IAAI;oBAACwC,IAAI;oBAACC,EAAE,EAAE,EAAE;8BACf,cAAA,KAAClC,aAAa;wBAAC4C,iBAAiB,EAAE7C,UAAU;kCAEzCmB,IAAI,KAAK2B,SAAS,kBAAI,KAACzC,eAAe;4BAAC0C,eAAe,EAAE9B,IAAI;4BAAEM,KAAK,EAAEJ,IAAI;4BAAEoB,QAAQ,EAAEnB,YAAY;0BAAI;sBACxF;kBACX;;UACF;MACF,CACP;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,MAAMW,iBAAiB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
|
+
export interface PanelSpecEditorProps extends OptionsEditorProps<unknown> {
|
|
4
|
+
panelPluginKind: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function PanelSpecEditor(props: PanelSpecEditorProps): JSX.Element | null;
|
|
7
|
+
//# sourceMappingURL=PanelSpecEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelSpecEditor.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAa,MAAM,2BAA2B,CAAC;AAE1E,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB,CAAC,OAAO,CAAC;IACvE,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,sBAkB1D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { usePlugin } from '@perses-dev/plugin-system';
|
|
15
|
+
export function PanelSpecEditor(props) {
|
|
16
|
+
const { panelPluginKind , ...others } = props;
|
|
17
|
+
const { data: plugin , isLoading } = usePlugin('Panel', panelPluginKind, {
|
|
18
|
+
useErrorBoundary: true,
|
|
19
|
+
enabled: panelPluginKind !== ''
|
|
20
|
+
});
|
|
21
|
+
// TODO: Proper loading indicator
|
|
22
|
+
if (isLoading) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (plugin === undefined) {
|
|
26
|
+
throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);
|
|
27
|
+
}
|
|
28
|
+
const { OptionsEditorComponent } = plugin;
|
|
29
|
+
return /*#__PURE__*/ _jsx(OptionsEditorComponent, {
|
|
30
|
+
...others
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=PanelSpecEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelSpecEditor.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 { OptionsEditorProps, usePlugin } from '@perses-dev/plugin-system';\n\nexport interface PanelSpecEditorProps extends OptionsEditorProps<unknown> {\n panelPluginKind: string;\n}\n\nexport function PanelSpecEditor(props: PanelSpecEditorProps) {\n const { panelPluginKind, ...others } = props;\n const { data: plugin, isLoading } = usePlugin('Panel', panelPluginKind, {\n useErrorBoundary: true,\n enabled: panelPluginKind !== '',\n });\n\n // TODO: Proper loading indicator\n if (isLoading) {\n return null;\n }\n\n if (plugin === undefined) {\n throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);\n }\n\n const { OptionsEditorComponent } = plugin;\n return <OptionsEditorComponent {...others} />;\n}\n"],"names":["usePlugin","PanelSpecEditor","props","panelPluginKind","others","data","plugin","isLoading","useErrorBoundary","enabled","undefined","Error","OptionsEditorComponent"],"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,SAA6BA,SAAS,QAAQ,2BAA2B,CAAC;AAM1E,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,eAAe,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGF,KAAK,AAAC;IAC7C,MAAM,EAAEG,IAAI,EAAEC,MAAM,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGP,SAAS,CAAC,OAAO,EAAEG,eAAe,EAAE;QACtEK,gBAAgB,EAAE,IAAI;QACtBC,OAAO,EAAEN,eAAe,KAAK,EAAE;KAChC,CAAC,AAAC;IAEH,iCAAiC;IACjC,IAAII,SAAS,EAAE;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAID,MAAM,KAAKI,SAAS,EAAE;QACxB,MAAM,IAAIC,KAAK,CAAC,CAAC,2DAA2D,EAAER,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IACpG,CAAC;IAED,MAAM,EAAES,sBAAsB,CAAA,EAAE,GAAGN,MAAM,AAAC;IAC1C,qBAAO,KAACM,sBAAsB;QAAE,GAAGR,MAAM;MAAI,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SelectProps } from '@mui/material';
|
|
3
|
+
export declare type PanelTypeSelectProps = Omit<SelectProps<string>, 'children'>;
|
|
4
|
+
/**
|
|
5
|
+
* Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.
|
|
6
|
+
*/
|
|
7
|
+
export declare function PanelTypeSelect(props: PanelTypeSelectProps): JSX.Element;
|
|
8
|
+
//# sourceMappingURL=PanelTypeSelect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PanelTypeSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelTypeSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,WAAW,EAAY,MAAM,eAAe,CAAC;AAG9D,oBAAY,oBAAoB,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AAEzE;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAiB1D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { Select, MenuItem } from '@mui/material';
|
|
15
|
+
import { useListPluginMetadata } from '@perses-dev/plugin-system';
|
|
16
|
+
/**
|
|
17
|
+
* Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.
|
|
18
|
+
*/ export function PanelTypeSelect(props) {
|
|
19
|
+
const { value: propValue , ...others } = props;
|
|
20
|
+
const { data , isLoading } = useListPluginMetadata('Panel');
|
|
21
|
+
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
22
|
+
const value = propValue !== '' && isLoading ? '' : propValue;
|
|
23
|
+
// TODO: Does this need a loading indicator of some kind?
|
|
24
|
+
return /*#__PURE__*/ _jsx(Select, {
|
|
25
|
+
...others,
|
|
26
|
+
value: value,
|
|
27
|
+
children: data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
28
|
+
value: metadata.kind,
|
|
29
|
+
children: metadata.display.name
|
|
30
|
+
}, metadata.kind))
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=PanelTypeSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelTypeSelect.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 { Select, SelectProps, MenuItem } from '@mui/material';\nimport { useListPluginMetadata } from '@perses-dev/plugin-system';\n\nexport type PanelTypeSelectProps = Omit<SelectProps<string>, 'children'>;\n\n/**\n * Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.\n */\nexport function PanelTypeSelect(props: PanelTypeSelectProps) {\n const { value: propValue, ...others } = props;\n const { data, isLoading } = useListPluginMetadata('Panel');\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = propValue !== '' && isLoading ? '' : propValue;\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <Select {...others} value={value}>\n {data?.map((metadata) => (\n <MenuItem key={metadata.kind} value={metadata.kind}>\n {metadata.display.name}\n </MenuItem>\n ))}\n </Select>\n );\n}\n"],"names":["Select","MenuItem","useListPluginMetadata","PanelTypeSelect","props","value","propValue","others","data","isLoading","map","metadata","kind","display","name"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,EAAeC,QAAQ,QAAQ,eAAe,CAAC;AAC9D,SAASC,qBAAqB,QAAQ,2BAA2B,CAAC;AAIlE;;CAEC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,KAAK,EAAEC,SAAS,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGH,KAAK,AAAC;IAC9C,MAAM,EAAEI,IAAI,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGP,qBAAqB,CAAC,OAAO,CAAC,AAAC;IAE3D,qHAAqH;IACrH,MAAMG,KAAK,GAAGC,SAAS,KAAK,EAAE,IAAIG,SAAS,GAAG,EAAE,GAAGH,SAAS,AAAC;IAE7D,yDAAyD;IACzD,qBACE,KAACN,MAAM;QAAE,GAAGO,MAAM;QAAEF,KAAK,EAAEA,KAAK;kBAC7BG,IAAI,aAAJA,IAAI,WAAK,GAATA,KAAAA,CAAS,GAATA,IAAI,CAAEE,GAAG,CAAC,CAACC,QAAQ,iBAClB,KAACV,QAAQ;gBAAqBI,KAAK,EAAEM,QAAQ,CAACC,IAAI;0BAC/CD,QAAQ,CAACE,OAAO,CAACC,IAAI;eADTH,QAAQ,CAACC,IAAI,CAEjB,AACZ,CAAC;MACK,CACT;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './PanelDrawer';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/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 './PanelDrawer';\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,eAAe,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface PanelEditorFormValues {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
group: number;
|
|
5
|
+
kind: string;
|
|
6
|
+
spec: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface PanelDrawerModel {
|
|
9
|
+
drawerTitle: string;
|
|
10
|
+
submitButtonText: string;
|
|
11
|
+
initialValues: PanelEditorFormValues;
|
|
12
|
+
applyChanges: (values: PanelEditorFormValues) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the
|
|
16
|
+
* drawer isn't open at all, returns undefined.
|
|
17
|
+
*/
|
|
18
|
+
export declare function usePanelDrawerModel(): PanelDrawerModel | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.
|
|
21
|
+
*/
|
|
22
|
+
export declare function usePanelSpecState(panelPluginKind: string, initialState: unknown): {
|
|
23
|
+
spec: unknown;
|
|
24
|
+
onSpecChange: (next: unknown) => void;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=panel-editor-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-editor-model.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/panel-editor-model.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAGD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,qBAAqB,CAAC;IACrC,YAAY,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACvD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAkFlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO;;yBAYlD,OAAO;EAUpC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useMemo } from 'react';
|
|
14
|
+
import { usePlugin } from '@perses-dev/plugin-system';
|
|
15
|
+
import { useImmer } from 'use-immer';
|
|
16
|
+
import { useDashboardApp, usePanels } from '../../context';
|
|
17
|
+
import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
|
|
18
|
+
/**
|
|
19
|
+
* Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the
|
|
20
|
+
* drawer isn't open at all, returns undefined.
|
|
21
|
+
*/ export function usePanelDrawerModel() {
|
|
22
|
+
const { panelDrawer } = useDashboardApp();
|
|
23
|
+
const { panels , updatePanel } = usePanels();
|
|
24
|
+
// If we're closed, no model to return
|
|
25
|
+
if (panelDrawer === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// If we don't have a panel key, we're adding a new panel
|
|
29
|
+
const { panelKey , groupIndex } = panelDrawer;
|
|
30
|
+
if (panelKey === undefined) {
|
|
31
|
+
return {
|
|
32
|
+
drawerTitle: 'Add Panel',
|
|
33
|
+
submitButtonText: 'Add',
|
|
34
|
+
initialValues: {
|
|
35
|
+
name: '',
|
|
36
|
+
description: '',
|
|
37
|
+
group: groupIndex !== null && groupIndex !== void 0 ? groupIndex : 0,
|
|
38
|
+
kind: '',
|
|
39
|
+
spec: {}
|
|
40
|
+
},
|
|
41
|
+
applyChanges: (values)=>{
|
|
42
|
+
const { name , description , group , kind , spec } = values;
|
|
43
|
+
const panelKey = removeWhiteSpacesAndSpecialCharacters(name);
|
|
44
|
+
updatePanel(panelKey, {
|
|
45
|
+
kind: 'Panel',
|
|
46
|
+
spec: {
|
|
47
|
+
display: {
|
|
48
|
+
name,
|
|
49
|
+
description
|
|
50
|
+
},
|
|
51
|
+
plugin: {
|
|
52
|
+
kind,
|
|
53
|
+
spec
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, group);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Otherwise we have a panel key, so we're trying to edit an existing panel
|
|
61
|
+
const existingPanel = panels[panelKey];
|
|
62
|
+
// TODO: Can we better express this via the type system on the dashboard store to avoid these states?
|
|
63
|
+
if (existingPanel === undefined) {
|
|
64
|
+
throw new Error(`Cannot find existing panel '${panelKey}' to edit`);
|
|
65
|
+
}
|
|
66
|
+
if (groupIndex === undefined) {
|
|
67
|
+
throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);
|
|
68
|
+
}
|
|
69
|
+
var _description;
|
|
70
|
+
return {
|
|
71
|
+
drawerTitle: 'Edit Panel',
|
|
72
|
+
submitButtonText: 'Apply',
|
|
73
|
+
initialValues: {
|
|
74
|
+
name: existingPanel.spec.display.name,
|
|
75
|
+
description: (_description = existingPanel.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
76
|
+
group: groupIndex,
|
|
77
|
+
kind: existingPanel.spec.plugin.kind,
|
|
78
|
+
spec: existingPanel.spec.plugin.spec
|
|
79
|
+
},
|
|
80
|
+
applyChanges: (values)=>{
|
|
81
|
+
const { name , description , group , kind , spec } = values;
|
|
82
|
+
updatePanel(panelKey, {
|
|
83
|
+
kind: 'Panel',
|
|
84
|
+
spec: {
|
|
85
|
+
display: {
|
|
86
|
+
name,
|
|
87
|
+
description
|
|
88
|
+
},
|
|
89
|
+
plugin: {
|
|
90
|
+
kind,
|
|
91
|
+
spec
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (group !== groupIndex) {
|
|
96
|
+
// TO DO: need to move panel if panel group changes
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.
|
|
103
|
+
*/ export function usePanelSpecState(panelPluginKind, initialState) {
|
|
104
|
+
// Keeping track of spec values by kind allows users to switch between panel types and come back with their old
|
|
105
|
+
// values intact from before the switch
|
|
106
|
+
const [specByKind, setSpecByKind] = useImmer({
|
|
107
|
+
[panelPluginKind]: initialState
|
|
108
|
+
});
|
|
109
|
+
const { data: plugin } = usePlugin('Panel', panelPluginKind, {
|
|
110
|
+
enabled: panelPluginKind !== ''
|
|
111
|
+
});
|
|
112
|
+
const pluginInitialSpec = useMemo(()=>{
|
|
113
|
+
return plugin === null || plugin === void 0 ? void 0 : plugin.createInitialOptions();
|
|
114
|
+
}, [
|
|
115
|
+
plugin
|
|
116
|
+
]);
|
|
117
|
+
var _panelPluginKind;
|
|
118
|
+
// Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)
|
|
119
|
+
const spec = (_panelPluginKind = specByKind[panelPluginKind]) !== null && _panelPluginKind !== void 0 ? _panelPluginKind : pluginInitialSpec;
|
|
120
|
+
// TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the
|
|
121
|
+
// current "onChange" API?
|
|
122
|
+
const onSpecChange = (next)=>{
|
|
123
|
+
setSpecByKind((draft)=>{
|
|
124
|
+
draft[panelPluginKind] = next;
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
spec,
|
|
129
|
+
onSpecChange
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=panel-editor-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/panel-editor-model.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo } from 'react';\nimport { usePlugin } from '@perses-dev/plugin-system';\nimport { useImmer } from 'use-immer';\nimport { useDashboardApp, usePanels } from '../../context';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\n\nexport interface PanelEditorFormValues {\n name: string;\n description: string;\n group: number;\n kind: string;\n spec: unknown;\n}\n\n// Props that vary based on whether the PanelDrawer is in add or edit mode\ninterface PanelDrawerModel {\n drawerTitle: string;\n submitButtonText: string;\n initialValues: PanelEditorFormValues;\n applyChanges: (values: PanelEditorFormValues) => void;\n}\n\n/**\n * Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the\n * drawer isn't open at all, returns undefined.\n */\nexport function usePanelDrawerModel(): PanelDrawerModel | undefined {\n const { panelDrawer } = useDashboardApp();\n const { panels, updatePanel } = usePanels();\n\n // If we're closed, no model to return\n if (panelDrawer === undefined) {\n return undefined;\n }\n\n // If we don't have a panel key, we're adding a new panel\n const { panelKey, groupIndex } = panelDrawer;\n if (panelKey === undefined) {\n return {\n drawerTitle: 'Add Panel',\n submitButtonText: 'Add',\n initialValues: {\n name: '',\n description: '',\n group: groupIndex ?? 0,\n kind: '',\n spec: {},\n },\n applyChanges: (values) => {\n const { name, description, group, kind, spec } = values;\n const panelKey = removeWhiteSpacesAndSpecialCharacters(name);\n updatePanel(\n panelKey,\n {\n kind: 'Panel',\n spec: {\n display: { name, description },\n plugin: {\n kind,\n spec,\n },\n },\n },\n group\n );\n },\n };\n }\n\n // Otherwise we have a panel key, so we're trying to edit an existing panel\n const existingPanel = panels[panelKey];\n\n // TODO: Can we better express this via the type system on the dashboard store to avoid these states?\n if (existingPanel === undefined) {\n throw new Error(`Cannot find existing panel '${panelKey}' to edit`);\n }\n if (groupIndex === undefined) {\n throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);\n }\n\n return {\n drawerTitle: 'Edit Panel',\n submitButtonText: 'Apply',\n initialValues: {\n name: existingPanel.spec.display.name,\n description: existingPanel.spec.display.description ?? '',\n group: groupIndex,\n kind: existingPanel.spec.plugin.kind,\n spec: existingPanel.spec.plugin.spec, // TODO: Should we clone to be safe?\n },\n applyChanges: (values) => {\n const { name, description, group, kind, spec } = values;\n updatePanel(panelKey, {\n kind: 'Panel',\n spec: {\n display: { name, description },\n plugin: {\n kind,\n spec,\n },\n },\n });\n\n if (group !== groupIndex) {\n // TO DO: need to move panel if panel group changes\n }\n },\n };\n}\n\n/**\n * Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.\n */\nexport function usePanelSpecState(panelPluginKind: string, initialState: unknown) {\n // Keeping track of spec values by kind allows users to switch between panel types and come back with their old\n // values intact from before the switch\n const [specByKind, setSpecByKind] = useImmer<Record<string, unknown>>({ [panelPluginKind]: initialState });\n const { data: plugin } = usePlugin('Panel', panelPluginKind, { enabled: panelPluginKind !== '' });\n const pluginInitialSpec = useMemo(() => plugin?.createInitialOptions(), [plugin]);\n\n // Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)\n const spec = specByKind[panelPluginKind] ?? pluginInitialSpec;\n\n // TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the\n // current \"onChange\" API?\n const onSpecChange = (next: unknown) => {\n setSpecByKind((draft) => {\n draft[panelPluginKind] = next;\n });\n };\n\n return {\n spec,\n onSpecChange,\n };\n}\n"],"names":["useMemo","usePlugin","useImmer","useDashboardApp","usePanels","removeWhiteSpacesAndSpecialCharacters","usePanelDrawerModel","panelDrawer","panels","updatePanel","undefined","panelKey","groupIndex","drawerTitle","submitButtonText","initialValues","name","description","group","kind","spec","applyChanges","values","display","plugin","existingPanel","Error","usePanelSpecState","panelPluginKind","initialState","specByKind","setSpecByKind","data","enabled","pluginInitialSpec","createInitialOptions","onSpecChange","next","draft"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CA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C,AAAC;IAEF,OAAO;QACLjB,IAAI;QACJgB,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelGroupDialog.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.tsx"],"names":[],"mappings":";AAkCA,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"PanelGroupDialog.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.tsx"],"names":[],"mappings":";AAkCA,QAAA,MAAM,gBAAgB,mBA2FrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|