From 0bd385799f35ebb983684a112b4a46ca2ff948c7 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 3 Mar 2025 23:12:15 -0700 Subject: [PATCH] Edit metric title types --- web/src/components/ui/select/Select.tsx | 92 +++-- web/src/components/ui/switch/index.ts | 1 + .../SelectAxisSettingsButton.tsx | 16 +- .../StylingMetric/EditDerivedHeader.tsx | 375 ------------------ .../StylingMetric/EditMetricField.tsx | 2 +- .../StylingMetric/EditMetricSubHeader.tsx | 44 -- .../StylingMetric/EditMetricType.tsx | 6 +- .../StylingMetric/helpers.tsx | 13 +- 8 files changed, 66 insertions(+), 483 deletions(-) create mode 100644 web/src/components/ui/switch/index.ts delete mode 100644 web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/StylingMetric/EditDerivedHeader.tsx delete mode 100644 web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/StylingMetric/EditMetricSubHeader.tsx diff --git a/web/src/components/ui/select/Select.tsx b/web/src/components/ui/select/Select.tsx index 663094861..3d421bb50 100644 --- a/web/src/components/ui/select/Select.tsx +++ b/web/src/components/ui/select/Select.tsx @@ -8,14 +8,15 @@ import { SelectTrigger, SelectValue } from './SelectBase'; +import { useMemoizedFn } from 'ahooks'; -interface SelectItemGroup { +interface SelectItemGroup { label: string; - items: SelectItem[]; + items: SelectItem[]; } -export interface SelectItem { - value: string; +export interface SelectItem { + value: T; label: string; //this will be used in the select item text secondaryLabel?: string; icon?: React.ReactNode; @@ -23,10 +24,10 @@ export interface SelectItem { disabled?: boolean; } -export interface SelectProps { - items: SelectItem[] | SelectItemGroup[]; +export interface SelectProps { + items: SelectItem[] | SelectItemGroup[]; disabled?: boolean; - onChange: (value: string) => void; + onChange: (value: T) => void; placeholder?: string; value?: string; onOpenChange?: (open: boolean) => void; @@ -35,44 +36,49 @@ export interface SelectProps { className?: string; } -export const Select: React.FC = React.memo( - ({ - items, - showIndex, - disabled, - onChange, - placeholder, - value, - onOpenChange, - open, - className = '' - }) => { - return ( - - - - - - {items.map((item, index) => ( - - ))} - - - ); - } -); +const _Select = ({ + items, + showIndex, + disabled, + onChange, + placeholder, + value, + onOpenChange, + open, + className = '' +}: SelectProps) => { + const onValueChange = useMemoizedFn((value: string) => { + onChange(value as T); + }); + return ( + + + + + + {items.map((item, index) => ( + + ))} + + + ); +}; +_Select.displayName = 'Select'; +export const Select = React.memo(_Select) as typeof _Select; -Select.displayName = 'Select'; - -const SelectItemSelector: React.FC<{ - item: SelectItem | SelectItemGroup; +const SelectItemSelector = ({ + item, + index, + showIndex +}: { + item: SelectItem | SelectItemGroup; index: number; showIndex?: boolean; -}> = React.memo(({ item, index, showIndex }) => { +}) => { const isGroup = typeof item === 'object' && 'items' in item; if (isGroup) { @@ -101,7 +107,7 @@ const SelectItemSelector: React.FC<{ {label} ); -}); +}; SelectItemSelector.displayName = 'SelectItemSelector'; const SelectItemSecondaryText: React.FC<{ children: React.ReactNode }> = ({ children }) => { diff --git a/web/src/components/ui/switch/index.ts b/web/src/components/ui/switch/index.ts new file mode 100644 index 000000000..5bb94a862 --- /dev/null +++ b/web/src/components/ui/switch/index.ts @@ -0,0 +1 @@ +export * from './AppSwitch'; diff --git a/web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/SelectAxis/SelectAxisSettingsContent/SelectAxisSettingsButton.tsx b/web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/SelectAxis/SelectAxisSettingsContent/SelectAxisSettingsButton.tsx index 939ebd095..af7ab153e 100644 --- a/web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/SelectAxis/SelectAxisSettingsContent/SelectAxisSettingsButton.tsx +++ b/web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppVisualize/SelectAxis/SelectAxisSettingsContent/SelectAxisSettingsButton.tsx @@ -1,10 +1,11 @@ -import { AppMaterialIcons, AppPopover } from '@/components/ui'; -import { Button } from 'antd'; +import { Button } from '@/components/ui/buttons'; import React, { useMemo } from 'react'; import { SelectAxisContainerId } from '../config'; import { SelectAxisSettingContent } from './SelectAxisSettingContent'; import { useSelectAxisContextSelector } from '../useSelectAxisContext'; import { zoneIdToAxisSettingContent } from './config'; +import { Popover } from '@/components/ui/tooltip/Popover'; +import { Sliders3 } from '@/components/ui/icons'; export const SelectAxisSettingsButton: React.FC<{ zoneId: SelectAxisContainerId; @@ -20,14 +21,13 @@ export const SelectAxisSettingsButton: React.FC<{ if (!canUseAxisSetting) return null; return ( - } trigger="click" - destroyTooltipOnHide - performant - placement="leftBottom"> -