diff --git a/src/webapp/components/form/FormSection.tsx b/src/webapp/components/form/FormSection.tsx index 2ddc013e..5e0380ef 100644 --- a/src/webapp/components/form/FormSection.tsx +++ b/src/webapp/components/form/FormSection.tsx @@ -61,7 +61,11 @@ export const FormSection: React.FC = React.memo( )} {addNewField && handleAddNew && ( - + )} {fields.length && fields.some(f => f.isVisible) ? ( diff --git a/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts b/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts index bfc2dcbb..17d5ed16 100644 --- a/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts +++ b/src/webapp/pages/form-page/incident-action/mapIncidentActionToInitialFormState.ts @@ -12,7 +12,6 @@ import { FormSectionState } from "../../../components/form/FormSectionsState"; import { FormState } from "../../../components/form/FormState"; import { Option as UIOption } from "../../../components/utils/option"; import { mapToPresentationOptions } from "../mapEntityToFormState"; -import { getAnotherOptionSection } from "../risk-assessment/mapRiskAssessmentToInitialFormState"; type ActionPlanSectionKeys = | "iapType" @@ -24,6 +23,22 @@ type ActionPlanSectionKeys = | "expectedResults" | "responseActivitiesNarrative"; +function getAnotherResponseActionSection(): FormSectionState { + return { + id: "addNewResponseActionSection", + isVisible: true, + fields: [], + addNewField: { + id: "addNewResponseAction", + isVisible: true, + errors: [], + type: "addNew", + value: null, + label: "Add new response action", + }, + }; +} + export function mapIncidentActionPlanToInitialFormState( incidentActionPlanFormData: ActionPlanFormData ): FormState { @@ -31,7 +46,7 @@ export function mapIncidentActionPlanToInitialFormState( const { iapType, phoecLevel } = options; const iapTypeOptions: UIOption[] = mapToPresentationOptions(iapType); - const phoexLevelOptions: UIOption[] = mapToPresentationOptions(phoecLevel); + const phoecLevelOptions: UIOption[] = mapToPresentationOptions(phoecLevel); const mainSections: Record = { iapType: { @@ -66,7 +81,7 @@ export function mapIncidentActionPlanToInitialFormState( errors: [], type: "select", multiple: false, - options: phoexLevelOptions, + options: phoecLevelOptions, value: incidentActionPlan?.phoecLevel || "", required: true, }, @@ -148,7 +163,7 @@ export function mapIncidentActionPlanToInitialFormState( ], }, expectedResults: { - title: "Expected results", + title: "Sections, functional area objectives, expected results", id: "expected_results_section", isVisible: true, direction: "column", @@ -242,7 +257,7 @@ export function mapIncidentResponseActionToInitialFormState( }) : [initialResponseActionSection]; - const addNewOptionSection: FormSectionState = getAnotherOptionSection(); + const addNewResponseActionSection: FormSectionState = getAnotherResponseActionSection(); return { id: eventTrackerDetails.id ?? "", @@ -252,7 +267,7 @@ export function mapIncidentResponseActionToInitialFormState( subtitleDescripton: "Assign response actions", saveButtonLabel: "Save plan", isValid: incidentResponseActions.length !== 0 ? true : false, - sections: [...responseActionSections, addNewOptionSection], + sections: [...responseActionSections, addNewResponseActionSection], }; } @@ -270,7 +285,7 @@ function getResponseActionSection(options: { const responseActionSection: FormSectionState = { title: "", - id: `response_action_section`, + id: `response_action_section_${index}`, isVisible: true, direction: "row", fields: [ @@ -379,7 +394,7 @@ function getResponseActionSection(options: { export function addNewResponseActionSection(sections: FormSectionState[]): FormSectionState { const responseActionSections = sections.filter( - section => !section.id.startsWith("addNewOptionSection") + section => !section.id.startsWith("addNewResponseActionSection") ); const newResponseActionSection = getResponseActionSection({ diff --git a/src/webapp/pages/form-page/mapFormStateToEntityData.ts b/src/webapp/pages/form-page/mapFormStateToEntityData.ts index 311bd867..4844d513 100644 --- a/src/webapp/pages/form-page/mapFormStateToEntityData.ts +++ b/src/webapp/pages/form-page/mapFormStateToEntityData.ts @@ -529,7 +529,7 @@ function mapFormStateToIncidentResponseAction( const allFields: FormFieldState[] = getAllFieldsFromSections(formState.sections); const incidentResponseActions: ResponseAction[] = formState.sections - .filter(section => !section.id.includes("addNewOptionSection")) + .filter(section => !section.id.includes("addNewResponseActionSection")) .map((_, index): ResponseAction => { const mainTask = allFields.find(field => field.id.includes(`${responseActionConstants.mainTask}_${index}`) @@ -612,30 +612,3 @@ function getRiskAssessmentQuestionsWithOption( return { likelihoodOption, consequencesOption, riskOption }; } - -// function getIncidentResponseActions( -// allFields: FormFieldState[], -// options: IncidentResponseActionOptions, -// index: string -// ) { -// const likelihood = allFields.find(field => -// field.id.includes(`${questionType}-likelihood${index}`) -// )?.value as string; -// const likelihoodOption = options.likelihood.find(option => option.id === likelihood); -// if (!likelihoodOption) throw new Error("Likelihood not found"); - -// const searchAssignRO = allFields.find(field => field.id.includes()); - -// const consequences = allFields.find(field => -// field.id.includes(`${questionType}-consequences${index}`) -// )?.value as string; -// const consequencesOption = options.consequences.find(option => option.id === consequences); -// if (!consequencesOption) throw new Error("Consequences not found"); - -// const risk = allFields.find(field => field.id.includes(`${questionType}-risk${index}`)) -// ?.value as string; -// const riskOption = options.risk.find(option => option.id === risk); -// if (!riskOption) throw new Error("Risk not found"); - -// return { likelihoodOption, consequencesOption, riskOption }; -// } diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index 81452be8..ad97f81f 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -139,7 +139,7 @@ export function useForm(formType: FormType, id?: Id): State { setFormState(prevState => { if (prevState.kind === "loaded") { const otherSections = prevState.data.sections.filter( - section => section.id !== "addNewOptionSection" + section => section.id !== "addNewResponseActionSection" ); const addAnotherSection = getAnotherOptionSection(); const newResponseActionSection = addNewResponseActionSection(