Skip to content

Commit 3b131a3

Browse files
(feat) Add configuration option to disable group sessions for specific form (#104)
1 parent 6182e3a commit 3b131a3

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

Diff for: src/config-schema.ts

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const configSchema = {
2626
_type: Type.String,
2727
_description: 'Name of form',
2828
},
29+
disableGroupSession: {
30+
_type: Type.Boolean,
31+
_description: 'Disable group sessions for this form',
32+
_default: false,
33+
},
2934
},
3035
},
3136
},
@@ -36,6 +41,7 @@ export const configSchema = {
3641
{
3742
formUUID: '0cefb866-110c-4f16-af58-560932a1db1f',
3843
name: 'Adult Triage',
44+
disableGroupSession: false,
3945
},
4046
],
4147
},
@@ -45,6 +51,7 @@ export const configSchema = {
4551
{
4652
formUUID: '9f26aad4-244a-46ca-be49-1196df1a8c9a',
4753
name: 'POC Sample Form 1',
54+
disableGroupSession: false,
4855
},
4956
],
5057
},
@@ -126,6 +133,7 @@ export const configSchema = {
126133
export type Form = {
127134
formUUID: Type.UUID;
128135
name: Type.String;
136+
disableGroupSession: Type.Boolean;
129137
};
130138

131139
export type Category = {

Diff for: src/forms-page/FormsPage.tsx

+24-12
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,37 @@ export const getFormPermissions = (forms) => {
2424
return output;
2525
};
2626

27-
// Function adds `id` field to rows so they will be accepted by DataTable
28-
// "display" is prefered for display name if present, otherwise fall back on "name'"
29-
const prepareRowsForTable = (rawFormData) => {
30-
if (rawFormData) {
31-
return rawFormData?.map((form) => ({
32-
...form,
33-
id: form.uuid,
34-
display: form.display || form.name,
35-
}));
36-
}
37-
return null;
27+
/**
28+
* Prepares the raw form data to be used in a DataTable.
29+
* Adds an `id` field based on the `uuid` property of the form.
30+
* Sets the `display` field based on the `display` property if present, otherwise falls back to the `name` field.
31+
* Also attaches the `disableGroupSession` flag from form categories config, if available.
32+
*
33+
* @param {Array} rawFormData
34+
* @param {Array} formCategories
35+
* @returns {Array}
36+
*/
37+
const prepareRowsForTable = (rawFormData = [], formCategories = []) => {
38+
const formCategoryMap = new Map(
39+
formCategories.flatMap(({ forms }) =>
40+
forms.map(({ formUUID, disableGroupSession }) => [formUUID, disableGroupSession]),
41+
),
42+
);
43+
44+
return rawFormData.map((form) => ({
45+
...form,
46+
id: form.uuid,
47+
display: form.display || form.name,
48+
disableGroupSession: formCategoryMap.get(form.uuid),
49+
}));
3850
};
3951

4052
const FormsPage = () => {
4153
const config = useConfig();
4254
const { t } = useTranslation();
4355
const { formCategories, formCategoriesToShow } = config;
4456
const { forms, isLoading, error } = useGetAllForms();
45-
const cleanRows = prepareRowsForTable(forms);
57+
const cleanRows = prepareRowsForTable(forms, formCategories);
4658
const { user } = useSession();
4759
const savedFormsData = localStorage.getItem(fdeWorkflowStorageName + ':' + user?.uuid);
4860
const savedGroupFormsData = localStorage.getItem(fdeGroupWorkflowStorageName + ':' + user?.uuid);

Diff for: src/forms-page/forms-table/FormsTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const FormsTable = ({ rows, error, isLoading, activeForms, activeGroupForms }) =
4545
{activeForms.includes(row.uuid) ? t('resumeSession', 'Resume Session') : t('fillForm', 'Fill Form')}
4646
</Link>
4747
),
48-
actions2: (
48+
actions2: !row.disableGroupSession && (
4949
<Link to={`groupform/${row.uuid}`}>
5050
{activeGroupForms.includes(row.uuid)
5151
? t('resumeGroupSession', 'Resume Group Session')

0 commit comments

Comments
 (0)