@perses-dev/dashboards 0.15.0 → 0.16.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 (71) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +2 -0
  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/GridTitle.js +8 -12
  5. package/dist/cjs/components/Panel/Panel.js +4 -2
  6. package/dist/cjs/components/Panel/PanelHeader.js +54 -50
  7. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
  8. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +3 -1
  9. package/dist/cjs/components/Variables/Variable.js +5 -0
  10. package/dist/cjs/components/Variables/VariableEditor.js +20 -1
  11. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +61 -5
  12. package/dist/cjs/components/Variables/VariableList.js +5 -0
  13. package/dist/cjs/components/index.js +1 -0
  14. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
  15. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  16. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
  17. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  18. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  19. package/dist/components/DashboardToolbar/DashboardToolbar.js +2 -0
  20. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  21. package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
  22. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
  23. package/dist/components/DownloadButton/DownloadButton.js +60 -0
  24. package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
  25. package/dist/components/DownloadButton/index.d.ts +2 -0
  26. package/dist/components/DownloadButton/index.d.ts.map +1 -0
  27. package/dist/{utils/component-ids.js → components/DownloadButton/index.js} +2 -14
  28. package/dist/components/DownloadButton/index.js.map +1 -0
  29. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  30. package/dist/components/GridLayout/GridTitle.js +8 -12
  31. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  32. package/dist/components/Panel/Panel.d.ts.map +1 -1
  33. package/dist/components/Panel/Panel.js +4 -2
  34. package/dist/components/Panel/Panel.js.map +1 -1
  35. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  36. package/dist/components/Panel/PanelHeader.js +54 -50
  37. package/dist/components/Panel/PanelHeader.js.map +1 -1
  38. package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
  39. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  40. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +4 -2
  41. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  42. package/dist/components/Variables/Variable.js +5 -0
  43. package/dist/components/Variables/Variable.js.map +1 -1
  44. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  45. package/dist/components/Variables/VariableEditor.js +22 -3
  46. package/dist/components/Variables/VariableEditor.js.map +1 -1
  47. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  48. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +23 -1
  49. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  50. package/dist/components/Variables/VariableList.js +5 -0
  51. package/dist/components/Variables/VariableList.js.map +1 -1
  52. package/dist/components/index.d.ts +1 -0
  53. package/dist/components/index.d.ts.map +1 -1
  54. package/dist/components/index.js +1 -0
  55. package/dist/components/index.js.map +1 -1
  56. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  57. package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
  58. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  59. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  60. package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  61. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  62. package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
  63. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  64. package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
  65. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  66. package/dist/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  67. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  68. package/package.json +4 -4
  69. package/dist/utils/component-ids.d.ts +0 -8
  70. package/dist/utils/component-ids.d.ts.map +0 -1
  71. package/dist/utils/component-ids.js.map +0 -1
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import React from 'react';
14
+ import React, { useMemo } from 'react';
15
15
  import { Box, Typography, Switch, TextField, Grid, FormControl, InputLabel, MenuItem, Select, Button, Stack } from '@mui/material';
16
16
  import { useImmer } from 'use-immer';
17
17
  import { PluginEditor } from '@perses-dev/plugin-system';
@@ -20,6 +20,21 @@ const VARIABLE_TYPES = [
20
20
  'ListVariable',
21
21
  'TextVariable'
22
22
  ];
23
+ // TODO: Replace with proper validation library
24
+ function getValidation(state) {
25
+ /** Name validation */ let name = null;
26
+ if (!state.name) {
27
+ name = 'Name is required';
28
+ }
29
+ // name can only contain alphanumeric characters and underscores and no spaces
30
+ if (state.name && !/^[a-zA-Z0-9_-]+$/.test(state.name)) {
31
+ name = 'Name can only contain alphanumeric characters, underscores, and dashes';
32
+ }
33
+ return {
34
+ name,
35
+ isValid: !name
36
+ };
37
+ }
23
38
  const SectionHeader = ({ children })=>/*#__PURE__*/ _jsx(Typography, {
24
39
  pb: 2,
25
40
  variant: "subtitle1",
@@ -27,6 +42,9 @@ const SectionHeader = ({ children })=>/*#__PURE__*/ _jsx(Typography, {
27
42
  });
28
43
  export function VariableEditForm({ initialVariableDefinition , onChange , onCancel }) {
29
44
  const [state, setState] = useImmer(getInitialState(initialVariableDefinition));
45
+ const validation = useMemo(()=>getValidation(state), [
46
+ state
47
+ ]);
30
48
  return /*#__PURE__*/ _jsxs(Box, {
31
49
  children: [
32
50
  /*#__PURE__*/ _jsx(SectionHeader, {
@@ -41,9 +59,12 @@ export function VariableEditForm({ initialVariableDefinition , onChange , onCanc
41
59
  item: true,
42
60
  xs: 6,
43
61
  children: /*#__PURE__*/ _jsx(TextField, {
62
+ required: true,
63
+ error: !!validation.name,
44
64
  fullWidth: true,
45
65
  label: "Name",
46
66
  value: state.name,
67
+ helperText: validation.name,
47
68
  onChange: (v)=>{
48
69
  setState((draft)=>{
49
70
  draft.name = v.target.value;
@@ -207,6 +228,7 @@ export function VariableEditForm({ initialVariableDefinition , onChange , onCanc
207
228
  justifyContent: "end",
208
229
  children: [
209
230
  /*#__PURE__*/ _jsx(Button, {
231
+ disabled: !validation.isValid,
210
232
  variant: "contained",
211
233
  onClick: ()=>{
212
234
  onChange(getVariableDefinitionFromState(state));
@@ -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,0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ACJ;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 } 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\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\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 return (\n <Box>\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 <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 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 );\n}\n"],"names":["React","useMemo","Box","Typography","Switch","TextField","Grid","FormControl","InputLabel","MenuItem","Select","Button","Stack","useImmer","PluginEditor","getVariableDefinitionFromState","getInitialState","VARIABLE_TYPES","getValidation","state","name","test","isValid","SectionHeader","children","pb","variant","VariableEditForm","initialVariableDefinition","onChange","onCancel","setState","validation","container","spacing","mb","item","xs","required","error","fullWidth","label","value","helperText","v","draft","target","id","labelId","kind","map","title","description","textVariableFields","width","pluginType","pluginKindLabel","listVariableFields","plugin","val","checked","allowMultiple","e","allowAll","direction","just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}
@@ -37,6 +37,11 @@ export function TemplateVariableList(props) {
37
37
  /*#__PURE__*/ _jsx(Drawer, {
38
38
  anchor: 'right',
39
39
  open: isEditing,
40
+ PaperProps: {
41
+ sx: {
42
+ width: '50%'
43
+ }
44
+ },
40
45
  children: /*#__PURE__*/ _jsx(VariableEditor, {
41
46
  onCancel: ()=>{
42
47
  setIsEditing(false);
@@ -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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AAG,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, 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} PaperProps={{ sx: { width: '50%' } }}>\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","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,MAAM,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACjG,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,8BAA8B,EAAEC,WAAW,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AACxG,SAASC,gBAAgB,QAAQ,YAAY,CAAC;AAC9C,SAASC,cAAc,QAAQ,kBAAkB,CAAC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CAACc,IAAI,CAACG,IAAI,CAEf,CAAA;6BACP,CAAC;0BACE;wBACPvC,KAAK,CAACK,uBAAuB,kBAC5B,KAAChB,UAAU;4BAACmC,OAAO,EAAE,IAAMpB,QAAQ,CAAC,CAACD,KAAK,CAAC;sCAAGA,KAAK,iBAAG,KAACX,UAAU,KAAG,iBAAG,KAACC,aAAa,KAAG;0BAAc,AACvG;;kBACG;cACC;;MACL,CACN;AACJ,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,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A;KAAC,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,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,EAAEqC,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 () {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupDefinition, PanelGroupId } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup: PanelGroupDefinition = {\n id: generateId(),\n itemLayouts: [],\n itemPanelKeys: {},\n ...next,\n };\n set((draft) => {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["generateId","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","id","itemLayouts","itemPanelKeys","draft","panelGroups","panelGroupOrder","unshift","close","openEditPanelGroup","panelGroupId","existingGroup","Error","group"],"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,SAASA,UAAU,QAAoB,UAAU,CAAC;AAmClD,OAAO,MAAMC,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0B;YAC1B,MAAMC,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,KAAK;gBACXC,aAAa,EAAE;oBACbC,KAAK,EAAE,EAAE;oBACTC,WAAW,EAAE,KAAK;iBACnB;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjB,MAAMC,QAAQ,GAAyB;wBACrCC,EAAE,EAAEf,UAAU,EAAE;wBAChBgB,WAAW,EAAE,EAAE;wBACfC,aAAa,EAAE,EAAE;wBACjB,GAAGJ,IAAI;qBACR,AAAC;oBACFX,GAAG,C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AAK,CAAC,CAAC,oBAAoB,EAAEF,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;wBACxE,CAAC;wBACDG,KAAK,CAACjB,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;wBACzBiB,KAAK,CAAChB,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDW,KAAK,IAAG;oBACNpB,GAAG,CAAC,CAACgB,KAAK,GAAK;wBACbA,KAAK,CAACd,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACgB,KAAK,GAAK;gBACbA,KAAK,CAACd,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupId, addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","Error","group"],"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,SAAwCA,aAAa,EAAEC,qBAAqB,QAAQ,qBAAqB,CAAC;AAkC1G,OAAO,MAAMC,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0B;YAC1B,MAAMC,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,KAAK;gBACXC,aAAa,EAAE;oBACbC,KAAK,EAAE,EAAE;oBACTC,WAAW,EAAE,KAAK;iBACnB;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjB,MAAMC,QAAQ,GAAGd,qBAAqB,EAAE,AAAC;oBACzCc,QAAQ,CAACJ,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;oBAC5BI,QAAQ,CAACH,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACxCT,GAAG,CAAC,CAACa,KAAK,GAAK;wBACbhB,aAAa,CAACgB,KAAK,EAAED,QAAQ,CAAC,CAAC;oBACjC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDE,KAAK,IAAG;oBACNd,GAAG,CAAC,CAACa,KAAK,GAAK;wBACbA,KAAK,CAACX,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACa,KAAK,GAAK;gBACbA,KAAK,CAACX,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;QAEDU,kBAAkB,EAAE,CAACC,YAAY,GAAK;YACpC,M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,5 @@
1
1
  import { LayoutDefinition } from '@perses-dev/core';
2
+ import { WritableDraft } from 'immer/dist/internal';
2
3
  import { Layout } from 'react-grid-layout';
3
4
  import { StateCreator } from 'zustand';
4
5
  import { Middleware } from './common';
@@ -47,4 +48,12 @@ export interface PanelGroupItemId {
47
48
  */
48
49
  export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
49
50
  export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
51
+ /**
52
+ * Private helper function for creating an empty panel group.
53
+ */
54
+ export declare function createEmptyPanelGroup(): PanelGroupDefinition;
55
+ /**
56
+ * Private helper function that modifies panel group state to add a new panel
57
+ */
58
+ export declare function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void;
50
59
  //# sourceMappingURL=panel-group-slice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D"}
1
+ {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MA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G"}
@@ -84,5 +84,22 @@ export function convertLayoutsToPanelGroups(layouts) {
84
84
  panelGroupOrder: panelGroupIdOrder
85
85
  };
86
86
  }
87
+ /**
88
+ * Private helper function for creating an empty panel group.
89
+ */ export function createEmptyPanelGroup() {
90
+ return {
91
+ id: generateId(),
92
+ title: undefined,
93
+ isCollapsed: false,
94
+ itemLayouts: [],
95
+ itemPanelKeys: {}
96
+ };
97
+ }
98
+ /**
99
+ * Private helper function that modifies panel group state to add a new panel
100
+ */ export function addPanelGroup(draft, newGroup) {
101
+ draft.panelGroups[newGroup.id] = newGroup;
102
+ draft.panelGroupOrder.unshift(newGroup.id);
103
+ }
87
104
 
88
105
  //# sourceMappingURL=panel-group-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAmDlD;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACqC;IAChE,MAAM,E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QAAEkB,IAAI,AAAN,CAAA,KAAW,KAAK;YAC1DC,KAAK,EAAEnB,CAAAA,IAAmB,GAAnBA,MAAM,CAACG,IAAI,CAACa,OAAO,cAAnBhB,IAAmB,WAAO,GAA1BA,KAAAA,CAA0B,GAA1BA,IAAmB,CAAEmB,KAAK;YACjCtB,WAAW;YACXI,aAAa;SACd,CAAC;QACFF,iBAAiB,CAACQ,IAAI,CAACX,YAAY,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACLd,WAAW;QACXC,eAAe,EAAEgB,iBAAiB;KACnC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition) {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AAC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