onchagne appsegmetned update

This commit is contained in:
Nate Kelley 2025-01-20 17:01:10 -07:00
parent 41ff258a35
commit 64ebeddb6e
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
16 changed files with 61 additions and 67 deletions

View File

@ -59,11 +59,7 @@ export const EditContentTopApp: React.FC<{
.map((option) => {
return {
value: option.name,
label: (
<AppTooltip title={option.name}>
<span>{option.name}</span>
</AppTooltip>
)
label: option.name
};
})
.filter((v) => {

View File

@ -1,14 +1,11 @@
import { IBusterThreadMessageChartConfig } from '@/api/buster-rest/threads/threadConfigInterfaces';
import React, { MouseEventHandler, useMemo, useState } from 'react';
import React, { MouseEventHandler, useMemo } from 'react';
import { LabelAndInput } from '../../../Common/LabelAndInput';
import { AppMaterialIcons, AppSegmented, AppTooltip } from '@/components';
import { Segmented, SegmentedProps } from 'antd';
import { ChartType, ColumnSettings } from '@/components/charts/interfaces';
import { SegmentedLabeledOption, SegmentedValue } from 'antd/es/segmented';
import { useMemoizedFn } from 'ahooks';
import { useEditAppSegmented } from './useEditAppSegmented';
const options: SegmentedLabeledOption<SegmentedValue>[] = [
const options = [
{
icon: <AppMaterialIcons icon="bar_chart" data-value="bar" />,
value: 'bar',

View File

@ -28,11 +28,8 @@ export const EditLabelStyle: React.FC<{
const filteredOptions = enabledOptions.map((option) => ColumnTypeIcon[option]);
return filteredOptions.map((option) => ({
value: option.value,
label: (
<AppTooltip mouseEnterDelay={0.75} className={cx(styles.icon)} title={option.tooltip}>
{option.icon}
</AppTooltip>
)
tooltip: option.tooltip,
icon: option.icon
}));
}, [enabledOptions]);

View File

@ -94,7 +94,7 @@ export const EditLineStyle: React.FC<{
<LabelAndInput label="Line settings">
<div className="flex justify-end">
<AppSegmented
options={shownOptions as SegmentedProps['options']}
options={shownOptions}
block={false}
bordered={false}
value={selectedOption}

View File

@ -102,7 +102,7 @@ export const CollectionHeader: React.FC<{}> = React.memo(() => {
});
CollectionHeader.displayName = 'CollectionHeader';
const filters: SegmentedLabeledOption<SegmentedValue>[] = [
const filters = [
{
label: 'All',
value: JSON.stringify({})

View File

@ -24,14 +24,11 @@ export const DatasetsHeaderOptions: React.FC<{
[isAdmin]
);
const options: SegmentedProps['options'] = useMemo(
const options = useMemo(
() =>
optionsItems.map((key) => ({
label: (
<Link prefetch href={keyToRoute(datasetId!, key)}>
{DataSetAppText[key as DatasetApps]}
</Link>
),
label: DataSetAppText[key as DatasetApps],
link: keyToRoute(datasetId!, key),
value: key
})),
[datasetId, optionsItems]

View File

@ -71,46 +71,12 @@ export const PermissionAppSegments: React.FC<{
[datasetId]
);
const onChange = useMemoizedFn((value: SegmentedValue) => {
// if (typeof value === 'string') {
// const linkRef = ref.current?.querySelector(`a[data-value="${value}"]`);
// const href = linkRef?.getAttribute('href');
// if (href) {
// router.push(href);
// }
// }
});
return (
<div ref={ref} className="flex flex-col justify-center space-x-0 space-y-2">
<AppSegmented options={options} value={selectedApp} onChange={onChange} />
<AppSegmented options={options} value={selectedApp} />
<Divider className="" />
</div>
);
});
PermissionAppSegments.displayName = 'PermissionAppSegments';
// const PrefetchRouteSegmentItem = React.memo(
// ({
// value,
// label,
// link,
// onHover
// }: {
// value: PermissionApps;
// label: string;
// link: string;
// onHover: (route: PermissionApps) => void;
// }) => {
// return (
// <Link href={link} data-value={value}>
// <span className="" onMouseEnter={() => onHover(value)}>
// {label}
// </span>
// </Link>
// );
// }
// );
// PrefetchRouteSegmentItem.displayName = 'PrefetchRouteSegmentItem';

View File

@ -203,6 +203,7 @@ const EmptyState: React.FC<{
return <MetricsEmptyState openNewCollectionModal={openNewCollectionModal} type={type} />;
});
EmptyState.displayName = 'EmptyState';
const MetricsEmptyState: React.FC<{
openNewCollectionModal: () => void;

View File

@ -3,7 +3,6 @@ import {
BusterInfiniteList,
BusterListColumn,
BusterListRowItem,
BusterListSelectedOptionPopupContainer,
InfiniteListContainer
} from '@/components/list';
import { Card } from 'antd';
@ -130,3 +129,5 @@ const EmptyState = React.memo(({ isFetched }: { isFetched: boolean }) => {
</div>
);
});
EmptyState.displayName = 'EmptyState';

View File

@ -27,3 +27,5 @@ const PermissionGroupAssignButton: React.FC<{
}> = React.memo(({ selectedRowKeys, onSelectChange }) => {
return <div>PermissionGroupAssignButton</div>;
});
PermissionGroupAssignButton.displayName = 'PermissionGroupAssignButton';

View File

@ -1,3 +1,5 @@
'use client';
import { Card } from 'antd';
import { createStyles } from 'antd-style';

View File

@ -1,3 +1,5 @@
'use client';
import { Card } from 'antd';
import { createStyles } from 'antd-style';

View File

@ -1,3 +1,5 @@
'use client';
import { Card } from 'antd';
import { createStyles } from 'antd-style';

View File

@ -1,3 +1,5 @@
'use client';
import { Card } from 'antd';
import { createStyles } from 'antd-style';

View File

@ -88,7 +88,7 @@ const SelectedButton: React.FC<{
<Text>{text}</Text>
<div
className="ml-1"
className="ml-1.5"
style={{
borderLeft: `0.5px dashed ${token.colorBorder}`,
height: token.controlHeight - 2

View File

@ -3,10 +3,20 @@ import { ConfigProvider, Segmented, SegmentedProps, ThemeConfig } from 'antd';
import { createStyles } from 'antd-style';
import { busterAppStyleConfig } from '@/styles/busterAntDStyleConfig';
import Link from 'next/link';
import { useMemoizedFn } from 'ahooks';
import { useRouter } from 'next/navigation';
import { AppTooltip } from '@/components/tooltip';
const token = busterAppStyleConfig.token!;
type SegmentedOption = { value: string; label: string; link?: string; onHover?: () => void };
export interface AppSegmentedProps extends SegmentedProps {
type SegmentedOption = {
value: string;
label?: string;
link?: string;
onHover?: () => void;
icon?: React.ReactNode;
tooltip?: string;
};
export interface AppSegmentedProps extends Omit<SegmentedProps, 'options'> {
bordered?: boolean;
options: SegmentedOption[];
}
@ -31,8 +41,9 @@ const THEME_CONFIG: ThemeConfig = {
};
export const AppSegmented = React.memo<AppSegmentedProps>(
({ size = 'small', bordered = true, options: optionsProps, ...props }) => {
({ size = 'small', bordered = true, onChange, options: optionsProps, ...props }) => {
const { cx, styles } = useStyles();
const router = useRouter();
const options = useMemo(() => {
return optionsProps.map((option) => ({
@ -41,10 +52,19 @@ export const AppSegmented = React.memo<AppSegmentedProps>(
}));
}, [optionsProps]);
const onChangePreflight = useMemoizedFn((value: string | number) => {
const link = optionsProps.find((option) => option.value === value)?.link;
if (link) {
router.push(link);
}
onChange?.(value);
});
return (
<ConfigProvider theme={THEME_CONFIG}>
<Segmented
{...props}
onChange={onChangePreflight}
options={options}
size={size}
className={cx(
@ -62,9 +82,14 @@ AppSegmented.displayName = 'AppSegmented';
const SegmentedItem: React.FC<{ option: SegmentedOption }> = ({ option }) => {
return (
<SegmentedItemLink href={option.link}>
<div onClick={option.onHover}>{option.label}</div>
</SegmentedItemLink>
<AppTooltip mouseEnterDelay={0.75} title={option.tooltip}>
<SegmentedItemLink href={option.link}>
<div className="flex items-center gap-0.5" onClick={option.onHover}>
{option.icon}
{option.label}
</div>
</SegmentedItemLink>
</AppTooltip>
);
};
@ -73,5 +98,9 @@ const SegmentedItemLink: React.FC<{ href?: string; children: React.ReactNode }>
children
}) => {
if (!href) return children;
return <Link href={href}>{children}</Link>;
return (
<Link prefetch={true} href={href}>
{children}
</Link>
);
};