Skip to content

Commit

Permalink
🐛 Check on the whole palette configuration to refresh local state
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed May 27, 2021
1 parent e8b62fb commit 13fb8cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import useUnmount from 'react-use/lib/useUnmount';
import { DEFAULT_COLOR } from './constants';
import { getDataMinMax, getStepValue, isValidColor } from './utils';
import { TooltipWrapper, useDebouncedValue } from '../index';
import { ColorStop } from './types';
import { ColorStop, CustomPaletteParams } from './types';

const idGeneratorFn = htmlIdGenerator();

Expand All @@ -43,19 +43,15 @@ function shouldSortStops(colorStops: Array<{ color: string; stop: string | numbe
export interface CustomStopsProps {
colorStops: ColorStop[];
onChange: (colorStops: ColorStop[]) => void;
rangeType: 'number' | 'percent';
dataBounds: { min: number; max: number };
reverse?: boolean;
palette?: string;
paletteConfiguration: CustomPaletteParams | undefined;
'data-test-prefix': string;
}
export const CustomStops = ({
colorStops,
onChange,
rangeType,
paletteConfiguration,
dataBounds,
reverse,
palette,
['data-test-prefix']: dataTestPrefix,
}: CustomStopsProps) => {
const onChangeWithValidation = useCallback(
Expand All @@ -76,7 +72,7 @@ export const CustomStops = ({
id: idGeneratorFn(),
}));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [palette, reverse]);
}, [paletteConfiguration?.name, paletteConfiguration?.reverse, paletteConfiguration?.rangeType]);

const { inputValue: localColorStops, handleInputChange: setLocalColorStops } = useDebouncedValue({
onChange: onChangeWithValidation,
Expand All @@ -101,6 +97,8 @@ export const CustomStops = ({
}
});

const rangeType = paletteConfiguration?.rangeType || 'percent';

return (
<>
{sortedReason ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function CustomizablePalette({
setPalette: (palette: PaletteOutput<CustomPaletteParams>) => void;
dataBounds: { min: number; max: number };
}) {
const rangeType = activePalette.params?.rangeType ?? defaultPaletteParams.rangeType;
const isCurrentPaletteCustom = activePalette.params?.name === CUSTOM_PALETTE;

const colorStopsToShow = roundStopValues(
Expand Down Expand Up @@ -315,11 +314,9 @@ export function CustomizablePalette({
}
>
<CustomStops
reverse={activePalette.params?.reverse}
palette={activePalette.params?.name}
paletteConfiguration={activePalette?.params}
data-test-prefix="lnsDatatable"
colorStops={colorStopsToShow}
rangeType={rangeType}
dataBounds={dataBounds}
onChange={(colorStops) => {
const newParams = getSwitchToCustomParams(
Expand Down

0 comments on commit 13fb8cb

Please sign in to comment.