@perses-dev/dashboards 0.15.0 → 0.17.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.
Files changed (86) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -12
  2. package/dist/cjs/components/DownloadButton/DownloadButton.js +109 -0
  3. package/dist/cjs/{utils/component-ids.js → components/DownloadButton/index.js} +11 -14
  4. package/dist/cjs/components/GridLayout/GridLayout.js +13 -2
  5. package/dist/cjs/components/GridLayout/GridTitle.js +11 -17
  6. package/dist/cjs/components/Panel/Panel.js +4 -2
  7. package/dist/cjs/components/Panel/PanelHeader.js +54 -50
  8. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -3
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +3 -1
  11. package/dist/cjs/components/Variables/Variable.js +7 -46
  12. package/dist/cjs/components/Variables/VariableEditor.js +157 -126
  13. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +353 -161
  14. package/dist/cjs/components/Variables/VariableList.js +15 -8
  15. package/dist/cjs/components/Variables/variable-model.js +74 -0
  16. package/dist/cjs/components/index.js +1 -0
  17. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
  18. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  19. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
  20. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  21. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  24. package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
  25. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
  26. package/dist/components/DownloadButton/DownloadButton.js +60 -0
  27. package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
  28. package/dist/components/DownloadButton/index.d.ts +2 -0
  29. package/dist/components/DownloadButton/index.d.ts.map +1 -0
  30. package/dist/{utils/component-ids.js → components/DownloadButton/index.js} +2 -14
  31. package/dist/components/DownloadButton/index.js.map +1 -0
  32. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +13 -2
  34. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  35. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  36. package/dist/components/GridLayout/GridTitle.js +11 -17
  37. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  38. package/dist/components/Panel/Panel.d.ts.map +1 -1
  39. package/dist/components/Panel/Panel.js +4 -2
  40. package/dist/components/Panel/Panel.js.map +1 -1
  41. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  42. package/dist/components/Panel/PanelHeader.js +54 -50
  43. package/dist/components/Panel/PanelHeader.js.map +1 -1
  44. package/dist/components/PanelDrawer/PanelDrawer.js +1 -3
  45. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  46. package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
  47. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  48. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +4 -2
  49. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  50. package/dist/components/Variables/Variable.d.ts.map +1 -1
  51. package/dist/components/Variables/Variable.js +8 -47
  52. package/dist/components/Variables/Variable.js.map +1 -1
  53. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditor.js +159 -128
  55. package/dist/components/Variables/VariableEditor.js.map +1 -1
  56. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  57. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +315 -162
  58. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  59. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  60. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  61. package/dist/components/Variables/VariableList.js +15 -8
  62. package/dist/components/Variables/VariableList.js.map +1 -1
  63. package/dist/components/Variables/variable-model.d.ts +8 -0
  64. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  65. package/dist/components/Variables/variable-model.js +64 -0
  66. package/dist/components/Variables/variable-model.js.map +1 -0
  67. package/dist/components/index.d.ts +1 -0
  68. package/dist/components/index.d.ts.map +1 -1
  69. package/dist/components/index.js +1 -0
  70. package/dist/components/index.js.map +1 -1
  71. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  72. package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
  73. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  74. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  75. package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  76. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  77. package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
  78. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  79. package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
  80. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  81. package/dist/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  82. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  83. package/package.json +4 -4
  84. package/dist/utils/component-ids.d.ts +0 -8
  85. package/dist/utils/component-ids.d.ts.map +0 -1
  86. package/dist/utils/component-ids.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React from 'react';\nimport {\n Box,\n Typography,\n Switch,\n TextField,\n Grid,\n FormControl,\n InputLabel,\n MenuItem,\n Select,\n Button,\n Stack,\n} from '@mui/material';\nimport { useImmer } from 'use-immer';\nimport { PluginEditor } from '@perses-dev/plugin-system';\nimport { VariableDefinition } from '@perses-dev/core';\nimport { VariableEditorState, getVariableDefinitionFromState, getInitialState } from './variable-editor-form-model';\n\nconst VARIABLE_TYPES = ['ListVariable', 'TextVariable'] as const;\n\nconst SectionHeader = ({ children }: React.PropsWithChildren) => (\n <Typography pb={2} variant=\"subtitle1\">\n {children}\n </Typography>\n);\n\nexport function VariableEditForm({\n initialVariableDefinition,\n onChange,\n onCancel,\n}: {\n initialVariableDefinition: VariableDefinition;\n onChange: (def: VariableDefinition) => void;\n onCancel: () => void;\n}) {\n const [state, setState] = useImmer(getInitialState(initialVariableDefinition));\n\n return (\n <Box>\n <SectionHeader>General</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={6}>\n <TextField\n fullWidth\n label=\"Name\"\n value={state.name}\n onChange={(v) => {\n setState((draft) => {\n draft.name = v.target.value as string;\n });\n }}\n />\n </Grid>\n <Grid item xs={6}>\n <FormControl fullWidth>\n <InputLabel id=\"variable-type-select-label\">Type</InputLabel>\n <Select\n labelId=\"variable-type-select-label\"\n id=\"variable-type-select\"\n label=\"Type\"\n value={state.kind}\n onChange={(v) => {\n setState((draft) => {\n draft.kind = v.target.value as VariableEditorState['kind'];\n });\n }}\n >\n {VARIABLE_TYPES.map((v) => (\n <MenuItem key={v} value={v}>\n {v}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n <Grid item xs={6}>\n <TextField\n fullWidth\n label=\"Label\"\n value={state.title}\n onChange={(v) => {\n setState((draft) => {\n draft.title = v.target.value;\n });\n }}\n />\n </Grid>\n <Grid item xs={12}>\n <TextField\n fullWidth\n label=\"Description\"\n value={state.description}\n onChange={(v) => {\n setState((draft) => {\n draft.description = v.target.value;\n });\n }}\n />\n </Grid>\n </Grid>\n\n {state.kind === 'TextVariable' && (\n <>\n <SectionHeader>Text Options</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={12}>\n <TextField\n label=\"Value\"\n value={state.textVariableFields.value}\n onChange={(v) => {\n setState((draft) => {\n draft.textVariableFields.value = v.target.value;\n });\n }}\n />\n </Grid>\n </Grid>\n </>\n )}\n\n {state.kind === 'ListVariable' && (\n <>\n <SectionHeader>List Options</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={6}>\n <PluginEditor\n width={500}\n pluginType=\"Variable\"\n pluginKindLabel=\"Source\"\n value={state.listVariableFields.plugin}\n onChange={(val) => {\n setState((draft) => {\n draft.listVariableFields.plugin = val;\n });\n }}\n />\n </Grid>\n </Grid>\n\n <SectionHeader>Dropdown Options</SectionHeader>\n <Grid container spacing={1} mb={1}>\n <Grid item xs={12}>\n Allow Multiple\n <Switch\n checked={state.listVariableFields.allowMultiple}\n onChange={(e) => {\n setState((draft) => {\n draft.listVariableFields.allowMultiple = e.target.checked;\n });\n }}\n />\n </Grid>\n <Grid item xs={12}>\n Allow All\n <Switch\n checked={state.listVariableFields.allowAll}\n onChange={(e) => {\n setState((draft) => {\n draft.listVariableFields.allowAll = e.target.checked;\n });\n }}\n />\n </Grid>\n </Grid>\n </>\n )}\n\n <Stack direction={'row'} spacing={2} justifyContent=\"end\">\n <Button\n variant=\"contained\"\n onClick={() => {\n onChange(getVariableDefinitionFromState(state));\n }}\n >\n Update\n </Button>\n <Button\n variant=\"outlined\"\n onClick={() => {\n onCancel();\n }}\n >\n Cancel\n </Button>\n </Stack>\n </Box>\n );\n}\n"],"names":["React","Box","Typography","Switch","TextField","Grid","FormControl","InputLabel","MenuItem","Select","Button","Stack","useImmer","PluginEditor","getVariableDefinitionFromState","getInitialState","VARIABLE_TYPES","SectionHeader","children","pb","variant","VariableEditForm","initialVariableDefinition","onChange","onCancel","state","setState","container","spacing","mb","item","xs","fullWidth","label","value","name","v","draft","target","id","labelId","kind","map","title","description","textVariableFields","width","pluginType","pluginKindLabel","listVariableFields","plugin","val","checked","allowMultiple","e","allowAll","direction","justifyContent","onClick"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,MAAM,OAAO,CAAC;AAC1B,SACEC,GAAG,EACHC,UAAU,EACVC,MAAM,EACNC,SAAS,EACTC,IAAI,EACJC,WAAW,EACXC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,KAAK,QACA,eAAe,CAAC;AACvB,SAASC,QAAQ,QAAQ,WAAW,CAAC;AACrC,SAASC,YAAY,QAAQ,2BAA2B,CAAC;AAEzD,SAA8BC,8BAA8B,EAAEC,eAAe,QAAQ,8BAA8B,CAAC;AAEpH,MAAMC,cAAc,GAAG;IAAC,cAAc;IAAE,cAAc;CAAC,AAAS,AAAC;AAEjE,MAAMC,aAAa,GAAG,CAAC,EAAEC,QAAQ,CAAA,EAA2B,iBAC1D,KAAChB,UAAU;QAACiB,EAAE,EAAE,CAAC;QAAEC,OAAO,EAAC,WAAW;kBACnCF,QAAQ;MACE,AACd,AAAC;AAEF,OAAO,SAASG,gBAAgB,CAAC,EAC/BC,yBAAyB,CAAA,EACzBC,QAAQ,CAAA,EACRC,QAAQ,CAAA,EAKT,EAAE;IACD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGd,QAAQ,CAACG,eAAe,CAACO,yBAAyB,CAAC,CAAC,AAAC;IAE/E,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E,WAEjB;kDAAA,KAAC5B,MAAM;wCACLiD,OAAO,EAAE3B,KAAK,CAACwB,kBAAkB,CAACM,QAAQ;wCAC1ChC,QAAQ,EAAE,CAAC+B,CAAC,GAAK;4CACf5B,QAAQ,CAAC,CAACW,KAAK,GAAK;gDAClBA,KAAK,CAACY,kBAAkB,CAACM,QAAQ,GAAGD,CAAC,CAAChB,MAAM,CAACc,OAAO,CAAC;4CACvD,CAAC,CAAC,CAAC;wCACL,CAAC;sCACD;;8BACG;;sBACF;;cACN,AACJ;0BAED,MAACzC,KAAK;gBAAC6C,SAAS,EAAE,KAAK;gBAAE5B,OAAO,EAAE,CAAC;gBAAE6B,cAAc,EAAC,KAAK;;kCACvD,KAAC/C,MAAM;wBACLU,OAAO,EAAC,WAAW;wBACnBsC,OAAO,EAAE,IAAM;4BACbnC,QAAQ,CAACT,8BAA8B,CAACW,KAAK,CAAC,CAAC,CAAC;wBAClD,CAAC;kCACF,QAED;sBAAS;kCACT,KAACf,MAAM;wBACLU,OAAO,EAAC,UAAU;wBAClBsC,OAAO,EAAE,IAAM;4BACblC,QAAQ,EAAE,CAAC;wBACb,CAAC;kCACF,QAED;sBAAS;;cACH;;MACJ,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useMemo, useState } from 'react';\nimport {\n Box,\n Typography,\n Switch,\n TextField,\n Grid,\n FormControl,\n InputLabel,\n MenuItem,\n Select,\n Button,\n Stack,\n Alert,\n Chip,\n IconButton,\n ClickAwayListener,\n} from '@mui/material';\nimport { useImmer } from 'use-immer';\nimport { PluginEditor } from '@perses-dev/plugin-system';\nimport { VariableDefinition, ListVariableDefinition } from '@perses-dev/core';\nimport { ErrorBoundary } from '@perses-dev/components';\nimport Refresh from 'mdi-material-ui/Refresh';\n\nimport { useListVariablePluginValues } from '../variable-model';\nimport { VariableEditorState, getVariableDefinitionFromState, getInitialState } from './variable-editor-form-model';\n\nconst VARIABLE_TYPES = ['ListVariable', 'TextVariable'] as const;\nconst DEFAULT_MAX_PREVIEW_VALUES = 50;\n\n// TODO: Replace with proper validation library\nfunction getValidation(state: ReturnType<typeof getInitialState>) {\n /** Name validation */\n let name = null;\n if (!state.name) {\n name = 'Name is required';\n }\n // name can only contain alphanumeric characters and underscores and no spaces\n if (state.name && !/^[a-zA-Z0-9_-]+$/.test(state.name)) {\n name = 'Name can only contain alphanumeric characters, underscores, and dashes';\n }\n\n return {\n name,\n isValid: !name,\n };\n}\n\nconst SectionHeader = ({ children }: React.PropsWithChildren) => (\n <Typography pb={2} variant=\"subtitle1\">\n {children}\n </Typography>\n);\n\nfunction VariableListPreview({ definition }: { definition: ListVariableDefinition }) {\n const { data, isFetching, error } = useListVariablePluginValues(definition);\n const [maxValues, setMaxValues] = useState<number | undefined>(DEFAULT_MAX_PREVIEW_VALUES);\n const showAll = () => {\n setMaxValues(undefined);\n };\n let notShown = 0;\n\n if (data && data?.length > 0 && maxValues) {\n notShown = data.length - maxValues;\n }\n const errorMessage = (error as Error)?.message;\n\n return (\n <Box>\n {errorMessage && <Alert severity=\"error\">{errorMessage}</Alert>}\n {isFetching && 'Loading...'}\n {data?.length === 0 && <Alert severity=\"info\">No results</Alert>}\n <>\n {data?.slice(0, maxValues).map((val) => (\n <Chip sx={{ mr: 1, mb: 1 }} size=\"small\" key={val.value} label={val.label} />\n ))}\n {notShown > 0 && (\n <Chip onClick={showAll} variant=\"outlined\" sx={{ mr: 1, mb: 1 }} size=\"small\" label={`+${notShown} more`} />\n )}\n </>\n </Box>\n );\n}\n\nexport function VariableEditForm({\n initialVariableDefinition,\n onChange,\n onCancel,\n}: {\n initialVariableDefinition: VariableDefinition;\n onChange: (def: VariableDefinition) => void;\n onCancel: () => void;\n}) {\n const [state, setState] = useImmer(getInitialState(initialVariableDefinition));\n const validation = useMemo(() => getValidation(state), [state]);\n\n const [previewKey, setPreviewKey] = React.useState(0);\n\n const refreshPreview = () => {\n setPreviewKey((prev) => prev + 1);\n };\n\n /** We use the `previewKey` that we increment to know when to explicity update the\n * spec that will be used for preview. The reason why we do this is to avoid\n * having to re-fetch the values when the user is still editing the spec.\n */\n const previewSpec = useMemo(() => {\n return getVariableDefinitionFromState(state) as ListVariableDefinition;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [previewKey]);\n\n return (\n <>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.grey[100]}`,\n }}\n >\n <Typography variant=\"h2\">Template Variables / Edit Variable</Typography>\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button\n disabled={!validation.isValid}\n variant=\"contained\"\n onClick={() => {\n onChange(getVariableDefinitionFromState(state));\n }}\n >\n Update\n </Button>\n <Button\n variant=\"outlined\"\n onClick={() => {\n onCancel();\n }}\n >\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Typography variant=\"h3\" mb={2}>\n Edit Variable\n </Typography>\n <SectionHeader>General</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={6}>\n <TextField\n required\n error={!!validation.name}\n fullWidth\n label=\"Name\"\n value={state.name}\n helperText={validation.name}\n onChange={(v) => {\n setState((draft) => {\n draft.name = v.target.value as string;\n });\n }}\n />\n </Grid>\n <Grid item xs={6}>\n <FormControl fullWidth>\n <InputLabel id=\"variable-type-select-label\">Type</InputLabel>\n <Select\n labelId=\"variable-type-select-label\"\n id=\"variable-type-select\"\n label=\"Type\"\n value={state.kind}\n onChange={(v) => {\n setState((draft) => {\n draft.kind = v.target.value as VariableEditorState['kind'];\n });\n }}\n >\n {VARIABLE_TYPES.map((v) => (\n <MenuItem key={v} value={v}>\n {v}\n </MenuItem>\n ))}\n </Select>\n </FormControl>\n </Grid>\n <Grid item xs={6}>\n <TextField\n fullWidth\n label=\"Label\"\n value={state.title}\n onChange={(v) => {\n setState((draft) => {\n draft.title = v.target.value;\n });\n }}\n />\n </Grid>\n <Grid item xs={12}>\n <TextField\n fullWidth\n label=\"Description\"\n value={state.description}\n onChange={(v) => {\n setState((draft) => {\n draft.description = v.target.value;\n });\n }}\n />\n </Grid>\n </Grid>\n\n {state.kind === 'TextVariable' && (\n <>\n <SectionHeader>Text Options</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={12}>\n <TextField\n label=\"Value\"\n value={state.textVariableFields.value}\n onChange={(v) => {\n setState((draft) => {\n draft.textVariableFields.value = v.target.value;\n });\n }}\n />\n </Grid>\n </Grid>\n </>\n )}\n\n {state.kind === 'ListVariable' && (\n <>\n <SectionHeader>List Options</SectionHeader>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={6}>\n {/** Hack?: Cool technique to refresh the preview to simulate onBlur event */}\n <ClickAwayListener onClickAway={() => refreshPreview()}>\n <Box />\n </ClickAwayListener>\n {/** */}\n <PluginEditor\n width={500}\n pluginType=\"Variable\"\n pluginKindLabel=\"Source\"\n value={state.listVariableFields.plugin}\n onChange={(val) => {\n setState((draft) => {\n draft.listVariableFields.plugin = val;\n });\n }}\n />\n </Grid>\n <Grid item xs={12}>\n <ErrorBoundary FallbackComponent={() => <div>Error</div>}>\n <Stack direction={'row'} spacing={1} alignItems=\"center\">\n <Typography variant=\"caption\">Preview Values</Typography>\n <IconButton onClick={refreshPreview} size=\"small\">\n <Refresh />\n </IconButton>\n </Stack>\n <VariableListPreview definition={previewSpec} />\n </ErrorBoundary>\n </Grid>\n </Grid>\n\n <SectionHeader>Dropdown Options</SectionHeader>\n <Grid container spacing={1} mb={1}>\n <Grid item xs={12}>\n Allow Multiple\n <Switch\n checked={state.listVariableFields.allowMultiple}\n onChange={(e) => {\n setState((draft) => {\n draft.listVariableFields.allowMultiple = e.target.checked;\n });\n }}\n />\n </Grid>\n <Grid item xs={12}>\n Allow All\n <Switch\n checked={state.listVariableFields.allowAll}\n onChange={(e) => {\n setState((draft) => {\n draft.listVariableFields.allowAll = e.target.checked;\n });\n }}\n />\n </Grid>\n </Grid>\n </>\n )}\n </Box>\n </>\n );\n}\n"],"names":["React","useMemo","useState","Box","Typography","Switch","TextField","Grid","FormControl","InputLabel","MenuItem","Select","Button","Stack","Alert","Chip","IconButton","ClickAwayListener","useImmer","PluginEditor","ErrorBoundary","Refresh","useListVariablePluginValues","getVariableDefinitionFromState","getInitialState","VARIABLE_TYPES","DEFAULT_MAX_PREVIEW_VALUES","getValidation","state","name","test","isValid","SectionHeader","children","pb","variant","VariableListPreview","definition","data","isFetching","error","maxValues","setMaxValues","showAll","undefined","notShown","length","errorMessage","message","severity","slice","map","val","sx","mr","mb","size","label","value","onClick","VariableEditForm","initialVariableDefinition","onChange","onCancel","setState","validation","previewKey","setPreviewKey","refreshPreview","prev","previewSpec","display","alignItems","padding","theme","spacing","borderBottom","palette","grey","direction","marginLeft","disabled","overflowY","container","item","xs","required","fullWidth","helperText","v","draft","target","id","labelId","kind","title","description","textVariableFields","onClickAway","width","pluginType","pluginKindLabel","listVariableFields","plugin","FallbackComponent","div","checked","allowMultiple","e","allowAll"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACjD,SACEC,GAA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AgB;0CAC/C,MAACzB,IAAI;gCAAC4E,SAAS;gCAACR,OAAO,EAAE,CAAC;gCAAEpB,EAAE,EAAE,CAAC;;kDAC/B,MAAChD,IAAI;wCAAC6E,IAAI;wCAACC,EAAE,EAAE,EAAE;;4CAAE,gBAEjB;0DAAA,KAAChF,MAAM;gDACLqG,OAAO,EAAE9E,KAAK,CAAC0E,kBAAkB,CAACK,aAAa;gDAC/C7C,QAAQ,EAAE,CAAC8C,CAAC,GAAK;oDACf5C,QAAQ,CAAC,CAAC0B,KAAK,GAAK;wDAClBA,KAAK,CAACY,kBAAkB,CAACK,aAAa,GAAGC,CAAC,CAACjB,MAAM,CAACe,OAAO,CAAC;oDAC5D,CAAC,CAAC,CAAC;gDACL,CAAC;8CACD;;sCACG;kDACP,MAACnG,IAAI;wCAAC6E,IAAI;wCAACC,EAAE,EAAE,EAAE;;4CAAE,WAEjB;0DAAA,KAAChF,MAAM;gDACLqG,OAAO,EAAE9E,KAAK,CAAC0E,kBAAkB,CAACO,QAAQ;gDAC1C/C,QAAQ,EAAE,CAAC8C,CAAC,GAAK;oDACf5C,QAAQ,CAAC,CAAC0B,KAAK,GAAK;wDAClBA,KAAK,CAACY,kBAAkB,CAACO,QAAQ,GAAGD,CAAC,CAACjB,MAAM,CAACe,OAAO,CAAC;oDACvD,CAAC,CAAC,CAAC;gDACL,CAAC;8CACD;;sCACG;;8BACF;;sBACN,AACJ;;cACG;;MACL,CACH;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-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 { VariableDefinition, TextVariableDefinition, ListVariableDefinition, Display } from '@perses-dev/core';\n\nexport function getInitialState(initialVariableDefinition: VariableDefinition) {\n const textVariableFields = {\n value: (initialVariableDefinition as TextVariableDefinition).spec.value ?? '',\n };\n\n const listVariableFields = {\n allowMultiple: false,\n allowAll: false,\n plugin: {\n kind: '',\n spec: {},\n },\n };\n if (initialVariableDefinition.kind === 'ListVariable') {\n listVariableFields.allowMultiple = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.allowAll = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.plugin = initialVariableDefinition.spec.plugin;\n }\n\n return {\n name: initialVariableDefinition.spec.name,\n title: initialVariableDefinition.spec.display?.name,\n kind: initialVariableDefinition.kind,\n description: '',\n listVariableFields,\n textVariableFields,\n };\n}\n\nexport type VariableEditorState = ReturnType<typeof getInitialState>;\n\nexport function getVariableDefinitionFromState(state: VariableEditorState): VariableDefinition {\n const { name, title, kind } = state;\n\n const commonSpec = {\n name,\n display: {\n name: title,\n } as Display,\n };\n\n if (kind === 'TextVariable') {\n const textVariableDefinition: TextVariableDefinition = {\n kind,\n spec: {\n ...commonSpec,\n ...state.textVariableFields,\n },\n };\n return textVariableDefinition;\n }\n\n if (kind === 'ListVariable') {\n const listVariableDefinition: ListVariableDefinition = {\n kind,\n spec: {\n ...commonSpec,\n allow_multiple: state.listVariableFields.allowMultiple,\n allow_all_value: state.listVariableFields.allowAll,\n plugin: state.listVariableFields.plugin,\n },\n };\n\n return listVariableDefinition;\n }\n throw new Error(`Unknown variable kind: ${kind}`);\n}\n"],"names":["getInitialState","initialVariableDefinition","textVariableFields","value","spec","listVariableFields","allowMultiple","allowAll","plugin","kind","allow_all_value","name","title","display","description","getVariableDefinitionFromState","state","commonSpec","textVariableDefinition","listVariableDefinition","allow_multiple","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;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,WAAW,EAAE,EAAE;QACfT,kBAAkB;QAClBH,kBAAkB;KACnB,CAAC;AACJ,CAAC;AAID,OAAO,SAASa,8BAA8B,CAACC,KAA0B,EAAsB;IAC7F,MAAM,EAAEL,IAAI,CAAA,EAAEC,KAAK,CAAA,EAAEH,IAAI,CAAA,EAAE,GAAGO,KAAK,AAAC;IAEpC,MAAMC,UAAU,GAAG;QACjBN,IAAI;QACJE,OAAO,EAAE;YACPF,IAAI,EAAEC,KAAK;SACZ;KACF,AAAC;IAEF,IAAIH,IAAI,KAAK,cAAc,EAAE;QAC3B,MAAMS,sBAAsB,GAA2B;YACrDT,IAAI;YACJL,IAAI,EAAE;gBACJ,GAAGa,UAAU;gBACb,GAAGD,KAAK,CAACd,kBAAkB;aAC5B;SACF,AAAC;QACF,OAAOgB,sBAAsB,CAAC;IAChC,CAAC;IAED,IAAIT,IAAI,KAAK,cAAc,EAAE;QAC3B,MAAMU,sBAAsB,GAA2B;YACrDV,IAAI;YACJL,IAAI,EAAE;gBACJ,GAAGa,UAAU;gBACbG,cAAc,EAAEJ,KAAK,CAACX,kBAAkB,CAACC,aAAa;gBACtDI,eAAe,EAAEM,KAAK,CAACX,kBAAkB,CAACE,QAAQ;gBAClDC,MAAM,EAAEQ,KAAK,CAACX,kBAAkB,CAACG,MAAM;aACxC;SACF,AAAC;QAEF,OAAOW,sBAAsB,CAAC;IAChC,CAAC;IACD,MAAM,IAAIE,KAAK,CAAC,CAAC,uBAAuB,EAAEZ,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
1
+ {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-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 { VariableDefinition, ListVariableDefinition, TextVariableDefinition, Display } from '@perses-dev/core';\n\nexport function getInitialState(initialVariableDefinition: VariableDefinition) {\n const textVariableFields = {\n value: (initialVariableDefinition as TextVariableDefinition).spec.value ?? '',\n };\n\n const listVariableFields = {\n allowMultiple: false,\n allowAll: false,\n plugin: {\n kind: '',\n spec: {},\n },\n };\n if (initialVariableDefinition.kind === 'ListVariable') {\n listVariableFields.allowMultiple = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.allowAll = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.plugin = initialVariableDefinition.spec.plugin;\n }\n\n return {\n name: initialVariableDefinition.spec.name,\n title: initialVariableDefinition.spec.display?.name,\n kind: initialVariableDefinition.kind,\n description: '',\n listVariableFields,\n textVariableFields,\n };\n}\n\nexport type VariableEditorState = ReturnType<typeof getInitialState>;\n\nexport function getVariableDefinitionFromState(state: VariableEditorState): VariableDefinition {\n const { name, title, kind } = state;\n\n const commonSpec = {\n name,\n display: {\n name: title,\n } as Display,\n };\n\n if (kind === 'TextVariable') {\n const textVariableDefinition: TextVariableDefinition = {\n kind,\n spec: {\n ...commonSpec,\n ...state.textVariableFields,\n },\n };\n return textVariableDefinition;\n }\n\n if (kind === 'ListVariable') {\n const listVariableDefinition: ListVariableDefinition = {\n kind,\n spec: {\n ...commonSpec,\n allow_multiple: state.listVariableFields.allowMultiple,\n allow_all_value: state.listVariableFields.allowAll,\n plugin: state.listVariableFields.plugin,\n },\n };\n\n return listVariableDefinition;\n }\n throw new Error(`Unknown variable kind: ${kind}`);\n}\n"],"names":["getInitialState","initialVariableDefinition","textVariableFields","value","spec","listVariableFields","allowMultiple","allowAll","plugin","kind","allow_all_value","name","title","display","description","getVariableDefinitionFromState","state","commonSpec","textVariableDefinition","listVariableDefinition","allow_multiple","Error"],"mappings":"AAAA,oCAAoC;AAC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,IAAI,EAAER,yBAAyB,CAACQ,IAAI;QACpCK,WAAW,EAAE,EAAE;QACfT,kBAAkB;QAClBH,kBAAkB;KACnB,CAAC;AACJ,CAAC;AAID,OAAO,SAASa,8BAA8B,CAACC,KAA0B,EAAsB;IAC7F,MAAM,EAAEL,IAAI,CAAA,EAAEC,KAAK,CAAA,EAAEH,IAAI,CAAA,EAAE,GAAGO,KAAK,AAAC;IAEpC,MAAMC,UAAU,GAAG;QACjBN,IAAI;QACJE,OAAO,EAAE;YACPF,IAAI,EAAEC,KAAK;SACZ;KACF,AAAC;IAEF,IAAIH,IAAI,KAAK,cAAc,EAAE;QAC3B,MAAMS,sBAAsB,GAA2B;YACrDT,IAAI;YACJL,IAAI,EAAE;gBACJ,GAAGa,UAAU;gBACb,GAAGD,KAAK,CAACd,kBAAkB;aAC5B;SACF,AAAC;QACF,OAAOgB,sBAAsB,CAAC;IAChC,CAAC;IAED,IAAIT,IAAI,KAAK,cAAc,EAAE;QAC3B,MAAMU,sBAAsB,GAA2B;YACrDV,IAAI;YACJL,IAAI,EAAE;gBACJ,GAAGa,UAAU;gBACbG,cAAc,EAAEJ,KAAK,CAACX,kBAAkB,CAACC,aAAa;gBACtDI,eAAe,EAAEM,KAAK,CAACX,kBAAkB,CAACE,QAAQ;gBAClDC,MAAM,EAAEQ,KAAK,CAACX,kBAAkB,CAACG,MAAM;aACxC;SACF,AAAC;QAEF,OAAOW,sBAAsB,CAAC;IAChC,CAAC;IACD,MAAM,IAAIE,KAAK,CAAC,CAAC,uBAAuB,EAAEZ,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"VariableList.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableList.tsx"],"names":[],"mappings":";AAuBA,UAAU,yBAAyB;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAoDpE"}
1
+ {"version":3,"file":"VariableList.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableList.tsx"],"names":[],"mappings":";AAwBA,UAAU,yBAAyB;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAuDpE"}
@@ -12,11 +12,12 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import React, { useState } from 'react';
15
- import { Button, Stack, Box, Drawer, AppBar, useScrollTrigger, IconButton } from '@mui/material';
15
+ import { Button, Stack, Box, AppBar, useScrollTrigger, IconButton } from '@mui/material';
16
16
  import EyeIcon from 'mdi-material-ui/Eye';
17
17
  import PencilIcon from 'mdi-material-ui/Pencil';
18
18
  import PinOutline from 'mdi-material-ui/PinOutline';
19
19
  import PinOffOutline from 'mdi-material-ui/PinOffOutline';
20
+ import { Drawer } from '@perses-dev/components';
20
21
  import { useTemplateVariableDefinitions, useEditMode, useTemplateVariableActions } from '../../context';
21
22
  import { TemplateVariable } from './Variable';
22
23
  import { VariableEditor } from './VariableEditor';
@@ -32,16 +33,22 @@ export function TemplateVariableList(props) {
32
33
  disableHysteresis: true
33
34
  });
34
35
  const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;
36
+ const onClose = ()=>{
37
+ setIsEditing(false);
38
+ };
35
39
  return /*#__PURE__*/ _jsxs(Box, {
36
40
  children: [
37
41
  /*#__PURE__*/ _jsx(Drawer, {
38
- anchor: 'right',
39
- open: isEditing,
42
+ isOpen: isEditing,
43
+ onClose: onClose,
44
+ PaperProps: {
45
+ sx: {
46
+ width: '50%'
47
+ }
48
+ },
40
49
  children: /*#__PURE__*/ _jsx(VariableEditor, {
41
- onCancel: ()=>{
42
- setIsEditing(false);
43
- },
44
50
  variableDefinitions: variableDefinitions,
51
+ onCancel: onClose,
45
52
  onChange: (v)=>{
46
53
  setVariableDefinitions(v);
47
54
  setIsEditing(false);
@@ -77,8 +84,8 @@ export function TemplateVariableList(props) {
77
84
  ml: isSticky ? 2 : 0,
78
85
  children: [
79
86
  /*#__PURE__*/ _jsx(Stack, {
80
- direction: 'row',
81
- spacing: 2,
87
+ direction: "row",
88
+ spacing: 1,
82
89
  children: showVariables && variableDefinitions.map((v)=>{
83
90
  var ref;
84
91
  /*#__PURE__*/ return _jsx(Box, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useState } from 'react';\nimport { Button, Stack, Box, Drawer, AppBar, useScrollTrigger, IconButton } from '@mui/material';\nimport EyeIcon from 'mdi-material-ui/Eye';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport PinOutline from 'mdi-material-ui/PinOutline';\nimport PinOffOutline from 'mdi-material-ui/PinOffOutline';\nimport { useTemplateVariableDefinitions, useEditMode, useTemplateVariableActions } from '../../context';\nimport { TemplateVariable } from './Variable';\nimport { VariableEditor } from './VariableEditor';\n\ninterface TemplateVariableListProps {\n initialVariableIsSticky?: boolean;\n}\n\nexport function TemplateVariableList(props: TemplateVariableListProps) {\n const [isEditing, setIsEditing] = useState(false);\n const [isPin, setIsPin] = useState(props.initialVariableIsSticky);\n const variableDefinitions = useTemplateVariableDefinitions();\n const { isEditMode } = useEditMode();\n const [showVariablesInEditMode, setShowVariablesInEditMode] = useState(true);\n const showVariables = isEditMode ? showVariablesInEditMode : true;\n const { setVariableDefinitions } = useTemplateVariableActions();\n const scrollTrigger = useScrollTrigger({ disableHysteresis: true });\n const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;\n return (\n <Box>\n <Drawer anchor={'right'} open={isEditing}>\n <VariableEditor\n onCancel={() => {\n setIsEditing(false);\n }}\n variableDefinitions={variableDefinitions}\n onChange={(v) => {\n setVariableDefinitions(v);\n setIsEditing(false);\n }}\n />\n </Drawer>\n {isEditMode && (\n <Box pb={2}>\n <Button onClick={() => setShowVariablesInEditMode(!showVariablesInEditMode)} startIcon={<EyeIcon />}>\n {showVariablesInEditMode ? 'Hide' : 'Show'} Variables\n </Button>\n <Button onClick={() => setIsEditing(true)} startIcon={<PencilIcon />}>\n Edit Variables\n </Button>\n </Box>\n )}\n\n <AppBar color={'inherit'} position={isSticky ? 'fixed' : 'static'} elevation={isSticky ? 4 : 0}>\n <Box display={'flex'} justifyContent=\"space-between\" my={isSticky ? 2 : 0} ml={isSticky ? 2 : 0}>\n <Stack direction={'row'} spacing={2}>\n {showVariables &&\n variableDefinitions.map((v) => (\n <Box key={v.spec.name} display={v.spec.display?.hidden ? 'none' : undefined}>\n <TemplateVariable key={v.spec.name} name={v.spec.name} />\n </Box>\n ))}\n </Stack>\n {props.initialVariableIsSticky && (\n <IconButton onClick={() => setIsPin(!isPin)}>{isPin ? <PinOutline /> : <PinOffOutline />}</IconButton>\n )}\n </Box>\n </AppBar>\n </Box>\n );\n}\n"],"names":["React","useState","Button","Stack","Box","Drawer","AppBar","useScrollTrigger","IconButton","EyeIcon","PencilIcon","PinOutline","PinOffOutline","useTemplateVariableDefinitions","useEditMode","useTemplateVariableActions","TemplateVariable","VariableEditor","TemplateVariableList","props","isEditing","setIsEditing","isPin","setIsPin","initialVariableIsSticky","variableDefinitions","isEditMode","showVariablesInEditMode","setShowVariablesInEditMode","showVariables","setVariableDefinitions","scrollTrigger","disableHysteresis","isSticky","anchor","open","onCancel","onChange","v","pb","onClick","startIcon","color","position","elevation","display","justifyContent","my","ml","direction","spacing","map","spec","hidden","undefined","name"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,m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G,CAAC,GAAG,CAAC;;sCAC7F,KAAC9B,KAAK;4BAAC8C,SAAS,EAAE,KAAK;4BAAEC,OAAO,EAAE,CAAC;sCAChCrB,aAAa,IACZJ,mBAAmB,CAAC0B,GAAG,CAAC,CAACb,CAAC;oCACQA,GAAc;8CAA9C,OAAA,KAAClC,GAAG;oCAAmByC,OAAO,EAAEP,CAAAA,CAAAA,GAAc,GAAdA,CAAC,CAACc,IAAI,CAACP,OAAO,cAAdP,GAAc,WAAQ,GAAtBA,KAAAA,CAAsB,GAAtBA,GAAc,CAAEe,MAAM,CAAA,GAAG,MAAM,GAAGC,SAAS;8CACzE,cAAA,KAACtC,gBAAgB;wCAAmBuC,IAAI,EAAEjB,CAAC,CAACc,IAAI,CAACG,IAAI;uCAA9BjB,CAAC,CAACc,IAAI,CAACG,IAAI,CAAuB;mCADjDjB,CAAC,CAACc,IAAI,CAACG,IAAI,CAEf,CAAA;6BACP,CAAC;0BACE;wBACPpC,KAAK,CAACK,uBAAuB,kBAC5B,KAAChB,UAAU;4BAACgC,OAAO,EAAE,IAAMjB,QAAQ,CAAC,CAACD,KAAK,CAAC;sCAAGA,KAAK,iBAAG,KAACX,UAAU,KAAG,iBAAG,KAACC,aAAa,KAAG;0BAAc,AACvG;;kBACG;cACC;;MACL,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useState } from 'react';\nimport { Button, Stack, Box, AppBar, useScrollTrigger, IconButton } from '@mui/material';\nimport EyeIcon from 'mdi-material-ui/Eye';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport PinOutline from 'mdi-material-ui/PinOutline';\nimport PinOffOutline from 'mdi-material-ui/PinOffOutline';\nimport { Drawer } from '@perses-dev/components';\nimport { useTemplateVariableDefinitions, useEditMode, useTemplateVariableActions } from '../../context';\nimport { TemplateVariable } from './Variable';\nimport { VariableEditor } from './VariableEditor';\n\ninterface TemplateVariableListProps {\n initialVariableIsSticky?: boolean;\n}\n\nexport function TemplateVariableList(props: TemplateVariableListProps) {\n const [isEditing, setIsEditing] = useState(false);\n const [isPin, setIsPin] = useState(props.initialVariableIsSticky);\n const variableDefinitions = useTemplateVariableDefinitions();\n const { isEditMode } = useEditMode();\n const [showVariablesInEditMode, setShowVariablesInEditMode] = useState(true);\n const showVariables = isEditMode ? showVariablesInEditMode : true;\n const { setVariableDefinitions } = useTemplateVariableActions();\n const scrollTrigger = useScrollTrigger({ disableHysteresis: true });\n const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;\n\n const onClose = () => {\n setIsEditing(false);\n };\n\n return (\n <Box>\n <Drawer isOpen={isEditing} onClose={onClose} PaperProps={{ sx: { width: '50%' } }}>\n <VariableEditor\n variableDefinitions={variableDefinitions}\n onCancel={onClose}\n onChange={(v) => {\n setVariableDefinitions(v);\n setIsEditing(false);\n }}\n />\n </Drawer>\n {isEditMode && (\n <Box pb={2}>\n <Button onClick={() => setShowVariablesInEditMode(!showVariablesInEditMode)} startIcon={<EyeIcon />}>\n {showVariablesInEditMode ? 'Hide' : 'Show'} Variables\n </Button>\n <Button onClick={() => setIsEditing(true)} startIcon={<PencilIcon />}>\n Edit Variables\n </Button>\n </Box>\n )}\n\n <AppBar color={'inherit'} position={isSticky ? 'fixed' : 'static'} elevation={isSticky ? 4 : 0}>\n <Box display={'flex'} justifyContent=\"space-between\" my={isSticky ? 2 : 0} ml={isSticky ? 2 : 0}>\n <Stack direction=\"row\" spacing={1}>\n {showVariables &&\n variableDefinitions.map((v) => (\n <Box key={v.spec.name} display={v.spec.display?.hidden ? 'none' : undefined}>\n <TemplateVariable key={v.spec.name} name={v.spec.name} />\n </Box>\n ))}\n </Stack>\n {props.initialVariableIsSticky && (\n <IconButton onClick={() => setIsPin(!isPin)}>{isPin ? <PinOutline /> : <PinOffOutline />}</IconButton>\n )}\n </Box>\n </AppBar>\n </Box>\n );\n}\n"],"names":["React","useState","Button","Stack","Box","AppBar","useScrollTrigger","IconButton","EyeIcon","PencilIcon","PinOutline","PinOffOutline","Drawer","useTemplateVariableDefinitions","useEditMode","useTemplateVariableActions","TemplateVariable","VariableEditor","TemplateVariableList","props","isEditing","setIsEditing","isPin","setIsPin","initialVariableIsSticky","variableDefinitions","isEditMode","showVariablesInEditMode","setShowVariablesInEditMode","showVariables","setVariableDefinitions","scrollTrigger","disableHysteresis","isSticky","onClose","isOpen","PaperProps","sx","width","onCancel","onChange","v","pb","onClick","startIcon","color","position","elevation","display","justifyContent","my","ml","direction","spacing","map","spec","hidden","undefined","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,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO,CAAC;AACxC,SAASC,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,MAAM,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACzF,OAAOC,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAOC,UAAU,MAAM,wBAAwB,CAAC;AAChD,OAAOC,UAAU,MAAM,4BAA4B,CAAC;AACpD,OAAOC,aAAa,MAAM,+BAA+B,CAAC;AAC1D,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAChD,SAASC,8BAA8B,EAAEC,WAAW,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AACxG,SAASC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AAI,EAAEjB,CAAC,CAACc,IAAI,CAACG,IAAI;uCAA9BjB,CAAC,CAACc,IAAI,CAACG,IAAI,CAAuB;mCADjDjB,CAAC,CAACc,IAAI,CAACG,IAAI,CAEf,CAAA;6BACP,CAAC;0BACE;wBACPvC,KAAK,CAACK,uBAAuB,kBAC5B,KAACjB,UAAU;4BAACoC,OAAO,EAAE,IAAMpB,QAAQ,CAAC,CAACD,KAAK,CAAC;sCAAGA,KAAK,iBAAG,KAACZ,UAAU,KAAG,iBAAG,KAACC,aAAa,KAAG;0BAAc,AACvG;;kBACG;cACC;;MACL,CACN;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { ListVariableDefinition } from '@perses-dev/core';
2
+ import { VariableStateMap } from '@perses-dev/plugin-system';
3
+ export declare function useListVariablePluginValues(definition: ListVariableDefinition): import("@tanstack/react-query").UseQueryResult<import("@perses-dev/plugin-system").VariableOption[], unknown>;
4
+ /**
5
+ * Returns a serialized string of the current state of variable values.
6
+ */
7
+ export declare function getVariableValuesKey(v: VariableStateMap): string;
8
+ //# sourceMappingURL=variable-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable-model.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/variable-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAKL,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAGnC,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,sBAAsB,iHAmC7E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,UAIvD"}
@@ -0,0 +1,64 @@
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 { usePlugin, useTemplateVariableValues, useDatasourceStore, useTimeRange } from '@perses-dev/plugin-system';
14
+ import { useQuery } from '@tanstack/react-query';
15
+ export function useListVariablePluginValues(definition) {
16
+ const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);
17
+ const datasourceStore = useDatasourceStore();
18
+ const allVariables = useTemplateVariableValues();
19
+ const { timeRange } = useTimeRange();
20
+ const variablePluginCtx = {
21
+ timeRange,
22
+ datasourceStore,
23
+ variables: allVariables
24
+ };
25
+ const spec = definition.spec.plugin.spec;
26
+ let dependsOnVariables;
27
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
28
+ const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
29
+ dependsOnVariables = dependencies.variables;
30
+ }
31
+ const variables = useTemplateVariableValues(dependsOnVariables);
32
+ let waitToLoad = false;
33
+ if (dependsOnVariables) {
34
+ waitToLoad = dependsOnVariables.some((v)=>{
35
+ var ref;
36
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
37
+ });
38
+ }
39
+ const variablesValueKey = getVariableValuesKey(variables);
40
+ const variablesOptionsQuery = useQuery([
41
+ name,
42
+ definition,
43
+ variablesValueKey,
44
+ timeRange
45
+ ], async ()=>{
46
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
47
+ datasourceStore,
48
+ variables,
49
+ timeRange
50
+ }));
51
+ var ref;
52
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
53
+ }, {
54
+ enabled: !!variablePlugin || waitToLoad
55
+ });
56
+ return variablesOptionsQuery;
57
+ }
58
+ /**
59
+ * Returns a serialized string of the current state of variable values.
60
+ */ export function getVariableValuesKey(v) {
61
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
62
+ }
63
+
64
+ //# sourceMappingURL=variable-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Variables/variable-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 { ListVariableDefinition } from '@perses-dev/core';\nimport {\n usePlugin,\n useTemplateVariableValues,\n useDatasourceStore,\n useTimeRange,\n VariableStateMap,\n} from '@perses-dev/plugin-system';\nimport { useQuery } from '@tanstack/react-query';\n\nexport function useListVariablePluginValues(definition: ListVariableDefinition) {\n const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);\n const datasourceStore = useDatasourceStore();\n const allVariables = useTemplateVariableValues();\n const { timeRange } = useTimeRange();\n\n const variablePluginCtx = { timeRange, datasourceStore, variables: allVariables };\n\n const spec = definition.spec.plugin.spec;\n\n let dependsOnVariables: string[] | undefined;\n if (variablePlugin?.dependsOn) {\n const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);\n dependsOnVariables = dependencies.variables;\n }\n\n const variables = useTemplateVariableValues(dependsOnVariables);\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n const variablesOptionsQuery = useQuery(\n [name, definition, variablesValueKey, timeRange],\n async () => {\n const resp = await variablePlugin?.getVariableOptions(spec, { datasourceStore, variables, timeRange });\n return resp?.data ?? [];\n },\n { enabled: !!variablePlugin || waitToLoad }\n );\n\n return variablesOptionsQuery;\n}\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nexport function getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n"],"names":["usePlugin","useTemplateVariableValues","useDatasourceStore","useTimeRange","useQuery","useListVariablePluginValues","definition","data","variablePlugin","spec","plugin","kind","datasourceStore","allVariables","timeRange","variablePluginCtx","variables","dependsOnVariables","dependsOn","dependencies","waitToLoad","some","v","loading","variablesValueKey","getVariableValuesKey","variablesOptionsQuery","name","resp","getVariableOptions","enabled","Object","values","map","JSON","stringify","value","join"],"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;AAGjC,SACEA,SAAS,EACTC,yBAAyB,EACzBC,kBAAkB,EAClBC,YAAY,QAEP,2BAA2B,CAAC;AACnC,SAASC,QAAQ,QAAQ,uBAAuB,CAAC;AAEjD,OAAO,SAASC,2BAA2B,CAACC,UAAkC,EAAE;IAC9E,MAAM,EAAEC,IAAI,EAAEC,cAAc,CAAA,EAAE,GAAGR,SAAS,CAAC,UAAU,EAAEM,UAAU,CAACG,IAAI,CAACC,MAAM,CAACC,IAAI,CAAC,AAAC;IACpF,MAAMC,eAAe,GAAGV,kBAAkB,EAAE,AAAC;IAC7C,MAAMW,YAAY,GAAGZ,yBAAyB,EAAE,AAAC;IACjD,MAAM,EAAEa,SAAS,CAAA,EAAE,GAAGX,YAAY,EAAE,AAAC;IAErC,MAAMY,iBAAiB,GAAG;QAAED,SAAS;QAAEF,eAAe;QAAEI,SAAS,EAAEH,YAAY;KAAE,AAAC;IAElF,MAAMJ,IAAI,GAAGH,UAAU,CAACG,IAAI,CAACC,MAAM,CAACD,IAAI,AAAC;IAEzC,IAAIQ,kBAAkB,AAAsB,AAAC;IAC7C,IAAIT,cA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qBAAqB,CAAC;AAC/B,CAAC;AAED;;CAEC,GACD,OAAO,SAASD,oBAAoB,CAACH,CAAmB,EAAE;IACxD,OAAOS,MAAM,CAACC,MAAM,CAACV,CAAC,CAAC,CACpBW,GAAG,CAAC,CAACX,CAAC,GAAKY,IAAI,CAACC,SAAS,CAACb,CAAC,CAACc,KAAK,CAAC,CAAC,CACnCC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -2,6 +2,7 @@ export * from './Dashboard';
2
2
  export * from './DashboardToolbar';
3
3
  export * from './DeletePanelDialog';
4
4
  export * from './DeletePanelGroupDialog';
5
+ export * from './DownloadButton';
5
6
  export * from './GridLayout';
6
7
  export * from './Panel';
7
8
  export * from './PanelDrawer';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC"}
@@ -14,6 +14,7 @@ export * from './Dashboard';
14
14
  export * from './DashboardToolbar';
15
15
  export * from './DeletePanelDialog';
16
16
  export * from './DeletePanelGroupDialog';
17
+ export * from './DownloadButton';
17
18
  export * from './GridLayout';
18
19
  export * from './Panel';
19
20
  export * from './PanelDrawer';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/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 './Dashboard';\nexport * from './DashboardToolbar';\nexport * from './DeletePanelDialog';\nexport * from './DeletePanelGroupDialog';\nexport * from './GridLayout';\nexport * from './Panel';\nexport * from './PanelDrawer';\nexport * from './PanelGroupDialog';\nexport * from './TimeRangeControls';\nexport * from './UnsavedChangesConfirmationDialog';\nexport * from './Variables';\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,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC"}
1
+ {"version":3,"sources":["../../src/components/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 './Dashboard';\nexport * from './DashboardToolbar';\nexport * from './DeletePanelDialog';\nexport * from './DeletePanelGroupDialog';\nexport * from './DownloadButton';\nexport * from './GridLayout';\nexport * from './Panel';\nexport * from './PanelDrawer';\nexport * from './PanelGroupDialog';\nexport * from './TimeRangeControls';\nexport * from './UnsavedChangesConfirmationDialog';\nexport * from './Variables';\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,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA+IA"}
1
+ {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CAyJA"}
@@ -12,6 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
14
14
  import { generateId } from './common';
15
+ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
15
16
  /**
16
17
  * Curried function for creating the PanelEditorSlice.
17
18
  */ export function createPanelEditorSlice() {
@@ -45,14 +46,14 @@ import { generateId } from './common';
45
46
  },
46
47
  applyChanges: (next)=>{
47
48
  const panelDefinititon = createPanelDefinitionFromEditorValues(next);
48
- set((draft)=>{
49
- draft.panels[panelKey] = panelDefinititon;
49
+ set((state)=>{
50
+ state.panels[panelKey] = panelDefinititon;
50
51
  // If the panel didn't change groups, nothing else to do
51
52
  if (next.groupId === panelGroupId) {
52
53
  return;
53
54
  }
54
55
  // Move panel to the new group
55
- const existingGroup = draft.panelGroups[panelGroupId];
56
+ const existingGroup = state.panelGroups[panelGroupId];
56
57
  if (existingGroup === undefined) {
57
58
  throw new Error(`Missing panel group ${panelGroupId}`);
58
59
  }
@@ -66,7 +67,7 @@ import { generateId } from './common';
66
67
  existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
67
68
  delete existingGroup.itemPanelKeys[panelGroupLayoutId];
68
69
  // Add item to the end of the new group
69
- const newGroup = draft.panelGroups[next.groupId];
70
+ const newGroup = state.panelGroups[next.groupId];
70
71
  if (newGroup === undefined) {
71
72
  throw new Error(`Could not find new group ${next.groupId}`);
72
73
  }
@@ -92,13 +93,13 @@ import { generateId } from './common';
92
93
  });
93
94
  },
94
95
  openAddPanel (panelGroupId) {
95
- // If a panel group isn't supplied, add to the first group
96
+ // If a panel group isn't supplied, add to the first group or create a group if there aren't any
97
+ let newGroup = undefined;
98
+ panelGroupId !== null && panelGroupId !== void 0 ? panelGroupId : panelGroupId = get().panelGroupOrder[0];
96
99
  if (panelGroupId === undefined) {
97
- const firstGroupId = get().panelGroupOrder[0];
98
- if (firstGroupId === undefined) {
99
- throw new Error('No panel groups to add a panel to');
100
- }
101
- panelGroupId = firstGroupId;
100
+ newGroup = createEmptyPanelGroup();
101
+ newGroup.title = 'Panel Group';
102
+ panelGroupId = newGroup.id;
102
103
  }
103
104
  const editorState = {
104
105
  mode: 'Add',
@@ -113,12 +114,17 @@ import { generateId } from './common';
113
114
  },
114
115
  applyChanges: (next)=>{
115
116
  const panelDef = createPanelDefinitionFromEditorValues(next);
116
- const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
117
- set((draft)=>{
117
+ const uniquePanelKeys = getUniquePanelKeys(get().panels);
118
+ let panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
119
+ // append count if panel key already exists
120
+ if (uniquePanelKeys[panelKey]) {
121
+ panelKey += `-${uniquePanelKeys[panelKey]}`;
122
+ }
123
+ set((state)=>{
118
124
  // Add a panel
119
- draft.panels[panelKey] = panelDef;
125
+ state.panels[panelKey] = panelDef;
120
126
  // Also add a panel group item referencing the panel
121
- const group = draft.panelGroups[next.groupId];
127
+ const group = state.panelGroups[next.groupId];
122
128
  if (group === undefined) {
123
129
  throw new Error(`Missing panel group ${next.groupId}`);
124
130
  }
@@ -139,8 +145,12 @@ import { generateId } from './common';
139
145
  });
140
146
  }
141
147
  };
142
- // Open the editor with the new state
143
148
  set((state)=>{
149
+ // Add the new panel group if one was created for the panel
150
+ if (newGroup !== undefined) {
151
+ addPanelGroup(state, newGroup);
152
+ }
153
+ // Open the editor with the new state
144
154
  state.panelEditor = editorState;
145
155
  });
146
156
  }
@@ -174,5 +184,20 @@ function getYForNewRow(group) {
174
184
  }
175
185
  return newRowY;
176
186
  }
187
+ // Find all the unique panel keys
188
+ // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
189
+ function getUniquePanelKeys(panels) {
190
+ const uniquePanelKeys = {};
191
+ Object.keys(panels).forEach((panelKey)=>{
192
+ const key = panelKey.replace(/-([0-9]+)/, '');
193
+ const count = uniquePanelKeys[key];
194
+ if (count) {
195
+ uniquePanelKeys[key] = count + 1;
196
+ } else {
197
+ uniquePanelKeys[key] = 1;
198
+ }
199
+ });
200
+ return uniquePanelKeys;
201
+ }
177
202
 
178
203
  //# sourceMappingURL=panel-editor-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.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 { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { generateId, Middleware } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\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 * 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((draft) => {\n draft.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 = draft.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 = draft.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\n if (panelGroupId === undefined) {\n const firstGroupId = get().panelGroupOrder[0];\n if (firstGroupId === undefined) {\n throw new Error('No panel groups to add a panel to');\n }\n panelGroupId = firstGroupId;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((draft) => {\n // Add a panel\n draft.panels[panelKey] = panelDef;\n\n // Also add a panel group item referencing the panel\n const group = draft.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 // Open the editor with the new state\n set((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\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","generateId","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","draft","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","getYForNewRow","w","h","close","state","openAddPanel","firstGroupId","panelGroupOrder","panelDef","group","toString","editorValues","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,qCAAqC,QAAQ,uBAAuB,CAAC;AAC9E,SAASC,UAAU,QAAoB,UAAU,CAAC;AA+DlD;;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,CAA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AAC,CAAC;AACL,CAAC;AAED,gDAAgD;AAChD,SAASa,qCAAqC,CAAC0B,YAA+B,EAAmB;IAC/F,OAAO;QACL/B,IAAI,EAAE,OAAO;QACbJ,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEoC,YAAY,CAACpC,IAAI;gBACvBG,WAAW,EAAEiC,YAAY,CAACjC,WAAW,KAAK,EAAE,GAAGiC,YAAY,CAACjC,WAAW,GAAGlB,SAAS;aACpF;YACDqB,MAAM,EAAE;gBACND,IAAI,EAAE+B,YAAY,CAAC/B,IAAI;gBACvBJ,IAAI,EAAEmC,YAAY,CAACnC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC;AAED,yHAAyH;AACzH,SAASwB,aAAa,CAACS,KAA2B,EAAE;IAClD,IAAIG,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMrB,MAAM,IAAIkB,KAAK,CAACpB,WAAW,CAAE;QACtC,MAAMwB,QAAQ,GAAGtB,MAAM,CAACQ,CAAC,GAAGR,MAAM,CAACW,CAAC,AAAC;QACrC,IAAIW,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.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 { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\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 * 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 // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const uniquePanelKeys = getUniquePanelKeys(get().panels);\n let panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n // append count if panel key already exists\n if (uniquePanelKeys[panelKey]) {\n panelKey += `-${uniquePanelKeys[panelKey]}`;\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\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n\n// Find all the unique panel keys\n// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name\nfunction getUniquePanelKeys(panels: Record<string, PanelDefinition>): Record<string, number> {\n const uniquePanelKeys: Record<string, number> = {};\n Object.keys(panels).forEach((panelKey) => {\n const key = panelKey.replace(/-([0-9]+)/, '');\n const count = uniquePanelKeys[key];\n if (count) {\n uniquePanelKeys[key] = count + 1;\n } else {\n uniquePanelKeys[key] = 1;\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","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","getYForNewRow","w","h","close","openAddPanel","panelGroupOrder","title","id","panelDef","uniquePanelKeys","getUniquePanelKeys","group","toString","editorValues","newRowY","itemMaxY","Object","keys","forEach","key","replace","count"],"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,qCAAqC,QAAQ,uBAAuB,CAAC;AAC9E,SAASC,UAAU,QAAoB,UAAU,CAAC;AAClD,SAMEC,aAAa,EACbC,qBAAqB,QAChB,qBAAqB,CAAC;AAwD7B;;CAEC,GACD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AEqC,YAAY,CAACrC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC;AAED,yHAAyH;AACzH,SAASwB,aAAa,CAACW,KAA2B,EAAE;IAClD,IAAIG,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMvB,MAAM,IAAIoB,KAAK,CAACtB,WAAW,CAAE;QACtC,MAAM0B,QAAQ,GAAGxB,MAAM,CAACQ,CAAC,GAAGR,MAAM,CAACW,CAAC,AAAC;QACrC,IAAIa,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC;AAED,iCAAiC;AACjC,0FAA0F;AAC1F,SAASJ,kBAAkB,CAAC9C,MAAuC,EAA0B;IAC3F,MAAM6C,eAAe,GAA2B,EAAE,AAAC;IACnDO,MAAM,CAACC,IAAI,CAACrD,MAAM,CAAC,CAACsD,OAAO,CAAC,CAAClD,QAAQ,GAAK;QACxC,MAAMmD,GAAG,GAAGnD,QAAQ,CAACoD,OAAO,cAAc,EAAE,CAAC,AAAC;QAC9C,MAAMC,KAAK,GAAGZ,eAAe,CAACU,GAAG,CAAC,AAAC;QACnC,IAAIE,KAAK,EAAE;YACTZ,eAAe,CAACU,GAAG,CAAC,GAAGE,KAAK,GAAG,CAAC,CAAC;QACnC,OAAO;YACLZ,eAAe,CAACU,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAOV,eAAe,CAAC;AACzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,eAAe,EAAwB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAwErB,CAAC"}
1
+ {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAwC,MAAM,qBAAqB,CAAC;AAE1G,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAoErB,CAAC"}
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { generateId } from './common';
13
+ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
14
14
  export const createPanelGroupEditorSlice = (set, get)=>({
15
15
  panelGroupEditor: undefined,
16
16
  openAddPanelGroup: ()=>{
@@ -22,15 +22,11 @@ export const createPanelGroupEditorSlice = (set, get)=>({
22
22
  isCollapsed: false
23
23
  },
24
24
  applyChanges (next) {
25
- const newGroup = {
26
- id: generateId(),
27
- itemLayouts: [],
28
- itemPanelKeys: {},
29
- ...next
30
- };
25
+ const newGroup = createEmptyPanelGroup();
26
+ newGroup.title = next.title;
27
+ newGroup.isCollapsed = next.isCollapsed;
31
28
  set((draft)=>{
32
- draft.panelGroups[newGroup.id] = newGroup;
33
- draft.panelGroupOrder.unshift(newGroup.id);
29
+ addPanelGroup(draft, newGroup);
34
30
  });
35
31
  },
36
32
  close () {