@perses-dev/dashboards 0.54.0-beta.4 → 0.54.0-beta.6

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 (77) hide show
  1. package/dist/cjs/components/Annotations/AnnotationsEditor.js +302 -0
  2. package/dist/cjs/components/Annotations/EditAnnotationsButton.js +83 -0
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -1
  4. package/dist/cjs/components/Variables/VariableEditor.js +2 -2
  5. package/dist/cjs/constants/user-interface-text.js +1 -0
  6. package/dist/cjs/context/AnnotationProvider/AnnotationHydrationWrapper.js +50 -0
  7. package/dist/cjs/context/AnnotationProvider/AnnotationProvider.js +145 -0
  8. package/dist/cjs/context/AnnotationProvider/index.js +30 -0
  9. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +14 -11
  10. package/dist/cjs/context/DatasourceStoreProvider.js +1 -1
  11. package/dist/cjs/context/index.js +1 -0
  12. package/dist/cjs/context/useDashboard.js +8 -0
  13. package/dist/cjs/model/index.js +1 -0
  14. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  15. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +29 -25
  16. package/dist/components/Annotations/AnnotationsEditor.d.ts +8 -0
  17. package/dist/components/Annotations/AnnotationsEditor.d.ts.map +1 -0
  18. package/dist/components/Annotations/AnnotationsEditor.js +289 -0
  19. package/dist/components/Annotations/AnnotationsEditor.js.map +1 -0
  20. package/dist/components/Annotations/EditAnnotationsButton.d.ts +18 -0
  21. package/dist/components/Annotations/EditAnnotationsButton.d.ts.map +1 -0
  22. package/dist/components/Annotations/EditAnnotationsButton.js +70 -0
  23. package/dist/components/Annotations/EditAnnotationsButton.js.map +1 -0
  24. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  25. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  26. package/dist/components/DashboardToolbar/DashboardToolbar.js +3 -1
  27. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  28. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  29. package/dist/components/Variables/VariableEditor.js +2 -2
  30. package/dist/components/Variables/VariableEditor.js.map +1 -1
  31. package/dist/constants/user-interface-text.d.ts +1 -0
  32. package/dist/constants/user-interface-text.d.ts.map +1 -1
  33. package/dist/constants/user-interface-text.js +1 -0
  34. package/dist/constants/user-interface-text.js.map +1 -1
  35. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts +7 -0
  36. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts.map +1 -0
  37. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js +48 -0
  38. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js.map +1 -0
  39. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts +40 -0
  40. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts.map +1 -0
  41. package/dist/context/AnnotationProvider/AnnotationProvider.js +114 -0
  42. package/dist/context/AnnotationProvider/AnnotationProvider.js.map +1 -0
  43. package/dist/context/AnnotationProvider/index.d.ts +2 -0
  44. package/dist/context/AnnotationProvider/index.d.ts.map +1 -0
  45. package/dist/context/AnnotationProvider/index.js +15 -0
  46. package/dist/context/AnnotationProvider/index.js.map +1 -0
  47. package/dist/context/DashboardProvider/DashboardProvider.d.ts +3 -2
  48. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  49. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  50. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  51. package/dist/context/DashboardProvider/panel-group-slice.js +14 -11
  52. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  53. package/dist/context/DatasourceStoreProvider.js +1 -1
  54. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  55. package/dist/context/index.d.ts +1 -0
  56. package/dist/context/index.d.ts.map +1 -1
  57. package/dist/context/index.js +1 -0
  58. package/dist/context/index.js.map +1 -1
  59. package/dist/context/useDashboard.d.ts.map +1 -1
  60. package/dist/context/useDashboard.js +8 -0
  61. package/dist/context/useDashboard.js.map +1 -1
  62. package/dist/model/DashboardResource.d.ts +2 -8
  63. package/dist/model/DashboardResource.d.ts.map +1 -1
  64. package/dist/model/DashboardResource.js +1 -4
  65. package/dist/model/DashboardResource.js.map +1 -1
  66. package/dist/model/index.d.ts +1 -0
  67. package/dist/model/index.d.ts.map +1 -1
  68. package/dist/model/index.js +1 -0
  69. package/dist/model/index.js.map +1 -1
  70. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  71. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  72. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  73. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  74. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  75. package/dist/views/ViewDashboard/ViewDashboard.js +30 -26
  76. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  77. package/package.json +4 -4
@@ -78,23 +78,26 @@ function convertLayoutsToPanelGroups(layouts) {
78
78
  const itemLayouts = [];
79
79
  const itemPanelKeys = {};
80
80
  // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
81
- for (const item of layout.spec.items){
82
- const panelGroupLayoutId = (0, _common.generateId)().toString();
83
- itemLayouts.push({
84
- i: panelGroupLayoutId,
85
- w: item.width,
86
- h: item.height,
87
- x: item.x,
88
- y: item.y
89
- });
90
- itemPanelKeys[panelGroupLayoutId] = (0, _spec.getPanelKeyFromRef)(item.content);
81
+ if ('items' in layout.spec) {
82
+ for (const item of layout.spec.items){
83
+ const panelGroupLayoutId = (0, _common.generateId)().toString();
84
+ itemLayouts.push({
85
+ i: panelGroupLayoutId,
86
+ w: item.width,
87
+ h: item.height,
88
+ x: item.x,
89
+ y: item.y
90
+ });
91
+ itemPanelKeys[panelGroupLayoutId] = (0, _spec.getPanelKeyFromRef)(item.content);
92
+ }
91
93
  }
92
94
  // Create the panel group and keep track of the ID order
95
+ const repeatVariable = 'repeatVariable' in layout.spec ? layout.spec.repeatVariable : undefined;
93
96
  const panelGroupId = (0, _common.generateId)();
94
97
  panelGroups[panelGroupId] = {
95
98
  id: panelGroupId,
96
99
  isCollapsed: layout.spec.display?.collapse?.open === false,
97
- repeatVariable: layout.spec.repeatVariable,
100
+ repeatVariable,
98
101
  title: layout.spec.display?.title,
99
102
  itemLayouts,
100
103
  itemPanelKeys
@@ -266,7 +266,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
266
266
  });
267
267
  usedNames.add(selectorName);
268
268
  const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
269
- if (results[0] && (isFirst || isExplicitDefault)) {
269
+ if (results[0] && isExplicitDefault) {
270
270
  // If we haven't added a default yet and this is a default, add default option to the beginning of the results
271
271
  results[0].items = [
272
272
  {
@@ -14,6 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ _export_star(require("./AnnotationProvider"), exports);
17
18
  _export_star(require("./DashboardProvider"), exports);
18
19
  _export_star(require("./DatasourceStoreProvider"), exports);
19
20
  _export_star(require("./VariableProvider"), exports);
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "useDashboard", {
23
23
  const _spec = require("@perses-dev/spec");
24
24
  const _DashboardProvider = require("./DashboardProvider");
25
25
  const _VariableProvider = require("./VariableProvider");
26
+ const _AnnotationProvider = require("./AnnotationProvider");
26
27
  function useDashboard() {
27
28
  const { panels, panelGroups, panelGroupOrder, setDashboard: setDashboardResource, kind, metadata, display, duration, refreshInterval, datasources, links, ttl } = (0, _DashboardProvider.useDashboardStore)(({ panels, panelGroups, panelGroupOrder, setDashboard, kind, metadata, display, duration, refreshInterval, datasources, links, ttl })=>({
28
29
  panels,
@@ -39,7 +40,9 @@ function useDashboard() {
39
40
  ttl
40
41
  }));
41
42
  const { setVariableDefinitions } = (0, _VariableProvider.useVariableDefinitionActions)();
43
+ const { setAnnotationSpecs } = (0, _AnnotationProvider.useAnnotationActions)();
42
44
  const variables = (0, _VariableProvider.useVariableDefinitions)();
45
+ const annotations = (0, _AnnotationProvider.useAnnotationSpecs)();
43
46
  const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
44
47
  const dashboard = kind === 'Dashboard' ? {
45
48
  kind,
@@ -49,6 +52,7 @@ function useDashboard() {
49
52
  panels,
50
53
  layouts,
51
54
  variables,
55
+ annotations,
52
56
  duration,
53
57
  refreshInterval,
54
58
  datasources,
@@ -62,6 +66,7 @@ function useDashboard() {
62
66
  panels,
63
67
  layouts,
64
68
  variables,
69
+ annotations,
65
70
  duration,
66
71
  refreshInterval,
67
72
  datasources,
@@ -71,6 +76,9 @@ function useDashboard() {
71
76
  };
72
77
  const setDashboard = (dashboardResource)=>{
73
78
  setVariableDefinitions(dashboardResource.spec.variables);
79
+ if (dashboardResource.spec.annotations) {
80
+ setAnnotationSpecs(dashboardResource.spec.annotations);
81
+ }
74
82
  setDashboardResource(dashboardResource);
75
83
  };
76
84
  return {
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _export_star(require("./DashboardResource"), exports);
18
18
  _export_star(require("./PanelGroupDefinition"), exports);
19
+ _export_star(require("./VariableDefinition"), exports);
19
20
  function _export_star(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
21
22
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -36,7 +36,7 @@ const DashboardApp = (props)=>{
36
36
  });
37
37
  };
38
38
  const DashboardAppContent = (props)=>{
39
- const { dashboardResource, emptyDashboardProps, isReadonly, isVariableEnabled, isDatasourceEnabled, disableShortcuts, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, onSave, onDiscard } = props;
39
+ const { dashboardResource, emptyDashboardProps, isReadonly, isVariableEnabled, isAnnotationEnabled, isDatasourceEnabled, disableShortcuts, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, onSave, onDiscard } = props;
40
40
  const chartsTheme = (0, _components.useChartsTheme)();
41
41
  const { isEditMode, setEditMode } = (0, _context.useEditMode)();
42
42
  const { dashboard, setDashboard } = (0, _context.useDashboard)();
@@ -97,6 +97,7 @@ const DashboardAppContent = (props)=>{
97
97
  onSave: onSave,
98
98
  isReadonly: isReadonly,
99
99
  isVariableEnabled: isVariableEnabled,
100
+ isAnnotationEnabled: isAnnotationEnabled,
100
101
  isDatasourceEnabled: isDatasourceEnabled,
101
102
  onEditButtonClick: onEditButtonClick,
102
103
  onCancelButtonClick: onCancelButtonClick
@@ -30,7 +30,7 @@ const _context = require("../../context");
30
30
  const _DashboardProviderWithQueryParams = require("../../context/DashboardProvider/DashboardProviderWithQueryParams");
31
31
  const _DashboardApp = require("./DashboardApp");
32
32
  function ViewDashboard(props) {
33
- const { dashboardResource, datasourceApi, externalVariableDefinitions, emptyDashboardProps, isReadonly, isVariableEnabled, isDatasourceEnabled, disableShortcuts, isEditing, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, onSave, onDiscard, sx, ...others } = props;
33
+ const { dashboardResource, datasourceApi, externalVariableDefinitions, emptyDashboardProps, isReadonly, isVariableEnabled, isAnnotationEnabled, isDatasourceEnabled, disableShortcuts, isEditing, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, onSave, onDiscard, sx, ...others } = props;
34
34
  const { spec } = dashboardResource;
35
35
  const dashboardDuration = spec.duration ?? _constants.DEFAULT_DASHBOARD_DURATION;
36
36
  const dashboardRefreshInterval = spec.refreshInterval ?? _constants.DEFAULT_REFRESH_INTERVAL;
@@ -90,30 +90,34 @@ function ViewDashboard(props) {
90
90
  initialVariableDefinitions: spec.variables,
91
91
  externalVariableDefinitions: externalVariableDefinitions,
92
92
  builtinVariableDefinitions: builtinVariables,
93
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
94
- sx: (0, _components.combineSx)({
95
- display: 'flex',
96
- width: '100%',
97
- height: '100%',
98
- position: 'relative',
99
- overflow: 'hidden'
100
- }, sx),
101
- ...others,
102
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
103
- FallbackComponent: _components.ErrorAlert,
104
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DashboardApp.DashboardApp, {
105
- dashboardResource: dashboardResource,
106
- emptyDashboardProps: emptyDashboardProps,
107
- isReadonly: isReadonly,
108
- isVariableEnabled: isVariableEnabled,
109
- isDatasourceEnabled: isDatasourceEnabled,
110
- disableShortcuts: disableShortcuts,
111
- isCreating: isCreating,
112
- isInitialVariableSticky: isInitialVariableSticky,
113
- isLeavingConfirmDialogEnabled: isLeavingConfirmDialogEnabled,
114
- dashboardTitleComponent: dashboardTitleComponent,
115
- onSave: onSave,
116
- onDiscard: onDiscard
93
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_context.AnnotationProvider, {
94
+ initialAnnotationSpecs: spec.annotations ?? [],
95
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
96
+ sx: (0, _components.combineSx)({
97
+ display: 'flex',
98
+ width: '100%',
99
+ height: '100%',
100
+ position: 'relative',
101
+ overflow: 'hidden'
102
+ }, sx),
103
+ ...others,
104
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
105
+ FallbackComponent: _components.ErrorAlert,
106
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DashboardApp.DashboardApp, {
107
+ dashboardResource: dashboardResource,
108
+ emptyDashboardProps: emptyDashboardProps,
109
+ isReadonly: isReadonly,
110
+ isVariableEnabled: isVariableEnabled,
111
+ isAnnotationEnabled: isAnnotationEnabled,
112
+ isDatasourceEnabled: isDatasourceEnabled,
113
+ disableShortcuts: disableShortcuts,
114
+ isCreating: isCreating,
115
+ isInitialVariableSticky: isInitialVariableSticky,
116
+ isLeavingConfirmDialogEnabled: isLeavingConfirmDialogEnabled,
117
+ dashboardTitleComponent: dashboardTitleComponent,
118
+ onSave: onSave,
119
+ onDiscard: onDiscard
120
+ })
117
121
  })
118
122
  })
119
123
  })
@@ -0,0 +1,8 @@
1
+ import { ReactElement } from 'react';
2
+ import { AnnotationSpec } from '@perses-dev/spec';
3
+ export declare function AnnotationEditor(props: {
4
+ annotationSpecs: AnnotationSpec[];
5
+ onChange: (annotationSpecs: AnnotationSpec[]) => void;
6
+ onCancel: () => void;
7
+ }): ReactElement;
8
+ //# sourceMappingURL=AnnotationsEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnnotationsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Annotations/AnnotationsEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqB,YAAY,EAAE,MAAM,OAAO,CAAC;AAkBxD,OAAO,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAC;AA8B3E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,QAAQ,EAAE,CAAC,eAAe,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IACtD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CAyMf"}
@@ -0,0 +1,289 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // Copyright The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { useState, useMemo } from 'react';
15
+ import { Button, Stack, Box, TableContainer, TableBody, TableRow, TableCell as MuiTableCell, Table, TableHead, Switch, Typography, IconButton, Alert, styled } from '@mui/material';
16
+ import AddIcon from 'mdi-material-ui/Plus';
17
+ import { useImmer } from 'use-immer';
18
+ import PencilIcon from 'mdi-material-ui/Pencil';
19
+ import TrashIcon from 'mdi-material-ui/TrashCan';
20
+ import ArrowUp from 'mdi-material-ui/ArrowUp';
21
+ import ArrowDown from 'mdi-material-ui/ArrowDown';
22
+ import { ValidationProvider, AnnotationEditorForm } from '@perses-dev/plugin-system';
23
+ import { useDiscardChangesConfirmationDialog } from '../../context';
24
+ function validateAnnotationSpecs(annotationSpecs) {
25
+ const errors = [];
26
+ const annotationNames = [];
27
+ for (const annotationSpec of annotationSpecs){
28
+ if (annotationNames.includes(annotationSpec.display.name)) {
29
+ errors.push(`Duplicate annotation name: ${annotationSpec.display.name}`);
30
+ } else {
31
+ annotationNames.push(annotationSpec.display.name);
32
+ }
33
+ }
34
+ return {
35
+ errors: errors,
36
+ isValid: errors.length === 0
37
+ };
38
+ }
39
+ export function AnnotationEditor(props) {
40
+ const [annotationSpecs, setAnnotationSpecs] = useImmer(props.annotationSpecs);
41
+ const [annotationEditIdx, setAnnotationEditIdx] = useState(null);
42
+ const [annotationFormAction, setAnnotationFormAction] = useState('update');
43
+ const validation = useMemo(()=>validateAnnotationSpecs(annotationSpecs), [
44
+ annotationSpecs
45
+ ]);
46
+ const currentEditingAnnotationSpec = annotationEditIdx !== null ? annotationSpecs[annotationEditIdx] : undefined;
47
+ const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } = useDiscardChangesConfirmationDialog();
48
+ const handleCancel = ()=>{
49
+ if (JSON.stringify(props.annotationSpecs) !== JSON.stringify(annotationSpecs)) {
50
+ openDiscardChangesConfirmationDialog({
51
+ onDiscardChanges: ()=>{
52
+ closeDiscardChangesConfirmationDialog();
53
+ props.onCancel();
54
+ },
55
+ onCancel: ()=>{
56
+ closeDiscardChangesConfirmationDialog();
57
+ },
58
+ description: 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.'
59
+ });
60
+ } else {
61
+ props.onCancel();
62
+ }
63
+ };
64
+ const removeAnnotation = (index)=>{
65
+ setAnnotationSpecs((draft)=>{
66
+ draft.splice(index, 1);
67
+ });
68
+ };
69
+ const addAnnotation = ()=>{
70
+ setAnnotationFormAction('create');
71
+ setAnnotationSpecs((draft)=>{
72
+ draft.push({
73
+ display: {
74
+ name: 'NewAnnotation'
75
+ },
76
+ plugin: {}
77
+ });
78
+ });
79
+ setAnnotationEditIdx(annotationSpecs.length);
80
+ };
81
+ const editAnnotation = (index)=>{
82
+ setAnnotationFormAction('update');
83
+ setAnnotationEditIdx(index);
84
+ };
85
+ const toggleAnnotationVisibility = (index, visible)=>{
86
+ setAnnotationSpecs((draft)=>{
87
+ const v = draft[index];
88
+ if (!v) {
89
+ return;
90
+ }
91
+ v.display.hidden = !visible;
92
+ });
93
+ };
94
+ const changeAnnotationOrder = (index, direction)=>{
95
+ const step = direction === 'up' ? -1 : 1;
96
+ setAnnotationSpecs((draft)=>{
97
+ const current = draft[index];
98
+ const adjacent = draft[index + step];
99
+ if (!current || !adjacent) {
100
+ return;
101
+ }
102
+ draft[index + step] = current;
103
+ draft[index] = adjacent;
104
+ });
105
+ };
106
+ return /*#__PURE__*/ _jsx(_Fragment, {
107
+ children: annotationEditIdx !== null && currentEditingAnnotationSpec ? /*#__PURE__*/ _jsx(ValidationProvider, {
108
+ children: /*#__PURE__*/ _jsx(AnnotationEditorForm, {
109
+ initialAnnotationSpec: currentEditingAnnotationSpec,
110
+ action: annotationFormAction,
111
+ isDraft: true,
112
+ onActionChange: setAnnotationFormAction,
113
+ onSave: (definition)=>{
114
+ setAnnotationSpecs((draft)=>{
115
+ draft[annotationEditIdx] = definition;
116
+ setAnnotationEditIdx(null);
117
+ });
118
+ },
119
+ onClose: ()=>{
120
+ if (annotationFormAction === 'create') {
121
+ removeAnnotation(annotationEditIdx);
122
+ }
123
+ setAnnotationEditIdx(null);
124
+ }
125
+ })
126
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
127
+ children: [
128
+ /*#__PURE__*/ _jsxs(Box, {
129
+ sx: {
130
+ display: 'flex',
131
+ alignItems: 'center',
132
+ padding: (theme)=>theme.spacing(1, 2),
133
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
134
+ },
135
+ children: [
136
+ /*#__PURE__*/ _jsx(Typography, {
137
+ variant: "h2",
138
+ children: "Edit Dashboard Annotations"
139
+ }),
140
+ /*#__PURE__*/ _jsxs(Stack, {
141
+ direction: "row",
142
+ spacing: 1,
143
+ marginLeft: "auto",
144
+ children: [
145
+ /*#__PURE__*/ _jsx(Button, {
146
+ disabled: props.annotationSpecs === annotationSpecs || !validation.isValid,
147
+ variant: "contained",
148
+ onClick: ()=>{
149
+ props.onChange(annotationSpecs);
150
+ },
151
+ children: "Apply"
152
+ }),
153
+ /*#__PURE__*/ _jsx(Button, {
154
+ color: "secondary",
155
+ variant: "outlined",
156
+ onClick: handleCancel,
157
+ children: "Cancel"
158
+ })
159
+ ]
160
+ })
161
+ ]
162
+ }),
163
+ /*#__PURE__*/ _jsx(Box, {
164
+ padding: 2,
165
+ sx: {
166
+ overflowY: 'scroll'
167
+ },
168
+ children: /*#__PURE__*/ _jsx(Stack, {
169
+ spacing: 2,
170
+ children: /*#__PURE__*/ _jsxs(Stack, {
171
+ spacing: 2,
172
+ children: [
173
+ !validation.isValid && validation.errors.map((error)=>/*#__PURE__*/ _jsx(Alert, {
174
+ severity: "error",
175
+ children: error
176
+ }, error)),
177
+ /*#__PURE__*/ _jsx(TableContainer, {
178
+ children: /*#__PURE__*/ _jsxs(Table, {
179
+ sx: {
180
+ minWidth: 650
181
+ },
182
+ "aria-label": "table of annotations",
183
+ children: [
184
+ /*#__PURE__*/ _jsx(TableHead, {
185
+ children: /*#__PURE__*/ _jsxs(TableRow, {
186
+ children: [
187
+ /*#__PURE__*/ _jsx(TableCell, {
188
+ children: "Visibility"
189
+ }),
190
+ /*#__PURE__*/ _jsx(TableCell, {
191
+ children: "Name"
192
+ }),
193
+ /*#__PURE__*/ _jsx(TableCell, {
194
+ children: "Type"
195
+ }),
196
+ /*#__PURE__*/ _jsx(TableCell, {
197
+ children: "Description"
198
+ }),
199
+ /*#__PURE__*/ _jsx(TableCell, {
200
+ align: "right",
201
+ children: "Actions"
202
+ })
203
+ ]
204
+ })
205
+ }),
206
+ /*#__PURE__*/ _jsx(TableBody, {
207
+ children: annotationSpecs.map((v, idx)=>/*#__PURE__*/ _jsxs(TableRow, {
208
+ children: [
209
+ /*#__PURE__*/ _jsx(TableCell, {
210
+ component: "th",
211
+ scope: "row",
212
+ children: /*#__PURE__*/ _jsx(Switch, {
213
+ checked: v.display?.hidden !== true,
214
+ onChange: (e)=>{
215
+ toggleAnnotationVisibility(idx, e.target.checked);
216
+ }
217
+ })
218
+ }),
219
+ /*#__PURE__*/ _jsx(TableCell, {
220
+ component: "th",
221
+ scope: "row",
222
+ sx: {
223
+ fontWeight: 'bold'
224
+ },
225
+ children: v.display.name
226
+ }),
227
+ /*#__PURE__*/ _jsx(TableCell, {
228
+ children: v.plugin.kind
229
+ }),
230
+ /*#__PURE__*/ _jsx(TableCell, {
231
+ children: v.display?.description ?? ''
232
+ }),
233
+ /*#__PURE__*/ _jsxs(TableCell, {
234
+ align: "right",
235
+ sx: {
236
+ whiteSpace: 'nowrap'
237
+ },
238
+ children: [
239
+ /*#__PURE__*/ _jsx(IconButton, {
240
+ onClick: ()=>changeAnnotationOrder(idx, 'up'),
241
+ disabled: idx === 0,
242
+ children: /*#__PURE__*/ _jsx(ArrowUp, {})
243
+ }),
244
+ /*#__PURE__*/ _jsx(IconButton, {
245
+ onClick: ()=>changeAnnotationOrder(idx, 'down'),
246
+ disabled: idx === annotationSpecs.length - 1,
247
+ children: /*#__PURE__*/ _jsx(ArrowDown, {})
248
+ }),
249
+ /*#__PURE__*/ _jsx(IconButton, {
250
+ onClick: ()=>editAnnotation(idx),
251
+ children: /*#__PURE__*/ _jsx(PencilIcon, {})
252
+ }),
253
+ /*#__PURE__*/ _jsx(IconButton, {
254
+ onClick: ()=>removeAnnotation(idx),
255
+ children: /*#__PURE__*/ _jsx(TrashIcon, {})
256
+ })
257
+ ]
258
+ })
259
+ ]
260
+ }, v.display.name))
261
+ })
262
+ ]
263
+ })
264
+ }),
265
+ /*#__PURE__*/ _jsx(Box, {
266
+ display: "flex",
267
+ children: /*#__PURE__*/ _jsx(Button, {
268
+ variant: "contained",
269
+ startIcon: /*#__PURE__*/ _jsx(AddIcon, {}),
270
+ sx: {
271
+ marginLeft: 'auto'
272
+ },
273
+ onClick: addAnnotation,
274
+ children: "Add Annotation"
275
+ })
276
+ })
277
+ ]
278
+ })
279
+ })
280
+ })
281
+ ]
282
+ })
283
+ });
284
+ }
285
+ const TableCell = styled(MuiTableCell)(({ theme })=>({
286
+ borderBottom: `solid 1px ${theme.palette.divider}`
287
+ }));
288
+
289
+ //# sourceMappingURL=AnnotationsEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Annotations/AnnotationsEditor.tsx"],"sourcesContent":["// Copyright 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} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { AnnotationSpec, Definition, UnknownSpec } from '@perses-dev/spec';\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';\n\nimport { ValidationProvider, AnnotationEditorForm } from '@perses-dev/plugin-system';\nimport { Action } from '@perses-dev/components';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nfunction validateAnnotationSpecs(annotationSpecs: AnnotationSpec[]): { isValid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n const annotationNames: string[] = [];\n\n for (const annotationSpec of annotationSpecs) {\n if (annotationNames.includes(annotationSpec.display.name)) {\n errors.push(`Duplicate annotation name: ${annotationSpec.display.name}`);\n } else {\n annotationNames.push(annotationSpec.display.name);\n }\n }\n\n return {\n errors: errors,\n isValid: errors.length === 0,\n };\n}\n\nexport function AnnotationEditor(props: {\n annotationSpecs: AnnotationSpec[];\n onChange: (annotationSpecs: AnnotationSpec[]) => void;\n onCancel: () => void;\n}): ReactElement {\n const [annotationSpecs, setAnnotationSpecs] = useImmer(props.annotationSpecs);\n const [annotationEditIdx, setAnnotationEditIdx] = useState<number | null>(null);\n const [annotationFormAction, setAnnotationFormAction] = useState<Action>('update');\n\n const validation = useMemo(() => validateAnnotationSpecs(annotationSpecs), [annotationSpecs]);\n const currentEditingAnnotationSpec: AnnotationSpec | undefined =\n annotationEditIdx !== null ? annotationSpecs[annotationEditIdx] : undefined;\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n const handleCancel = (): void => {\n if (JSON.stringify(props.annotationSpecs) !== JSON.stringify(annotationSpecs)) {\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 removeAnnotation = (index: number): void => {\n setAnnotationSpecs((draft) => {\n draft.splice(index, 1);\n });\n };\n\n const addAnnotation = (): void => {\n setAnnotationFormAction('create');\n setAnnotationSpecs((draft) => {\n draft.push({\n display: { name: 'NewAnnotation' },\n plugin: {} as Definition<UnknownSpec>,\n });\n });\n setAnnotationEditIdx(annotationSpecs.length);\n };\n\n const editAnnotation = (index: number): void => {\n setAnnotationFormAction('update');\n setAnnotationEditIdx(index);\n };\n\n const toggleAnnotationVisibility = (index: number, visible: boolean): void => {\n setAnnotationSpecs((draft) => {\n const v = draft[index];\n if (!v) {\n return;\n }\n v.display.hidden = !visible;\n });\n };\n\n const changeAnnotationOrder = (index: number, direction: 'up' | 'down'): void => {\n const step = direction === 'up' ? -1 : 1;\n\n setAnnotationSpecs((draft) => {\n const current = draft[index];\n const adjacent = draft[index + step];\n\n if (!current || !adjacent) {\n return;\n }\n\n draft[index + step] = current;\n draft[index] = adjacent;\n });\n };\n\n return (\n <>\n {annotationEditIdx !== null && currentEditingAnnotationSpec ? (\n <ValidationProvider>\n <AnnotationEditorForm\n initialAnnotationSpec={currentEditingAnnotationSpec}\n action={annotationFormAction}\n isDraft={true}\n onActionChange={setAnnotationFormAction}\n onSave={(definition: AnnotationSpec) => {\n setAnnotationSpecs((draft) => {\n draft[annotationEditIdx] = definition;\n setAnnotationEditIdx(null);\n });\n }}\n onClose={() => {\n if (annotationFormAction === 'create') {\n removeAnnotation(annotationEditIdx);\n }\n setAnnotationEditIdx(null);\n }}\n />\n </ValidationProvider>\n ) : (\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 Annotations</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.annotationSpecs === annotationSpecs || !validation.isValid}\n variant=\"contained\"\n onClick={() => {\n props.onChange(annotationSpecs);\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 annotations\">\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 {annotationSpecs.map((v, idx) => (\n <TableRow key={v.display.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch\n checked={v.display?.hidden !== true}\n onChange={(e) => {\n toggleAnnotationVisibility(idx, e.target.checked);\n }}\n />\n </TableCell>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {v.display.name}\n </TableCell>\n <TableCell>{v.plugin.kind}</TableCell>\n <TableCell>{v.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => changeAnnotationOrder(idx, 'up')} disabled={idx === 0}>\n <ArrowUp />\n </IconButton>\n <IconButton\n onClick={() => changeAnnotationOrder(idx, 'down')}\n disabled={idx === annotationSpecs.length - 1}\n >\n <ArrowDown />\n </IconButton>\n <IconButton onClick={() => editAnnotation(idx)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeAnnotation(idx)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addAnnotation}\n >\n Add Annotation\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n\nconst TableCell = styled(MuiTableCell)(({ theme }) => ({\n borderBottom: `solid 1px ${theme.palette.divider}`,\n}));\n"],"names":["useState","useMemo","Button","Stack","Box","TableContainer","TableBody","TableRow","TableCell","MuiTableCell","Table","TableHead","Switch","Typography","IconButton","Alert","styled","AddIcon","useImmer","PencilIcon","TrashIcon","ArrowUp","ArrowDown","ValidationProvider","AnnotationEditorForm","useDiscardChangesConfirmationDialog","validateAnnotationSpecs","annotationSpecs","errors","annotationNames","annotationSpec","includes","display","name","push","isValid","length","AnnotationEditor","props","setAnnotationSpecs","annotationEditIdx","setAnnotationEditIdx","annotationFormAction","setAnnotationFormAction","validation","currentEditingAnnotationSpec","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeAnnotation","index","draft","splice","addAnnotation","plugin","editAnnotation","toggleAnnotationVisibility","visible","v","hidden","changeAnnotationOrder","direction","step","current","adjacent","initialAnnotationSpec","action","isDraft","onActionChange","onSave","definition","onClose","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","marginLeft","disabled","onClick","onChange","color","overflowY","map","error","severity","minWidth","aria-label","align","idx","component","scope","checked","e","target","fontWeight","kind","whiteSpace","startIcon"],"mappings":";AAAA,+BAA+B;AAC/B,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,QACD,gBAAgB;AACvB,OAAOC,aAAa,uBAAuB;AAE3C,SA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ReactElement } from 'react';
2
+ import { ButtonProps } from '@mui/material';
3
+ export interface EditAnnotationsButtonProps extends Pick<ButtonProps, 'fullWidth'> {
4
+ /**
5
+ * The variant to use to display the button.
6
+ */
7
+ variant?: 'text' | 'outlined';
8
+ /**
9
+ * The color to use to display the button.
10
+ */
11
+ color?: 'primary' | 'secondary';
12
+ /**
13
+ * The label used inside the button.
14
+ */
15
+ label?: string;
16
+ }
17
+ export declare function EditAnnotationsButton({ variant, label, color, fullWidth, }: EditAnnotationsButtonProps): ReactElement;
18
+ //# sourceMappingURL=EditAnnotationsButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditAnnotationsButton.d.ts","sourceRoot":"","sources":["../../../src/components/Annotations/EditAnnotationsButton.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAU,WAAW,EAAE,MAAM,eAAe,CAAC;AAQpD,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC;IAChF;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAEhC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,qBAAqB,CAAC,EACpC,OAAgB,EAChB,KAAqB,EACrB,KAAiB,EACjB,SAAS,GACV,EAAE,0BAA0B,GAAG,YAAY,CA6C3C"}
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // Copyright The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { useState } from 'react';
15
+ import { Button } from '@mui/material';
16
+ import PencilIcon from 'mdi-material-ui/PencilOutline';
17
+ import { Drawer, InfoTooltip } from '@perses-dev/components';
18
+ import { TOOLTIP_TEXT, editButtonStyle } from '../../constants';
19
+ import { useAnnotationActions, useAnnotationSpecs } from '../../context';
20
+ import { AnnotationEditor } from './AnnotationsEditor';
21
+ export function EditAnnotationsButton({ variant = 'text', label = 'Annotations', color = 'primary', fullWidth }) {
22
+ const [isAnnotationEditorOpen, setIsAnnotationEditorOpen] = useState(false);
23
+ const annotationSpecs = useAnnotationSpecs();
24
+ const { setAnnotationSpecs } = useAnnotationActions();
25
+ const openAnnotationEditor = ()=>{
26
+ setIsAnnotationEditorOpen(true);
27
+ };
28
+ const closeAnnotationEditor = ()=>{
29
+ setIsAnnotationEditorOpen(false);
30
+ };
31
+ return /*#__PURE__*/ _jsxs(_Fragment, {
32
+ children: [
33
+ /*#__PURE__*/ _jsx(InfoTooltip, {
34
+ description: TOOLTIP_TEXT.editAnnotations,
35
+ children: /*#__PURE__*/ _jsx(Button, {
36
+ startIcon: /*#__PURE__*/ _jsx(PencilIcon, {}),
37
+ onClick: openAnnotationEditor,
38
+ "aria-label": TOOLTIP_TEXT.editAnnotations,
39
+ variant: variant,
40
+ color: color,
41
+ fullWidth: fullWidth,
42
+ sx: editButtonStyle,
43
+ children: label
44
+ })
45
+ }),
46
+ /*#__PURE__*/ _jsx(Drawer, {
47
+ isOpen: isAnnotationEditorOpen,
48
+ onClose: closeAnnotationEditor,
49
+ slotProps: {
50
+ paper: {
51
+ sx: {
52
+ width: '50%'
53
+ }
54
+ }
55
+ },
56
+ "data-testid": "annotation-editor",
57
+ children: /*#__PURE__*/ _jsx(AnnotationEditor, {
58
+ annotationSpecs: annotationSpecs,
59
+ onCancel: closeAnnotationEditor,
60
+ onChange: (annotations)=>{
61
+ setAnnotationSpecs(annotations);
62
+ setIsAnnotationEditorOpen(false);
63
+ }
64
+ })
65
+ })
66
+ ]
67
+ });
68
+ }
69
+
70
+ //# sourceMappingURL=EditAnnotationsButton.js.map