@perses-dev/dashboards 0.5.2 → 0.6.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 (30) hide show
  1. package/dist/cjs/components/VariableAutocomplete.js +3 -3
  2. package/dist/cjs/components/{VariableOptionsDrawer/VariableOptionsDrawer.js → VariableList/VariableList.js} +10 -14
  3. package/dist/cjs/components/{VariableOptionsDrawer/VariableOptionsDrawer.test.js → VariableList/VariableList.test.js} +13 -8
  4. package/dist/cjs/components/VariableList/index.js +29 -0
  5. package/dist/cjs/components/index.js +2 -2
  6. package/dist/cjs/views/ViewDashboard.js +7 -7
  7. package/dist/components/VariableAutocomplete.d.ts +5 -1
  8. package/dist/components/VariableAutocomplete.d.ts.map +1 -1
  9. package/dist/components/VariableAutocomplete.js +1 -1
  10. package/dist/components/VariableList/VariableList.d.ts +11 -0
  11. package/dist/components/VariableList/VariableList.d.ts.map +1 -0
  12. package/dist/components/VariableList/VariableList.js +1 -0
  13. package/dist/components/VariableList/VariableList.test.d.ts +2 -0
  14. package/dist/components/VariableList/VariableList.test.d.ts.map +1 -0
  15. package/dist/components/VariableList/VariableList.test.js +1 -0
  16. package/dist/components/VariableList/index.d.ts +2 -0
  17. package/dist/components/VariableList/index.d.ts.map +1 -0
  18. package/dist/components/VariableList/index.js +1 -0
  19. package/dist/components/index.d.ts +1 -1
  20. package/dist/components/index.d.ts.map +1 -1
  21. package/dist/components/index.js +1 -1
  22. package/dist/views/ViewDashboard.d.ts.map +1 -1
  23. package/dist/views/ViewDashboard.js +1 -1
  24. package/package.json +9 -6
  25. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.d.ts +0 -11
  26. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.d.ts.map +0 -1
  27. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.js +0 -1
  28. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.d.ts +0 -2
  29. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.d.ts.map +0 -1
  30. package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.js +0 -1
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VariableAutocomplete = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
5
+ // Copyright 2022 The Perses Authors
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
7
7
  // you may not use this file except in compliance with the License.
8
8
  // You may obtain a copy of the License at
@@ -22,7 +22,7 @@ const plugin_system_1 = require("@perses-dev/plugin-system");
22
22
  * appropriate plugin.
23
23
  */
24
24
  function VariableAutocomplete(props) {
25
- const { definition, state, onChange, onOptionsChange, TextFieldProps } = props;
25
+ const { definition, state, onChange, onOptionsChange, TextFieldProps, ...others } = props;
26
26
  const { value, options } = state;
27
27
  const allValue = 'all_value' in definition.selection ? definition.selection.all_value : undefined;
28
28
  const displayOptions = (0, react_1.useMemo)(() => {
@@ -58,6 +58,6 @@ function VariableAutocomplete(props) {
58
58
  }, getOptionLabel: (option) => (option === allValue ? 'All' : option), ChipProps: {
59
59
  color: 'default',
60
60
  variant: 'outlined',
61
- } }));
61
+ }, ...others }));
62
62
  }
63
63
  exports.VariableAutocomplete = VariableAutocomplete;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VariableOptionsDrawer = void 0;
3
+ exports.VariableList = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
5
+ // Copyright 2022 The Perses Authors
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
7
7
  // you may not use this file except in compliance with the License.
8
8
  // You may obtain a copy of the License at
@@ -19,20 +19,14 @@ const components_1 = require("@perses-dev/components");
19
19
  const plugin_system_1 = require("@perses-dev/plugin-system");
20
20
  const context_1 = require("../../context");
21
21
  const VariableAutocomplete_1 = require("../VariableAutocomplete");
22
- const DRAWER_WIDTH = 296;
23
22
  /**
24
- * Dashboard options drawer that includes variable inputs.
23
+ * Displays the list of variable inputs for a dashboard.
25
24
  */
26
- function VariableOptionsDrawer(props) {
27
- const { variables, sx, ...others } = props;
25
+ function VariableList(props) {
26
+ const { variables, ...others } = props;
28
27
  const { variables: variablesState } = (0, plugin_system_1.useTemplateVariables)();
29
28
  const { setValue, setOptions } = (0, context_1.useTemplateVariablesSetters)();
30
- return ((0, jsx_runtime_1.jsxs)(material_1.Paper, { sx: (0, components_1.combineSx)({
31
- width: DRAWER_WIDTH,
32
- flexShrink: 0,
33
- padding: (theme) => theme.spacing(1, 2),
34
- borderLeft: (theme) => `1px solid ${theme.palette.divider}`,
35
- }, sx), square: true, elevation: 0, ...others, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", variant: "h6", children: "Variables" }), Object.entries(variables).map(([variableName, variableDef]) => {
29
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: { xs: 'column', sm: 'row' }, alignItems: { sm: 'center' }, spacing: 2, ...others, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: { fontWeight: (theme) => theme.typography.fontWeightMedium }, children: "Variables" }), Object.entries(variables).map(([variableName, variableDef]) => {
36
30
  if (variableDef.display.hide === true)
37
31
  return null;
38
32
  const variableState = variablesState[variableName];
@@ -40,7 +34,9 @@ function VariableOptionsDrawer(props) {
40
34
  const error = new Error(`Variable state for '${variableName}' not found`);
41
35
  return (0, jsx_runtime_1.jsx)(components_1.ErrorAlert, { error: error }, variableName);
42
36
  }
43
- return ((0, jsx_runtime_1.jsx)(plugin_system_1.PluginBoundary, { loadingFallback: "Loading...", ErrorFallbackComponent: components_1.ErrorAlert, children: (0, jsx_runtime_1.jsx)(VariableAutocomplete_1.VariableAutocomplete, { definition: variableDef, state: variableState, onChange: (value) => setValue(variableName, value), onOptionsChange: (options) => setOptions(variableName, options) }) }, variableName));
37
+ return ((0, jsx_runtime_1.jsx)(plugin_system_1.PluginBoundary, { loadingFallback: "Loading...", ErrorFallbackComponent: components_1.ErrorAlert, children: (0, jsx_runtime_1.jsx)(VariableAutocomplete_1.VariableAutocomplete, { definition: variableDef, state: variableState, onChange: (value) => setValue(variableName, value), onOptionsChange: (options) => setOptions(variableName, options), TextFieldProps: {
38
+ margin: 'none',
39
+ }, sx: { minWidth: 250 } }) }, variableName));
44
40
  })] }));
45
41
  }
46
- exports.VariableOptionsDrawer = VariableOptionsDrawer;
42
+ exports.VariableList = VariableList;
@@ -21,8 +21,8 @@ const user_event_1 = __importDefault(require("@testing-library/user-event"));
21
21
  const plugin_system_1 = require("@perses-dev/plugin-system");
22
22
  const test_1 = require("../../test");
23
23
  const context_1 = require("../../context");
24
- const VariableOptionsDrawer_1 = require("./VariableOptionsDrawer");
25
- describe('VariableOptionsDrawer', () => {
24
+ const VariableList_1 = require("./VariableList");
25
+ describe('VariableList', () => {
26
26
  const variables = {
27
27
  job: {
28
28
  display: {
@@ -55,27 +55,32 @@ describe('VariableOptionsDrawer', () => {
55
55
  const renderVariableOptionsDrawer = () => {
56
56
  const { addMockPlugin, pluginRegistryProps } = (0, test_1.mockPluginRegistryProps)();
57
57
  addMockPlugin(FAKE_PANEL_PLUGIN);
58
- (0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(plugin_system_1.PluginRegistry, { ...pluginRegistryProps, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariablesProvider, { variableDefinitions: variables, children: (0, jsx_runtime_1.jsx)(VariableOptionsDrawer_1.VariableOptionsDrawer, { variables: variables }) }) }));
58
+ (0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(plugin_system_1.PluginRegistry, { ...pluginRegistryProps, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariablesProvider, { variableDefinitions: variables, children: (0, jsx_runtime_1.jsx)(VariableList_1.VariableList, { variables: variables }) }) }));
59
59
  };
60
60
  it('should display Variables as the title', async () => {
61
61
  renderVariableOptionsDrawer();
62
- await react_1.screen.findByText('Variables');
62
+ const title = await react_1.screen.findByText('Variables');
63
+ expect(title).toBeInTheDocument();
63
64
  });
64
65
  describe('VariableAutocomplete', () => {
65
66
  it('should display correct variable', async () => {
66
67
  renderVariableOptionsDrawer();
67
- await react_1.screen.findByLabelText('Job');
68
+ const jobInput = await react_1.screen.findByLabelText('Job');
69
+ expect(jobInput).toBeInTheDocument();
68
70
  });
69
71
  it('should display correct default value', async () => {
70
72
  renderVariableOptionsDrawer();
71
- await react_1.screen.findByDisplayValue('node');
73
+ const jobValue = await react_1.screen.findByDisplayValue('node');
74
+ expect(jobValue).toBeInTheDocument();
72
75
  });
73
76
  it('should display correct options', async () => {
74
77
  renderVariableOptionsDrawer();
75
78
  const openButton = await react_1.screen.findByRole('button', { name: 'Open' });
76
79
  user_event_1.default.click(openButton);
77
- await react_1.screen.findByText('all');
78
- react_1.screen.getByText('node');
80
+ const option1 = await react_1.screen.findByText('all');
81
+ expect(option1).toBeInTheDocument();
82
+ const option2 = react_1.screen.getByText('node');
83
+ expect(option2).toBeInTheDocument();
79
84
  });
80
85
  });
81
86
  });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright 2022 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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./VariableList"), exports);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -30,4 +30,4 @@ __exportStar(require("./Dashboard"), exports);
30
30
  __exportStar(require("./GridLayout"), exports);
31
31
  __exportStar(require("./Panel/Panel"), exports);
32
32
  __exportStar(require("./VariableAutocomplete"), exports);
33
- __exportStar(require("./VariableOptionsDrawer/VariableOptionsDrawer"), exports);
33
+ __exportStar(require("./VariableList"), exports);
@@ -23,17 +23,17 @@ const components_2 = require("../components");
23
23
  */
24
24
  function ViewDashboard(props) {
25
25
  const { dashboardResource, sx, children, ...others } = props;
26
- return ((0, jsx_runtime_1.jsx)(context_1.TimeRangeStateProvider, { initialValue: { pastDuration: dashboardResource.spec.duration }, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariablesProvider, { variableDefinitions: dashboardResource.spec.variables, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: (0, components_1.combineSx)({
26
+ return ((0, jsx_runtime_1.jsx)(context_1.TimeRangeStateProvider, { initialValue: { pastDuration: dashboardResource.spec.duration }, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariablesProvider, { variableDefinitions: dashboardResource.spec.variables, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: (0, components_1.combineSx)({
27
27
  display: 'flex',
28
28
  width: '100%',
29
29
  height: '100%',
30
30
  position: 'relative',
31
31
  overflow: 'hidden',
32
- }, sx), ...others, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
33
- padding: (theme) => theme.spacing(1, 2),
34
- flexGrow: 1,
35
- overflowX: 'hidden',
36
- overflowY: 'auto',
37
- }, children: [(0, jsx_runtime_1.jsx)(components_2.Dashboard, { spec: dashboardResource.spec }), children] }), (0, jsx_runtime_1.jsx)(components_2.VariableOptionsDrawer, { variables: dashboardResource.spec.variables })] }) }) }));
32
+ }, sx), ...others, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
33
+ padding: (theme) => theme.spacing(1, 2),
34
+ flexGrow: 1,
35
+ overflowX: 'hidden',
36
+ overflowY: 'auto',
37
+ }, children: [(0, jsx_runtime_1.jsx)(components_2.VariableList, { variables: dashboardResource.spec.variables, sx: { margin: (theme) => theme.spacing(1, 0, 2) } }), (0, jsx_runtime_1.jsx)(components_2.Dashboard, { spec: dashboardResource.spec }), children] }) }) }) }));
38
38
  }
39
39
  exports.ViewDashboard = ViewDashboard;
@@ -1,17 +1,21 @@
1
1
  /// <reference types="react" />
2
- import { TextFieldProps } from '@mui/material';
2
+ import { AutocompleteProps as MuiAutocompleteProps, TextFieldProps } from '@mui/material';
3
3
  import { VariableDefinition } from '@perses-dev/core';
4
4
  import { VariableState } from '@perses-dev/plugin-system';
5
+ declare type AutocompleteProps = MuiAutocompleteProps<string, boolean, true, false>;
5
6
  export interface VariableAutocompleteProps {
6
7
  definition: VariableDefinition;
7
8
  state: VariableState;
8
9
  onChange: (value: string | string[]) => void;
9
10
  onOptionsChange: (options: string[]) => void;
10
11
  TextFieldProps?: TextFieldProps;
12
+ className?: AutocompleteProps['className'];
13
+ sx?: AutocompleteProps['sx'];
11
14
  }
12
15
  /**
13
16
  * A MUI Autocomplete that displays variable options, loaded from the
14
17
  * appropriate plugin.
15
18
  */
16
19
  export declare function VariableAutocomplete(props: VariableAutocompleteProps): JSX.Element;
20
+ export {};
17
21
  //# sourceMappingURL=VariableAutocomplete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VariableAutocomplete.d.ts","sourceRoot":"","sources":["../../src/components/VariableAutocomplete.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAsE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAsB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK9E,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;CACjC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAgEpE"}
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 +1 @@
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}=e,{value:a,options:n}=r,s="all_value"in o.selection?o.selection.all_value:void 0,u=useMemo((()=>{let e=n;return void 0===e&&(e=Array.isArray(a)?a:[a]),void 0!==s&&e[0]!==s&&(e=[s,...e]),e}),[n,a,s]),{data:p,loading:m,error:d}=useVariableOptions(o);return useEffect((()=>{m||t(p)}),[p,m]),_jsx(Autocomplete,{options:u,loading:m,value:a,multiple:Array.isArray(a),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!==d,helperText:null!==(r=null==d?void 0:d.message)&&void 0!==r?r:"",...i})},getOptionLabel:e=>e===s?"All":e,ChipProps:{color:"default",variant:"outlined"}})}
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})}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1 @@
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)}))]})}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=VariableList.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VariableList.test.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/VariableList.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
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()}))}))}));
@@ -0,0 +1,2 @@
1
+ export * from './VariableList';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./VariableList";
@@ -2,5 +2,5 @@ export * from './Dashboard';
2
2
  export * from './GridLayout';
3
3
  export * from './Panel/Panel';
4
4
  export * from './VariableAutocomplete';
5
- export * from './VariableOptionsDrawer/VariableOptionsDrawer';
5
+ export * from './VariableList';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,+CAA+C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
@@ -1 +1 @@
1
- export*from"./Dashboard";export*from"./GridLayout";export*from"./Panel/Panel";export*from"./VariableAutocomplete";export*from"./VariableOptionsDrawer/VariableOptionsDrawer";
1
+ export*from"./Dashboard";export*from"./GridLayout";export*from"./Panel/Panel";export*from"./VariableAutocomplete";export*from"./VariableList";
@@ -1 +1 @@
1
- {"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../src/views/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,MAAM,WAAW,kBAAmB,SAAQ,QAAQ;IAClD,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAoCtD"}
1
+ {"version":3,"file":"ViewDashboard.d.ts","sourceRoot":"","sources":["../../src/views/ViewDashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,MAAM,WAAW,kBAAmB,SAAQ,QAAQ;IAClD,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,eAsCtD"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Box}from"@mui/material";import{combineSx}from"@perses-dev/components";import{TimeRangeStateProvider,TemplateVariablesProvider}from"../context";import{Dashboard,VariableOptionsDrawer}from"../components";export function ViewDashboard(e){const{dashboardResource:r,sx:i,children:a,...o}=e;return _jsx(TimeRangeStateProvider,{initialValue:{pastDuration:r.spec.duration},children:_jsx(TemplateVariablesProvider,{variableDefinitions:r.spec.variables,children:_jsxs(Box,{sx:combineSx({display:"flex",width:"100%",height:"100%",position:"relative",overflow:"hidden"},i),...o,children:[_jsxs(Box,{sx:{padding:e=>e.spacing(1,2),flexGrow:1,overflowX:"hidden",overflowY:"auto"},children:[_jsx(Dashboard,{spec:r.spec}),a]}),_jsx(VariableOptionsDrawer,{variables:r.spec.variables})]})})})}
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Box}from"@mui/material";import{combineSx}from"@perses-dev/components";import{TimeRangeStateProvider,TemplateVariablesProvider}from"../context";import{Dashboard,VariableList}from"../components";export function ViewDashboard(e){const{dashboardResource:i,sx:r,children:s,...a}=e;return _jsx(TimeRangeStateProvider,{initialValue:{pastDuration:i.spec.duration},children:_jsx(TemplateVariablesProvider,{variableDefinitions:i.spec.variables,children:_jsx(Box,{sx:combineSx({display:"flex",width:"100%",height:"100%",position:"relative",overflow:"hidden"},r),...a,children:_jsxs(Box,{sx:{padding:e=>e.spacing(1,2),flexGrow:1,overflowX:"hidden",overflowY:"auto"},children:[_jsx(VariableList,{variables:i.spec.variables,sx:{margin:e=>e.spacing(1,0,2)}}),_jsx(Dashboard,{spec:i.spec}),s]})})})})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/dashboards",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "The dashboards feature in Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -24,10 +24,12 @@
24
24
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
25
25
  },
26
26
  "dependencies": {
27
- "@perses-dev/components": "^0.5.2",
28
- "@perses-dev/core": "^0.5.2",
29
- "@perses-dev/plugin-system": "^0.5.2",
27
+ "@perses-dev/components": "^0.6.0",
28
+ "@perses-dev/core": "^0.6.0",
29
+ "@perses-dev/plugin-system": "^0.6.0",
30
30
  "immer": "^9.0.15",
31
+ "react": "^17.0.2",
32
+ "react-dom": "^17.0.2",
31
33
  "react-intersection-observer": "^9.4.0",
32
34
  "use-immer": "^0.7.0",
33
35
  "use-resize-observer": "^8.0.0"
@@ -36,8 +38,9 @@
36
38
  "intersection-observer": "^0.12.2"
37
39
  },
38
40
  "peerDependencies": {
39
- "@mui/material": "^5.5.1",
40
- "react": "^17.0.2"
41
+ "react": "^17.0.2",
42
+ "react-dom": "^17.0.2",
43
+ "@mui/material": "^5.5.1"
41
44
  },
42
45
  "files": [
43
46
  "dist"
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { PaperProps } from '@mui/material';
3
- import { DashboardSpec } from '@perses-dev/core';
4
- export interface VariableOptionsDrawerProps extends PaperProps {
5
- variables: DashboardSpec['variables'];
6
- }
7
- /**
8
- * Dashboard options drawer that includes variable inputs.
9
- */
10
- export declare function VariableOptionsDrawer(props: VariableOptionsDrawerProps): JSX.Element;
11
- //# sourceMappingURL=VariableOptionsDrawer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VariableOptionsDrawer.d.ts","sourceRoot":"","sources":["../../../src/components/VariableOptionsDrawer/VariableOptionsDrawer.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAqB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOjD,MAAM,WAAW,0BAA2B,SAAQ,UAAU;IAC5D,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,eA8CtE"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Paper,Typography}from"@mui/material";import{ErrorAlert,combineSx}from"@perses-dev/components";import{PluginBoundary,useTemplateVariables}from"@perses-dev/plugin-system";import{useTemplateVariablesSetters}from"../../context";import{VariableAutocomplete}from"../VariableAutocomplete";const DRAWER_WIDTH=296;export function VariableOptionsDrawer(e){const{variables:r,sx:t,...a}=e,{variables:o}=useTemplateVariables(),{setValue:i,setOptions:s}=useTemplateVariablesSetters();return _jsxs(Paper,{sx:combineSx({width:296,flexShrink:0,padding:e=>e.spacing(1,2),borderLeft:e=>`1px solid ${e.palette.divider}`},t),square:!0,elevation:0,...a,children:[_jsx(Typography,{component:"h2",variant:"h6",children:"Variables"}),Object.entries(r).map((([e,r])=>{if(!0===r.display.hide)return null;const t=o[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=>i(e,r),onOptionsChange:r=>s(e,r)})},e)}))]})}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=VariableOptionsDrawer.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VariableOptionsDrawer.test.d.ts","sourceRoot":"","sources":["../../../src/components/VariableOptionsDrawer/VariableOptionsDrawer.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{VariableOptionsDrawer}from"./VariableOptionsDrawer";describe("VariableOptionsDrawer",(()=>{const e={job:{display:{label:"Job"},kind:"PrometheusLabelValues",selection:{default_value:"node"},options:{label_name:"job",match:["node_uname_info"]}}},i={data:["node","all"],isLoading:!1,error:void 0},r={pluginType:"Variable",kind:"PrometheusLabelValues",plugin:{useVariableOptions:()=>i}},a=()=>{const{addMockPlugin:i,pluginRegistryProps:a}=mockPluginRegistryProps();i(r),renderWithContext(_jsx(PluginRegistry,{...a,children:_jsx(TemplateVariablesProvider,{variableDefinitions:e,children:_jsx(VariableOptionsDrawer,{variables:e})})}))};it("should display Variables as the title",(async()=>{a(),await screen.findByText("Variables")})),describe("VariableAutocomplete",(()=>{it("should display correct variable",(async()=>{a(),await screen.findByLabelText("Job")})),it("should display correct default value",(async()=>{a(),await screen.findByDisplayValue("node")})),it("should display correct options",(async()=>{a();const e=await screen.findByRole("button",{name:"Open"});userEvent.click(e),await screen.findByText("all"),screen.getByText("node")}))}))}));