Skip to content

Commit

Permalink
chore: rewrite code to better clarify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
justynoh committed Feb 21, 2024
1 parent c0375ac commit 296d3a4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions frontend/src/features/form/utils/augmentWithWorkflowDisabling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { NON_RESPONSE_FIELD_SET } from '../constants'
export const isFieldEnabledByWorkflow = (
workflowStep: FormWorkflowStep | undefined,
field: FormFieldDto,
) =>
// Field is enabled if:
// 1. there is no workflow OR
// 2. it is a non-response field OR
// 3. (by this point it is workflow + response field) has been explicitly set to be editable in the workflow
!workflowStep ||
NON_RESPONSE_FIELD_SET.has(field.fieldType) ||
workflowStep.edit.includes(field._id)
) => {
// If no workflow, default to enabled
if (!workflowStep) return true

// There is a workflow, but enable if it's a non-response field
if (NON_RESPONSE_FIELD_SET.has(field.fieldType)) return true

// (By this point a workflow exists and it is a response field, so check if it
// has been explicitly set to be editable in the workflow
return workflowStep.edit.includes(field._id)
}

export const augmentWithWorkflowDisabling = (
workflowStep: FormWorkflowStep | undefined,
Expand Down

0 comments on commit 296d3a4

Please sign in to comment.