Skip to content

Commit

Permalink
make list separate from free text
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Sep 24, 2024
1 parent f34d0a6 commit 3c42e7f
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 140 deletions.
1 change: 0 additions & 1 deletion backend/src/provision/dto/create-provision.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class CreateProvisionDto extends PickType(ProvisionDto, [
'provision_name',
'free_text',
'list_items',
'list_enabled',
'help_text',
'category',
'sequence_value',
Expand Down
1 change: 0 additions & 1 deletion backend/src/provision/dto/provision.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export class ProvisionDto {
provision_name?: string;
free_text?: string;
list_items?: string[];
list_enabled?: boolean;
help_text?: string;
category?: string;
sequence_value?: number;
Expand Down
1 change: 0 additions & 1 deletion backend/src/provision/dto/update-provision.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class UpdateProvisionDto extends PickType(ProvisionDto, [
'provision_name',
'free_text',
'list_items',
'list_enabled',
'help_text',
'category',
'sequence_value',
Expand Down
5 changes: 0 additions & 5 deletions backend/src/provision/entities/provision.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export class Provision {
@Column({ type: 'text', array: true, default: '{}' })
list_items: string[];

@Column({ nullable: true })
list_enabled: boolean;

@Column({ nullable: true })
help_text: string;

Expand Down Expand Up @@ -66,7 +63,6 @@ export class Provision {
provision_name?: string,
free_text?: string,
list_items?: string[],
list_enabled?: boolean,
category?: string,
active_flag?: boolean,
create_userid?: string,
Expand All @@ -75,7 +71,6 @@ 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 || '';
Expand Down
1 change: 0 additions & 1 deletion backend/src/provision/provision.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class ProvisionController {
provision: string;
free_text: string;
list_items: string[];
list_enabled: boolean;
help_text: string;
category: string;
},
Expand Down
2 changes: 0 additions & 2 deletions backend/src/provision/provision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class ProvisionService {
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;
Expand Down Expand Up @@ -275,7 +274,6 @@ export class ProvisionService {
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,
Expand Down
9 changes: 2 additions & 7 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class ReportService {
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 }) => {
provisionJson.forEach(({ provision_name, provision_group, free_text, list_items }) => {
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) {
Expand Down Expand Up @@ -192,12 +192,7 @@ export class ReportService {
provisions[key] = [];
}

// 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: [] });
}
provisions[key].push({ provision_name, free_text, list });
});

// get the TTLS DB_ variables
Expand Down
2 changes: 0 additions & 2 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type ProvisionJSON = {
provision_group: number;
free_text: string;
list_items: string[];
list_enabled: boolean;
provision_id: number;
sequence_value: number;
doc_type_provision_id: number;
Expand Down Expand Up @@ -62,7 +61,6 @@ export type ManageDocTypeProvision = {
provision_name: string;
free_text: string;
list_items: string[];
list_enabled: boolean;
help_text: string;
category: string;
active_flag: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
const [provisionName, setProvisionName] = useState<string>('');
const [freeText, setFreeText] = useState<string>('');
const [listItems, setListItems] = useState<string[]>(['']);
const [listEnabled, setListEnabled] = useState<boolean>(false);
const [helpText, setHelpText] = useState<string>('');
const [category, setCategory] = useState<string>('');

Expand All @@ -35,10 +34,6 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
setCategory(e.target.value);
};

const handleListEnabledChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setListEnabled(e.target.checked);
};

const handleListItemChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, index: number) => {
const newListItems = [...listItems];
newListItems[index] = e.target.value;
Expand All @@ -62,8 +57,7 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
const provisionUpload: ProvisionUpload = {
provision_name: provisionName,
free_text: freeText,
list_items: listEnabled ? listItems : [],
list_enabled: listEnabled,
list_items: listItems ? listItems : [],
help_text: helpText,
category: category,
};
Expand All @@ -80,7 +74,6 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio

const handleOnHide = () => {
onHide();
setListEnabled(false);
setListItems(['']);
};

Expand Down Expand Up @@ -112,55 +105,43 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
</Col>
</Form.Group>

<Form.Group className="mb-3" style={{ marginLeft: '15px', marginTop: '30px' }}>
<Form.Check
type="checkbox"
id="listEnabledCheckbox"
label={<label htmlFor="listEnabledCheckbox">Enable List</label>}
checked={listEnabled}
onChange={handleListEnabledChange}
/>
<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control as="textarea" rows={3} name="free_text" onChange={handleFreeTextChange} />
</Col>
</Form.Group>

{listEnabled ? (
<Form.Group className="mb-3">
<Form.Label column sm="12">
List Items
</Form.Label>
{listItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<Col sm="10">
<Form.Control
as="input"
type="text"
name={`list_item_${index}`}
value={item}
onChange={(e) => handleListItemChange(e, index)}
/>
</Col>
<Col sm="2">
<Button variant="link" onClick={() => handleRemoveListItem(index)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
</Col>
</div>
))}
<div style={{ marginLeft: '15px' }}>
<Button variant="success" onClick={handleAddListItem}>
<FontAwesomeIcon icon={faPlus} />
</Button>
<Form.Group className="mb-3">
<Form.Label column sm="12">
List Items
</Form.Label>
{listItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<Col sm="10">
<Form.Control
as="input"
type="text"
name={`list_item_${index}`}
value={item}
onChange={(e) => handleListItemChange(e, index)}
/>
</Col>
<Col sm="2">
<Button variant="link" onClick={() => handleRemoveListItem(index)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
</Col>
</div>
</Form.Group>
) : (
<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control as="textarea" rows={3} name="free_text" onChange={handleFreeTextChange} />
</Col>
</Form.Group>
)}
))}
<div style={{ marginLeft: '15px' }}>
<Button variant="success" onClick={handleAddListItem}>
<FontAwesomeIcon icon={faPlus} />
</Button>
</div>
</Form.Group>

<Form.Group className="mb-3">
<Form.Label column sm="12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const EditProvisionModalForm: React.FC<EditProvisionModalFormProps> = ({
const [provisionName, setProvisionName] = useState<string>('');
const [freeText, setFreeText] = useState<string>('');
const [listItems, setListItems] = useState<string[]>(['']);
const [listEnabled, setListEnabled] = useState<boolean>(false);
const [helpText, setHelpText] = useState<string>('');
const [category, setCategory] = useState<string>('');

Expand All @@ -39,7 +38,6 @@ const EditProvisionModalForm: React.FC<EditProvisionModalFormProps> = ({
setProvisionName(provision.provision_name);
setFreeText(provision.free_text);
setListItems(provision.list_items);
setListEnabled(provision.list_enabled);
setHelpText(provision.help_text);
setCategory(provision.category);
}
Expand All @@ -64,10 +62,6 @@ const EditProvisionModalForm: React.FC<EditProvisionModalFormProps> = ({
setCategory(e.target.value);
};

const handleListEnabledChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setListEnabled(e.target.checked);
};

const handleListItemChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, index: number) => {
const newListItems = [...listItems];
newListItems[index] = e.target.value;
Expand All @@ -90,7 +84,6 @@ const EditProvisionModalForm: React.FC<EditProvisionModalFormProps> = ({
provision_name: provisionName,
free_text: freeText,
list_items: listItems,
list_enabled: listEnabled,
help_text: helpText,
category: category,
};
Expand Down Expand Up @@ -131,61 +124,49 @@ const EditProvisionModalForm: React.FC<EditProvisionModalFormProps> = ({
</Col>
</Form.Group>

<Form.Group className="mb-3" style={{ marginLeft: '15px', marginTop: '30px' }}>
<Form.Check
type="checkbox"
id="listEnabledCheckbox"
label={<label htmlFor="listEnabledCheckbox">Enable List</label>}
checked={listEnabled}
onChange={handleListEnabledChange}
/>
<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control
as="textarea"
defaultValue={freeText}
rows={3}
name="free_text"
onChange={handleFreeTextChange}
/>
</Col>
</Form.Group>

{listEnabled ? (
<Form.Group className="mb-3">
<Form.Label column sm="12">
List Items
</Form.Label>
{listItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<Col sm="10">
<Form.Control
as="input"
type="text"
name={`list_item_${index}`}
value={item}
onChange={(e) => handleListItemChange(e, index)}
/>
</Col>
<Col sm="2">
<Button variant="link" onClick={() => handleRemoveListItem(index)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
</Col>
</div>
))}
<div style={{ marginLeft: '15px' }}>
<Button variant="success" onClick={handleAddListItem}>
<FontAwesomeIcon icon={faPlus} />
</Button>
<Form.Group className="mb-3">
<Form.Label column sm="12">
List Items
</Form.Label>
{listItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<Col sm="10">
<Form.Control
as="input"
type="text"
name={`list_item_${index}`}
value={item}
onChange={(e) => handleListItemChange(e, index)}
/>
</Col>
<Col sm="2">
<Button variant="link" onClick={() => handleRemoveListItem(index)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
</Col>
</div>
</Form.Group>
) : (
<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control
as="textarea"
defaultValue={freeText}
rows={3}
name="free_text"
onChange={handleFreeTextChange}
/>
</Col>
</Form.Group>
)}
))}
<div style={{ marginLeft: '15px' }}>
<Button variant="success" onClick={handleAddListItem}>
<FontAwesomeIcon icon={faPlus} />
</Button>
</div>
</Form.Group>

<Form.Group className="mb-3">
<Form.Label column sm="12">
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/content/pages/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ const LandingPage: FC = () => {
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));
Expand Down
Loading

0 comments on commit 3c42e7f

Please sign in to comment.