Skip to content

Commit

Permalink
Fixed components and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Jun 13, 2024
1 parent 34552b3 commit cc4c804
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
7 changes: 6 additions & 1 deletion frontend/src/lib/components/Dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,14 @@ export const Dropdown = withDefaults<DropdownProps>()(defaultProps, (props) => {
clearTimeout(debounceTimerRef.current);
}

if (!props.debounceTimeMs) {
onChange(value);
return;
}

debounceTimerRef.current = setTimeout(() => {
onChange(value);
}, props.debounceTimeMs ?? 0);
}, props.debounceTimeMs);
},
[onChange, props.debounceTimeMs]
);
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/components/Input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ export const Input = React.forwardRef((props: InputProps, ref: React.ForwardedRe
clearTimeout(debounceTimerRef.current);
}

if (!debounceTimeMs) {
onChange(event);
return;
}

debounceTimerRef.current = setTimeout(() => {
onChange(event);
}, debounceTimeMs ?? 0);
}, debounceTimeMs);
},
[props.min, props.max, onChange, props.type, debounceTimeMs]
);
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/components/Select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ export const Select = withDefaults<SelectProps>()(defaultProps, (props) => {
clearTimeout(debounceTimerRef.current);
}

if (!props.debounceTimeMs) {
onChange(values);
return;
}

debounceTimerRef.current = setTimeout(() => {
onChange(values);
}, props.debounceTimeMs ?? 0);
}, props.debounceTimeMs);
},
[onChange, props.debounceTimeMs]
);
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/components/Slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ export const Slider = React.forwardRef((props: SliderProps, ref: React.Forwarded
clearTimeout(debounceTimerRef.current);
}

if (!props.debounceTimeMs) {
props.onChange?.(event, value, activeThumb);
return;
}

debounceTimerRef.current = setTimeout(() => {
debounceTimerRef.current = null;
props.onChange?.(event, value, activeThumb);
}, debounceTimeMs ?? 0);
}, debounceTimeMs);
}

function makeLabel(): React.ReactNode {
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lib/components/TableSelect/tableSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ export const TableSelect = withDefaults<TableSelectProps>()(defaultProps, (props
clearTimeout(debounceTimerRef.current);
}

if (!props.debounceTimeMs) {
onChange(values);
return;
}

debounceTimerRef.current = setTimeout(() => {
onChange(values);
}, props.debounceTimeMs ?? 0);
}, props.debounceTimeMs);
},
[onChange, props.debounceTimeMs]
);
Expand Down
34 changes: 17 additions & 17 deletions frontend/tests/ct/resizablePanels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ test.describe("ResizablePanels", () => {
content1,
{ x: 0, y: 0 },
{ width: expectedWidths[0], height: viewPortSize.height },
3.0
10.0
)
).toBeTruthy();

Expand All @@ -434,7 +434,7 @@ test.describe("ResizablePanels", () => {
content2,
{ x: expectedWidths[0] + 1, y: 0 },
{ width: expectedWidths[1], height: viewPortSize.height },
3.0
10.0
)
).toBeTruthy();

Expand All @@ -443,7 +443,7 @@ test.describe("ResizablePanels", () => {
content3,
{ x: expectedWidths[0] + expectedWidths[1] + 2, y: 0 },
{ width: expectedWidths[2], height: viewPortSize.height },
3.0
10.0
)
).toBeTruthy();
});
Expand Down Expand Up @@ -484,7 +484,7 @@ test.describe("ResizablePanels", () => {
content1,
{ x: 0, y: 0 },
{ width: viewPortSize.width, height: expectedHeights[0] },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -493,7 +493,7 @@ test.describe("ResizablePanels", () => {
content2,
{ x: 0, y: expectedHeights[0] + 1 },
{ width: viewPortSize.width, height: expectedHeights[1] },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -502,7 +502,7 @@ test.describe("ResizablePanels", () => {
content3,
{ x: 0, y: expectedHeights[0] + expectedHeights[1] + 2 },
{ width: viewPortSize.width, height: expectedHeights[2] },
5.0
10.0
)
).toBeTruthy();
});
Expand Down Expand Up @@ -538,7 +538,7 @@ test.describe("ResizablePanels", () => {
content1,
{ x: 0, y: 0 },
{ width: expectedWidths[0], height: viewPortSize.height },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -547,7 +547,7 @@ test.describe("ResizablePanels", () => {
content2,
{ x: expectedWidths[0] + 1, y: 0 },
{ width: expectedWidths[1], height: viewPortSize.height },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -556,7 +556,7 @@ test.describe("ResizablePanels", () => {
content3,
{ x: expectedWidths[0] + expectedWidths[1] + 2, y: 0 },
{ width: expectedWidths[2], height: viewPortSize.height },
5.0
10.0
)
).toBeTruthy();
});
Expand Down Expand Up @@ -601,7 +601,7 @@ test.describe("ResizablePanels", () => {
content1,
{ x: 50, y: 0 },
{ width: expectedWidths[0], height: resizablePanelsSize.height },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -610,7 +610,7 @@ test.describe("ResizablePanels", () => {
content2,
{ x: 50 + expectedWidths[0] + 1, y: 0 },
{ width: expectedWidths[1], height: resizablePanelsSize.height },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -619,7 +619,7 @@ test.describe("ResizablePanels", () => {
content3,
{ x: 50 + expectedWidths[0] + expectedWidths[1] + 2, y: 0 },
{ width: expectedWidths[2], height: resizablePanelsSize.height },
5.0
10.0
)
).toBeTruthy();
});
Expand Down Expand Up @@ -659,7 +659,7 @@ test.describe("ResizablePanels", () => {
content1,
{ x: 0, y: 0 },
{ width: viewPortSize.width, height: expectedHeights[0] },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -668,7 +668,7 @@ test.describe("ResizablePanels", () => {
content2,
{ x: 0, y: expectedHeights[0] + 1 },
{ width: viewPortSize.width, height: expectedHeights[1] },
5.0
10.0
)
).toBeTruthy();

Expand All @@ -677,7 +677,7 @@ test.describe("ResizablePanels", () => {
content3,
{ x: 0, y: expectedHeights[0] + expectedHeights[1] + 2 },
{ width: viewPortSize.width, height: expectedHeights[2] },
5.0
10.0
)
).toBeTruthy();
});
Expand Down Expand Up @@ -788,7 +788,7 @@ test.describe("ResizablePanels", () => {

for (let i = 0; i < 3; i++) {
expect(
compareWithTolerance(callbackSizes[i], (expectedWidths[i] / viewPortSize.width) * 100, 5.0)
compareWithTolerance(callbackSizes[i], (expectedWidths[i] / viewPortSize.width) * 100, 10.0)
).toBeTruthy();
}

Expand All @@ -811,7 +811,7 @@ test.describe("ResizablePanels", () => {

for (let i = 0; i < 3; i++) {
expect(
compareWithTolerance(callbackSizes[i], (expectedWidths[i] / viewPortSize.width) * 100, 5.0)
compareWithTolerance(callbackSizes[i], (expectedWidths[i] / viewPortSize.width) * 100, 10.0)
).toBeTruthy();
}
});
Expand Down

0 comments on commit cc4c804

Please sign in to comment.