@perses-dev/dashboards 0.52.0-rc.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/LeaveDialog/LeaveDialog.js +45 -17
- package/dist/cjs/components/Panel/PanelActions.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +204 -185
- package/dist/cjs/components/Variables/VariableEditor.js +22 -15
- package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +1 -1
- package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -2
- package/dist/components/LeaveDialog/LeaveDialog.d.ts +6 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.js +40 -15
- package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
- package/dist/components/Panel/HeaderIconButton.d.ts +1 -1
- package/dist/components/Panel/PanelActions.js +1 -1
- package/dist/components/Panel/PanelActions.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +207 -188
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +24 -17
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js +2 -2
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +2 -3
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/utils/panelUtils.d.ts +3 -0
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js +3 -0
- package/dist/utils/panelUtils.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/VariableEditor.tsx"],"sourcesContent":["// Copyright 2024 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 { useState, useMemo, ReactElement } from 'react';\nimport {\n Button,\n Stack,\n Box,\n TableContainer,\n TableBody,\n TableRow,\n TableCell as MuiTableCell,\n Table,\n TableHead,\n Switch,\n Typography,\n IconButton,\n Alert,\n styled,\n capitalize,\n Tooltip,\n Accordion,\n AccordionSummary,\n AccordionDetails,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { Action, BuiltinVariableDefinition, VariableDefinition } from '@perses-dev/core';\nimport { useImmer } from 'use-immer';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport ArrowUp from 'mdi-material-ui/ArrowUp';\nimport ArrowDown from 'mdi-material-ui/ArrowDown';\nimport ContentDuplicate from 'mdi-material-ui/ContentDuplicate';\nimport OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport ExpandMoreIcon from 'mdi-material-ui/ChevronUp';\n\nimport { ValidationProvider, VariableEditorForm, VariableState, VARIABLE_TYPES } from '@perses-dev/plugin-system';\nimport { InfoTooltip } from '@perses-dev/components';\nimport { ExternalVariableDefinition, useDiscardChangesConfirmationDialog } from '../../context';\nimport { hydrateVariableDefinitionStates } from '../../context/VariableProvider/hydrationUtils';\nimport { BuiltinVariableAccordions } from './BuiltinVariableAccordions';\n\nfunction getVariableLabelByKind(kind: string): 'List' | 'Text' | undefined {\n return VARIABLE_TYPES.find((variableType) => variableType.kind === kind)?.label;\n}\n\nfunction getValidation(variableDefinitions: VariableDefinition[]): { isValid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n /** Variable names must be unique */\n const variableNames = variableDefinitions.map((variableDefinition) => variableDefinition.spec.name);\n const uniqueVariableNames = new Set(variableNames);\n if (variableNames.length !== uniqueVariableNames.size) {\n errors.push('Variable names must be unique');\n }\n return {\n errors: errors,\n isValid: errors.length === 0,\n };\n}\n\nexport function VariableEditor(props: {\n variableDefinitions: VariableDefinition[];\n externalVariableDefinitions: ExternalVariableDefinition[];\n builtinVariableDefinitions: BuiltinVariableDefinition[];\n onChange: (variableDefinitions: VariableDefinition[]) => void;\n onCancel: () => void;\n}): ReactElement {\n const [variableDefinitions, setVariableDefinitions] = useImmer(props.variableDefinitions);\n const [variableEditIdx, setVariableEditIdx] = useState<number | null>(null);\n const [variableFormAction, setVariableFormAction] = useState<Action>('update');\n\n const externalVariableDefinitions = props.externalVariableDefinitions;\n const builtinVariableDefinitions = props.builtinVariableDefinitions;\n const validation = useMemo(() => getValidation(variableDefinitions), [variableDefinitions]);\n const [variableState] = useMemo(() => {\n return [hydrateVariableDefinitionStates(variableDefinitions, {}, externalVariableDefinitions)];\n }, [externalVariableDefinitions, variableDefinitions]);\n const currentEditingVariableDefinition = typeof variableEditIdx === 'number' && variableDefinitions[variableEditIdx];\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n const handleCancel = (): void => {\n if (JSON.stringify(props.variableDefinitions) !== JSON.stringify(variableDefinitions)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeVariable = (index: number): void => {\n setVariableDefinitions((draft) => {\n draft.splice(index, 1);\n });\n };\n\n const addVariable = (): void => {\n setVariableFormAction('create');\n setVariableDefinitions((draft) => {\n draft.push({\n kind: 'TextVariable',\n spec: {\n name: 'NewVariable',\n value: '',\n },\n });\n });\n setVariableEditIdx(variableDefinitions.length);\n };\n\n const editVariable = (index: number): void => {\n setVariableFormAction('update');\n setVariableEditIdx(index);\n };\n\n const toggleVariableVisibility = (index: number, visible: boolean): void => {\n setVariableDefinitions((draft) => {\n const v = draft[index];\n if (!v) {\n return;\n }\n if (!v.spec.display) {\n v.spec.display = {\n name: v.spec.name,\n hidden: false,\n };\n }\n v.spec.display.hidden = visible === false;\n });\n };\n\n const changeVariableOrder = (index: number, direction: 'up' | 'down'): void => {\n setVariableDefinitions((draft) => {\n if (direction === 'up') {\n const prevElement = draft[index - 1];\n const currentElement = draft[index];\n if (index === 0 || !prevElement || !currentElement) {\n return;\n }\n draft[index - 1] = currentElement;\n draft[index] = prevElement;\n } else {\n const nextElement = draft[index + 1];\n const currentElement = draft[index];\n if (index === draft.length - 1 || !nextElement || !currentElement) {\n return;\n }\n draft[index + 1] = currentElement;\n draft[index] = nextElement;\n }\n });\n };\n\n const overrideVariable = (v: VariableDefinition): void => {\n setVariableDefinitions((draft) => {\n draft.push(v);\n });\n };\n\n return (\n <>\n {currentEditingVariableDefinition && (\n <ValidationProvider>\n <VariableEditorForm\n initialVariableDefinition={currentEditingVariableDefinition}\n action={variableFormAction}\n isDraft={true}\n onActionChange={setVariableFormAction}\n onSave={(definition: VariableDefinition) => {\n setVariableDefinitions((draft) => {\n draft[variableEditIdx] = definition;\n setVariableEditIdx(null);\n });\n }}\n onClose={() => {\n if (variableFormAction === 'create') {\n removeVariable(variableEditIdx);\n }\n setVariableEditIdx(null);\n }}\n />\n </ValidationProvider>\n )}\n {!currentEditingVariableDefinition && (\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.divider}`,\n }}\n >\n <Typography variant=\"h2\">Edit Dashboard Variables</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.variableDefinitions === variableDefinitions || !validation.isValid}\n variant=\"contained\"\n onClick={() => {\n props.onChange(variableDefinitions);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n {!validation.isValid &&\n validation.errors.map((error) => (\n <Alert severity=\"error\" key={error}>\n {error}\n </Alert>\n ))}\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of variables\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {variableDefinitions.map((v, idx) => (\n <TableRow key={v.spec.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch\n checked={v.spec.display?.hidden !== true}\n onChange={(e) => {\n toggleVariableVisibility(idx, e.target.checked);\n }}\n />\n </TableCell>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n <VariableName name={v.spec.name} state={variableState.get({ name: v.spec.name })} />\n </TableCell>\n <TableCell>{getVariableLabelByKind(v.kind) ?? v.kind}</TableCell>\n <TableCell>{v.spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => changeVariableOrder(idx, 'up')} disabled={idx === 0}>\n <ArrowUp />\n </IconButton>\n <IconButton\n onClick={() => changeVariableOrder(idx, 'down')}\n disabled={idx === variableDefinitions.length - 1}\n >\n <ArrowDown />\n </IconButton>\n <IconButton onClick={() => editVariable(idx)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeVariable(idx)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginLeft: 'auto' }} onClick={addVariable}>\n Add Variable\n </Button>\n </Box>\n </Stack>\n {externalVariableDefinitions &&\n !externalVariableDefinitions.every((v) => v.definitions.length === 0) &&\n externalVariableDefinitions.map(\n (extVar, key) =>\n extVar.definitions.length > 0 && (\n <Accordion\n key={key}\n sx={(theme) => ({\n '.MuiAccordionSummary-root': {\n backgroundColor: theme.palette.background.lighter,\n },\n '.MuiAccordionDetails-root': {\n backgroundColor: theme.palette.background.lighter,\n },\n })}\n >\n <AccordionSummary\n expandIcon={<ExpandMoreIcon />}\n aria-controls={extVar.source}\n id={extVar.source}\n >\n <Stack flexDirection=\"row\" alignItems=\"center\" justifyContent=\"start\">\n <>\n {extVar.tooltip ? (\n <Typography variant=\"h2\">\n <InfoTooltip\n title={extVar.tooltip.title || ''}\n description={extVar.tooltip.description || ''}\n >\n <span>{capitalize(extVar.source)} Variables</span>\n </InfoTooltip>\n </Typography>\n ) : (\n <Typography variant=\"h2\">{capitalize(extVar.source)} Variables</Typography>\n )}\n {extVar.editLink && (\n <IconButton href={extVar.editLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n )}\n </>\n </Stack>\n </AccordionSummary>\n <AccordionDetails>\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of external variables\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {extVar.definitions.map((v) => (\n <TableRow key={v.spec.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch checked={v.spec.display?.hidden !== true} disabled />\n </TableCell>\n\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n <VariableName\n name={v.spec.name}\n state={variableState.get({ name: v.spec.name, source: extVar.source })}\n />\n </TableCell>\n <TableCell>{getVariableLabelByKind(v.kind) ?? v.kind}</TableCell>\n <TableCell>{v.spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\">\n <Tooltip title=\"Override\">\n <IconButton\n onClick={() => overrideVariable(v)}\n disabled={!!variableState.get({ name: v.spec.name })}\n >\n <ContentDuplicate />\n </IconButton>\n </Tooltip>\n <IconButton disabled>\n <ArrowUp />\n </IconButton>\n <IconButton disabled>\n <ArrowDown />\n </IconButton>\n <IconButton disabled>\n <PencilIcon />\n </IconButton>\n <IconButton disabled>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n </AccordionDetails>\n </Accordion>\n )\n )}\n {builtinVariableDefinitions && (\n <BuiltinVariableAccordions builtinVariableDefinitions={builtinVariableDefinitions} />\n )}\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n\nconst TableCell = styled(MuiTableCell)(({ theme }) => ({\n borderBottom: `solid 1px ${theme.palette.divider}`,\n}));\n\nexport function VariableName(props: { name: string; state: VariableState | undefined }): ReactElement {\n const { name, state } = props;\n return (\n <>\n {!state?.overridden && `${name} `}\n {!state?.overridden && state?.overriding && (\n <Box fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {state?.overridden && (\n <>\n <Box color={(theme) => theme.palette.grey[500]}>{name}</Box>\n <Box fontWeight=\"normal\" color={(theme) => theme.palette.grey[500]}>\n (overridden)\n </Box>\n </>\n )}\n </>\n );\n}\n"],"names":["useState","useMemo","Button","Stack","Box","TableContainer","TableBody","TableRow","TableCell","MuiTableCell","Table","TableHead","Switch","Typography","IconButton","Alert","styled","capitalize","Tooltip","Accordion","AccordionSummary","AccordionDetails","AddIcon","useImmer","PencilIcon","TrashIcon","ArrowUp","ArrowDown","ContentDuplicate","OpenInNewIcon","ExpandMoreIcon","ValidationProvider","VariableEditorForm","VARIABLE_TYPES","InfoTooltip","useDiscardChangesConfirmationDialog","hydrateVariableDefinitionStates","BuiltinVariableAccordions","getVariableLabelByKind","kind","find","variableType","label","getValidation","variableDefinitions","errors","variableNames","map","variableDefinition","spec","name","uniqueVariableNames","Set","length","size","push","isValid","VariableEditor","props","setVariableDefinitions","variableEditIdx","setVariableEditIdx","variableFormAction","setVariableFormAction","externalVariableDefinitions","builtinVariableDefinitions","validation","variableState","currentEditingVariableDefinition","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeVariable","index","draft","splice","addVariable","value","editVariable","toggleVariableVisibility","visible","v","display","hidden","changeVariableOrder","direction","prevElement","currentElement","nextElement","overrideVariable","initialVariableDefinition","action","isDraft","onActionChange","onSave","definition","onClose","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","marginLeft","disabled","onClick","onChange","color","overflowY","error","severity","minWidth","aria-label","align","idx","component","scope","checked","e","target","fontWeight","VariableName","state","get","whiteSpace","startIcon","every","definitions","extVar","key","backgroundColor","background","lighter","expandIcon","aria-controls","source","id","flexDirection","justifyContent","tooltip","title","span","editLink","href","fontSize","overridden","overriding","primary","main","grey"],"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,QAAQ,EAAEC,OAAO,QAAsB,QAAQ;AACxD,SACEC,MAAM,EACNC,KAAK,EACLC,GAAG,EACHC,cAAc,EACdC,SA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AAOP,cAAc,CAAC,EAAEgG,KAAK,EAAE,GAAM,CAAA;QACrDE,cAAc,CAAC,UAAU,EAAEF,MAAMG,OAAO,CAACC,OAAO,EAAE;IACpD,CAAA;AAEA,OAAO,SAASoB,aAAavE,KAAyD;IACpF,MAAM,EAAER,IAAI,EAAEgF,KAAK,EAAE,GAAGxE;IACxB,qBACE;;YACG,CAACwE,OAAOuB,cAAc,GAAGvG,KAAK,CAAC,CAAC;YAChC,CAACgF,OAAOuB,cAAcvB,OAAOwB,4BAC5B,KAACtJ;gBAAI4H,YAAW;gBAASb,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAAC+C,OAAO,CAACC,IAAI;0BAAE;;YAIxE1B,OAAOuB,4BACN;;kCACE,KAACrJ;wBAAI+G,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAACiD,IAAI,CAAC,IAAI;kCAAG3G;;kCACjD,KAAC9C;wBAAI4H,YAAW;wBAASb,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAACiD,IAAI,CAAC,IAAI;kCAAE;;;;;;AAO9E"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/VariableEditor.tsx"],"sourcesContent":["// Copyright 2024 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 { useState, useMemo, ReactElement } from 'react';\nimport {\n Button,\n Stack,\n Box,\n TableContainer,\n TableBody,\n TableRow,\n TableCell as MuiTableCell,\n Table,\n TableHead,\n Switch,\n Typography,\n IconButton,\n Alert,\n styled,\n capitalize,\n Tooltip,\n Accordion,\n AccordionSummary,\n AccordionDetails,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { Action, BuiltinVariableDefinition, DEFAULT_DASHBOARD_DURATION, VariableDefinition } from '@perses-dev/core';\nimport { useImmer } from 'use-immer';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport ArrowUp from 'mdi-material-ui/ArrowUp';\nimport ArrowDown from 'mdi-material-ui/ArrowDown';\nimport ContentDuplicate from 'mdi-material-ui/ContentDuplicate';\nimport OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport ExpandMoreIcon from 'mdi-material-ui/ChevronUp';\n\nimport {\n ValidationProvider,\n VariableEditorForm,\n VariableState,\n VARIABLE_TYPES,\n useInitialTimeRange,\n TimeRangeProvider,\n} from '@perses-dev/plugin-system';\nimport { InfoTooltip } from '@perses-dev/components';\nimport { ExternalVariableDefinition, useDashboard, useDiscardChangesConfirmationDialog } from '../../context';\nimport { hydrateVariableDefinitionStates } from '../../context/VariableProvider/hydrationUtils';\nimport { BuiltinVariableAccordions } from './BuiltinVariableAccordions';\n\nfunction getVariableLabelByKind(kind: string): 'List' | 'Text' | undefined {\n return VARIABLE_TYPES.find((variableType) => variableType.kind === kind)?.label;\n}\n\nfunction getValidation(variableDefinitions: VariableDefinition[]): { isValid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n /** Variable names must be unique */\n const variableNames = variableDefinitions.map((variableDefinition) => variableDefinition.spec.name);\n const uniqueVariableNames = new Set(variableNames);\n if (variableNames.length !== uniqueVariableNames.size) {\n errors.push('Variable names must be unique');\n }\n return {\n errors: errors,\n isValid: errors.length === 0,\n };\n}\n\nexport function VariableEditor(props: {\n variableDefinitions: VariableDefinition[];\n externalVariableDefinitions: ExternalVariableDefinition[];\n builtinVariableDefinitions: BuiltinVariableDefinition[];\n onChange: (variableDefinitions: VariableDefinition[]) => void;\n onCancel: () => void;\n}): ReactElement {\n const [variableDefinitions, setVariableDefinitions] = useImmer(props.variableDefinitions);\n const [variableEditIdx, setVariableEditIdx] = useState<number | null>(null);\n const [variableFormAction, setVariableFormAction] = useState<Action>('update');\n\n const externalVariableDefinitions = props.externalVariableDefinitions;\n const builtinVariableDefinitions = props.builtinVariableDefinitions;\n const validation = useMemo(() => getValidation(variableDefinitions), [variableDefinitions]);\n const [variableState] = useMemo(() => {\n return [hydrateVariableDefinitionStates(variableDefinitions, {}, externalVariableDefinitions)];\n }, [externalVariableDefinitions, variableDefinitions]);\n const currentEditingVariableDefinition = typeof variableEditIdx === 'number' && variableDefinitions[variableEditIdx];\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n const handleCancel = (): void => {\n if (JSON.stringify(props.variableDefinitions) !== JSON.stringify(variableDefinitions)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeVariable = (index: number): void => {\n setVariableDefinitions((draft) => {\n draft.splice(index, 1);\n });\n };\n\n const addVariable = (): void => {\n setVariableFormAction('create');\n setVariableDefinitions((draft) => {\n draft.push({\n kind: 'TextVariable',\n spec: {\n name: 'NewVariable',\n value: '',\n },\n });\n });\n setVariableEditIdx(variableDefinitions.length);\n };\n\n const editVariable = (index: number): void => {\n setVariableFormAction('update');\n setVariableEditIdx(index);\n };\n\n const toggleVariableVisibility = (index: number, visible: boolean): void => {\n setVariableDefinitions((draft) => {\n const v = draft[index];\n if (!v) {\n return;\n }\n if (!v.spec.display) {\n v.spec.display = {\n name: v.spec.name,\n hidden: false,\n };\n }\n v.spec.display.hidden = visible === false;\n });\n };\n\n const changeVariableOrder = (index: number, direction: 'up' | 'down'): void => {\n setVariableDefinitions((draft) => {\n if (direction === 'up') {\n const prevElement = draft[index - 1];\n const currentElement = draft[index];\n if (index === 0 || !prevElement || !currentElement) {\n return;\n }\n draft[index - 1] = currentElement;\n draft[index] = prevElement;\n } else {\n const nextElement = draft[index + 1];\n const currentElement = draft[index];\n if (index === draft.length - 1 || !nextElement || !currentElement) {\n return;\n }\n draft[index + 1] = currentElement;\n draft[index] = nextElement;\n }\n });\n };\n\n const overrideVariable = (v: VariableDefinition): void => {\n setVariableDefinitions((draft) => {\n draft.push(v);\n });\n };\n\n const { dashboard } = useDashboard();\n const dashboardDuration = dashboard?.kind === 'Dashboard' ? dashboard.spec.duration : DEFAULT_DASHBOARD_DURATION;\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n\n return (\n <>\n {currentEditingVariableDefinition && (\n <ValidationProvider>\n <TimeRangeProvider timeRange={initialTimeRange}>\n <VariableEditorForm\n initialVariableDefinition={currentEditingVariableDefinition}\n action={variableFormAction}\n isDraft={true}\n onActionChange={setVariableFormAction}\n onSave={(definition: VariableDefinition) => {\n setVariableDefinitions((draft) => {\n draft[variableEditIdx] = definition;\n setVariableEditIdx(null);\n });\n }}\n onClose={() => {\n if (variableFormAction === 'create') {\n removeVariable(variableEditIdx);\n }\n setVariableEditIdx(null);\n }}\n />\n </TimeRangeProvider>\n </ValidationProvider>\n )}\n {!currentEditingVariableDefinition && (\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.divider}`,\n }}\n >\n <Typography variant=\"h2\">Edit Dashboard Variables</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.variableDefinitions === variableDefinitions || !validation.isValid}\n variant=\"contained\"\n onClick={() => {\n props.onChange(variableDefinitions);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n {!validation.isValid &&\n validation.errors.map((error) => (\n <Alert severity=\"error\" key={error}>\n {error}\n </Alert>\n ))}\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of variables\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {variableDefinitions.map((v, idx) => (\n <TableRow key={v.spec.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch\n checked={v.spec.display?.hidden !== true}\n onChange={(e) => {\n toggleVariableVisibility(idx, e.target.checked);\n }}\n />\n </TableCell>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n <VariableName name={v.spec.name} state={variableState.get({ name: v.spec.name })} />\n </TableCell>\n <TableCell>{getVariableLabelByKind(v.kind) ?? v.kind}</TableCell>\n <TableCell>{v.spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => changeVariableOrder(idx, 'up')} disabled={idx === 0}>\n <ArrowUp />\n </IconButton>\n <IconButton\n onClick={() => changeVariableOrder(idx, 'down')}\n disabled={idx === variableDefinitions.length - 1}\n >\n <ArrowDown />\n </IconButton>\n <IconButton onClick={() => editVariable(idx)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeVariable(idx)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginLeft: 'auto' }} onClick={addVariable}>\n Add Variable\n </Button>\n </Box>\n </Stack>\n {externalVariableDefinitions &&\n !externalVariableDefinitions.every((v) => v.definitions.length === 0) &&\n externalVariableDefinitions.map(\n (extVar, key) =>\n extVar.definitions.length > 0 && (\n <Accordion\n key={key}\n sx={(theme) => ({\n '.MuiAccordionSummary-root': {\n backgroundColor: theme.palette.background.lighter,\n },\n '.MuiAccordionDetails-root': {\n backgroundColor: theme.palette.background.lighter,\n },\n })}\n >\n <AccordionSummary\n expandIcon={<ExpandMoreIcon />}\n aria-controls={extVar.source}\n id={extVar.source}\n >\n <Stack flexDirection=\"row\" alignItems=\"center\" justifyContent=\"start\">\n <>\n {extVar.tooltip ? (\n <Typography variant=\"h2\">\n <InfoTooltip\n title={extVar.tooltip.title || ''}\n description={extVar.tooltip.description || ''}\n >\n <span>{capitalize(extVar.source)} Variables</span>\n </InfoTooltip>\n </Typography>\n ) : (\n <Typography variant=\"h2\">{capitalize(extVar.source)} Variables</Typography>\n )}\n {extVar.editLink && (\n <IconButton href={extVar.editLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n )}\n </>\n </Stack>\n </AccordionSummary>\n <AccordionDetails>\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of external variables\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {extVar.definitions.map((v) => (\n <TableRow key={v.spec.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch checked={v.spec.display?.hidden !== true} disabled />\n </TableCell>\n\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n <VariableName\n name={v.spec.name}\n state={variableState.get({ name: v.spec.name, source: extVar.source })}\n />\n </TableCell>\n <TableCell>{getVariableLabelByKind(v.kind) ?? v.kind}</TableCell>\n <TableCell>{v.spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\">\n <Tooltip title=\"Override\">\n <IconButton\n onClick={() => overrideVariable(v)}\n disabled={!!variableState.get({ name: v.spec.name })}\n >\n <ContentDuplicate />\n </IconButton>\n </Tooltip>\n <IconButton disabled>\n <ArrowUp />\n </IconButton>\n <IconButton disabled>\n <ArrowDown />\n </IconButton>\n <IconButton disabled>\n <PencilIcon />\n </IconButton>\n <IconButton disabled>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n </AccordionDetails>\n </Accordion>\n )\n )}\n {builtinVariableDefinitions && (\n <BuiltinVariableAccordions builtinVariableDefinitions={builtinVariableDefinitions} />\n )}\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n\nconst TableCell = styled(MuiTableCell)(({ theme }) => ({\n borderBottom: `solid 1px ${theme.palette.divider}`,\n}));\n\nexport function VariableName(props: { name: string; state: VariableState | undefined }): ReactElement {\n const { name, state } = props;\n return (\n <>\n {!state?.overridden && `${name} `}\n {!state?.overridden && state?.overriding && (\n <Box fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {state?.overridden && (\n <>\n <Box color={(theme) => theme.palette.grey[500]}>{name}</Box>\n <Box fontWeight=\"normal\" color={(theme) => theme.palette.grey[500]}>\n (overridden)\n </Box>\n </>\n )}\n </>\n );\n}\n"],"names":["useState","useMemo","Button","Stack","Box","TableContainer","TableBody","TableRow","TableCell","MuiTableCell","Table","TableHead","Switch","Typography","IconButton","Alert","styled","capitalize","Tooltip","Accordion","AccordionSummary","AccordionDetails","AddIcon","DEFAULT_DASHBOARD_DURATION","useImmer","PencilIcon","TrashIcon","ArrowUp","ArrowDown","ContentDuplicate","OpenInNewIcon","ExpandMoreIcon","ValidationProvider","VariableEditorForm","VARIABLE_TYPES","useInitialTimeRange","TimeRangeProvider","InfoTooltip","useDashboard","useDiscardChangesConfirmationDialog","hydrateVariableDefinitionStates","BuiltinVariableAccordions","getVariableLabelByKind","kind","find","variableType","label","getValidation","variableDefinitions","errors","variableNames","map","variableDefinition","spec","name","uniqueVariableNames","Set","length","size","push","isValid","VariableEditor","props","setVariableDefinitions","variableEditIdx","setVariableEditIdx","variableFormAction","setVariableFormAction","externalVariableDefinitions","builtinVariableDefinitions","validation","variableState","currentEditingVariableDefinition","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeVariable","index","draft","splice","addVariable","value","editVariable","toggleVariableVisibility","visible","v","display","hidden","changeVariableOrder","direction","prevElement","currentElement","nextElement","overrideVariable","dashboard","dashboardDuration","duration","initialTimeRange","timeRange","initialVariableDefinition","action","isDraft","onActionChange","onSave","definition","onClose","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","marginLeft","disabled","onClick","onChange","color","overflowY","error","severity","minWidth","aria-label","align","idx","component","scope","checked","e","target","fontWeight","VariableName","state","get","whiteSpace","startIcon","every","definitions","extVar","key","backgroundColor","background","lighter","expandIcon","aria-controls","source","id","flexDirection","justifyContent","tooltip","title","span","editLink","href","fontSize","overridden","overriding","primary","main","grey"],"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,QAAQ,EAAEC,OAAO,QAAsB,QAAQ;AACxD,SACEC,MAAM,EACNC,KAAK,EACLC,GAAG,EACHC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,aAAaC,YAAY,EACzBC,KAAK,EACLC,SAAS,EACTC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,OAAO,EACPC,SAAS,EACTC,gBAAgB,EAChBC,gBAAgB,QACX,gBAAgB;AACvB,OAAOC,aAAa,uBAAuB;AAC3C,SAA4CC,0BAA0B,QAA4B,mBAAmB;AACrH,SAASC,QAAQ,QAAQ,YAAY;AACrC,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,eAAe,2BAA2B;AACjD,OAAOC,aAAa,0BAA0B;AAC9C,OAAOC,eAAe,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,EAAE;IACpD,CAAA;AAEA,OAAO,SAASoB,aAAa5E,KAAyD;IACpF,MAAM,EAAER,IAAI,EAAEqF,KAAK,EAAE,GAAG7E;IACxB,qBACE;;YACG,CAAC6E,OAAOuB,cAAc,GAAG5G,KAAK,CAAC,CAAC;YAChC,CAACqF,OAAOuB,cAAcvB,OAAOwB,4BAC5B,KAAC/J;gBAAIqI,YAAW;gBAASb,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAAC+C,OAAO,CAACC,IAAI;0BAAE;;YAIxE1B,OAAOuB,4BACN;;kCACE,KAAC9J;wBAAIwH,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAACiD,IAAI,CAAC,IAAI;kCAAGhH;;kCACjD,KAAClD;wBAAIqI,YAAW;wBAASb,OAAO,CAACV,QAAUA,MAAMG,OAAO,CAACiD,IAAI,CAAC,IAAI;kCAAE;;;;;;AAO9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardProviderWithQueryParams.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DashboardProviderWithQueryParams.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,EAAqB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,sBAAsB,GAAG,YAAY,CAcjH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"sourcesContent":["// Copyright 2025 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 { ReactElement } from 'react';\nimport { JsonParam, useQueryParam } from 'use-query-params';\nimport { DashboardProvider, DashboardProviderProps } from './DashboardProvider';\n\nexport function DashboardProviderWithQueryParams({ children, initialState }: DashboardProviderProps): ReactElement {\n const [viewPanelRef, setViewPanelRef] = useQueryParam('viewPanelRef', JsonParam);\n\n return (\n <DashboardProvider\n initialState={{\n ...initialState,\n viewPanelRef: viewPanelRef ?? undefined, // viewPanelRef can be null, forcing to undefined\n setViewPanelRef: setViewPanelRef,\n }}\n >\n {children}\n </DashboardProvider>\n );\n}\n"],"names":["JsonParam","useQueryParam","DashboardProvider","DashboardProviderWithQueryParams","children","initialState","viewPanelRef","setViewPanelRef","undefined"],"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,SAAS,EAAEC,aAAa,QAAQ,mBAAmB;AAC5D,SAASC,iBAAiB,QAAgC,sBAAsB;AAEhF,OAAO,SAASC,iCAAiC,EAAEC,QAAQ,EAAEC,YAAY,EAA0B;IACjG,MAAM,CAACC,cAAcC,gBAAgB,GAAGN,cAAc,gBAAgBD;IAEtE,qBACE,KAACE;QACCG,cAAc;YACZ,GAAGA,YAAY;YACfC,cAAcA,gBAAgBE;YAC9BD,iBAAiBA;QACnB;kBAECH;;AAGP"}
|
|
@@ -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 {
|
|
13
|
+
import { insertPanelInLayout } from '../../utils/panelUtils';
|
|
14
14
|
import { generateId } from './common';
|
|
15
15
|
/**
|
|
16
16
|
* Curried function for duplicating a panel.
|
|
@@ -41,7 +41,7 @@ import { generateId } from './common';
|
|
|
41
41
|
if (matchingLayout === undefined) {
|
|
42
42
|
throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);
|
|
43
43
|
}
|
|
44
|
-
const dupePanelKey =
|
|
44
|
+
const dupePanelKey = crypto.randomUUID().replaceAll('-', '');
|
|
45
45
|
state.panels[dupePanelKey] = panelToDupe;
|
|
46
46
|
const duplicateLayout = {
|
|
47
47
|
i: generateId().toString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { insertPanelInLayout, UnpositionedPanelGroupItemLayout } from '../../utils/panelUtils';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles duplicating Panels.\n */\nexport interface DuplicatePanelSlice {\n /**\n * Duplicate panel.\n */\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n}\n\n/**\n * Curried function for duplicating a panel.\n */\nexport function createDuplicatePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DuplicatePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DuplicatePanelSlice\n> {\n return (set) => ({\n duplicatePanel(panelGroupItemId: PanelGroupItemId): void {\n set((state) => {\n const panels = state.panels;\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const panelKey = group.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 panelToDupe = panels[panelKey];\n if (panelToDupe === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n // Find the layout for the item being duped\n const matchingLayout = group.itemLayouts.find((itemLayout) => {\n return itemLayout.i === panelGroupLayoutId;\n });\n\n if (matchingLayout === undefined) {\n throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);\n }\n\n const dupePanelKey = crypto.randomUUID().replaceAll('-', '');\n\n state.panels[dupePanelKey] = panelToDupe;\n\n const duplicateLayout: UnpositionedPanelGroupItemLayout = {\n i: generateId().toString(),\n w: matchingLayout.w,\n h: matchingLayout.h,\n };\n\n group.itemLayouts = insertPanelInLayout(duplicateLayout, matchingLayout, group.itemLayouts);\n\n group.itemPanelKeys[duplicateLayout.i] = dupePanelKey;\n });\n },\n });\n}\n"],"names":["insertPanelInLayout","generateId","createDuplicatePanelSlice","set","duplicatePanel","panelGroupItemId","state","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","group","panelGroups","undefined","Error","panelKey","itemPanelKeys","panelToDupe","matchingLayout","itemLayouts","find","itemLayout","i","dupePanelKey","crypto","randomUUID","replaceAll","duplicateLayout","toString","w","h"],"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,mBAAmB,QAA0C,yBAAyB;AAC/F,SAASC,UAAU,QAAoB,WAAW;AAclD;;CAEC,GACD,OAAO,SAASC;IAOd,OAAO,CAACC,MAAS,CAAA;YACfC,gBAAeC,gBAAkC;gBAC/CF,IAAI,CAACG;oBACH,MAAMC,SAASD,MAAMC,MAAM;oBAE3B,4CAA4C;oBAC5C,MAAM,EAAEC,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;oBACrE,MAAMM,QAAQL,MAAMM,WAAW,CAACJ,aAAa;oBAC7C,IAAIG,UAAUE,WAAW;wBACvB,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAEN,cAAc;oBACvD;oBACA,MAAMO,WAAWJ,MAAMK,aAAa,CAACN,mBAAmB;oBACxD,IAAIK,aAAaF,WAAW;wBAC1B,MAAM,IAAIC,MAAM,CAAC,gCAAgC,EAAET,kBAAkB;oBACvE;oBAEA,yBAAyB;oBACzB,MAAMY,cAAcV,MAAM,CAACQ,SAAS;oBACpC,IAAIE,gBAAgBJ,WAAW;wBAC7B,MAAM,IAAIC,MAAM,CAAC,4BAA4B,EAAEC,SAAS,CAAC,CAAC;oBAC5D;oBAEA,2CAA2C;oBAC3C,MAAMG,iBAAiBP,MAA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AAK,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,MAAM,CAAC;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;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,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,
|
|
1
|
+
{"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAyB,MAAM,UAAU,CAAC;AACzE,OAAO,EACL,eAAe,EACf,gBAAgB,EAKjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAE3D;;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,MAAM,CAAC;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;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,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA2IA"}
|
|
@@ -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 { getYForNewRow
|
|
13
|
+
import { getYForNewRow } from '../../utils';
|
|
14
14
|
import { generateId, createPanelDefinition } from './common';
|
|
15
15
|
import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
|
|
16
16
|
/**
|
|
@@ -102,8 +102,7 @@ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
|
|
|
102
102
|
panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition()
|
|
103
103
|
},
|
|
104
104
|
applyChanges: (next)=>{
|
|
105
|
-
const
|
|
106
|
-
const panelKey = getValidPanelKey(name, get().panels);
|
|
105
|
+
const panelKey = crypto.randomUUID().replaceAll('-', '');
|
|
107
106
|
set((state)=>{
|
|
108
107
|
// Add a panel
|
|
109
108
|
state.panels[panelKey] = next.panelDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /*\n * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\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 * 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): void {\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: 'update',\n panelGroupItemId: panelGroupItemId,\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\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: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,cAAc;AAC9D,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAuD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,kBAAkB;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAAM;oBACNX,kBAAkBA;oBAClBY,eAAe;wBACbC,SAASb,iBAAiBG,YAAY;wBACtCW,iBAAiBL;oBACnB;oBACAM,cAAc,CAACC;wBACbrB,IAAI,CAACsB;4BACHA,MAAMhB,MAAM,CAACK,SAAS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;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /*\n * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\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 * 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): void {\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: 'update',\n panelGroupItemId: panelGroupItemId,\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\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: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const panelKey = crypto.randomUUID().replaceAll('-', '');\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","crypto","randomUUID","replaceAll","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAuD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,kBAAkB;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAA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;gBAEAH,IAAI,CAACsB;oBACH,2DAA2D;oBAC3D,IAAIU,aAAa7B,WAAW;wBAC1BN,cAAcyB,OAAOU;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
|
|
@@ -19,9 +19,12 @@ export type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' |
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function insertPanelInLayout(newLayout: UnpositionedPanelGroupItemLayout, referenceLayout: PanelGroupItemLayout, itemLayouts: PanelGroupItemLayout[]): PanelGroupItemLayout[];
|
|
21
21
|
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
*
|
|
22
24
|
* Get a valid panel key, where a valid key:
|
|
23
25
|
* - does not include invalid characters
|
|
24
26
|
* - is unique
|
|
27
|
+
* TODO: It is not clear why too much complexity is needed for generating a panel key
|
|
25
28
|
*/
|
|
26
29
|
export declare function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string;
|
|
27
30
|
//# sourceMappingURL=panelUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panelUtils.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CASjE;AA8BD,MAAM,MAAM,gCAAgC,GAAG,IAAI,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gCAAgC,EAC3C,eAAe,EAAE,oBAAoB,EACrC,WAAW,EAAE,oBAAoB,EAAE,GAClC,oBAAoB,EAAE,CAyExB;AAED
|
|
1
|
+
{"version":3,"file":"panelUtils.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CASjE;AA8BD,MAAM,MAAM,gCAAgC,GAAG,IAAI,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gCAAgC,EAC3C,eAAe,EAAE,oBAAoB,EACrC,WAAW,EAAE,oBAAoB,EAAE,GAClC,oBAAoB,EAAE,CAyExB;AAED;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,MAAM,CASlG"}
|
package/dist/utils/panelUtils.js
CHANGED
|
@@ -122,9 +122,12 @@ function getPanelBounds({ x, y, w, h }) {
|
|
|
122
122
|
];
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
+
* @deprecated
|
|
126
|
+
*
|
|
125
127
|
* Get a valid panel key, where a valid key:
|
|
126
128
|
* - does not include invalid characters
|
|
127
129
|
* - is unique
|
|
130
|
+
* TODO: It is not clear why too much complexity is needed for generating a panel key
|
|
128
131
|
*/ export function getValidPanelKey(panelKey, panels) {
|
|
129
132
|
const uniquePanelKeys = getUniquePanelKeys(panels);
|
|
130
133
|
let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/panelUtils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nexport function getYForNewRow(group: PanelGroupDefinition): number {\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\ntype PanelGroupItemBounds = {\n /**\n * Left horizontal position.\n */\n x1: number;\n /**\n * Right horizontal position.\n */\n x2: number;\n /**\n * Top vertical position.\n */\n y1: number;\n /**\n * Bottom vertical position\n */\n y2: number;\n};\n\nfunction getPanelBounds({ x, y, w, h }: PanelGroupItemLayout): PanelGroupItemBounds {\n return {\n x1: x,\n x2: x + w,\n y1: y,\n y2: y + h,\n };\n}\n\nexport type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;\n\n/**\n * Inserts a new panel into the layout with placement determined by a specified\n * reference panel. The new panel is placed:\n * - To the right of the reference panel if there is space available without\n * moving other panels.\n * - Otherwise, directly below the reference panel. If other panels are below\n * this location, they will also shift downward because the grid uses\n * vertical-based compacting.\n *\n * @param newLayout - Layout for new panel to insert into the grid.\n * @param referenceLayout - Layout for reference panel used to determine the\n * placement of the new panel.\n * @param itemLayouts - Full grid layout.\n * @returns - Item layouts modified to insert the new panel.\n */\nexport function insertPanelInLayout(\n newLayout: UnpositionedPanelGroupItemLayout,\n referenceLayout: PanelGroupItemLayout,\n itemLayouts: PanelGroupItemLayout[]\n): PanelGroupItemLayout[] {\n const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];\n\n const referenceBounds = getPanelBounds(referenceLayout);\n\n // Organize layouts based on vertical relation to the item being inserted\n // after.\n const aboveInsertRow: PanelGroupItemLayout[] = [];\n const insertRow: PanelGroupItemLayout[] = [];\n const belowInsertRow: PanelGroupItemLayout[] = [];\n itemLayouts.forEach((itemLayout) => {\n const itemBounds = getPanelBounds(itemLayout);\n\n if (itemBounds.y2 <= referenceBounds.y1) {\n aboveInsertRow.push(itemLayout);\n } else if (itemBounds.y1 >= referenceBounds.y2) {\n belowInsertRow.push(itemLayout);\n } else {\n insertRow.push(itemLayout);\n }\n });\n\n // Cannot safely assume that the order of item layouts array is strictly\n // left to right. Sorting the row by horizontal position to more easily find\n // gaps.\n insertRow.sort((a, b) => a.x - b.x);\n const insertAfterIndex = insertRow.findIndex((item) => item.i === referenceLayout.i);\n\n if (insertAfterIndex === insertRow.length - 1) {\n // Insert to the right when space is available and the reference is the last\n // item in the row.\n if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {\n return [\n ...aboveInsertRow,\n ...insertRow,\n {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n },\n ...belowInsertRow,\n ];\n }\n } else if (insertAfterIndex >= 0) {\n const nextItem = insertRow[insertAfterIndex + 1];\n\n if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {\n // Insert to the right when space is available between the reference and\n // the next item in the row.\n insertRow.splice(insertAfterIndex + 1, 0, {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n });\n\n return [...aboveInsertRow, ...insertRow, ...belowInsertRow];\n }\n }\n\n // Insert the new item below the original and shift the items below the\n // row where the reference is located.\n return [\n ...aboveInsertRow,\n ...insertRow,\n { x: referenceBounds.x1, y: referenceBounds.y2, ...newLayout },\n ...belowInsertRow.map((itemLayout) => {\n // Note: the grid will not necessarily display all of these items shifted\n // all the way down because of vertical compacting, but shifing their\n // y position ensures the new item gets vertical precedence over items\n // below it in that compacting.\n return { ...itemLayout, y: itemLayout.y + newLayout.h };\n }),\n ];\n}\n\n/**\n * Get a valid panel key, where a valid key:\n * - does not include invalid characters\n * - is unique\n */\nexport function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string {\n const uniquePanelKeys = getUniquePanelKeys(panels);\n let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;\n\n const matchingKey = uniquePanelKeys[normalizedPanelKey];\n if (typeof matchingKey === 'number') {\n normalizedPanelKey += `-${matchingKey + 1}`;\n }\n return normalizedPanelKey;\n}\n\ntype PanelKeyParts = {\n name: string;\n number?: number;\n};\n\nconst removeWhiteSpaces = (str: string): string => {\n return str.replace(/\\s+/g, '');\n};\n\n/**\n * Breaks the specified panel key into the name and the optional `-number` used\n * for deduping panels with the same name.\n */\nfunction getPanelKeyParts(panelKey: string): PanelKeyParts {\n const parts = panelKey.match(/(.+)-([0-9]+)/);\n if (parts && parts[1] && parts[2]) {\n return {\n name: parts[1],\n number: parseInt(parts[2], 10),\n };\n }\n\n return {\n name: panelKey,\n };\n}\n\n// Find all the unique panel keys and the largest number used for each.\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 { name, number } = getPanelKeyParts(panelKey);\n if (uniquePanelKeys[name] === undefined) {\n uniquePanelKeys[name] = 0;\n }\n const currentValue = uniquePanelKeys[name];\n if (typeof currentValue === 'number' && number) {\n // Check for the maximum value because we cannot rely on a sequential\n // set of numbers when panels are modified.\n uniquePanelKeys[name] = Math.max(currentValue, number);\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["GRID_LAYOUT_SMALL_BREAKPOINT","GRID_LAYOUT_COLS","getYForNewRow","group","newRowY","layout","itemLayouts","itemMaxY","y","h","getPanelBounds","x","w","x1","x2","y1","y2","insertPanelInLayout","newLayout","referenceLayout","MAX_LAYOUT_WIDTH","referenceBounds","aboveInsertRow","insertRow","belowInsertRow","forEach","itemLayout","itemBounds","push","sort","a","b","insertAfterIndex","findIndex","item","i","length","nextItem","splice","map","getValidPanelKey","panelKey","panels","uniquePanelKeys","getUniquePanelKeys","normalizedPanelKey","getPanelKeyParts","removeWhiteSpaces","name","matchingKey","str","replace","parts","match","number","parseInt","Object","keys","undefined","currentValue","Math","max"],"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,4BAA4B,EAAEC,gBAAgB,QAAQ,eAAe;AAE9E,yHAAyH;AACzH,OAAO,SAASC,cAAcC,KAA2B;IACvD,IAAIC,UAAU;IACd,KAAK,MAAMC,UAAUF,MAAMG,WAAW,CAAE;QACtC,MAAMC,WAAWF,OAAOG,CAAC,GAAGH,OAAOI,CAAC;QACpC,IAAIF,WAAWH,SAAS;YACtBA,UAAUG;QACZ;IACF;IACA,OAAOH;AACT;AAqBA,SAASM,eAAe,EAAEC,CAAC,EAAEH,CAAC,EAAEI,CAAC,EAAEH,CAAC,EAAwB;IAC1D,OAAO;QACLI,IAAIF;QACJG,IAAIH,IAAIC;QACRG,IAAIP;QACJQ,IAAIR,IAAIC;IACV;AACF;AAIA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASQ,oBACdC,SAA2C,EAC3CC,eAAqC,EACrCb,WAAmC;IAEnC,MAAMc,mBAAmBnB,gBAAgB,CAACD,6BAA6B;IAEvE,MAAMqB,kBAAkBX,eAAeS;IAEvC,yEAAyE;IACzE,SAAS;IACT,MAAMG,iBAAyC,EAAE;IACjD,MAAMC,YAAoC,EAAE;IA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AW;YACvCf,eAAe,CAACK,KAAK,GAAG;QAC1B;QACA,MAAMW,eAAehB,eAAe,CAACK,KAAK;QAC1C,IAAI,OAAOW,iBAAiB,YAAYL,QAAQ;YAC9C,qEAAqE;YACrE,2CAA2C;YAC3CX,eAAe,CAACK,KAAK,GAAGY,KAAKC,GAAG,CAACF,cAAcL;QACjD;IACF;IACA,OAAOX;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/panelUtils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nexport function getYForNewRow(group: PanelGroupDefinition): number {\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\ntype PanelGroupItemBounds = {\n /**\n * Left horizontal position.\n */\n x1: number;\n /**\n * Right horizontal position.\n */\n x2: number;\n /**\n * Top vertical position.\n */\n y1: number;\n /**\n * Bottom vertical position\n */\n y2: number;\n};\n\nfunction getPanelBounds({ x, y, w, h }: PanelGroupItemLayout): PanelGroupItemBounds {\n return {\n x1: x,\n x2: x + w,\n y1: y,\n y2: y + h,\n };\n}\n\nexport type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;\n\n/**\n * Inserts a new panel into the layout with placement determined by a specified\n * reference panel. The new panel is placed:\n * - To the right of the reference panel if there is space available without\n * moving other panels.\n * - Otherwise, directly below the reference panel. If other panels are below\n * this location, they will also shift downward because the grid uses\n * vertical-based compacting.\n *\n * @param newLayout - Layout for new panel to insert into the grid.\n * @param referenceLayout - Layout for reference panel used to determine the\n * placement of the new panel.\n * @param itemLayouts - Full grid layout.\n * @returns - Item layouts modified to insert the new panel.\n */\nexport function insertPanelInLayout(\n newLayout: UnpositionedPanelGroupItemLayout,\n referenceLayout: PanelGroupItemLayout,\n itemLayouts: PanelGroupItemLayout[]\n): PanelGroupItemLayout[] {\n const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];\n\n const referenceBounds = getPanelBounds(referenceLayout);\n\n // Organize layouts based on vertical relation to the item being inserted\n // after.\n const aboveInsertRow: PanelGroupItemLayout[] = [];\n const insertRow: PanelGroupItemLayout[] = [];\n const belowInsertRow: PanelGroupItemLayout[] = [];\n itemLayouts.forEach((itemLayout) => {\n const itemBounds = getPanelBounds(itemLayout);\n\n if (itemBounds.y2 <= referenceBounds.y1) {\n aboveInsertRow.push(itemLayout);\n } else if (itemBounds.y1 >= referenceBounds.y2) {\n belowInsertRow.push(itemLayout);\n } else {\n insertRow.push(itemLayout);\n }\n });\n\n // Cannot safely assume that the order of item layouts array is strictly\n // left to right. Sorting the row by horizontal position to more easily find\n // gaps.\n insertRow.sort((a, b) => a.x - b.x);\n const insertAfterIndex = insertRow.findIndex((item) => item.i === referenceLayout.i);\n\n if (insertAfterIndex === insertRow.length - 1) {\n // Insert to the right when space is available and the reference is the last\n // item in the row.\n if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {\n return [\n ...aboveInsertRow,\n ...insertRow,\n {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n },\n ...belowInsertRow,\n ];\n }\n } else if (insertAfterIndex >= 0) {\n const nextItem = insertRow[insertAfterIndex + 1];\n\n if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {\n // Insert to the right when space is available between the reference and\n // the next item in the row.\n insertRow.splice(insertAfterIndex + 1, 0, {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n });\n\n return [...aboveInsertRow, ...insertRow, ...belowInsertRow];\n }\n }\n\n // Insert the new item below the original and shift the items below the\n // row where the reference is located.\n return [\n ...aboveInsertRow,\n ...insertRow,\n { x: referenceBounds.x1, y: referenceBounds.y2, ...newLayout },\n ...belowInsertRow.map((itemLayout) => {\n // Note: the grid will not necessarily display all of these items shifted\n // all the way down because of vertical compacting, but shifing their\n // y position ensures the new item gets vertical precedence over items\n // below it in that compacting.\n return { ...itemLayout, y: itemLayout.y + newLayout.h };\n }),\n ];\n}\n\n/**\n * @deprecated\n *\n * Get a valid panel key, where a valid key:\n * - does not include invalid characters\n * - is unique\n * TODO: It is not clear why too much complexity is needed for generating a panel key\n */\n\nexport function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string {\n const uniquePanelKeys = getUniquePanelKeys(panels);\n let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;\n\n const matchingKey = uniquePanelKeys[normalizedPanelKey];\n if (typeof matchingKey === 'number') {\n normalizedPanelKey += `-${matchingKey + 1}`;\n }\n return normalizedPanelKey;\n}\n\ntype PanelKeyParts = {\n name: string;\n number?: number;\n};\n\nconst removeWhiteSpaces = (str: string): string => {\n return str.replace(/\\s+/g, '');\n};\n\n/**\n * Breaks the specified panel key into the name and the optional `-number` used\n * for deduping panels with the same name.\n */\nfunction getPanelKeyParts(panelKey: string): PanelKeyParts {\n const parts = panelKey.match(/(.+)-([0-9]+)/);\n if (parts && parts[1] && parts[2]) {\n return {\n name: parts[1],\n number: parseInt(parts[2], 10),\n };\n }\n\n return {\n name: panelKey,\n };\n}\n\n// Find all the unique panel keys and the largest number used for each.\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 { name, number } = getPanelKeyParts(panelKey);\n if (uniquePanelKeys[name] === undefined) {\n uniquePanelKeys[name] = 0;\n }\n const currentValue = uniquePanelKeys[name];\n if (typeof currentValue === 'number' && number) {\n // Check for the maximum value because we cannot rely on a sequential\n // set of numbers when panels are modified.\n uniquePanelKeys[name] = Math.max(currentValue, number);\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["GRID_LAYOUT_SMALL_BREAKPOINT","GRID_LAYOUT_COLS","getYForNewRow","group","newRowY","layout","itemLayouts","itemMaxY","y","h","getPanelBounds","x","w","x1","x2","y1","y2","insertPanelInLayout","newLayout","referenceLayout","MAX_LAYOUT_WIDTH","referenceBounds","aboveInsertRow","insertRow","belowInsertRow","forEach","itemLayout","itemBounds","push","sort","a","b","insertAfterIndex","findIndex","item","i","length","nextItem","splice","map","getValidPanelKey","panelKey","panels","uniquePanelKeys","getUniquePanelKeys","normalizedPanelKey","getPanelKeyParts","removeWhiteSpaces","name","matchingKey","str","replace","parts","match","number","parseInt","Object","keys","undefined","currentValue","Math","max"],"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,4BAA4B,EAAEC,gBAAgB,QAAQ,eAAe;AAE9E,yHAAyH;AACzH,OAAO,SAASC,cAAcC,KAA2B;IACvD,IAAIC,UAAU;IACd,KAAK,MAAMC,UAAUF,MAAMG,WAAW,CAAE;QACtC,MAAMC,WAAWF,OAAOG,CAAC,GAAGH,OAAOI,CAAC;QACpC,IAAIF,WAAWH,SAAS;YACtBA,UAAUG;QACZ;IACF;IACA,OAAOH;AACT;AAqB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AAC,EAAE,IAAIA,KAAK,CAAC,EAAE,EAAE;QACjC,OAAO;YACLJ,MAAMI,KAAK,CAAC,EAAE;YACdE,QAAQC,SAASH,KAAK,CAAC,EAAE,EAAE;QAC7B;IACF;IAEA,OAAO;QACLJ,MAAMP;IACR;AACF;AAEA,uEAAuE;AACvE,0FAA0F;AAC1F,SAASG,mBAAmBF,MAAuC;IACjE,MAAMC,kBAA0C,CAAC;IACjDa,OAAOC,IAAI,CAACf,QAAQjB,OAAO,CAAC,CAACgB;QAC3B,MAAM,EAAEO,IAAI,EAAEM,MAAM,EAAE,GAAGR,iBAAiBL;QAC1C,IAAIE,eAAe,CAACK,KAAK,KAAKU,WAAW;YACvCf,eAAe,CAACK,KAAK,GAAG;QAC1B;QACA,MAAMW,eAAehB,eAAe,CAACK,KAAK;QAC1C,IAAI,OAAOW,iBAAiB,YAAYL,QAAQ;YAC9C,qEAAqE;YACrE,2CAA2C;YAC3CX,eAAe,CAACK,KAAK,GAAGY,KAAKC,GAAG,CAACF,cAAcL;QACjD;IACF;IACA,OAAOX;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/dashboards",
|
|
3
|
-
"version": "0.52.0
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "The dashboards feature in Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@perses-dev/components": "0.52.0
|
|
33
|
-
"@perses-dev/core": "0.52.0
|
|
34
|
-
"@perses-dev/plugin-system": "0.52.0
|
|
32
|
+
"@perses-dev/components": "0.52.0",
|
|
33
|
+
"@perses-dev/core": "0.52.0",
|
|
34
|
+
"@perses-dev/plugin-system": "0.52.0",
|
|
35
35
|
"@types/react-grid-layout": "^1.3.2",
|
|
36
36
|
"date-fns": "^4.1.0",
|
|
37
37
|
"immer": "^10.1.1",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"react-hook-form": "^7.46.1",
|
|
41
41
|
"react-intersection-observer": "^9.4.0",
|
|
42
42
|
"use-immer": "^0.11.0",
|
|
43
|
-
"use-query-params": "^2.
|
|
43
|
+
"use-query-params": "^2.2.1",
|
|
44
44
|
"use-resize-observer": "^9.0.0",
|
|
45
45
|
"yaml": "^2.7.0",
|
|
46
46
|
"zustand": "^4.3.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@perses-dev/internal-utils": "0.52.0
|
|
49
|
+
"@perses-dev/internal-utils": "0.52.0",
|
|
50
50
|
"history": "^5.3.0",
|
|
51
51
|
"intersection-observer": "^0.12.2"
|
|
52
52
|
},
|