@perses-dev/dashboards 0.54.0-beta.5 → 0.54.0-beta.7
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/Annotations/AnnotationsEditor.js +302 -0
- package/dist/cjs/components/Annotations/EditAnnotationsButton.js +83 -0
- package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -1
- package/dist/cjs/components/Variables/VariableEditor.js +2 -2
- package/dist/cjs/constants/user-interface-text.js +1 -0
- package/dist/cjs/context/AnnotationProvider/AnnotationHydrationWrapper.js +50 -0
- package/dist/cjs/context/AnnotationProvider/AnnotationProvider.js +145 -0
- package/dist/cjs/{model/DashboardResource.js → context/AnnotationProvider/index.js} +14 -0
- package/dist/cjs/context/DatasourceStoreProvider.js +34 -4
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/context/useDashboard.js +8 -0
- package/dist/cjs/model/index.js +0 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +29 -25
- package/dist/components/Annotations/AnnotationsEditor.d.ts +8 -0
- package/dist/components/Annotations/AnnotationsEditor.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationsEditor.js +289 -0
- package/dist/components/Annotations/AnnotationsEditor.js.map +1 -0
- package/dist/components/Annotations/EditAnnotationsButton.d.ts +18 -0
- package/dist/components/Annotations/EditAnnotationsButton.d.ts.map +1 -0
- package/dist/components/Annotations/EditAnnotationsButton.js +70 -0
- package/dist/components/Annotations/EditAnnotationsButton.js.map +1 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +3 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
- package/dist/components/DownloadButton/serializeDashboard.d.ts +1 -1
- package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
- package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- 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 +2 -2
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/constants/user-interface-text.d.ts +1 -0
- package/dist/constants/user-interface-text.d.ts.map +1 -1
- package/dist/constants/user-interface-text.js +1 -0
- package/dist/constants/user-interface-text.js.map +1 -1
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts +7 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js +48 -0
- package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.d.ts +40 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.d.ts.map +1 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.js +114 -0
- package/dist/context/AnnotationProvider/AnnotationProvider.js.map +1 -0
- package/dist/context/AnnotationProvider/index.d.ts +2 -0
- package/dist/context/AnnotationProvider/index.d.ts.map +1 -0
- package/dist/{model/DashboardResource.js → context/AnnotationProvider/index.js} +2 -2
- package/dist/context/AnnotationProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +1 -2
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +1 -2
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +35 -5
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +8 -0
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +0 -1
- package/dist/model/index.js.map +1 -1
- package/dist/test/dashboard-provider.d.ts +1 -1
- package/dist/test/dashboard-provider.d.ts.map +1 -1
- package/dist/test/dashboard-provider.js.map +1 -1
- package/dist/test/testDashboard.d.ts +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +2 -1
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +30 -26
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +5 -4
- package/dist/model/DashboardResource.d.ts +0 -9
- package/dist/model/DashboardResource.d.ts.map +0 -1
- package/dist/model/DashboardResource.js.map +0 -1
|
@@ -27,15 +27,24 @@ function DatasourceStoreProvider(props) {
|
|
|
27
27
|
const { projectName, datasourceApi, onCreate, children } = props;
|
|
28
28
|
const [dashboardResource, setDashboardResource] = (0, _react.useState)(props.dashboardResource);
|
|
29
29
|
const [savedDatasources, setSavedDatasources] = (0, _react.useState)(props.savedDatasources ?? {});
|
|
30
|
+
// Cache for synchronous datasource spec access
|
|
31
|
+
const datasourceSpecCache = (0, _react.useRef)(new Map());
|
|
30
32
|
const project = projectName ?? dashboardResource?.metadata.project;
|
|
31
33
|
const { getPlugin, listPluginMetadata } = (0, _pluginsystem.usePluginRegistry)();
|
|
34
|
+
// Helper to create cache key from DatasourceSelector
|
|
35
|
+
const createCacheKey = (0, _react.useCallback)((selector)=>{
|
|
36
|
+
const name = selector.name === undefined ? '__undefined__' : selector.name;
|
|
37
|
+
return `${selector.kind}:${name}:${project ?? 'global'}`;
|
|
38
|
+
}, [
|
|
39
|
+
project
|
|
40
|
+
]);
|
|
32
41
|
const findDatasource = (0, _pluginsystem.useEvent)(async (selector)=>{
|
|
33
42
|
// Try to find it in dashboard spec
|
|
34
43
|
if (dashboardResource) {
|
|
35
44
|
const { datasources } = dashboardResource.spec;
|
|
36
45
|
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
37
46
|
if (dashboardDatasource !== undefined) {
|
|
38
|
-
|
|
47
|
+
const result = {
|
|
39
48
|
spec: dashboardDatasource.spec,
|
|
40
49
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
41
50
|
project: dashboardResource.metadata.project,
|
|
@@ -43,30 +52,42 @@ function DatasourceStoreProvider(props) {
|
|
|
43
52
|
name: dashboardDatasource.name
|
|
44
53
|
})
|
|
45
54
|
};
|
|
55
|
+
// Cache the spec for synchronous access
|
|
56
|
+
const cacheKey = createCacheKey(selector);
|
|
57
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
58
|
+
return result;
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
if (project) {
|
|
49
62
|
// Try to find it at the project level as a Datasource resource
|
|
50
63
|
const datasource = await datasourceApi.getDatasource(String(project), selector);
|
|
51
64
|
if (datasource !== undefined) {
|
|
52
|
-
|
|
65
|
+
const result = {
|
|
53
66
|
spec: datasource.spec,
|
|
54
67
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
55
68
|
project: datasource.metadata.project,
|
|
56
69
|
name: datasource.metadata.name
|
|
57
70
|
})
|
|
58
71
|
};
|
|
72
|
+
// Cache the spec for synchronous access
|
|
73
|
+
const cacheKey = createCacheKey(selector);
|
|
74
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
75
|
+
return result;
|
|
59
76
|
}
|
|
60
77
|
}
|
|
61
78
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
62
79
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
63
80
|
if (globalDatasource !== undefined) {
|
|
64
|
-
|
|
81
|
+
const result = {
|
|
65
82
|
spec: globalDatasource.spec,
|
|
66
83
|
proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
|
|
67
84
|
name: globalDatasource.metadata.name
|
|
68
85
|
})
|
|
69
86
|
};
|
|
87
|
+
// Cache the spec for synchronous access
|
|
88
|
+
const cacheKey = createCacheKey(selector);
|
|
89
|
+
datasourceSpecCache.current.set(cacheKey, result.spec);
|
|
90
|
+
return result;
|
|
70
91
|
}
|
|
71
92
|
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
72
93
|
});
|
|
@@ -161,6 +182,13 @@ function DatasourceStoreProvider(props) {
|
|
|
161
182
|
}, [
|
|
162
183
|
savedDatasources
|
|
163
184
|
]);
|
|
185
|
+
// Gets a cached datasource spec synchronously if available
|
|
186
|
+
const getDatasourceSpecSync = (0, _react.useCallback)((selector)=>{
|
|
187
|
+
const cacheKey = createCacheKey(selector);
|
|
188
|
+
return datasourceSpecCache.current.get(cacheKey);
|
|
189
|
+
}, [
|
|
190
|
+
createCacheKey
|
|
191
|
+
]);
|
|
164
192
|
const setLocalDatasources = (0, _react.useCallback)((datasources)=>{
|
|
165
193
|
if (dashboardResource) {
|
|
166
194
|
setDashboardResource({
|
|
@@ -177,6 +205,7 @@ function DatasourceStoreProvider(props) {
|
|
|
177
205
|
const ctxValue = (0, _react.useMemo)(()=>({
|
|
178
206
|
getDatasource,
|
|
179
207
|
getDatasourceClient,
|
|
208
|
+
getDatasourceSpecSync,
|
|
180
209
|
getLocalDatasources,
|
|
181
210
|
setLocalDatasources,
|
|
182
211
|
setSavedDatasources,
|
|
@@ -185,6 +214,7 @@ function DatasourceStoreProvider(props) {
|
|
|
185
214
|
}), [
|
|
186
215
|
getDatasource,
|
|
187
216
|
getDatasourceClient,
|
|
217
|
+
getDatasourceSpecSync,
|
|
188
218
|
getLocalDatasources,
|
|
189
219
|
setLocalDatasources,
|
|
190
220
|
listDatasourceSelectItems,
|
|
@@ -266,7 +296,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
266
296
|
});
|
|
267
297
|
usedNames.add(selectorName);
|
|
268
298
|
const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
|
|
269
|
-
if (results[0] &&
|
|
299
|
+
if (results[0] && isExplicitDefault) {
|
|
270
300
|
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
271
301
|
results[0].items = [
|
|
272
302
|
{
|
|
@@ -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 {
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_export_star(require("./DashboardResource"), exports);
|
|
18
17
|
_export_star(require("./PanelGroupDefinition"), exports);
|
|
19
18
|
_export_star(require("./VariableDefinition"), exports);
|
|
20
19
|
function _export_star(from, to) {
|
|
@@ -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)(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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/client';\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,SAASC,QAAQ,QAAQ,YAAY;AACrC,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,eAAe,2BAA2B;AACjD,OAAOC,aAAa,0BAA0B;AAC9C,OAAOC,eAAe,4BAA4B;AAElD,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,4BAA4B;AAErF,SAASC,mCAAmC,QAAQ,gBAAgB;AAEpE,SAASC,wBAAwBC,eAAiC;IAChE,MAAMC,SAAmB,EAAE;IAE3B,MAAMC,kBAA4B,EAAE;IAEpC,KAAK,MAAMC,kBAAkBH,gBAAiB;QAC5C,IAAIE,gBAAgBE,QAAQ,CAACD,eAAeE,OAAO,CAACC,IAAI,GAAG;YACzDL,OAAOM,IAAI,CAAC,CAAC,2BAA2B,EAAEJ,eAAeE,OAAO,CAACC,IAAI,EAAE;QACzE,OAAO;YACLJ,gBAAgBK,IAAI,CAACJ,eAAeE,O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kFAC7E,cAAA,KAAC9E;;kFAEH,KAACP;wEACC2E,SAAS,IAAMvB,sBAAsBiC,KAAK;wEAC1CX,UAAUW,QAAQxE,gBAAgBS,MAAM,GAAG;kFAE3C,cAAA,KAACd;;kFAEH,KAACR;wEAAW2E,SAAS,IAAM5B,eAAesC;kFACxC,cAAA,KAAChF;;kFAEH,KAACL;wEAAW2E,SAAS,IAAMlC,iBAAiB4C;kFAC1C,cAAA,KAAC/E;;;;;uDA5BQ4C,EAAEhC,OAAO,CAACC,IAAI;;;;;8CAoCrC,KAAC7B;oCAAI4B,SAAQ;8CACX,cAAA,KAAC9B;wCACCoF,SAAQ;wCACRsB,yBAAW,KAAC3F;wCACZ6D,IAAI;4CAAES,YAAY;wCAAO;wCACzBE,SAAS9B;kDACV;;;;;;;;;;AAWnB;AAEA,MAAMnD,YAAYQ,OAAOP,cAAc,CAAC,EAAEwE,KAAK,EAAE,GAAM,CAAA;QACrDE,cAAc,CAAC,UAAU,EAAEF,MAAMG,OAAO,CAACC,OAAO,EAAE;IACpD,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { 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"}
|