Skip to content

Commit d6225c1

Browse files
committed
[IGNORE] sync with perses core repo
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
1 parent f266181 commit d6225c1

73 files changed

Lines changed: 1061 additions & 582 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@codemirror/lang-json": "^6.0.1",
3434
"@fontsource/lato": "^4.5.10",
3535
"@mui/x-date-pickers": "^7.23.1",
36-
"@perses-dev/core": "0.52.0",
36+
"@perses-dev/core": "0.53.0-beta.1",
3737
"@tanstack/react-table": "^8.20.5",
3838
"@uiw/react-codemirror": "^4.19.1",
3939
"date-fns": "^4.1.0",
@@ -62,4 +62,4 @@
6262
"files": [
6363
"dist"
6464
]
65-
}
65+
}

components/src/RefreshIntervalPicker/RefreshIntervalPicker.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ interface RefreshIntervalPickerProps {
2525

2626
export function RefreshIntervalPicker(props: RefreshIntervalPickerProps): ReactElement {
2727
const { value, onChange, timeOptions, height } = props;
28-
const formattedValue = value;
2928

3029
// If the dashboard refresh interval is not provided in timeOptions, it will create a specific option for the select
3130
const customInterval = useMemo(() => {
@@ -39,13 +38,13 @@ export function RefreshIntervalPicker(props: RefreshIntervalPickerProps): ReactE
3938
<Box>
4039
<Select
4140
id="refreshInterval"
42-
value={formattedValue}
41+
value={value}
4342
onChange={(event) => {
4443
const duration = event.target.value as DurationString;
4544
onChange(duration);
4645
}}
4746
inputProps={{
48-
'aria-label': `Select refresh interval. Currently set to ${formattedValue}`,
47+
'aria-label': `Select refresh interval. Currently set to ${value}`,
4948
}}
5049
sx={{
5150
'.MuiSelect-select': height ? { lineHeight: height, paddingY: 0 } : {},

components/src/theme/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const getModalBackgroundStyle = ({
4444
* Need to reinstantiate the theme everytime to support switching between light and dark themes
4545
* https://github.com/mui-org/material-ui/issues/18831
4646
*/
47-
export function getTheme(mode: PaletteMode, options: ThemeOptions = {}): Theme {
47+
export function getTheme(mode: PaletteMode, options: Parameters<typeof createTheme>[0] = {}): Theme {
4848
return createTheme({
4949
palette: getPaletteOptions(mode),
5050
typography,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2023 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+
14+
import { useState, useCallback } from 'react';
15+
16+
type StorageTuple<T> = [T, (next: T) => void];
17+
18+
/**
19+
* Just like useState but gets/sets the value in the browser's local storage.
20+
* 'key' should be a constant string. 'initialValue' is returned when local
21+
* storage does not have any data yet.
22+
*/
23+
export function useLocalStorage<T>(key: string, initialValue: T): StorageTuple<T> {
24+
const { value, setValueAndStore } = useStorage(window.localStorage, key, initialValue);
25+
return [value, setValueAndStore];
26+
}
27+
28+
// Common functionality used by all storage hooks
29+
function useStorage<T>(
30+
storage: Storage,
31+
key: string,
32+
initialValue: T
33+
): {
34+
setValueAndStore: (value: T) => void;
35+
setValue: (value: T) => void;
36+
value: T;
37+
} {
38+
// Use state so that changes cause the page to re-render
39+
const [value, setValue] = useState<T>(() => {
40+
try {
41+
const json = storage.getItem(key);
42+
if (json !== null) {
43+
return JSON.parse(json);
44+
}
45+
} catch {
46+
// No-op
47+
}
48+
49+
// Either the value isn't in storage yet or JSON parsing failed, so
50+
// set to the initial value in both places
51+
storage.setItem(key, JSON.stringify(initialValue));
52+
return initialValue;
53+
});
54+
55+
// Set in both places
56+
const setValueAndStore = useCallback(
57+
(val: T) => {
58+
setValue(val);
59+
storage.setItem(key, JSON.stringify(val));
60+
},
61+
[setValue, storage, key]
62+
);
63+
64+
return { value, setValue, setValueAndStore };
65+
}

components/src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
// limitations under the License.
1313

1414
export * from './axis';
15+
export * from './browser-storage';
1516
export * from './chart-actions';
1617
export * from './combine-sx';
1718
export * from './component-ids';
1819
export * from './format';
1920
export * from './theme-gen';
21+
export * from './memo';

components/src/utils/memo.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2023 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+
14+
import { useRef, DependencyList } from 'react';
15+
import isEqual from 'lodash/isEqual';
16+
17+
type MemoRef<T> = {
18+
value: T;
19+
deps: DependencyList;
20+
};
21+
22+
/**
23+
* Like React's useMemo, but guarantees the value will only be recalulated if
24+
* a dependency changes. Uses strict equality (===) for comparison. (React's
25+
* useMemo does not offer this guarantee, it's only a performance optimization).
26+
*/
27+
export function useMemoized<T>(factory: () => T, deps: DependencyList): T {
28+
const ref = useRef<MemoRef<T>>();
29+
30+
let areEqual = true;
31+
for (let i = 0; i < deps.length; i++) {
32+
if (ref.current?.deps[i] !== deps[i]) {
33+
areEqual = false;
34+
break;
35+
}
36+
}
37+
38+
if (ref.current === undefined || areEqual === false) {
39+
ref.current = { value: factory(), deps: deps };
40+
}
41+
42+
return ref.current.value;
43+
}
44+
45+
/**
46+
* Like React's useMemo, except it does a deep equality comparison with lodash's
47+
* isEqual on the dependency list.
48+
*/
49+
export function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {
50+
const ref = useRef<MemoRef<T>>();
51+
if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {
52+
ref.current = { value: factory(), deps };
53+
}
54+
return ref.current.value;
55+
}

dashboards/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
"lint:fix": "eslint --fix src --ext .ts,.tsx"
3030
},
3131
"dependencies": {
32-
"@perses-dev/components": "0.53.0",
33-
"@perses-dev/core": "0.52.0",
34-
"@perses-dev/plugin-system": "0.53.0",
32+
"@perses-dev/components": "0.53.0-beta.1",
33+
"@perses-dev/core": "0.53.0-beta.1",
34+
"@perses-dev/plugin-system": "0.53.0-beta.1",
3535
"@types/react-grid-layout": "^1.3.2",
3636
"date-fns": "^4.1.0",
3737
"immer": "^10.1.1",

dashboards/src/components/GridLayout/GridItemContent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The Perses Authors
1+
// Copyright 2025 The Perses Authors
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -15,9 +15,9 @@ import { Box } from '@mui/material';
1515
import { useInView } from 'react-intersection-observer';
1616
import { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';
1717
import React, { ReactElement, useMemo, useState } from 'react';
18-
import { PanelGroupItemId, useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';
18+
import { isPanelGroupItemIdEqual, PanelGroupItemId } from '@perses-dev/core';
19+
import { useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';
1920
import { Panel, PanelProps, PanelOptions } from '../Panel';
20-
import { isPanelGroupItemIdEqual } from '../../context/DashboardProvider/panel-group-slice';
2121
import { QueryViewerDialog } from '../QueryViewerDialog';
2222

2323
export interface GridItemContentProps {

dashboards/src/components/GridLayout/GridLayout.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The Perses Authors
1+
// Copyright 2025 The Perses Authors
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -12,15 +12,9 @@
1212
// limitations under the License.
1313
import { ReactElement, useState } from 'react';
1414
import { Layouts, Layout } from 'react-grid-layout';
15-
import { PanelGroupId } from '@perses-dev/core';
15+
import { PanelGroupId, PanelGroupDefinition } from '@perses-dev/core';
1616
import { useVariableValues, VariableContext } from '@perses-dev/plugin-system';
17-
import {
18-
useEditMode,
19-
usePanelGroup,
20-
usePanelGroupActions,
21-
useViewPanelGroup,
22-
PanelGroupDefinition,
23-
} from '../../context';
17+
import { useEditMode, usePanelGroup, usePanelGroupActions, useViewPanelGroup } from '../../context';
2418
import { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';
2519
import { PanelOptions } from '../Panel';
2620
import { Row, RowProps } from './Row';

dashboards/src/components/GridLayout/Row.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// limitations under the License.
1313

1414
import { Collapse, useTheme } from '@mui/material';
15-
import { PanelGroupId } from '@perses-dev/core';
16-
import { PanelGroupDefinition, PanelGroupItemLayout, PanelOptions, useViewPanelGroup } from '@perses-dev/dashboards';
15+
import { PanelGroupId, PanelGroupDefinition, PanelGroupItemLayout } from '@perses-dev/core';
16+
import { PanelOptions, useViewPanelGroup } from '@perses-dev/dashboards';
1717
import { ReactElement, useEffect, useMemo, useState } from 'react';
1818
import { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';
1919
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';

0 commit comments

Comments
 (0)