@perses-dev/dashboards 0.7.1 → 0.8.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 (161) hide show
  1. package/dist/cjs/components/Dashboard.js +1 -1
  2. package/dist/cjs/components/DashboardToolbar.js +3 -18
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +3 -3
  4. package/dist/cjs/components/GridLayout/GridLayout.js +6 -9
  5. package/dist/cjs/components/GridLayout/GridTitle.js +15 -9
  6. package/dist/cjs/components/Panel/Panel.js +11 -6
  7. package/dist/cjs/components/Panel/Panel.test.js +17 -13
  8. package/dist/cjs/components/Panel/PanelContent.js +15 -0
  9. package/dist/cjs/components/Panel/index.js +29 -0
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +124 -0
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +111 -0
  12. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +19 -0
  13. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +60 -0
  14. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -0
  15. package/dist/cjs/components/{TimeRangeControls.js → TimeRangeControls/TimeRangeControls.js} +20 -31
  16. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +51 -0
  17. package/dist/cjs/components/TimeRangeControls/index.js +29 -0
  18. package/dist/cjs/components/Variables/Variable.js +57 -0
  19. package/dist/cjs/components/Variables/VariableList.js +27 -0
  20. package/dist/cjs/components/{VariableList → Variables}/index.js +1 -0
  21. package/dist/cjs/components/index.js +2 -3
  22. package/dist/cjs/context/DashboardAppSlice.js +45 -0
  23. package/dist/cjs/context/DashboardProvider.js +54 -36
  24. package/dist/cjs/context/LayoutsSlice.js +42 -0
  25. package/dist/cjs/context/QueryStringProvider.js +35 -0
  26. package/dist/cjs/context/TemplateVariableProvider.js +216 -0
  27. package/dist/cjs/context/TimeRangeProvider.js +66 -0
  28. package/dist/cjs/context/index.js +6 -3
  29. package/dist/cjs/css/styles.js +173 -169
  30. package/dist/cjs/test/plugin-registry.js +24 -17
  31. package/dist/cjs/test/render.js +11 -2
  32. package/dist/cjs/test/testDashboard.js +14 -37
  33. package/dist/cjs/views/DashboardApp.js +4 -4
  34. package/dist/cjs/views/ViewDashboard.js +30 -2
  35. package/dist/cjs/views/index.js +1 -1
  36. package/dist/components/Dashboard.d.ts.map +1 -1
  37. package/dist/components/Dashboard.js +1 -1
  38. package/dist/components/DashboardToolbar.d.ts +0 -1
  39. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  40. package/dist/components/DashboardToolbar.js +1 -1
  41. package/dist/components/GridLayout/GridItemContent.d.ts +1 -0
  42. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  43. package/dist/components/GridLayout/GridItemContent.js +1 -1
  44. package/dist/components/GridLayout/GridLayout.d.ts +2 -1
  45. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  46. package/dist/components/GridLayout/GridLayout.js +1 -1
  47. package/dist/components/GridLayout/GridTitle.d.ts +1 -0
  48. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  49. package/dist/components/GridLayout/GridTitle.js +1 -1
  50. package/dist/components/Panel/Panel.d.ts +2 -0
  51. package/dist/components/Panel/Panel.d.ts.map +1 -1
  52. package/dist/components/Panel/Panel.js +1 -1
  53. package/dist/components/Panel/Panel.test.d.ts.map +1 -1
  54. package/dist/components/Panel/Panel.test.js +1 -1
  55. package/dist/components/Panel/PanelContent.d.ts +11 -0
  56. package/dist/components/Panel/PanelContent.d.ts.map +1 -0
  57. package/dist/components/Panel/PanelContent.js +1 -0
  58. package/dist/components/Panel/index.d.ts +2 -0
  59. package/dist/components/Panel/index.d.ts.map +1 -0
  60. package/dist/components/Panel/index.js +1 -0
  61. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -0
  62. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -0
  63. package/dist/components/PanelDrawer/PanelDrawer.js +1 -0
  64. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts +2 -0
  65. package/dist/components/PanelDrawer/PanelDrawer.test.d.ts.map +1 -0
  66. package/dist/components/PanelDrawer/PanelDrawer.test.js +1 -0
  67. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +9 -0
  68. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +1 -0
  69. package/dist/components/PanelDrawer/PanelOptionsEditor.js +1 -0
  70. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -0
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -0
  72. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  73. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts +2 -0
  74. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.d.ts.map +1 -0
  75. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -0
  76. package/dist/components/{TimeRangeControls.d.ts → TimeRangeControls/TimeRangeControls.d.ts} +0 -0
  77. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
  78. package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -0
  79. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts +2 -0
  80. package/dist/components/TimeRangeControls/TimeRangeControls.test.d.ts.map +1 -0
  81. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -0
  82. package/dist/components/TimeRangeControls/index.d.ts +2 -0
  83. package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
  84. package/dist/components/TimeRangeControls/index.js +1 -0
  85. package/dist/components/Variables/Variable.d.ts +8 -0
  86. package/dist/components/Variables/Variable.d.ts.map +1 -0
  87. package/dist/components/Variables/Variable.js +1 -0
  88. package/dist/components/Variables/VariableList.d.ts +3 -0
  89. package/dist/components/Variables/VariableList.d.ts.map +1 -0
  90. package/dist/components/Variables/VariableList.js +1 -0
  91. package/dist/components/Variables/index.d.ts +3 -0
  92. package/dist/components/Variables/index.d.ts.map +1 -0
  93. package/dist/components/Variables/index.js +1 -0
  94. package/dist/components/index.d.ts +2 -3
  95. package/dist/components/index.d.ts.map +1 -1
  96. package/dist/components/index.js +1 -1
  97. package/dist/context/DashboardAppSlice.d.ts +26 -0
  98. package/dist/context/DashboardAppSlice.d.ts.map +1 -0
  99. package/dist/context/DashboardAppSlice.js +1 -0
  100. package/dist/context/DashboardProvider.d.ts +8 -19
  101. package/dist/context/DashboardProvider.d.ts.map +1 -1
  102. package/dist/context/DashboardProvider.js +1 -1
  103. package/dist/context/LayoutsSlice.d.ts +12 -0
  104. package/dist/context/LayoutsSlice.d.ts.map +1 -0
  105. package/dist/context/LayoutsSlice.js +1 -0
  106. package/dist/context/QueryStringProvider.d.ts +13 -0
  107. package/dist/context/QueryStringProvider.d.ts.map +1 -0
  108. package/dist/context/QueryStringProvider.js +1 -0
  109. package/dist/context/TemplateVariableProvider.d.ts +25 -0
  110. package/dist/context/TemplateVariableProvider.d.ts.map +1 -0
  111. package/dist/context/TemplateVariableProvider.js +1 -0
  112. package/dist/context/TimeRangeProvider.d.ts +12 -0
  113. package/dist/context/TimeRangeProvider.d.ts.map +1 -0
  114. package/dist/context/TimeRangeProvider.js +1 -0
  115. package/dist/context/index.d.ts +5 -2
  116. package/dist/context/index.d.ts.map +1 -1
  117. package/dist/context/index.js +1 -1
  118. package/dist/css/styles.d.ts +7 -7
  119. package/dist/css/styles.d.ts.map +1 -1
  120. package/dist/css/styles.js +1 -1
  121. package/dist/test/plugin-registry.d.ts +4 -2
  122. package/dist/test/plugin-registry.d.ts.map +1 -1
  123. package/dist/test/plugin-registry.js +1 -1
  124. package/dist/test/render.d.ts +2 -1
  125. package/dist/test/render.d.ts.map +1 -1
  126. package/dist/test/render.js +1 -1
  127. package/dist/test/testDashboard.d.ts.map +1 -1
  128. package/dist/test/testDashboard.js +1 -1
  129. package/dist/views/DashboardApp.js +1 -1
  130. package/dist/views/ViewDashboard.d.ts.map +1 -1
  131. package/dist/views/ViewDashboard.js +1 -1
  132. package/package.json +9 -11
  133. package/dist/cjs/components/AddPanel/AddPanel.js +0 -75
  134. package/dist/cjs/components/VariableAutocomplete.js +0 -63
  135. package/dist/cjs/components/VariableList/VariableList.js +0 -42
  136. package/dist/cjs/components/VariableList/VariableList.test.js +0 -86
  137. package/dist/cjs/context/TemplateVariablesProvider.js +0 -142
  138. package/dist/cjs/context/TimeRangeStateProvider.js +0 -49
  139. package/dist/components/AddPanel/AddPanel.d.ts +0 -8
  140. package/dist/components/AddPanel/AddPanel.d.ts.map +0 -1
  141. package/dist/components/AddPanel/AddPanel.js +0 -1
  142. package/dist/components/TimeRangeControls.d.ts.map +0 -1
  143. package/dist/components/TimeRangeControls.js +0 -1
  144. package/dist/components/VariableAutocomplete.d.ts +0 -21
  145. package/dist/components/VariableAutocomplete.d.ts.map +0 -1
  146. package/dist/components/VariableAutocomplete.js +0 -1
  147. package/dist/components/VariableList/VariableList.d.ts +0 -11
  148. package/dist/components/VariableList/VariableList.d.ts.map +0 -1
  149. package/dist/components/VariableList/VariableList.js +0 -1
  150. package/dist/components/VariableList/VariableList.test.d.ts +0 -2
  151. package/dist/components/VariableList/VariableList.test.d.ts.map +0 -1
  152. package/dist/components/VariableList/VariableList.test.js +0 -1
  153. package/dist/components/VariableList/index.d.ts +0 -2
  154. package/dist/components/VariableList/index.d.ts.map +0 -1
  155. package/dist/components/VariableList/index.js +0 -1
  156. package/dist/context/TemplateVariablesProvider.d.ts +0 -23
  157. package/dist/context/TemplateVariablesProvider.d.ts.map +0 -1
  158. package/dist/context/TemplateVariablesProvider.js +0 -1
  159. package/dist/context/TimeRangeStateProvider.d.ts +0 -22
  160. package/dist/context/TimeRangeStateProvider.d.ts.map +0 -1
  161. package/dist/context/TimeRangeStateProvider.js +0 -1
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTemplateVariablesSetters = exports.TemplateVariablesSettersContext = exports.TemplateVariablesProvider = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
6
- // Licensed under the Apache License, Version 2.0 (the "License");
7
- // you may not use this file except in compliance with the License.
8
- // You may obtain a copy of the License at
9
- //
10
- // http://www.apache.org/licenses/LICENSE-2.0
11
- //
12
- // Unless required by applicable law or agreed to in writing, software
13
- // distributed under the License is distributed on an "AS IS" BASIS,
14
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- // See the License for the specific language governing permissions and
16
- // limitations under the License.
17
- const react_1 = require("react");
18
- const use_immer_1 = require("use-immer");
19
- const plugin_system_1 = require("@perses-dev/plugin-system");
20
- /**
21
- * Provider implementation that supplies the TemplateVariables at runtime.
22
- */
23
- function TemplateVariablesProvider(props) {
24
- const { children, variableDefinitions } = props;
25
- // TODO: Do we need to support re-init if variableDefinitions changes?
26
- const [state, setState] = (0, use_immer_1.useImmer)(() => {
27
- const variables = {};
28
- Object.entries(variableDefinitions).forEach(([variableName, definition]) => {
29
- variables[variableName] = {
30
- value: definition.selection.default_value,
31
- options: undefined,
32
- };
33
- });
34
- return variables;
35
- });
36
- const setValue = (0, react_1.useCallback)((name, next) => {
37
- const variableDef = variableDefinitions[name];
38
- if (variableDef === undefined) {
39
- throw new Error(`Unknown variable '${name}'`);
40
- }
41
- const defaultValue = variableDef.selection.default_value;
42
- const allValue = 'all_value' in variableDef.selection ? variableDef.selection.all_value : undefined;
43
- if (typeof defaultValue === 'object') {
44
- // Shouldn't be able to assign a string to a multi select
45
- if (typeof next !== 'object') {
46
- throw new Error(`Invalid value '${next}' for multi-select`);
47
- }
48
- // If selections are completely removed, just go back to the default
49
- // value
50
- if (next.length === 0) {
51
- next = defaultValue;
52
- }
53
- }
54
- else {
55
- // Shouldn't be able to assign a string[] to a single select
56
- if (typeof next !== 'string') {
57
- throw new Error(`Invalid value '${next}' for single-select`);
58
- }
59
- }
60
- setState((draft) => {
61
- const variableState = draft[name];
62
- if (variableState === undefined) {
63
- throw new Error(`Unknown variable '${name}'`);
64
- }
65
- // If the "All" value is in the next selections, we need to either
66
- // remove it (because they selected something more specific) or
67
- // ensure it's the only selection (because they just selected it)
68
- if (allValue !== undefined && typeof next === 'object' && next.length > 1 && next.includes(allValue)) {
69
- const current = variableState.value;
70
- if (typeof current === 'object') {
71
- const hasAll = current.includes(allValue);
72
- if (hasAll) {
73
- next = next.filter((val) => val !== allValue);
74
- }
75
- else {
76
- next = [allValue];
77
- }
78
- }
79
- }
80
- variableState.value = next;
81
- });
82
- }, [setState, variableDefinitions]);
83
- const setOptions = (0, react_1.useCallback)((name, options) => {
84
- const variableDef = variableDefinitions[name];
85
- if (variableDef === undefined) {
86
- throw new Error(`Unknown variable '${name}'`);
87
- }
88
- let capturingRegex = undefined;
89
- if (variableDef.capturing_regexp !== undefined) {
90
- let pattern = variableDef.capturing_regexp;
91
- let flags = '';
92
- // Regex expressions can start with / so that flags can be provided
93
- // at the end, so account for those
94
- if (pattern.startsWith('/')) {
95
- const endIdx = pattern.lastIndexOf('/');
96
- if (endIdx > 0) {
97
- flags = pattern.substring(endIdx + 1);
98
- pattern = pattern.substring(1, endIdx);
99
- }
100
- }
101
- // TODO: Do we need to account for stateful flags (gy) and create a
102
- // new Regex each time to compare an option to?
103
- capturingRegex = new RegExp(pattern, flags);
104
- }
105
- // Get the unique options, optionally running the capturing regex
106
- const uniqueOptions = new Set();
107
- options.forEach((option) => {
108
- if (capturingRegex !== undefined) {
109
- const match = capturingRegex.exec(option);
110
- if (match !== null && match[0] !== undefined) {
111
- option = match[0];
112
- }
113
- }
114
- uniqueOptions.add(option);
115
- });
116
- // Set the options in variable state
117
- setState((draft) => {
118
- const variableState = draft[name];
119
- if (variableState === undefined) {
120
- throw new Error(`Unknown variable '${name}'`);
121
- }
122
- variableState.options = Array.from(uniqueOptions);
123
- });
124
- }, [setState, variableDefinitions]);
125
- // Memo since it's being passed via context
126
- const ctx = (0, react_1.useMemo)(() => ({ variables: state }), [state]);
127
- const setters = (0, react_1.useMemo)(() => ({ setValue, setOptions }), [setValue, setOptions]);
128
- return ((0, jsx_runtime_1.jsx)(exports.TemplateVariablesSettersContext.Provider, { value: setters, children: (0, jsx_runtime_1.jsx)(plugin_system_1.TemplateVariablesContext.Provider, { value: ctx, children: children }) }));
129
- }
130
- exports.TemplateVariablesProvider = TemplateVariablesProvider;
131
- exports.TemplateVariablesSettersContext = (0, react_1.createContext)(undefined);
132
- /**
133
- * Gets the setters for Template Variables provided by the TemplateVariablesProvider at runtime.
134
- */
135
- function useTemplateVariablesSetters() {
136
- const ctx = (0, react_1.useContext)(exports.TemplateVariablesSettersContext);
137
- if (ctx === undefined) {
138
- throw new Error('No TemplateVariablesSettersContext found. Did you forget a Provider?');
139
- }
140
- return ctx;
141
- }
142
- exports.useTemplateVariablesSetters = useTemplateVariablesSetters;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTimeRangeSetter = exports.TimeRangeSetterContext = exports.TimeRangeStateProvider = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
6
- // Licensed under the Apache License, Version 2.0 (the "License");
7
- // you may not use this file except in compliance with the License.
8
- // You may obtain a copy of the License at
9
- //
10
- // http://www.apache.org/licenses/LICENSE-2.0
11
- //
12
- // Unless required by applicable law or agreed to in writing, software
13
- // distributed under the License is distributed on an "AS IS" BASIS,
14
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- // See the License for the specific language governing permissions and
16
- // limitations under the License.
17
- const react_1 = require("react");
18
- const core_1 = require("@perses-dev/core");
19
- const plugin_system_1 = require("@perses-dev/plugin-system");
20
- /**
21
- * Provider implementation that supplies the TimeRangeState at runtime.
22
- */
23
- function TimeRangeStateProvider(props) {
24
- const { initialValue, children } = props;
25
- const defaultTimeRange = (0, core_1.toAbsoluteTimeRange)(initialValue);
26
- const [timeRange, setActiveTimeRange] = (0, react_1.useState)(defaultTimeRange);
27
- // TODO: add support for passing relative time ranges in setTimeRange, ex: { from: 'now-1h', to: 'now' }
28
- const setTimeRange = (0, react_1.useCallback)((value) => {
29
- if (!(0, core_1.isRelativeValue)(value)) {
30
- setActiveTimeRange(value);
31
- }
32
- }, []);
33
- const ctx = (0, react_1.useMemo)(() => ({ timeRange, defaultDuration: initialValue.pastDuration }), [timeRange, initialValue]);
34
- const setters = (0, react_1.useMemo)(() => ({ setTimeRange }), [setTimeRange]);
35
- return ((0, jsx_runtime_1.jsx)(exports.TimeRangeSetterContext.Provider, { value: setters, children: (0, jsx_runtime_1.jsx)(plugin_system_1.TimeRangeContext.Provider, { value: ctx, children: children }) }));
36
- }
37
- exports.TimeRangeStateProvider = TimeRangeStateProvider;
38
- exports.TimeRangeSetterContext = (0, react_1.createContext)(undefined);
39
- /**
40
- * Gets the setters for time range selection provided by the TimeRangeStateProvider at runtime.
41
- */
42
- function useTimeRangeSetter() {
43
- const ctx = (0, react_1.useContext)(exports.TimeRangeSetterContext);
44
- if (ctx === undefined) {
45
- throw new Error('No TimeRangeSetterContext found. Did you forget a Provider?');
46
- }
47
- return ctx;
48
- }
49
- exports.useTimeRangeSetter = useTimeRangeSetter;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- interface AddPanelProps {
3
- isOpen: boolean;
4
- onClose: () => void;
5
- }
6
- declare const AddPanel: ({ isOpen, onClose }: AddPanelProps) => JSX.Element;
7
- export default AddPanel;
8
- //# sourceMappingURL=AddPanel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddPanel.d.ts","sourceRoot":"","sources":["../../../src/components/AddPanel/AddPanel.tsx"],"names":[],"mappings":";AA+BA,UAAU,aAAa;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,QAAA,MAAM,QAAQ,wBAAyB,aAAa,gBA6EnD,CAAC;AA0BF,eAAe,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{MenuItem,Stack,Select,TextField,InputLabel,FormControl,Grid,Box,Button,Typography}from"@mui/material";import{Drawer}from"@perses-dev/components";import{useState}from"react";import{useLayouts,usePanels}from"../../context";import{removeWhiteSpacesAndSpecialCharacters}from"../../utils/functions";const AddPanel=({isOpen:e,onClose:t})=>{const{layouts:r,addItemToLayout:n}=useLayouts(),{addPanel:a}=usePanels(),[s,o]=useState(0),[i,l]=useState(""),[d,c]=useState("");return _jsx(Drawer,{isOpen:e,onClose:t,children:_jsxs("form",{onSubmit:e=>{var o;e.preventDefault();const l=removeWhiteSpacesAndSpecialCharacters(i);a(l,{kind:"EmptyChart",display:{name:i,description:d},options:{}});let c=0;null===(o=r[s])||void 0===o||o.spec.items.forEach((e=>{e.y>c&&(c=e.y)})),n(s,{x:0,y:c+1,width:12,height:6,content:{$ref:`#/spec/panels/${l}`}}),t()},children:[_jsx(AddPanelHeader,{onClose:t}),_jsxs(Grid,{container:!0,spacing:2,children:[_jsx(Grid,{item:!0,xs:4,children:_jsxs(FormControl,{children:[_jsx(InputLabel,{id:"select-group",children:"Group"}),_jsx(Select,{required:!0,labelId:"select-group",label:"Group",value:s,onChange:e=>{o(e.target.value)},children:r.map(((e,t)=>{var r;return _jsx(MenuItem,{value:t,children:(null===(r=e.spec.display)||void 0===r?void 0:r.title)||`Group ${t+1}`},t)}))})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsxs(Stack,{spacing:2,sx:{flexGrow:"1"},children:[_jsx(FormControl,{children:_jsx(TextField,{required:!0,label:"Panel Name",variant:"outlined",onChange:e=>{l(e.target.value)}})}),_jsx(FormControl,{children:_jsx(TextField,{label:"Description",variant:"outlined",onChange:e=>{c(e.target.value)}})})]})})]})]})})},AddPanelHeader=({onClose:e})=>_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginBottom:e=>e.spacing(2),paddingBottom:e=>e.spacing(2),borderBottom:e=>`1px solid ${e.palette.grey[100]}`},children:[_jsx(Typography,{variant:"h5",children:"Add Panel"}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(Button,{type:"submit",variant:"contained",children:"Add Panel"}),_jsx(Button,{variant:"outlined",onClick:e,children:"Cancel"})]})]});export default AddPanel;
@@ -1 +0,0 @@
1
- {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../src/components/TimeRangeControls.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAyC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAc3F,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAIF,wBAAgB,iBAAiB,gBAsEhC"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useRef,useState}from"react";import{Box,FormControl,InputLabel,Popover,Stack}from"@mui/material";import{sub}from"date-fns";import{AbsoluteTimePicker,TimeRangeSelector}from"@perses-dev/components";import{parseDurationString,toAbsoluteTimeRange,isRelativeValue}from"@perses-dev/core";import{useTimeRange}from"@perses-dev/plugin-system";import{useTimeRangeSetter}from"../context/TimeRangeStateProvider";export const TIME_OPTIONS=[{value:{pastDuration:"5m"},display:"Last 5 minutes"},{value:{pastDuration:"15m"},display:"Last 15 minutes"},{value:{pastDuration:"30m"},display:"Last 30 minutes"},{value:{pastDuration:"1h"},display:"Last 1 hour"},{value:{pastDuration:"6h"},display:"Last 6 hours"},{value:{pastDuration:"12h"},display:"Last 12 hours"},{value:{pastDuration:"24h"},display:"Last 1 day"},{value:{pastDuration:"7d"},display:"Last 7 days"},{value:{pastDuration:"14d"},display:"Last 14 days"}];const FORM_CONTROL_LABEL="Time Range";export function TimeRangeControls(){const{setTimeRange:e}=useTimeRangeSetter(),{defaultDuration:t}=useTimeRange(),a=parseDurationString(t),[s,i]=useState({pastDuration:t}),[n,o]=useState({start:sub(new Date,{...a}),end:new Date}),[r,u]=useState(!1),l=useRef();return _jsxs(Stack,{direction:"row",spacing:1,children:[_jsx(Popover,{anchorEl:l.current,anchorOrigin:{vertical:"bottom",horizontal:"center"},open:r,onClose:()=>u(!1),sx:e=>({padding:e.spacing(2)}),children:_jsx(AbsoluteTimePicker,{initialTimeRange:n,onChange:t=>{e(t),isRelativeValue(t)||o({start:t.start,end:t.end}),i(t),u(!1)}})}),_jsxs(FormControl,{fullWidth:!0,children:[_jsx(InputLabel,{children:"Time Range"}),_jsx(Box,{ref:l,children:_jsx(TimeRangeSelector,{inputLabel:"Time Range",timeOptions:TIME_OPTIONS,value:s,onSelectChange:t=>{const a={pastDuration:t.target.value,end:new Date};i(a);const s=toAbsoluteTimeRange(a);e(s),o(s),u(!1)},onCustomClick:()=>{u(!0)}})})]})]})}
@@ -1,21 +0,0 @@
1
- /// <reference types="react" />
2
- import { AutocompleteProps as MuiAutocompleteProps, TextFieldProps } from '@mui/material';
3
- import { VariableDefinition } from '@perses-dev/core';
4
- import { VariableState } from '@perses-dev/plugin-system';
5
- declare type AutocompleteProps = MuiAutocompleteProps<string, boolean, true, false>;
6
- export interface VariableAutocompleteProps {
7
- definition: VariableDefinition;
8
- state: VariableState;
9
- onChange: (value: string | string[]) => void;
10
- onOptionsChange: (options: string[]) => void;
11
- TextFieldProps?: TextFieldProps;
12
- className?: AutocompleteProps['className'];
13
- sx?: AutocompleteProps['sx'];
14
- }
15
- /**
16
- * A MUI Autocomplete that displays variable options, loaded from the
17
- * appropriate plugin.
18
- */
19
- export declare function VariableAutocomplete(props: VariableAutocompleteProps): JSX.Element;
20
- export {};
21
- //# sourceMappingURL=VariableAutocomplete.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VariableAutocomplete.d.ts","sourceRoot":"","sources":["../../src/components/VariableAutocomplete.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAgB,iBAAiB,IAAI,oBAAoB,EAAa,cAAc,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAsB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG9E,aAAK,iBAAiB,GAAG,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAE5E,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC;IAC7C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC7C,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3C,EAAE,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAiEpE"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useMemo}from"react";import{Autocomplete,TextField}from"@mui/material";import{useVariableOptions}from"@perses-dev/plugin-system";export function VariableAutocomplete(e){const{definition:o,state:r,onChange:l,onOptionsChange:t,TextFieldProps:i,...a}=e,{value:n,options:s}=r,u="all_value"in o.selection?o.selection.all_value:void 0,p=useMemo((()=>{let e=s;return void 0===e&&(e=Array.isArray(n)?n:[n]),void 0!==u&&e[0]!==u&&(e=[u,...e]),e}),[s,n,u]),{data:m,loading:d,error:v}=useVariableOptions(o);return useEffect((()=>{d||t(m)}),[m,d]),_jsx(Autocomplete,{options:p,loading:d,value:n,multiple:Array.isArray(n),disableClearable:!0,freeSolo:!1,onChange:(e,o)=>{l(o)},renderInput:e=>{var r;return _jsx(TextField,{...e,margin:"normal",label:o.display.label,error:void 0!==v,helperText:null!==(r=null==v?void 0:v.message)&&void 0!==r?r:"",...i})},getOptionLabel:e=>e===u?"All":e,ChipProps:{color:"default",variant:"outlined"},...a})}
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { StackProps } from '@mui/material';
3
- import { DashboardSpec } from '@perses-dev/core';
4
- export interface VariableListProps extends StackProps {
5
- variables: DashboardSpec['variables'];
6
- }
7
- /**
8
- * Displays the list of variable inputs for a dashboard.
9
- */
10
- export declare function VariableList(props: VariableListProps): JSX.Element;
11
- //# sourceMappingURL=VariableList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VariableList.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/VariableList.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAS,UAAU,EAAc,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKjD,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqCpD"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Stack,Typography}from"@mui/material";import{ErrorAlert}from"@perses-dev/components";import{PluginBoundary,useTemplateVariables}from"@perses-dev/plugin-system";import{useTemplateVariablesSetters}from"../../context";import{VariableAutocomplete}from"../VariableAutocomplete";export function VariableList(e){const{variables:r,...t}=e,{variables:a}=useTemplateVariables(),{setValue:o,setOptions:s}=useTemplateVariablesSetters();return _jsxs(Stack,{direction:{xs:"column",sm:"row"},alignItems:{sm:"center"},spacing:2,...t,children:[_jsx(Typography,{variant:"body2",sx:{fontWeight:e=>e.typography.fontWeightMedium},children:"Variables"}),Object.entries(r).map((([e,r])=>{if(!0===r.display.hide)return null;const t=a[e];if(void 0===t){const r=new Error(`Variable state for '${e}' not found`);return _jsx(ErrorAlert,{error:r},e)}return _jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:_jsx(VariableAutocomplete,{definition:r,state:t,onChange:r=>o(e,r),onOptionsChange:r=>s(e,r),TextFieldProps:{margin:"none"},sx:{minWidth:250}})},e)}))]})}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=VariableList.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VariableList.test.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/VariableList.test.tsx"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import{PluginRegistry}from"@perses-dev/plugin-system";import{mockPluginRegistryProps,renderWithContext}from"../../test";import{TemplateVariablesProvider}from"../../context";import{VariableList}from"./VariableList";describe("VariableList",(()=>{const e={job:{display:{label:"Job"},kind:"PrometheusLabelValues",selection:{default_value:"node"},options:{label_name:"job",match:["node_uname_info"]}}},t={data:["node","all"],isLoading:!1,error:void 0},i={pluginType:"Variable",kind:"PrometheusLabelValues",plugin:{useVariableOptions:()=>t}},a=()=>{const{addMockPlugin:t,pluginRegistryProps:a}=mockPluginRegistryProps();t(i),renderWithContext(_jsx(PluginRegistry,{...a,children:_jsx(TemplateVariablesProvider,{variableDefinitions:e,children:_jsx(VariableList,{variables:e})})}))};it("should display Variables as the title",(async()=>{a();const e=await screen.findByText("Variables");expect(e).toBeInTheDocument()})),describe("VariableAutocomplete",(()=>{it("should display correct variable",(async()=>{a();const e=await screen.findByLabelText("Job");expect(e).toBeInTheDocument()})),it("should display correct default value",(async()=>{a();const e=await screen.findByDisplayValue("node");expect(e).toBeInTheDocument()})),it("should display correct options",(async()=>{a();const e=await screen.findByRole("button",{name:"Open"});userEvent.click(e);const t=await screen.findByText("all");expect(t).toBeInTheDocument();const i=screen.getByText("node");expect(i).toBeInTheDocument()}))}))}));
@@ -1,2 +0,0 @@
1
- export * from './VariableList';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC"}
@@ -1 +0,0 @@
1
- export*from"./VariableList";
@@ -1,23 +0,0 @@
1
- /// <reference types="react" />
2
- import { DashboardSpec } from '@perses-dev/core';
3
- export interface TemplateVariablesProviderProps {
4
- children?: React.ReactNode;
5
- variableDefinitions: DashboardSpec['variables'];
6
- }
7
- /**
8
- * Provider implementation that supplies the TemplateVariables at runtime.
9
- */
10
- export declare function TemplateVariablesProvider(props: TemplateVariablesProviderProps): JSX.Element;
11
- /**
12
- * Setters for manipulating Template Variable state.
13
- */
14
- export interface TemplateVariablesSetters {
15
- setValue: (name: string, value: string | string[]) => void;
16
- setOptions: (name: string, options: string[]) => void;
17
- }
18
- export declare const TemplateVariablesSettersContext: import("react").Context<TemplateVariablesSetters | undefined>;
19
- /**
20
- * Gets the setters for Template Variables provided by the TemplateVariablesProvider at runtime.
21
- */
22
- export declare function useTemplateVariablesSetters(): TemplateVariablesSetters;
23
- //# sourceMappingURL=TemplateVariablesProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TemplateVariablesProvider.d.ts","sourceRoot":"","sources":["../../src/context/TemplateVariablesProvider.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,8BAA8B,eAiI9E;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3D,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACvD;AAED,eAAO,MAAM,+BAA+B,+DAAiE,CAAC;AAE9G;;GAEG;AACH,wBAAgB,2BAA2B,6BAM1C"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useMemo,useCallback,createContext,useContext}from"react";import{useImmer}from"use-immer";import{TemplateVariablesContext}from"@perses-dev/plugin-system";export function TemplateVariablesProvider(e){const{children:t,variableDefinitions:o}=e,[r,n]=useImmer((()=>{const e={};return Object.entries(o).forEach((([t,o])=>{e[t]={value:o.selection.default_value,options:void 0}})),e})),i=useCallback(((e,t)=>{const r=o[e];if(void 0===r)throw new Error(`Unknown variable '${e}'`);const i=r.selection.default_value,s="all_value"in r.selection?r.selection.all_value:void 0;if("object"==typeof i){if("object"!=typeof t)throw new Error(`Invalid value '${t}' for multi-select`);0===t.length&&(t=i)}else if("string"!=typeof t)throw new Error(`Invalid value '${t}' for single-select`);n((o=>{const r=o[e];if(void 0===r)throw new Error(`Unknown variable '${e}'`);if(void 0!==s&&"object"==typeof t&&t.length>1&&t.includes(s)){const e=r.value;if("object"==typeof e){const o=e.includes(s);t=o?t.filter((e=>e!==s)):[s]}}r.value=t}))}),[n,o]),s=useCallback(((e,t)=>{const r=o[e];if(void 0===r)throw new Error(`Unknown variable '${e}'`);let i;if(void 0!==r.capturing_regexp){let e=r.capturing_regexp,t="";if(e.startsWith("/")){const o=e.lastIndexOf("/");o>0&&(t=e.substring(o+1),e=e.substring(1,o))}i=new RegExp(e,t)}const s=new Set;t.forEach((e=>{if(void 0!==i){const t=i.exec(e);null!==t&&void 0!==t[0]&&(e=t[0])}s.add(e)})),n((t=>{const o=t[e];if(void 0===o)throw new Error(`Unknown variable '${e}'`);o.options=Array.from(s)}))}),[n,o]),a=useMemo((()=>({variables:r})),[r]),l=useMemo((()=>({setValue:i,setOptions:s})),[i,s]);return _jsx(TemplateVariablesSettersContext.Provider,{value:l,children:_jsx(TemplateVariablesContext.Provider,{value:a,children:t})})}export const TemplateVariablesSettersContext=createContext(void 0);export function useTemplateVariablesSetters(){const e=useContext(TemplateVariablesSettersContext);if(void 0===e)throw new Error("No TemplateVariablesSettersContext found. Did you forget a Provider?");return e}
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- import { TimeRangeValue, RelativeTimeRange } from '@perses-dev/core';
3
- export interface TimeRangeProviderProps {
4
- initialValue: RelativeTimeRange;
5
- children?: React.ReactNode;
6
- }
7
- /**
8
- * Provider implementation that supplies the TimeRangeState at runtime.
9
- */
10
- export declare function TimeRangeStateProvider(props: TimeRangeProviderProps): JSX.Element;
11
- /**
12
- * Setters for manipulating time range state.
13
- */
14
- export interface TimeRangeSetter {
15
- setTimeRange: (value: TimeRangeValue) => void;
16
- }
17
- export declare const TimeRangeSetterContext: import("react").Context<TimeRangeSetter | undefined>;
18
- /**
19
- * Gets the setters for time range selection provided by the TimeRangeStateProvider at runtime.
20
- */
21
- export declare function useTimeRangeSetter(): TimeRangeSetter;
22
- //# sourceMappingURL=TimeRangeStateProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TimeRangeStateProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeRangeStateProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,EACL,cAAc,EAEd,iBAAiB,EAGlB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,iBAAiB,CAAC;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,eAqBnE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CAC/C;AAED,eAAO,MAAM,sBAAsB,sDAAwD,CAAC;AAE5F;;GAEG;AACH,wBAAgB,kBAAkB,oBAMjC"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useState,useMemo,createContext,useContext,useCallback}from"react";import{toAbsoluteTimeRange,isRelativeValue}from"@perses-dev/core";import{TimeRangeContext}from"@perses-dev/plugin-system";export function TimeRangeStateProvider(e){const{initialValue:t,children:o}=e,r=toAbsoluteTimeRange(t),[n,i]=useState(r),a=useCallback((e=>{isRelativeValue(e)||i(e)}),[]),s=useMemo((()=>({timeRange:n,defaultDuration:t.pastDuration})),[n,t]),u=useMemo((()=>({setTimeRange:a})),[a]);return _jsx(TimeRangeSetterContext.Provider,{value:u,children:_jsx(TimeRangeContext.Provider,{value:s,children:o})})}export const TimeRangeSetterContext=createContext(void 0);export function useTimeRangeSetter(){const e=useContext(TimeRangeSetterContext);if(void 0===e)throw new Error("No TimeRangeSetterContext found. Did you forget a Provider?");return e}