Skip to content
Merged
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 @@ -66,6 +66,12 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
variables: { id: flowId },
})

const { options, suggestions, uploadedItems } = useAttachmentOptions(
flowData,
priorExecutionSteps,
variableTypes,
)

const onSuggestionClick = useCallback(
(
variable: CheckboxVariable,
Expand All @@ -76,26 +82,28 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
// We also add curly braces to check for attachments that are variables
const { name: filename, uploaded } = variable
const nameToCheck = uploaded ? filename : `{{${filename}}}`
const currentValues = getValues(name) ?? []

// NOTE: if the attachment has been deleted from the form
// it also needs to be removed from the step parameters
const optionsWithVariables = options.map((o) =>
o.name.startsWith('s3:') ? o.name : `{{${o.name}}}`,
)
const currentValues = (getValues(name) ?? []).filter((v: string) =>
optionsWithVariables.includes(v),
)

if (!checked) {
onChange?.(currentValues.filter((v: string) => v !== nameToCheck))
} else {
const { isValid, error } = validateFiles(variable, getValues(name))
const { isValid, error } = validateFiles(variable, currentValues)
if (!isValid) {
setError(name, { type: 'invalidFile', message: error })
} else {
onChange?.(currentValues.concat(nameToCheck))
}
}
},
[getValues, name, setError],
)

const { options, suggestions, uploadedItems } = useAttachmentOptions(
flowData,
priorExecutionSteps,
variableTypes,
[getValues, name, setError, options],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Validation Inconsistency with Deleted Attachments

The validateFiles function validates against unfiltered form values, while the form update operates on filtered values that exclude deleted attachments. This inconsistency causes validation (e.g., attachment limit checks) to incorrectly count deleted attachments, leading to premature failures.

Locations (1)

Fix in Cursor Fix in Web

)

useOutsideClick({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ export function validateFiles(
const totalSize = currentTotalSize + fileSize
const currentFileCount = selectedOptions.length + 1

if (currentFileCount >= MAX_NUM_FILES) {
if (currentFileCount > MAX_NUM_FILES) {
return {
isValid: false,
error: 'Total number of files exceeds 10',
error: 'Total number of files cannot exceed 10',
}
}
if (fileSize > MAX_FILE_SIZE) {
Expand Down