Skip to content

Commit d8f5606

Browse files
authored
[IGNORE] remove some of the core dependencies (#115)
Signed-off-by: Seyed Mahmoud SHAHROKNI <[email protected]>
1 parent a9cd755 commit d8f5606

40 files changed

Lines changed: 497 additions & 42 deletions

components/src/ContentWithLegend/ContentWithLegend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import { ReactElement } from 'react';
1515
import { Box, useTheme } from '@mui/material';
16-
import { getLegendSize } from '@perses-dev/core'; // TODO
16+
import { getLegendSize } from '../model';
1717
import { Legend } from '../Legend';
1818
import { ContentWithLegendProps, getContentWithLegendLayout } from './model/content-with-legend-model';
1919

components/src/ContentWithLegend/model/content-with-legend-model.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313

1414
import { createTheme } from '@mui/material';
15-
import { legendModes, legendSizes } from '@perses-dev/core'; // TODO
15+
import { legendModes, legendSizes } from '../../model';
1616
import * as table from '../../Table';
1717
import {
1818
ContentWithLegendLayoutOpts,

components/src/ContentWithLegend/model/content-with-legend-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313

1414
import { Theme } from '@mui/material';
15-
import { LegendPositions, getLegendMode, LegendSize } from '@perses-dev/core'; //TODO
15+
import { LegendPositions, getLegendMode, LegendSize } from '../../model';
1616
import { LegendProps } from '../../Legend';
1717
import { getTableCellLayout } from '../../Table';
1818

components/src/Legend/Legend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import { Box } from '@mui/material';
1515
import { produce } from 'immer';
1616
import { ReactElement, ReactNode } from 'react';
17-
import { getLegendMode } from '@perses-dev/core'; // TODO
17+
import { getLegendMode } from '../model';
1818
import { ListLegend } from './ListLegend';
1919
import { CompactLegend } from './CompactLegend';
2020
import { TableLegend, TableLegendProps } from './TableLegend';

components/src/Legend/legend-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313

1414
import { MouseEventHandler } from 'react';
15-
import { LegendOptionsBase } from '@perses-dev/core'; // TODO
15+
import { LegendOptionsBase } from '../model';
1616

1717
// This file contains legend-related model code specific to the legend component.
1818
// See the `core` package for common/shared legend model code and the

components/src/model/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from './theme';
1616
export * from './timeOption';
1717
export * from './timeZoneOption';
1818
export * from './action';
19+
export * from './legend';

components/src/model/legend.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 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+
export const legendPositions = ['bottom', 'right'] as const;
15+
export type LegendPositions = (typeof legendPositions)[number];
16+
17+
export const legendModes = ['list', 'table'] as const;
18+
export type LegendMode = (typeof legendModes)[number];
19+
20+
export const legendSizes = ['small', 'medium'] as const;
21+
export type LegendSize = (typeof legendSizes)[number];
22+
23+
// Common legend options used across some UI components and panel specifications
24+
export interface LegendOptionsBase {
25+
position: LegendPositions;
26+
mode?: LegendMode;
27+
size?: LegendSize;
28+
}
29+
30+
export function isValidLegendPosition(position: LegendPositions): boolean {
31+
return (legendPositions as readonly string[]).includes(position);
32+
}
33+
34+
export function isValidLegendMode(mode: LegendMode): boolean {
35+
return (legendModes as readonly string[]).includes(mode);
36+
}
37+
38+
export function isValidLegendSize(size: LegendSize): boolean {
39+
return (legendSizes as readonly string[]).includes(size);
40+
}
41+
42+
export const DEFAULT_LEGEND: Required<LegendOptionsBase> = {
43+
position: 'bottom',
44+
mode: 'list',
45+
size: 'medium',
46+
};
47+
48+
export function getLegendPosition(position?: LegendPositions): 'bottom' | 'right' {
49+
if (position === undefined) {
50+
return DEFAULT_LEGEND.position;
51+
}
52+
if (isValidLegendPosition(position)) {
53+
return position;
54+
}
55+
return DEFAULT_LEGEND.position;
56+
}
57+
58+
export function getLegendMode(mode?: LegendMode): 'list' | 'table' {
59+
if (!mode || !isValidLegendMode(mode)) {
60+
return DEFAULT_LEGEND.mode;
61+
}
62+
63+
return mode;
64+
}
65+
66+
export function getLegendSize(size?: LegendSize): 'small' | 'medium' {
67+
if (!size || !isValidLegendSize(size)) {
68+
return DEFAULT_LEGEND.size;
69+
}
70+
71+
return size;
72+
}

dashboards/src/components/DashboardShortcuts/useDashboardShortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import { useCallback } from 'react';
1515
import { AbsoluteTimeRange, TimeRangeValue, isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/spec';
16-
import { PanelGroupItemId } from '@perses-dev/core';
1716
import { useSnackbar } from '@perses-dev/components';
1817
import { useTimeRange } from '@perses-dev/plugin-system';
1918
import { useHotkeys, useHotkeySequences } from '@tanstack/react-hotkeys';
19+
import { PanelGroupItemId } from '../../model';
2020
import {
2121
useFocusedPanel,
2222
buildShortcutOptions,

dashboards/src/components/GridLayout/GridItemContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Box, useForkRef } 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 { isPanelGroupItemIdEqual, PanelGroupItemId } from '@perses-dev/core'; // TODO
18+
import { isPanelGroupItemIdEqual, PanelGroupItemId } from '../../model'; // TODO
1919
import { useEditMode, usePanel, usePanelActions, useViewPanelGroup } from '../../context';
2020
import { usePanelFocusHandlers } from '../../keyboard-shortcuts';
2121
import { Panel, PanelProps, PanelOptions } from '../Panel';

dashboards/src/components/GridLayout/GridLayout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
// limitations under the License.
1313
import { ReactElement, useState } from 'react';
1414
import { Layouts, Layout } from 'react-grid-layout';
15-
import { PanelGroupDefinition } from '@perses-dev/core'; // TODO what should we do about the PanelGroupDefinition ?
15+
1616
import { PanelGroupId } from '@perses-dev/spec';
1717
import { useVariableValues, VariableContext } from '@perses-dev/plugin-system';
1818
import { useEditMode, usePanelGroup, usePanelGroupActions, useViewPanelGroup } from '../../context';
1919
import { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';
2020
import { PanelOptions } from '../Panel';
21+
import { PanelGroupDefinition } from '../../model';
2122
import { Row, RowProps } from './Row';
2223

2324
export interface GridLayoutProps {

0 commit comments

Comments
 (0)