@perses-dev/dashboards 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +49 -32
  2. package/dist/cjs/components/GridLayout/GridContainer.js +2 -2
  3. package/dist/cjs/components/GridLayout/GridTitle.js +1 -1
  4. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +2 -1
  5. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +28 -5
  6. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +11 -5
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +17 -2
  8. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +5 -4
  9. package/dist/cjs/components/Variables/VariableList.js +3 -0
  10. package/dist/cjs/components/Variables/variable-model.js +38 -6
  11. package/dist/cjs/components/Variables/variable-model.test.js +106 -0
  12. package/dist/cjs/context/TemplateVariableProvider/query-params.js +3 -1
  13. package/dist/cjs/context/index.js +0 -1
  14. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  15. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +6 -4
  16. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +4 -2
  17. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  18. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  19. package/dist/components/DashboardToolbar/DashboardToolbar.js +50 -33
  20. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  21. package/dist/components/GridLayout/GridContainer.js +2 -2
  22. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  23. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  24. package/dist/components/GridLayout/GridTitle.js +1 -1
  25. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  26. package/dist/components/PanelDrawer/PanelDrawer.js +2 -1
  27. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  28. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  29. package/dist/components/TimeRangeControls/TimeRangeControls.js +24 -7
  30. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  31. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +11 -5
  32. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  33. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  34. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +17 -2
  35. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  36. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -0
  37. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  38. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +5 -4
  39. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  40. package/dist/components/Variables/VariableList.d.ts +2 -0
  41. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  42. package/dist/components/Variables/VariableList.js +3 -0
  43. package/dist/components/Variables/VariableList.js.map +1 -1
  44. package/dist/components/Variables/variable-model.d.ts +3 -2
  45. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  46. package/dist/components/Variables/variable-model.js +38 -7
  47. package/dist/components/Variables/variable-model.js.map +1 -1
  48. package/dist/components/Variables/variable-model.test.d.ts +2 -0
  49. package/dist/components/Variables/variable-model.test.d.ts.map +1 -0
  50. package/dist/components/Variables/variable-model.test.js +104 -0
  51. package/dist/components/Variables/variable-model.test.js.map +1 -0
  52. package/dist/context/TemplateVariableProvider/query-params.js +3 -1
  53. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -1
  54. package/dist/context/index.d.ts +0 -1
  55. package/dist/context/index.d.ts.map +1 -1
  56. package/dist/context/index.js +0 -1
  57. package/dist/context/index.js.map +1 -1
  58. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  59. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  60. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  61. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  62. package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
  63. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  64. package/dist/views/ViewDashboard/ViewDashboard.js +5 -3
  65. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  66. package/dist/views/ViewDashboard/tests/panelGroups.test.js +4 -2
  67. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  68. package/package.json +5 -5
  69. package/dist/cjs/context/TimeRangeProvider/TimeRangeProvider.js +0 -91
  70. package/dist/cjs/context/TimeRangeProvider/index.js +0 -29
  71. package/dist/cjs/context/TimeRangeProvider/query-params.js +0 -157
  72. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts +0 -19
  73. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts.map +0 -1
  74. package/dist/context/TimeRangeProvider/TimeRangeProvider.js +0 -44
  75. package/dist/context/TimeRangeProvider/TimeRangeProvider.js.map +0 -1
  76. package/dist/context/TimeRangeProvider/index.d.ts +0 -3
  77. package/dist/context/TimeRangeProvider/index.d.ts.map +0 -1
  78. package/dist/context/TimeRangeProvider/index.js +0 -16
  79. package/dist/context/TimeRangeProvider/index.js.map +0 -1
  80. package/dist/context/TimeRangeProvider/query-params.d.ts +0 -25
  81. package/dist/context/TimeRangeProvider/query-params.d.ts.map +0 -1
  82. package/dist/context/TimeRangeProvider/query-params.js +0 -149
  83. package/dist/context/TimeRangeProvider/query-params.js.map +0 -1
@@ -34,7 +34,7 @@ function _interopRequireDefault(obj) {
34
34
  };
35
35
  }
36
36
  const DashboardToolbar = (props)=>{
37
- const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , onEditButtonClick , onCancelButtonClick } = props;
37
+ const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , isReadonly , onEditButtonClick , onCancelButtonClick , } = props;
38
38
  const { isEditMode , setEditMode } = (0, _context.useEditMode)();
39
39
  const { openAddPanelGroup , openAddPanel } = (0, _context.useDashboardActions)();
40
40
  const isLaptopSize = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.up('sm'));
@@ -47,55 +47,68 @@ const DashboardToolbar = (props)=>{
47
47
  };
48
48
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
49
49
  children: isEditMode ? /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
50
- spacing: 2,
50
+ spacing: 1,
51
51
  children: [
52
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
53
+ p: 2,
54
+ display: "flex",
53
55
  sx: {
54
- backgroundColor: (theme)=>theme.palette.primary.light + '20'
56
+ backgroundColor: (theme)=>theme.palette.primary.main + '30'
55
57
  },
56
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
57
- padding: 2,
58
- display: "flex",
59
- children: [
60
- dashboardTitle,
61
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
62
- direction: "row",
63
- spacing: 1,
64
- marginLeft: "auto",
65
- children: [
66
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
67
- variant: "contained",
68
- onClick: onSave,
69
- children: "Save"
70
- }),
71
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
72
- variant: "outlined",
73
- onClick: onCancelButtonClick,
74
- children: "Cancel"
75
- })
76
- ]
77
- })
78
- ]
79
- })
58
+ children: [
59
+ dashboardTitle,
60
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
61
+ direction: "row",
62
+ spacing: 1,
63
+ marginLeft: "auto",
64
+ children: [
65
+ isReadonly && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Alert, {
66
+ severity: 'warning',
67
+ sx: {
68
+ backgroundColor: 'transparent',
69
+ padding: 0
70
+ },
71
+ children: "Dashboard managed via code only. Download JSON and commit changes to save."
72
+ }),
73
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
74
+ variant: "contained",
75
+ onClick: onSave,
76
+ disabled: isReadonly,
77
+ children: "Save"
78
+ }),
79
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
80
+ variant: "outlined",
81
+ onClick: onCancelButtonClick,
82
+ children: "Cancel"
83
+ })
84
+ ]
85
+ })
86
+ ]
80
87
  }),
81
88
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
82
89
  sx: {
83
90
  display: 'flex',
84
91
  width: '100%',
85
92
  alignItems: 'flex-start',
86
- padding: (theme)=>theme.spacing(2)
93
+ padding: (theme)=>theme.spacing(0, 2, 2, 2)
87
94
  },
88
95
  children: [
89
96
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
90
97
  FallbackComponent: _components.ErrorAlert,
91
98
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
92
- initialVariableIsSticky: initialVariableIsSticky
99
+ initialVariableIsSticky: initialVariableIsSticky,
100
+ sx: {
101
+ backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper
102
+ }
93
103
  })
94
104
  }),
95
105
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
96
106
  direction: "row",
97
107
  spacing: 1,
98
108
  marginLeft: "auto",
109
+ sx: {
110
+ whiteSpace: 'nowrap'
111
+ },
99
112
  children: [
100
113
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
101
114
  startIcon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plusBoxOutline.default, {}),
@@ -107,7 +120,8 @@ const DashboardToolbar = (props)=>{
107
120
  onClick: openAddPanel,
108
121
  children: "Add Panel"
109
122
  }),
110
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
123
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {}),
124
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_downloadButton.DownloadButton, {})
111
125
  ]
112
126
  })
113
127
  ]
@@ -149,7 +163,10 @@ const DashboardToolbar = (props)=>{
149
163
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
150
164
  FallbackComponent: _components.ErrorAlert,
151
165
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
152
- initialVariableIsSticky: initialVariableIsSticky
166
+ initialVariableIsSticky: initialVariableIsSticky,
167
+ sx: {
168
+ backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper
169
+ }
153
170
  })
154
171
  })
155
172
  })
@@ -98,8 +98,8 @@ function GridContainer(props) {
98
98
  bottom: '3px',
99
99
  width: '5px',
100
100
  height: '5px',
101
- borderRight: '2px solid rgba(0, 0, 0, 0.4)',
102
- borderBottom: '2px solid rgba(0, 0, 0, 0.4)'
101
+ borderRight: `2px solid ${theme.palette.text.secondary}`,
102
+ borderBottom: `2px solid ${theme.palette.text.secondary}`
103
103
  },
104
104
  '& .react-resizable-hide > .react-resizable-handle': {
105
105
  display: 'none'
@@ -51,7 +51,7 @@ function GridTitle(props) {
51
51
  justifyContent: 'start',
52
52
  alignItems: 'center',
53
53
  padding: (theme)=>theme.spacing(1),
54
- backgroundColor: (theme)=>theme.palette.background.default
54
+ backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.paper : palette.background.default
55
55
  },
56
56
  children: collapse ? /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
57
57
  children: [
@@ -57,7 +57,7 @@ const PanelDrawer = ()=>{
57
57
  display: 'flex',
58
58
  alignItems: 'center',
59
59
  padding: (theme)=>theme.spacing(1, 2),
60
- borderBottom: (theme)=>`1px solid ${theme.palette.grey[100]}`
60
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
61
61
  },
62
62
  children: [
63
63
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
@@ -79,6 +79,7 @@ const PanelDrawer = ()=>{
79
79
  children: panelEditor.mode === 'Add' ? 'Add' : 'Apply'
80
80
  }),
81
81
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
82
+ color: "secondary",
82
83
  variant: "outlined",
83
84
  onClick: handleClose,
84
85
  children: "Cancel"
@@ -25,9 +25,17 @@ _export(exports, {
25
25
  TimeRangeControls: ()=>TimeRangeControls
26
26
  });
27
27
  const _jsxRuntime = require("react/jsx-runtime");
28
+ const _refresh = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Refresh"));
29
+ const _material = require("@mui/material");
28
30
  const _components = require("@perses-dev/components");
31
+ const _pluginSystem = require("@perses-dev/plugin-system");
29
32
  const _core = require("@perses-dev/core");
30
33
  const _context = require("../../context");
34
+ function _interopRequireDefault(obj) {
35
+ return obj && obj.__esModule ? obj : {
36
+ default: obj
37
+ };
38
+ }
31
39
  const TIME_OPTIONS = [
32
40
  {
33
41
  value: {
@@ -85,7 +93,7 @@ const TIME_OPTIONS = [
85
93
  }
86
94
  ];
87
95
  function TimeRangeControls() {
88
- const { timeRange , setTimeRange } = (0, _context.useDashboardTimeRange)();
96
+ const { timeRange , setTimeRange , refresh } = (0, _pluginSystem.useTimeRange)();
89
97
  const defaultTimeRange = (0, _context.useDefaultTimeRange)();
90
98
  // add time shortcut if one does not match duration from dashboard JSON
91
99
  if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === defaultTimeRange.pastDuration)) {
@@ -98,9 +106,24 @@ function TimeRangeControls() {
98
106
  });
99
107
  }
100
108
  }
101
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DateTimeRangePicker, {
102
- timeOptions: TIME_OPTIONS,
103
- value: timeRange,
104
- onChange: setTimeRange
109
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
110
+ children: [
111
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DateTimeRangePicker, {
112
+ timeOptions: TIME_OPTIONS,
113
+ value: timeRange,
114
+ onChange: setTimeRange
115
+ }),
116
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(RefreshIconButton, {
117
+ "aria-label": "Refresh Dashboard",
118
+ onClick: refresh,
119
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_refresh.default, {})
120
+ })
121
+ ]
105
122
  });
106
123
  }
124
+ const RefreshIconButton = (0, _material.styled)(_material.IconButton)(({ theme })=>({
125
+ border: `1px solid ${theme.palette.grey[300]}`,
126
+ borderRadius: theme.shape.borderRadius,
127
+ padding: theme.spacing(0.5),
128
+ color: theme.palette.grey[900]
129
+ }));
@@ -19,6 +19,7 @@ const _reactRouter = require("react-router");
19
19
  const _history = require("history");
20
20
  const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
21
21
  const _react = require("@testing-library/react");
22
+ const _pluginSystem = require("@perses-dev/plugin-system");
22
23
  const _test = require("../../test");
23
24
  const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
24
25
  const _context = require("../../context");
@@ -30,6 +31,7 @@ function _interopRequireDefault(obj) {
30
31
  }
31
32
  const history = (0, _history.createMemoryHistory)({
32
33
  initialEntries: [
34
+ (0, _reactRouter.generatePath)('/home'),
33
35
  (0, _reactRouter.generatePath)('/dashboards/:id', {
34
36
  id: 'test'
35
37
  })
@@ -48,7 +50,7 @@ describe('TimeRangeControls', ()=>{
48
50
  const renderTimeRangeControls = (testURLParams)=>{
49
51
  (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
50
52
  initialState: initialState,
51
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
53
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
52
54
  initialTimeRange: testDefaultTimeRange,
53
55
  enabledURLParams: testURLParams,
54
56
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
@@ -58,7 +60,9 @@ describe('TimeRangeControls', ()=>{
58
60
  it('should default to dashboard duration and update selected time option when clicked', async ()=>{
59
61
  renderTimeRangeControls(false);
60
62
  expect(_react.screen.getByText('Last 30 minutes')).toBeInTheDocument();
61
- const dateButton = _react.screen.getByRole('button');
63
+ const dateButton = _react.screen.getByRole('button', {
64
+ name: /last/i
65
+ });
62
66
  _userEvent.default.click(dateButton);
63
67
  const firstSelected = _react.screen.getByRole('option', {
64
68
  name: 'Last 5 minutes'
@@ -68,7 +72,9 @@ describe('TimeRangeControls', ()=>{
68
72
  });
69
73
  it('should update URL params with correct time range values', ()=>{
70
74
  renderTimeRangeControls(true);
71
- const dateButton = _react.screen.getByRole('button');
75
+ const dateButton = _react.screen.getByRole('button', {
76
+ name: /last/i
77
+ });
72
78
  _userEvent.default.click(dateButton);
73
79
  const firstSelected = _react.screen.getByRole('option', {
74
80
  name: 'Last 5 minutes'
@@ -79,11 +85,11 @@ describe('TimeRangeControls', ()=>{
79
85
  const secondSelected = _react.screen.getByText('Last 12 hours');
80
86
  _userEvent.default.click(secondSelected);
81
87
  expect(history.location.search).toEqual('?start=12h');
82
- // back button should return to first option selected
88
+ // back button should return to previous page selected
83
89
  (0, _react.act)(()=>{
84
90
  history.back();
85
91
  });
86
- expect(history.location.search).toEqual('?start=5m');
92
+ expect(history.location.pathname).toEqual('/home');
87
93
  });
88
94
  // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
89
95
  });
@@ -334,6 +334,18 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
334
334
  item: true,
335
335
  xs: 6,
336
336
  children: [
337
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
338
+ sx: {
339
+ mb: 1
340
+ },
341
+ label: "Capturing Regexp",
342
+ value: state.listVariableFields.capturing_regexp,
343
+ onChange: (e)=>{
344
+ setState((draft)=>{
345
+ draft.listVariableFields.capturing_regexp = e.target.value;
346
+ });
347
+ }
348
+ }),
337
349
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
338
350
  onClickAway: ()=>refreshPreview(),
339
351
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {})
@@ -351,13 +363,16 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
351
363
  })
352
364
  ]
353
365
  }),
354
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
366
+ state.listVariableFields.plugin.kind && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
355
367
  item: true,
356
368
  xs: 12,
357
369
  children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.ErrorBoundary, {
358
370
  FallbackComponent: ()=>/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
359
- children: "Error"
371
+ children: "Error previewing values"
360
372
  }),
373
+ resetKeys: [
374
+ previewSpec
375
+ ],
361
376
  children: [
362
377
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
363
378
  direction: 'row',
@@ -33,6 +33,7 @@ function getInitialState(initialVariableDefinition) {
33
33
  const listVariableFields = {
34
34
  allowMultiple: false,
35
35
  allowAll: false,
36
+ capturing_regexp: undefined,
36
37
  plugin: {
37
38
  kind: '',
38
39
  spec: {}
@@ -43,6 +44,7 @@ function getInitialState(initialVariableDefinition) {
43
44
  listVariableFields.allowMultiple = (_allow_all_value = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value !== void 0 ? _allow_all_value : false;
44
45
  var _allow_all_value1;
45
46
  listVariableFields.allowAll = (_allow_all_value1 = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value1 !== void 0 ? _allow_all_value1 : false;
47
+ listVariableFields.capturing_regexp = initialVariableDefinition.spec.capturing_regexp;
46
48
  listVariableFields.plugin = initialVariableDefinition.spec.plugin;
47
49
  }
48
50
  return {
@@ -63,26 +65,25 @@ function getVariableDefinitionFromState(state) {
63
65
  }
64
66
  };
65
67
  if (kind === 'TextVariable') {
66
- const textVariableDefinition = {
68
+ return {
67
69
  kind,
68
70
  spec: {
69
71
  ...commonSpec,
70
72
  ...state.textVariableFields
71
73
  }
72
74
  };
73
- return textVariableDefinition;
74
75
  }
75
76
  if (kind === 'ListVariable') {
76
- const listVariableDefinition = {
77
+ return {
77
78
  kind,
78
79
  spec: {
79
80
  ...commonSpec,
80
81
  allow_multiple: state.listVariableFields.allowMultiple,
81
82
  allow_all_value: state.listVariableFields.allowAll,
83
+ capturing_regexp: state.listVariableFields.capturing_regexp,
82
84
  plugin: state.listVariableFields.plugin
83
85
  }
84
86
  };
85
- return listVariableDefinition;
86
87
  }
87
88
  throw new Error(`Unknown variable kind: ${kind}`);
88
89
  }
@@ -129,6 +129,9 @@ function TemplateVariableList(props) {
129
129
  color: 'inherit',
130
130
  position: isSticky ? 'fixed' : 'static',
131
131
  elevation: isSticky ? 4 : 0,
132
+ sx: {
133
+ ...props.sx
134
+ },
132
135
  children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
133
136
  display: 'flex',
134
137
  justifyContent: "space-between",
@@ -21,22 +21,49 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ filterVariableList: ()=>filterVariableList,
24
25
  useListVariablePluginValues: ()=>useListVariablePluginValues,
25
26
  getVariableValuesKey: ()=>getVariableValuesKey
26
27
  });
27
28
  const _pluginSystem = require("@perses-dev/plugin-system");
28
29
  const _reactQuery = require("@tanstack/react-query");
30
+ function filterVariableList(data, capturedRegexp) {
31
+ const result = [];
32
+ const filteredSet = new Set();
33
+ for (const variableValue of data){
34
+ const matches = variableValue.value.matchAll(capturedRegexp);
35
+ let concat = '';
36
+ for (const match of matches){
37
+ for(let i = 1; i < match.length; i++){
38
+ const m = match[i];
39
+ if (m !== undefined) {
40
+ concat = `${concat}${m}`;
41
+ }
42
+ }
43
+ }
44
+ if (concat !== '' && !filteredSet.has(concat)) {
45
+ // like that we are avoiding to have duplicating variable value
46
+ filteredSet.add(concat);
47
+ result.push({
48
+ label: variableValue.label,
49
+ value: concat
50
+ });
51
+ }
52
+ }
53
+ return result;
54
+ }
29
55
  function useListVariablePluginValues(definition) {
30
56
  const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
31
57
  const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
32
58
  const allVariables = (0, _pluginSystem.useTemplateVariableValues)();
33
- const { timeRange } = (0, _pluginSystem.useTimeRange)();
59
+ const { absoluteTimeRange: timeRange , refreshKey } = (0, _pluginSystem.useTimeRange)();
34
60
  const variablePluginCtx = {
35
61
  timeRange,
36
62
  datasourceStore,
37
63
  variables: allVariables
38
64
  };
39
65
  const spec = definition.spec.plugin.spec;
66
+ const capturingRegexp = definition.spec.capturing_regexp !== undefined ? new RegExp(definition.spec.capturing_regexp, 'g') : undefined;
40
67
  let dependsOnVariables;
41
68
  if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
42
69
  const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
@@ -51,23 +78,28 @@ function useListVariablePluginValues(definition) {
51
78
  });
52
79
  }
53
80
  const variablesValueKey = getVariableValuesKey(variables);
54
- const variablesOptionsQuery = (0, _reactQuery.useQuery)([
81
+ return (0, _reactQuery.useQuery)([
55
82
  name,
56
83
  definition,
57
84
  variablesValueKey,
58
- timeRange
85
+ timeRange,
86
+ refreshKey
59
87
  ], async ()=>{
60
88
  const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
61
89
  datasourceStore,
62
90
  variables,
63
91
  timeRange
64
92
  }));
65
- var ref;
66
- return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
93
+ if (resp === undefined) {
94
+ return [];
95
+ }
96
+ if (capturingRegexp === undefined) {
97
+ return resp.data;
98
+ }
99
+ return filterVariableList(resp.data, capturingRegexp);
67
100
  }, {
68
101
  enabled: !!variablePlugin || waitToLoad
69
102
  });
70
- return variablesOptionsQuery;
71
103
  }
72
104
  function getVariableValuesKey(v) {
73
105
  return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
@@ -0,0 +1,106 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _variableModel = require("./variable-model");
18
+ describe('filterVariableList', ()=>{
19
+ const testSuite = [
20
+ {
21
+ title: 'basic case',
22
+ capturing_regexp: /([^-]*)-host-([^-]*)/g,
23
+ originalValues: [
24
+ {
25
+ label: 'l1',
26
+ value: 'us1-host-ahdix'
27
+ },
28
+ {
29
+ label: 'l2',
30
+ value: 'us1-host-diua'
31
+ },
32
+ {
33
+ label: 'l3',
34
+ value: 'eu1-host-adf'
35
+ },
36
+ {
37
+ label: 'l4',
38
+ value: 'bar'
39
+ }
40
+ ],
41
+ result: [
42
+ {
43
+ label: 'l1',
44
+ value: 'us1ahdix'
45
+ },
46
+ {
47
+ label: 'l2',
48
+ value: 'us1diua'
49
+ },
50
+ {
51
+ label: 'l3',
52
+ value: 'eu1adf'
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ title: 'duplicate captured value',
58
+ capturing_regexp: /prometheus-(.+):\d+/g,
59
+ originalValues: [
60
+ {
61
+ label: 'l1',
62
+ value: 'prometheus-app:9090'
63
+ },
64
+ {
65
+ label: 'l2',
66
+ value: 'prometheus-app:9091'
67
+ },
68
+ {
69
+ label: 'l3',
70
+ value: 'prometheus-platform:9091'
71
+ },
72
+ {
73
+ label: 'l4',
74
+ value: 'prometheus-database:9091'
75
+ },
76
+ {
77
+ label: 'l5',
78
+ value: 'prometheus-perses:9091'
79
+ }
80
+ ],
81
+ result: [
82
+ {
83
+ label: 'l1',
84
+ value: 'app'
85
+ },
86
+ {
87
+ label: 'l3',
88
+ value: 'platform'
89
+ },
90
+ {
91
+ label: 'l4',
92
+ value: 'database'
93
+ },
94
+ {
95
+ label: 'l5',
96
+ value: 'perses'
97
+ }
98
+ ]
99
+ }
100
+ ];
101
+ testSuite.forEach(({ title , capturing_regexp , originalValues , result })=>{
102
+ it(title, ()=>{
103
+ expect((0, _variableModel.filterVariableList)(originalValues, capturing_regexp)).toEqual(result);
104
+ });
105
+ });
106
+ });
@@ -63,7 +63,9 @@ function useVariableQueryParams(defs) {
63
63
  const name = getURLQueryParamName(def.spec.name);
64
64
  config[name] = VariableValueParam;
65
65
  });
66
- return (0, _useQueryParams.useQueryParams)(config);
66
+ return (0, _useQueryParams.useQueryParams)(config, {
67
+ updateType: 'replaceIn'
68
+ });
67
69
  }
68
70
  function getInitalValuesFromQueryParameters(queryParamValues) {
69
71
  const values = {};
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _exportStar(require("./DashboardProvider"), exports);
18
18
  _exportStar(require("./DatasourceStoreProvider"), exports);
19
19
  _exportStar(require("./TemplateVariableProvider"), exports);
20
- _exportStar(require("./TimeRangeProvider"), exports);
21
20
  _exportStar(require("./useDashboard"), exports);
22
21
  function _exportStar(from, to) {
23
22
  Object.keys(from).forEach(function(k) {
@@ -25,7 +25,7 @@ const _components = require("@perses-dev/components");
25
25
  const _components1 = require("../../components");
26
26
  const _context = require("../../context");
27
27
  const DashboardApp = (props)=>{
28
- const { dashboardResource , dashboardTitleComponent , initialVariableIsSticky } = props;
28
+ const { dashboardResource , dashboardTitleComponent , initialVariableIsSticky , isReadonly } = props;
29
29
  const { setEditMode } = (0, _context.useEditMode)();
30
30
  const { dashboard , setDashboard } = (0, _context.useDashboard)();
31
31
  const [originalDashboard, setOriginalDashboard] = (0, _react.useState)(undefined);
@@ -67,6 +67,7 @@ const DashboardApp = (props)=>{
67
67
  dashboardName: dashboardResource.metadata.name,
68
68
  dashboardTitleComponent: dashboardTitleComponent,
69
69
  initialVariableIsSticky: initialVariableIsSticky,
70
+ isReadonly: isReadonly,
70
71
  onEditButtonClick: onEditButtonClick,
71
72
  onCancelButtonClick: onCancelButtonClick
72
73
  }),
@@ -21,14 +21,15 @@ Object.defineProperty(exports, "ViewDashboard", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _components = require("@perses-dev/components");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
24
25
  const _context = require("../../context");
25
26
  const _dashboardApp = require("./DashboardApp");
26
27
  function ViewDashboard(props) {
27
- const { dashboardResource , datasourceApi , dashboardTitleComponent , initialVariableIsSticky , sx , ...others } = props;
28
+ const { dashboardResource , datasourceApi , dashboardTitleComponent , initialVariableIsSticky , isReadonly , sx , ...others } = props;
28
29
  const { spec } = dashboardResource;
29
30
  var _duration;
30
31
  const dashboardDuration = (_duration = spec.duration) !== null && _duration !== void 0 ? _duration : '1h';
31
- const initialTimeRange = (0, _context.useInitialTimeRange)(dashboardDuration);
32
+ const initialTimeRange = (0, _pluginSystem.useInitialTimeRange)(dashboardDuration);
32
33
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DatasourceStoreProvider, {
33
34
  dashboardResource: dashboardResource,
34
35
  datasourceApi: datasourceApi,
@@ -36,7 +37,7 @@ function ViewDashboard(props) {
36
37
  initialState: {
37
38
  dashboardResource
38
39
  },
39
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
40
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
40
41
  initialTimeRange: initialTimeRange,
41
42
  enabledURLParams: true,
42
43
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TemplateVariableProvider, {
@@ -55,7 +56,8 @@ function ViewDashboard(props) {
55
56
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboardApp.DashboardApp, {
56
57
  dashboardResource: dashboardResource,
57
58
  dashboardTitleComponent: dashboardTitleComponent,
58
- initialVariableIsSticky: initialVariableIsSticky
59
+ initialVariableIsSticky: initialVariableIsSticky,
60
+ isReadonly: isReadonly
59
61
  })
60
62
  })
61
63
  })