From 27b7e60d88f87f7e33d2fc0fa53f75c56f22eadb Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:01:48 -0700 Subject: [PATCH 1/7] re-organize frontend types --- frontend/src/app/types/types.ts | 297 ++++++++++++++++---------------- 1 file changed, 153 insertions(+), 144 deletions(-) diff --git a/frontend/src/app/types/types.ts b/frontend/src/app/types/types.ts index b4762f97..b250e63a 100644 --- a/frontend/src/app/types/types.ts +++ b/frontend/src/app/types/types.ts @@ -1,3 +1,7 @@ +/************************ + ************************ + * TTLS Types + */ export interface DTR { dtid: number | null; fileNum: string | null; @@ -112,43 +116,10 @@ export interface InterestedParties { address: string | null; } -export type DocumentDataVariableObject = { - data_variable_value: string; - id: number; - provision_variable: ProvisionVariableObject; -}; - -export type ProvisionVariableObject = { - id: number; - variable_name: string; - variable_value: string; - help_text: string; - create_userid: string; - update_userid: string; - create_timestamp: string; - update_timestamp: string; - provision: Provision; -}; - -export type SimpleVariableObject = { - id: number; - variable_name: string; - variable_value: string; - help_text: string; - create_userid: string; - update_userid: string; - create_timestamp: string; - update_timestamp: string; - provision_id: number; -}; - -export type DocumentDataProvisionObject = { - provision_free_text: string; - id: number; - provision: ProvisionObject; -}; +/********************************************* + * Provision + */ -// Used on manage-templates page? export type ProvisionObject = { type: string; provision_name: string; @@ -172,38 +143,6 @@ export type ProvisionGroup = { max: number; }; -export type DocumentDataObject = { - documentData: { - dtid: number; - template_id: number; - status: string; - create_userid: string; - update_userid: string; - id: number; - active: boolean; - create_timestamp: string; - update_timestamp: string; - document_data_provisions: DocumentDataProvisionObject; - document_data_variables: DocumentDataVariableObject; - document_type: any; // - }; - provisionIds: number[]; - variableIds: number[]; -}; - -export type TemplateInfo = { - template_version: number; - file_name: string; - create_timestamp: string; - update_timestamp: string; - active_flag: boolean; - view: any; // remove from route - remove: any; // remove from route - preview: any; // remove from route - edit: any; - id: number; -}; - export type GroupMax = { provision_group: number; max: number; @@ -224,6 +163,70 @@ export type Provision = { update_userid: string; }; +// used on Manage Provisions page +export type ProvisionUpload = { + provision_name: string; + free_text: string; + help_text: string; + category: string; +}; + +// doc types have their own version of each global provision known as a DocType Provision +export type DocTypeProvision = { + id: number; + associated: boolean; + sequence_value: number; + type: string; + document_type?: DocumentType; + provision?: Provision; + provision_group?: ProvisionGroup; + document_data_provisions?: DocumentDataProvision[]; +}; + +// used in various tables +export type ProvisionDataObject = { + id: number; + associated: boolean; + sequence_value: number; + type: string; + provision_id: number; + provision_name: string; + category: string; + free_text: string; + help_text: string; + active_flag: boolean; // from global provision + is_deleted: boolean; // from global provision + create_userid: string; + create_timestamp: string; + update_userid: string; + update_timestamp: string; + provision_group: ProvisionGroup; + document_type: DocumentType; +}; + +export type ReducedProvisionDataObject = { + id: number; + associated: boolean; + sequence_value: number; + type: string; + provision_id: number; + provision_name: string; + category: string; + free_text: string; + help_text: string; + active_flag: boolean; // from global provision + is_deleted: boolean; // from global provision + create_userid: string; + create_timestamp: string; + update_userid: string; + update_timestamp: string; + provision_group: ProvisionGroup; +}; + +/********************************************* + * Variable + */ + export type Variable = { variable_name: string; variable_value: string; @@ -232,12 +235,22 @@ export type Variable = { provision_id: number; }; -// used on Manage Provisions page -export type ProvisionUpload = { - provision_name: string; - free_text: string; +export type DocumentDataVariableObject = { + data_variable_value: string; + id: number; + provision_variable: ProvisionVariableObject; +}; + +export type ProvisionVariableObject = { + id: number; + variable_name: string; + variable_value: string; help_text: string; - category: string; + create_userid: string; + update_userid: string; + create_timestamp: string; + update_timestamp: string; + provision: Provision; }; export type VariableUpload = { @@ -247,28 +260,51 @@ export type VariableUpload = { help_text: string; }; -export type SearchData = { - dtid: number; - version: number; - file_name: string; - updated_date: string; - status: string; - active: boolean; - document_data_id: number; // - document_type: DocType; // +// used on Landing Page +export type SavedVariableInfo = { + id: number; + variable_id: number; + saved_value: string; }; -export type DocType = { +export type VariableData = { id: number; - name: string; - prefix: string; - active: boolean; - created_by: string; - created_date: string; + variable_name: string; + variable_value: string; + help_text: string; create_userid: string; update_userid: string; create_timestamp: string; update_timestamp: string; + provision: Provision; +}; +/********************************************* + * Document Data + */ + +export type DocumentDataObject = { + documentData: { + dtid: number; + template_id: number; + status: string; + create_userid: string; + update_userid: string; + id: number; + active: boolean; + create_timestamp: string; + update_timestamp: string; + document_data_provisions: DocumentDataProvisionObject; + document_data_variables: DocumentDataVariableObject; + document_type: any; // + }; + provisionIds: number[]; + variableIds: number[]; +}; + +export type DocumentDataProvisionObject = { + provision_free_text: string; + id: number; + provision: ProvisionObject; }; export type DocumentData = { @@ -285,17 +321,6 @@ export type DocumentData = { document_type?: DocumentType; }; -export type DocTypeProvision = { - id: number; - associated: boolean; - sequence_value: number; - type: string; - document_type?: DocumentType; - provision?: Provision; - provision_group?: ProvisionGroup; - document_data_provisions?: DocumentDataProvision[]; -}; - export type DocumentDataProvision = { id: number; document_type_provision?: DocTypeProvision; @@ -310,12 +335,6 @@ export type DocumentDataVariable = { document_data_id: number; }; -export type SavedVariableInfo = { - id: number; - variable_id: number; - saved_value: string; -}; - export type DocumentDataDTO = { provisions: ProvisionDataObject[]; variables: ProvisionVariableObject[]; @@ -325,55 +344,45 @@ export type DocumentDataDTO = { savedVariableInfo: SavedVariableInfo[]; }; -export type ProvisionDataObject = { - id: number; - associated: boolean; - sequence_value: number; - type: string; - provision_id: number; - provision_name: string; - category: string; - free_text: string; - help_text: string; - active_flag: boolean; // from global provision - is_deleted: boolean; // from global provision - create_userid: string; - create_timestamp: string; - update_userid: string; - update_timestamp: string; - provision_group: ProvisionGroup; - document_type: DocumentType; +/********************************************* + * Other + */ + +export type SearchData = { + dtid: number; + version: number; + file_name: string; + updated_date: string; + status: string; + active: boolean; + document_data_id: number; // + document_type: DocType; // }; -export type ReducedProvisionDataObject = { +export type DocType = { id: number; - associated: boolean; - sequence_value: number; - type: string; - provision_id: number; - provision_name: string; - category: string; - free_text: string; - help_text: string; - active_flag: boolean; // from global provision - is_deleted: boolean; // from global provision + name: string; + prefix: string; + active: boolean; + created_by: string; + created_date: string; create_userid: string; - create_timestamp: string; update_userid: string; + create_timestamp: string; update_timestamp: string; - provision_group: ProvisionGroup; }; -export type VariableData = { - id: number; - variable_name: string; - variable_value: string; - help_text: string; - create_userid: string; - update_userid: string; +export type TemplateInfo = { + template_version: number; + file_name: string; create_timestamp: string; update_timestamp: string; - provision: Provision; + active_flag: boolean; + view: any; // remove from route + remove: any; // remove from route + preview: any; // remove from route + edit: any; + id: number; }; export type UserObject = { From e64b8dbc5e079fcf4328d48b2246fd734942e011 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:01:52 -0700 Subject: [PATCH 2/7] Delete api-request-parameters.ts --- frontend/src/app/types/api-request-parameters.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 frontend/src/app/types/api-request-parameters.ts diff --git a/frontend/src/app/types/api-request-parameters.ts b/frontend/src/app/types/api-request-parameters.ts deleted file mode 100644 index ee99226f..00000000 --- a/frontend/src/app/types/api-request-parameters.ts +++ /dev/null @@ -1 +0,0 @@ -export interface GetReportRequest {} From ea3a3ed103c032d9a7153fceae145f166432a028 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:02:20 -0700 Subject: [PATCH 3/7] update backend provision types & entity --- backend/src/provision/entities/provision.entity.ts | 10 ++++++++++ backend/src/provision/provision.service.ts | 2 ++ backend/src/types.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/backend/src/provision/entities/provision.entity.ts b/backend/src/provision/entities/provision.entity.ts index ec78f87c..cf917fe7 100644 --- a/backend/src/provision/entities/provision.entity.ts +++ b/backend/src/provision/entities/provision.entity.ts @@ -14,6 +14,12 @@ export class Provision { @Column({ nullable: true }) free_text: string; + @Column({ nullable: true }) + list_items: string[]; + + @Column({ nullable: true }) + list_enabled: boolean; + @Column({ nullable: true }) help_text: string; @@ -59,6 +65,8 @@ export class Provision { constructor( provision_name?: string, free_text?: string, + list_items?: string[], + list_enabled?: boolean, category?: string, active_flag?: boolean, create_userid?: string, @@ -66,6 +74,8 @@ export class Provision { ) { this.provision_name = provision_name || ''; this.free_text = free_text || ''; + this.list_items = list_items || []; + this.list_enabled = list_enabled || false; this.category = category || ''; this.active_flag = active_flag || true; this.create_userid = create_userid || ''; diff --git a/backend/src/provision/provision.service.ts b/backend/src/provision/provision.service.ts index 6cfc7136..af2618a4 100644 --- a/backend/src/provision/provision.service.ts +++ b/backend/src/provision/provision.service.ts @@ -272,6 +272,8 @@ export class ProvisionService { type: docTypeProvision.type, provision_name: docTypeProvision.provision.provision_name, free_text: docTypeProvision.provision.free_text, + list_items: docTypeProvision.provision.list_items, + list_enabled: docTypeProvision.provision.list_enabled, help_text: docTypeProvision.provision.help_text, category: docTypeProvision.provision.category, active_flag: docTypeProvision.provision.active_flag, diff --git a/backend/src/types.ts b/backend/src/types.ts index 2e465a22..f46782e7 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -27,6 +27,8 @@ export type ProvisionJSON = { provision_name: string; provision_group: number; free_text: string; + list_items: string[]; + list_enabled: boolean; provision_id: number; sequence_value: number; doc_type_provision_id: number; @@ -59,6 +61,8 @@ export type ManageDocTypeProvision = { type: string; provision_name: string; free_text: string; + list_items: string[]; + list_enabled: boolean; help_text: string; category: string; active_flag: boolean; From fea98b22c7b02efb7e76c3f2dba316b3b9376982 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:02:32 -0700 Subject: [PATCH 4/7] add provision list migration --- migrations/sql/V1.0.20__provision_list.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 migrations/sql/V1.0.20__provision_list.sql diff --git a/migrations/sql/V1.0.20__provision_list.sql b/migrations/sql/V1.0.20__provision_list.sql new file mode 100644 index 00000000..548879e6 --- /dev/null +++ b/migrations/sql/V1.0.20__provision_list.sql @@ -0,0 +1,7 @@ +ALTER TABLE provision +ADD COLUMN list_items text[] DEFAULT '{}', +ADD COLUMN list_enabled boolean DEFAULT false; + +UPDATE provision +SET list_items = '{}', + list_enabled = false; From 3a6a82c8e2770476026bb540cb295f7ff0390c29 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:15:01 -0700 Subject: [PATCH 5/7] more provision types/entity updates --- backend/src/provision/dto/create-provision.dto.ts | 5 ++--- backend/src/provision/dto/provision.dto.ts | 5 ++--- backend/src/provision/dto/update-provision.dto.ts | 5 ++--- backend/src/provision/entities/provision.entity.ts | 2 +- backend/src/provision/provision.controller.ts | 2 ++ backend/src/provision/provision.service.ts | 2 ++ 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/backend/src/provision/dto/create-provision.dto.ts b/backend/src/provision/dto/create-provision.dto.ts index 294f4630..1b9e0ae8 100644 --- a/backend/src/provision/dto/create-provision.dto.ts +++ b/backend/src/provision/dto/create-provision.dto.ts @@ -4,11 +4,10 @@ import { ProvisionDto } from './provision.dto'; export class CreateProvisionDto extends PickType(ProvisionDto, [ 'dtid', 'type', - // 'provision_group', - // 'provision_group_text', - // 'max', 'provision_name', 'free_text', + 'list_items', + 'list_enabled', 'help_text', 'category', 'sequence_value', diff --git a/backend/src/provision/dto/provision.dto.ts b/backend/src/provision/dto/provision.dto.ts index 0756ccbb..fcac0ce7 100644 --- a/backend/src/provision/dto/provision.dto.ts +++ b/backend/src/provision/dto/provision.dto.ts @@ -1,11 +1,10 @@ export class ProvisionDto { dtid?: number; type?: string; - // provision_group?: number; - // provision_group_text?: string; - // max?: number; provision_name?: string; free_text?: string; + list_items?: string[]; + list_enabled?: boolean; help_text?: string; category?: string; sequence_value?: number; diff --git a/backend/src/provision/dto/update-provision.dto.ts b/backend/src/provision/dto/update-provision.dto.ts index 3d5b9b24..b412bbb2 100644 --- a/backend/src/provision/dto/update-provision.dto.ts +++ b/backend/src/provision/dto/update-provision.dto.ts @@ -4,11 +4,10 @@ import { ProvisionDto } from './provision.dto'; export class UpdateProvisionDto extends PickType(ProvisionDto, [ 'dtid', 'type', - // 'provision_group', - // 'provision_group_text', - // 'max', 'provision_name', 'free_text', + 'list_items', + 'list_enabled', 'help_text', 'category', 'sequence_value', diff --git a/backend/src/provision/entities/provision.entity.ts b/backend/src/provision/entities/provision.entity.ts index cf917fe7..1849e942 100644 --- a/backend/src/provision/entities/provision.entity.ts +++ b/backend/src/provision/entities/provision.entity.ts @@ -14,7 +14,7 @@ export class Provision { @Column({ nullable: true }) free_text: string; - @Column({ nullable: true }) + @Column({ type: 'text', array: true, default: '{}' }) list_items: string[]; @Column({ nullable: true }) diff --git a/backend/src/provision/provision.controller.ts b/backend/src/provision/provision.controller.ts index 06b5180d..33dc8bd1 100644 --- a/backend/src/provision/provision.controller.ts +++ b/backend/src/provision/provision.controller.ts @@ -60,6 +60,8 @@ export class ProvisionController { id: number; provision: string; free_text: string; + list_items: string[]; + list_enabled: boolean; help_text: string; category: string; }, diff --git a/backend/src/provision/provision.service.ts b/backend/src/provision/provision.service.ts index af2618a4..9a0af85f 100644 --- a/backend/src/provision/provision.service.ts +++ b/backend/src/provision/provision.service.ts @@ -48,6 +48,8 @@ export class ProvisionService { const existingProvision: Provision = await this.provisionRepository.findOneBy({ id }); existingProvision.provision_name = provision.provision_name; existingProvision.free_text = provision.free_text; + existingProvision.list_items = provision.list_items; + existingProvision.list_enabled = provision.list_enabled; existingProvision.help_text = provision.help_text; existingProvision.category = provision.category; existingProvision.update_userid = provision.update_userid; From 03f8dc29a8f366da767828bca5ec4d725d56d9f7 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:27:25 -0700 Subject: [PATCH 6/7] adjust report generation to hand list --- backend/src/report/report.service.ts | 38 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/backend/src/report/report.service.ts b/backend/src/report/report.service.ts index 11279804..ca933f15 100644 --- a/backend/src/report/report.service.ts +++ b/backend/src/report/report.service.ts @@ -137,8 +137,10 @@ export class ReportService { } return a.provision_group - b.provision_group; }); - let provisions: { [key: string]: { provision_name: string; free_text: string }[] } = {}; - provisionJson.forEach(({ provision_name, provision_group, free_text }) => { + let provisions: { + [key: string]: { provision_name: string; free_text: string; list: { item: string }[] }[]; + } = {}; + provisionJson.forEach(({ provision_name, provision_group, free_text, list_items, list_enabled }) => { if (free_text.includes('«')) { // regex which converts «DB_TENURE_TYPE» to {d.DB_Tenure_Type}, also works for VAR_ free_text = free_text.replace(/«([^»]+)»/g, function (match, innerText) { @@ -161,11 +163,41 @@ export class ReportService { free_text = free_text.replace(/db_name_tenant:convcrlf\(\)}/gi, 'DB_NAME_TENANT:convCRLF()}'); } + // do same conversions for list items + let list = list_items.map((item) => { + if (item.includes('«')) { + // regex which converts «DB_TENURE_TYPE» to {d.DB_Tenure_Type}, also works for VAR_ + item = item.replace(/«([^»]+)»/g, function (match, innerText) { + innerText = convertToSpecialCamelCase(innerText); + return '{d.' + innerText + '}'; + }); + } else if (item.includes('<<')) { + // regex which converts <> to {d.DB_Tenure_Type}, also works for VAR_ + item = item.replace(/<<([^>>]+)>>/g, function (match, innerText) { + innerText = convertToSpecialCamelCase(innerText); + return '{d.' + innerText + '}'; + }); + } + + if (item.toLowerCase().includes('db_name_tenant}')) { + item = item.replace(/db_name_tenant}/gi, 'DB_NAME_TENANT:convCRLF()}'); + } else if (item.toLowerCase().includes('db_name_tenant:convcrlf()}')) { + item = item.replace(/db_name_tenant:convcrlf\(\)}/gi, 'DB_NAME_TENANT:convCRLF()}'); + } + return { item }; + }); + const key = `SECTION_${provision_group}`; if (!provisions[key]) { provisions[key] = []; } - provisions[key].push({ provision_name, free_text }); + + // for now, only pass free_text or list, not both + if (list_enabled) { + provisions[key].push({ provision_name, free_text: null, list }); + } else { + provisions[key].push({ provision_name, free_text, list: [] }); + } }); // get the TTLS DB_ variables From 82515ed1c015efbf76bbb146b3aa98eeaffd2913 Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:09:48 -0700 Subject: [PATCH 7/7] list item frontend --- .../manage-provisions/AddProvisionModal.tsx | 86 ++++++++++++++++--- .../forms/EditProvisionModalForm.tsx | 84 +++++++++++++++--- .../ManageProvisionsTable.tsx | 1 - .../src/app/content/pages/LandingPage.tsx | 2 + .../content/pages/ManageProvisionsPage.tsx | 3 +- frontend/src/app/types/types.ts | 12 +++ 6 files changed, 160 insertions(+), 28 deletions(-) diff --git a/frontend/src/app/components/modal/manage-provisions/AddProvisionModal.tsx b/frontend/src/app/components/modal/manage-provisions/AddProvisionModal.tsx index c2c7d599..9b677044 100644 --- a/frontend/src/app/components/modal/manage-provisions/AddProvisionModal.tsx +++ b/frontend/src/app/components/modal/manage-provisions/AddProvisionModal.tsx @@ -1,18 +1,21 @@ import { useState } from 'react'; import { ProvisionUpload } from '../../../types/types'; import { Button, Col, Form, Modal, Spinner } from 'react-bootstrap'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faPlus, faMinus } from '@fortawesome/free-solid-svg-icons'; interface AddProvisionModalProps { show: boolean; - addProvisionHandler: (provision: ProvisionUpload) => void; + addProvisionHandler: (provision: ProvisionUpload) => Promise; onHide: () => void; - refreshTables: () => void; } -const AddProvisionModal: React.FC = ({ show, addProvisionHandler, onHide, refreshTables }) => { +const AddProvisionModal: React.FC = ({ show, addProvisionHandler, onHide }) => { const [loading, setLoading] = useState(false); const [provisionName, setProvisionName] = useState(''); const [freeText, setFreeText] = useState(''); + const [listItems, setListItems] = useState(['']); + const [listEnabled, setListEnabled] = useState(false); const [helpText, setHelpText] = useState(''); const [category, setCategory] = useState(''); @@ -32,19 +35,41 @@ const AddProvisionModal: React.FC = ({ show, addProvisio setCategory(e.target.value); }; - const handleSaveButton = () => { + const handleListEnabledChange = (e: React.ChangeEvent) => { + setListEnabled(e.target.checked); + }; + + const handleListItemChange = (e: React.ChangeEvent, index: number) => { + const newListItems = [...listItems]; + newListItems[index] = e.target.value; + setListItems(newListItems); + }; + + const handleAddListItem = () => { + setListItems([...listItems, '']); + }; + + const handleRemoveListItem = (index: number) => { + const newListItems = [...listItems]; + newListItems.splice(index, 1); + setListItems(newListItems); + }; + + const handleSaveButton = async () => { try { setLoading(true); const provisionUpload: ProvisionUpload = { provision_name: provisionName, free_text: freeText, + list_items: listEnabled ? listItems : [], + list_enabled: listEnabled, help_text: helpText, category: category, }; - addProvisionHandler(provisionUpload); + + await addProvisionHandler(provisionUpload); onHide(); - refreshTables(); } catch (err) { console.log('Error adding provision'); console.log(err); @@ -81,15 +106,50 @@ const AddProvisionModal: React.FC = ({ show, addProvisio - - - Free Text - - - - + + + {listEnabled ? ( + + + List Items + + {listItems.map((item, index) => ( +
+ + handleListItemChange(e, index)} + /> + + + + +
+ ))} +
+ +
+
+ ) : ( + + + Free Text + + + + + + )} + Help Text diff --git a/frontend/src/app/components/modal/manage-provisions/forms/EditProvisionModalForm.tsx b/frontend/src/app/components/modal/manage-provisions/forms/EditProvisionModalForm.tsx index 06cd2d2c..2c07963b 100644 --- a/frontend/src/app/components/modal/manage-provisions/forms/EditProvisionModalForm.tsx +++ b/frontend/src/app/components/modal/manage-provisions/forms/EditProvisionModalForm.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from 'react'; import { Provision, ProvisionUpload, Variable } from '../../../../types/types'; import { Button, Col, Form, Modal, Spinner } from 'react-bootstrap'; import ManageVariablesTable from '../../../table/manage-provisions/ManageVariablesTable'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faPlus, faMinus } from '@fortawesome/free-solid-svg-icons'; interface EditProvisionModalFormProps { provision: Provision | undefined; @@ -26,6 +28,8 @@ const EditProvisionModalForm: React.FC = ({ }) => { const [provisionName, setProvisionName] = useState(''); const [freeText, setFreeText] = useState(''); + const [listItems, setListItems] = useState(['']); + const [listEnabled, setListEnabled] = useState(false); const [helpText, setHelpText] = useState(''); const [category, setCategory] = useState(''); @@ -34,6 +38,8 @@ const EditProvisionModalForm: React.FC = ({ if (provision) { setProvisionName(provision.provision_name); setFreeText(provision.free_text); + setListItems(provision.list_items); + setListEnabled(provision.list_enabled); setHelpText(provision.help_text); setCategory(provision.category); } @@ -58,14 +64,37 @@ const EditProvisionModalForm: React.FC = ({ setCategory(e.target.value); }; + const handleListEnabledChange = (e: React.ChangeEvent) => { + setListEnabled(e.target.checked); + }; + + const handleListItemChange = (e: React.ChangeEvent, index: number) => { + const newListItems = [...listItems]; + newListItems[index] = e.target.value; + setListItems(newListItems); + }; + + const handleAddListItem = () => { + setListItems([...listItems, '']); + }; + + const handleRemoveListItem = (index: number) => { + const newListItems = [...listItems]; + newListItems.splice(index, 1); + setListItems(newListItems); + }; + const handleSaveButton = () => { if (provision) { const provisionUpload: ProvisionUpload = { provision_name: provisionName, free_text: freeText, + list_items: listItems, + list_enabled: listEnabled, help_text: helpText, category: category, }; + console.log(provisionUpload); updateProvisionHandler(provisionUpload, provision.id); } }; @@ -103,21 +132,50 @@ const EditProvisionModalForm: React.FC = ({ - - - Free Text - - - - + + + {listEnabled ? ( + + + List Items + + {listItems.map((item, index) => ( +
+ + handleListItemChange(e, index)} + /> + + + + +
+ ))} +
+ +
+
+ ) : ( + + + Free Text + + + + + + )} + Help Text diff --git a/frontend/src/app/components/table/manage-provisions/ManageProvisionsTable.tsx b/frontend/src/app/components/table/manage-provisions/ManageProvisionsTable.tsx index 5dab34c9..5388f0ed 100644 --- a/frontend/src/app/components/table/manage-provisions/ManageProvisionsTable.tsx +++ b/frontend/src/app/components/table/manage-provisions/ManageProvisionsTable.tsx @@ -27,7 +27,6 @@ const ManageProvisionsTable: React.FC = ({ if (provisions) { const sortedData = basicSort(provisions); setAllProvisions(sortedData); - console.log(provisions[0]); } if (variables) { setAllVariables(variables); diff --git a/frontend/src/app/content/pages/LandingPage.tsx b/frontend/src/app/content/pages/LandingPage.tsx index af78866b..986349dd 100644 --- a/frontend/src/app/content/pages/LandingPage.tsx +++ b/frontend/src/app/content/pages/LandingPage.tsx @@ -334,6 +334,8 @@ const LandingPage: FC = () => { doc_type_provision_id: provision.id, provision_name: provision.provision_name, free_text: provision.free_text, + list_items: provision.list_items, + list_enabled: provision.list_enabled, }; }); const selectedVariables: Variable[] = variables.filter((variable) => selectedVariableIds.includes(variable.id)); diff --git a/frontend/src/app/content/pages/ManageProvisionsPage.tsx b/frontend/src/app/content/pages/ManageProvisionsPage.tsx index be9374e0..56c0d566 100644 --- a/frontend/src/app/content/pages/ManageProvisionsPage.tsx +++ b/frontend/src/app/content/pages/ManageProvisionsPage.tsx @@ -70,10 +70,12 @@ const ManageProvisionsPage: FC = () => { const updateProvisionHandler = async (provisionUpload: ProvisionUpload, provisionId: number) => { await updateProvision({ ...provisionUpload, id: provisionId }); + refreshTables(); }; const addProvisionHandler = async (provisionUpload: ProvisionUpload) => { await addProvision(provisionUpload); + refreshTables(); }; const removeProvisionHandler = async (id: number) => { await removeProvision(id); @@ -136,7 +138,6 @@ const ManageProvisionsPage: FC = () => { show={showAddProvisionModal} onHide={() => setShowAddProvisionModal(false)} addProvisionHandler={addProvisionHandler} - refreshTables={refreshTables} />