Skip to content

Commit

Permalink
🐛 Fix debouncing sync issue in panel
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Sep 21, 2021
1 parent 81fa3bd commit 69768de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export interface VisualizationToolbarProps<T = unknown> {
export type VisualizationDimensionEditorProps<T = unknown> = VisualizationConfigProps<T> & {
groupId: string;
accessor: string;
setState: (newState: T) => void;
setState(newState: T | ((currState: T) => T)): void;
panelRef: MutableRefObject<HTMLDivElement | null>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,27 @@ export const ThresholdPanel = (
const index = state.layers.findIndex((l) => l.layerId === layerId);
const layer = state.layers[index];

const setYConfig = (yConfig: Partial<YConfig>) => {
const newYConfigs = [...(layer.yConfig || [])];
const existingIndex = newYConfigs.findIndex(
(yAxisConfig) => yAxisConfig.forAccessor === accessor
);
if (existingIndex !== -1) {
newYConfigs[existingIndex] = { ...newYConfigs[existingIndex], ...yConfig };
} else {
newYConfigs.push({
forAccessor: accessor,
...yConfig,
const setYConfig = useCallback(
(yConfig: Partial<YConfig> | undefined) => {
if (yConfig == null) {
return;
}
setState((currState) => {
const currLayer = currState.layers[index];
const newYConfigs = [...(currLayer.yConfig || [])];
const existingIndex = newYConfigs.findIndex(
(yAxisConfig) => yAxisConfig.forAccessor === accessor
);
if (existingIndex !== -1) {
newYConfigs[existingIndex] = { ...newYConfigs[existingIndex], ...yConfig };
} else {
newYConfigs.push({ forAccessor: accessor, ...yConfig });
}
return updateLayer(currState, { ...currLayer, yConfig: newYConfigs }, index);
});
}
setState(updateLayer(state, { ...layer, yConfig: newYConfigs }, index));
};
},
[accessor, index, setState]
);

const currentYConfig = layer.yConfig?.find((yConfig) => yConfig.forAccessor === accessor);

Expand Down Expand Up @@ -187,7 +193,7 @@ export const ThresholdPanel = (
idSelected={`${idPrefix}${currentYConfig?.lineStyle || 'solid'}`}
onChange={(id) => {
const newMode = id.replace(idPrefix, '') as LineStyle;
setYConfig({ lineStyle: newMode });
setYConfig({ forAccessor: accessor, lineStyle: newMode });
}}
/>
</EuiFormRow>
Expand All @@ -201,7 +207,7 @@ export const ThresholdPanel = (
<LineThicknessSlider
value={currentYConfig?.lineWidth || 1}
onChange={(value) => {
setYConfig({ lineWidth: value });
setYConfig({ forAccessor: accessor, lineWidth: value });
}}
/>
</EuiFormRow>
Expand Down Expand Up @@ -246,7 +252,7 @@ export const ThresholdPanel = (
idSelected={`${idPrefix}${currentYConfig?.fill || 'none'}`}
onChange={(id) => {
const newMode = id.replace(idPrefix, '') as FillStyle;
setYConfig({ fill: newMode });
setYConfig({ forAccessor: accessor, fill: newMode });
}}
/>
</EuiFormRow>
Expand All @@ -260,7 +266,7 @@ export const ThresholdPanel = (
<IconSelect
value={currentYConfig?.icon}
onChange={(newIcon) => {
setYConfig({ icon: newIcon });
setYConfig({ forAccessor: accessor, icon: newIcon });
}}
/>
</EuiFormRow>
Expand Down

0 comments on commit 69768de

Please sign in to comment.