1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

random ramblings to get started

This commit is contained in:
Thomas Heartman 2025-04-28 13:26:27 +02:00
parent 5c483c7d8d
commit 9567f60c5a
3 changed files with 16 additions and 13 deletions

View File

@ -166,6 +166,7 @@ type Props = {
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;
@ -187,6 +188,7 @@ export const EditableConstraint: FC<Props> = ({
constraintValue,
setValue,
setValues,
addValues,
setValuesWithRecord,
setError,
removeValue,
@ -313,7 +315,6 @@ export const EditableConstraint: FC<Props> = ({
<ValueList
values={localConstraint.values}
removeValue={removeValue}
setValues={setValuesWithRecord}
getExternalFocusTarget={() =>
addValuesButtonRef.current ??
deleteButtonRef.current
@ -323,14 +324,11 @@ export const EditableConstraint: FC<Props> = ({
<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);
// setValuesWithRecord([
// ...(localConstraint.values || []),
// ...newValues,
// ]);
}}
/>
) : null}
@ -351,7 +349,7 @@ export const EditableConstraint: FC<Props> = ({
</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}

View File

@ -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);
@ -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;
});

View File

@ -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;
};