Skip to content

refactor: move away from "setValues" #9848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
setValues: (values: string[]) => void;
setValuesWithRecord: (values: string[]) => void;
setError: React.Dispatch<React.SetStateAction<string>>;
addValues: (...values: string[]) => void;
removeValue: (index: number) => void;
input: Input;
error: string;
Expand All @@ -187,6 +188,7 @@
constraintValue,
setValue,
setValues,
addValues,
setValuesWithRecord,
setError,
removeValue,
Expand Down Expand Up @@ -313,7 +315,6 @@
<ValueList
values={localConstraint.values}
removeValue={removeValue}
setValues={setValuesWithRecord}
getExternalFocusTarget={() =>
addValuesButtonRef.current ??
deleteButtonRef.current
Expand All @@ -323,14 +324,11 @@
<AddValuesWidget
ref={addValuesButtonRef}
onAddValues={(newValues) => {
// todo (`addEditStrategy`): move deduplication logic higher up in the context handling
const combinedValues = new Set([
...(localConstraint.values || []),
...newValues,
]);
setValuesWithRecord(
Array.from(combinedValues),
);
addValues(...newValues);

Check failure on line 327 in frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx

View workflow job for this annotation

GitHub Actions / build

Unhandled error

TypeError: addValues is not a function ❯ onAddValues src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx:327:37 ❯ handleAdd src/component/feature/FeatureStrategy/FeatureStrategyConstraints/AddValuesWidget.tsx:94:13 ❯ onSubmit src/component/feature/FeatureStrategy/FeatureStrategyConstraints/AddValuesWidget.tsx:128:29 ❯ HTMLUnknownElement.callCallback node_modules/react-dom/cjs/react-dom.development.js:4164:14 ❯ HTMLUnknownElement.callTheUserObjectsOperation node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30 ❯ innerInvokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25 ❯ invokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3 ❯ HTMLUnknownElementImpl._dispatch node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9 ❯ HTMLUnknownElementImpl.dispatchEvent node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17 ❯ HTMLUnknownElement.dispatchEvent node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34 This error originated in "src/component/feature/FeatureStrategy/FeatureStrategyCreate/FeatureStrategyCreate.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should change targeting settings". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
// setValuesWithRecord([
// ...(localConstraint.values || []),
// ...newValues,
// ]);
}}
/>
) : null}
Expand All @@ -351,7 +349,7 @@
</TopRow>
{showInputField ? (
<InputContainer>
<ResolveInput
<ResolveInput // todo (`addEditStrategy`) can we get rid of `setValues` in favor of `addValues` (and removeValues / clearValues)? that way, downstream components don't need to know anything about how to handle constraint values. Only that they need to call these functions. Can also be grouped into `constraintValueActions: { add, remove, clear }` or something.
setValues={setValues}
setValuesWithRecord={setValuesWithRecord}
setValue={setValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export const EditableConstraintWrapper = ({

const setValuesWithRecord = useCallback((values: string[]) => {
setLocalConstraint((prev) => {
const localConstraint = { ...prev, values };
const localConstraint = {
...prev,
values: Array.from(new Set(values)),
};

recordChange(localConstraint);

Expand All @@ -135,7 +138,10 @@ export const EditableConstraintWrapper = ({

const setValues = useCallback((values: string[]) => {
setLocalConstraint((prev) => {
const localConstraint = { ...prev, values };
const localConstraint = {
...prev,
values: Array.from(new Set(values)),
};

return localConstraint;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const ValueChip = styled(ValueChipBase)(({ theme }) => ({
type Props = {
values: string[] | undefined;
removeValue: (index: number) => void;
setValues: (values: string[]) => void;
// the element that should receive focus when all value chips are deleted
getExternalFocusTarget: () => HTMLElement | null;
};
Expand Down
Loading