Skip to content

Commit 854f710

Browse files
committed
fix: remove deleted attachments from step params
1 parent 14a2840 commit 854f710

File tree

1 file changed

+16
-8
lines changed
  • packages/frontend/src/components/AttachmentSuggestions

1 file changed

+16
-8
lines changed

packages/frontend/src/components/AttachmentSuggestions/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
6666
variables: { id: flowId },
6767
})
6868

69+
const { options, suggestions, uploadedItems } = useAttachmentOptions(
70+
flowData,
71+
priorExecutionSteps,
72+
variableTypes,
73+
)
74+
6975
const onSuggestionClick = useCallback(
7076
(
7177
variable: CheckboxVariable,
@@ -76,7 +82,15 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
7682
// We also add curly braces to check for attachments that are variables
7783
const { name: filename, uploaded } = variable
7884
const nameToCheck = uploaded ? filename : `{{${filename}}}`
79-
const currentValues = getValues(name) ?? []
85+
86+
// NOTE: if the attachment has been deleted from the form
87+
// it also needs to be removed from the step parameters
88+
const optionsWithVariables = options.map((o) =>
89+
o.name.startsWith('s3:') ? o.name : `{{${o.name}}}`,
90+
)
91+
const currentValues = (getValues(name) ?? []).filter((v: string) =>
92+
optionsWithVariables.includes(v),
93+
)
8094

8195
if (!checked) {
8296
onChange?.(currentValues.filter((v: string) => v !== nameToCheck))
@@ -89,13 +103,7 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
89103
}
90104
}
91105
},
92-
[getValues, name, setError],
93-
)
94-
95-
const { options, suggestions, uploadedItems } = useAttachmentOptions(
96-
flowData,
97-
priorExecutionSteps,
98-
variableTypes,
106+
[getValues, name, setError, options],
99107
)
100108

101109
useOutsideClick({

0 commit comments

Comments
 (0)