buster/web/src/controllers/MetricController/MetricViewChart/MetricEditController/MetricStylingApp/StylingAppStyling/EditSmoothLinesGlobal.tsx

35 lines
1.2 KiB
TypeScript

import { IBusterMetricChartConfig } from '@/api/asset_interfaces';
import React, { useMemo } from 'react';
import { LabelAndInput } from '../Common';
import { Switch } from 'antd';
import { useMemoizedFn } from 'ahooks';
export const EditSmoothLinesGlobal: React.FC<{
columnSettings: IBusterMetricChartConfig['columnSettings'];
onUpdateChartConfig: (config: Partial<IBusterMetricChartConfig>) => void;
}> = React.memo(({ columnSettings, onUpdateChartConfig }) => {
const allSmooth = useMemo(() => {
return Object.values(columnSettings).every((column) => column.lineType === 'smooth');
}, [columnSettings]);
const onChangeAllSmooth = useMemoizedFn((value: boolean) => {
onUpdateChartConfig({
columnSettings: Object.keys(columnSettings).reduce<
IBusterMetricChartConfig['columnSettings']
>((acc, curr) => {
acc[curr] = { ...columnSettings[curr], lineType: value ? 'smooth' : 'normal' };
return acc;
}, {})
});
});
return (
<LabelAndInput label="Smooth lines">
<div className="flex w-full justify-end">
<Switch defaultChecked={allSmooth} onChange={onChangeAllSmooth} />
</div>
</LabelAndInput>
);
});
EditSmoothLinesGlobal.displayName = 'EditSmoothLinesGlobal';