Skip to content

Commit ff9d150

Browse files
[Explore Vis]delete debounce for add threshold and deletion (#10880)
* fix debounce Signed-off-by: Qxisylolo <[email protected]> * Changeset file for PR #10880 created/updated * fix Signed-off-by: Qxisylolo <[email protected]> --------- Signed-off-by: Qxisylolo <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent ea74ed6 commit ff9d150

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

changelogs/fragments/10880.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Delete debounce for add threshold and deletion ([#10880](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10880))

src/plugins/explore/public/components/visualizations/style_panel/threshold/threshold_custom_values.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ describe('ThresholdCustomValues component', () => {
3030
expect(screen.getByTestId('exploreVisThreshold-0')).toBeInTheDocument();
3131
});
3232

33-
it('adds a new range when "+ Add threshold" is clicked', async () => {
33+
it('adds a new range when "+ Add threshold" is clicked', () => {
3434
const { handleChange } = setup([{ value: 0, color: '#f8f8f8ff' }]);
3535

3636
fireEvent.click(screen.getByText('+ Add threshold'));
37-
await new Promise((resolve) => setTimeout(resolve, 1000));
3837
expect(handleChange).toHaveBeenCalledWith([
3938
{ value: 0, color: '#f8f8f8ff' },
4039
{ value: 100, color: '#FF6A3D' },
@@ -51,11 +50,10 @@ describe('ThresholdCustomValues component', () => {
5150
expect(handleChange).toHaveBeenCalledWith([{ value: 5, color: '#f8f8f8ff' }]);
5251
});
5352

54-
it('deletes a threshold when trash icon is clicked', async () => {
53+
it('deletes a threshold when trash icon is clicked', () => {
5554
const { handleChange } = setup([{ value: 0, color: '#f8f8f8ff' }]);
5655
const deleteButton = screen.getByTestId('exploreVisThresholdDeleteButton-0');
5756
fireEvent.click(deleteButton);
58-
await new Promise((resolve) => setTimeout(resolve, 1000));
5957
expect(handleChange).toHaveBeenCalledWith([]);
6058
});
6159

src/plugins/explore/public/components/visualizations/style_panel/threshold/threshold_custom_values.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ export const ThresholdCustomValues: React.FC<ThresholdCustomValuesProps> = ({
142142
const newRange = { value: newDefaultValue, color: getNextColor(curRangeLength + 1) };
143143

144144
const updated = [...ranges, newRange];
145-
debouncedSort(updated);
146-
}, [ranges, debouncedSort]);
145+
setRanges(updated);
146+
onThresholdValuesChange(updated);
147+
}, [ranges, onThresholdValuesChange]);
147148

148149
const getNextColor = (rangesLength: number): string => {
149150
const index = rangesLength % THRESHOLD_COLORS.length;
@@ -153,9 +154,10 @@ export const ThresholdCustomValues: React.FC<ThresholdCustomValuesProps> = ({
153154
const handleDeleteRange = useCallback(
154155
(index: number) => {
155156
const updated = ranges.filter((_, i) => i !== index);
156-
debouncedSort(updated);
157+
setRanges(updated);
158+
onThresholdValuesChange(updated);
157159
},
158-
[debouncedSort, ranges]
160+
[onThresholdValuesChange, ranges]
159161
);
160162

161163
const [localBaseColor, setLocalBaseColor] = useDebouncedValue<string>(

0 commit comments

Comments
 (0)