diff --git a/editor.planx.uk/src/@planx/components/SetValue/Editor.tsx b/editor.planx.uk/src/@planx/components/SetValue/Editor.tsx index 69e6de5c4d..f3926067ee 100644 --- a/editor.planx.uk/src/@planx/components/SetValue/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/SetValue/Editor.tsx @@ -106,18 +106,20 @@ function SetValueComponent(props: Props) { /> - - - - - + {formik.values.operation !== "removeAll" && + + + + + + } diff --git a/editor.planx.uk/src/@planx/components/SetValue/model.ts b/editor.planx.uk/src/@planx/components/SetValue/model.ts index 4433ce54e4..70b7575e1d 100644 --- a/editor.planx.uk/src/@planx/components/SetValue/model.ts +++ b/editor.planx.uk/src/@planx/components/SetValue/model.ts @@ -1,11 +1,21 @@ import { MoreInformation, parseMoreInformation } from "../shared"; -export interface SetValue extends MoreInformation { +export interface BaseSetValue extends MoreInformation { fn: string; +} + +interface SetValueWithVal extends BaseSetValue { val: string; - operation: "replace" | "append" | "removeOne" | "removeAll"; + operation: "replace" | "append" | "removeOne"; } +interface SetValueWithoutVal extends BaseSetValue { + val?: string; + operation: "removeAll"; +} + +export type SetValue = SetValueWithVal | SetValueWithoutVal; + export const parseSetValue = ( data: Record | undefined, ): SetValue => ({ diff --git a/editor.planx.uk/src/@planx/components/SetValue/utils.ts b/editor.planx.uk/src/@planx/components/SetValue/utils.ts index 46df9c9431..46530bfbcd 100644 --- a/editor.planx.uk/src/@planx/components/SetValue/utils.ts +++ b/editor.planx.uk/src/@planx/components/SetValue/utils.ts @@ -15,7 +15,7 @@ type HandleSetValue = (params: { * Called by computePassport() */ export const handleSetValue: HandleSetValue = ({ - nodeData: { operation, fn, val: current }, + nodeData, previousValues, passport, }) => { @@ -31,31 +31,28 @@ export const handleSetValue: HandleSetValue = ({ const previous = formatPreviousValues(previousValues); const newValues = calculateNewValues({ - operation, + nodeData, previous, - current, }); if (newValues) { - passport.data![fn] = newValues; + passport.data![nodeData.fn] = newValues; // Operation has cleared passport value - if (!newValues.length) delete passport.data![fn]; + if (!newValues.length) delete passport.data![nodeData.fn]; } return passport; }; type CalculateNewValues = (params: { - operation: SetValue["operation"]; + nodeData: SetValue; previous: string[]; - current: string; }) => string | string[] | undefined; const calculateNewValues: CalculateNewValues = ({ - operation, + nodeData: { operation, val: current }, previous, - current, }) => { switch (operation) { case "replace":