Skip to content

Commit 530c4e6

Browse files
authored
Merge pull request #1145 from david-roper/subject-id-fix
Allow for subject id display length to be changes as a group setting
2 parents c26feeb + ba0d827 commit 530c4e6

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

apps/api/prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type GroupSettings {
6868
defaultIdentificationMethod SubjectIdentificationMethod
6969
idValidationRegex String?
7070
idValidationRegexErrorMessage ErrorMessage?
71+
subjectIdDisplayLength Int?
7172
}
7273

7374
model Group {
@@ -82,7 +83,7 @@ model Group {
8283
settings GroupSettings
8384
sessions Session[]
8485
subjects Subject[] @relation(fields: [subjectIds], references: [id])
85-
subjectIds String[]
86+
subjectIds String[]
8687
type GroupType
8788
userIds String[] @db.ObjectId
8889
users User[] @relation(fields: [userIds], references: [id])

apps/web/src/features/datahub/components/MasterDataTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
44
import type { Subject } from '@opendatacapture/schemas/subject';
55
import { removeSubjectIdScope } from '@opendatacapture/subject-utils';
66

7+
import { useAppStore } from '@/store';
8+
79
export type MasterDataTableProps = {
810
data: Subject[];
911
onSelect: (subject: Subject) => void;
1012
};
1113

1214
export const MasterDataTable = ({ data, onSelect }: MasterDataTableProps) => {
1315
const { t } = useTranslation();
16+
const subjectIdDisplaySetting = useAppStore((store) => store.currentGroup?.settings.subjectIdDisplayLength);
1417
return (
1518
<ClientTable<Subject>
1619
columns={[
1720
{
18-
field: (subject) => removeSubjectIdScope(subject.id).slice(0, 9),
21+
field: (subject) => removeSubjectIdScope(subject.id).slice(0, subjectIdDisplaySetting ?? 9),
1922
label: t('datahub.index.table.subject')
2023
},
2124
{

apps/web/src/features/datahub/components/SubjectLayout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Outlet, useParams } from 'react-router-dom';
88
import { LoadingFallback } from '@/components/LoadingFallback';
99
import { PageHeader } from '@/components/PageHeader';
1010
import { config } from '@/config';
11+
import { useAppStore } from '@/store';
1112

1213
import { TabLink } from './TabLink';
1314

@@ -16,6 +17,7 @@ export const SubjectLayout = () => {
1617
const { t } = useTranslation('datahub');
1718
const subjectId = params.subjectId!;
1819
const basePathname = `/datahub/${subjectId}`;
20+
const subjectIdDisplaySetting = useAppStore((store) => store.currentGroup?.settings.subjectIdDisplayLength);
1921

2022
return (
2123
<React.Fragment>
@@ -26,7 +28,7 @@ export const SubjectLayout = () => {
2628
en: 'Instrument Records for Subject {}',
2729
fr: "Dossiers d'instruments pour le client {}"
2830
},
29-
removeSubjectIdScope(subjectId).slice(0, 9)
31+
removeSubjectIdScope(subjectId).slice(0, subjectIdDisplaySetting ?? 9)
3032
)}
3133
</Heading>
3234
</PageHeader>

apps/web/src/features/group/components/ManageGroupForm.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type ManageGroupFormProps = {
2222
accessibleInteractiveInstrumentIds: Set<string>;
2323
defaultIdentificationMethod?: SubjectIdentificationMethod;
2424
idValidationRegex?: null | string;
25+
subjectIdDisplayLength?: number;
2526
};
2627
};
2728
onSubmit: (data: Partial<UpdateGroupData>) => Promisable<any>;
@@ -59,6 +60,22 @@ export const ManageGroupForm = ({ data, onSubmit, readOnly }: ManageGroupFormPro
5960
},
6061
title: t('group.manage.accessibleInstruments')
6162
},
63+
{
64+
fields: {
65+
subjectIdDisplayLength: {
66+
kind: 'number',
67+
label: t({
68+
en: 'Preferred Subject ID Display Length',
69+
fr: "La longueur d'affichage préférée de l'ID"
70+
}),
71+
variant: 'input'
72+
}
73+
},
74+
title: t({
75+
en: 'Display Settings',
76+
fr: "Paramètres d'affichage"
77+
})
78+
},
6279
{
6380
fields: {
6481
defaultIdentificationMethod: {
@@ -129,7 +146,8 @@ export const ManageGroupForm = ({ data, onSubmit, readOnly }: ManageGroupFormPro
129146
defaultIdentificationMethod: $SubjectIdentificationMethod.optional(),
130147
idValidationRegex: $RegexString.optional(),
131148
idValidationRegexErrorMessageEn: z.string().optional(),
132-
idValidationRegexErrorMessageFr: z.string().optional()
149+
idValidationRegexErrorMessageFr: z.string().optional(),
150+
subjectIdDisplayLength: z.number().int().min(1)
133151
})}
134152
onSubmit={(data) => {
135153
void onSubmit({
@@ -140,7 +158,8 @@ export const ManageGroupForm = ({ data, onSubmit, readOnly }: ManageGroupFormPro
140158
idValidationRegexErrorMessage: {
141159
en: data.idValidationRegexErrorMessageEn,
142160
fr: data.idValidationRegexErrorMessageFr
143-
}
161+
},
162+
subjectIdDisplayLength: data.subjectIdDisplayLength
144163
}
145164
});
146165
}}

packages/schemas/src/group/group.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const $GroupSettings = z.object({
1212
en: z.string().nullish(),
1313
fr: z.string().nullish()
1414
})
15-
.nullish()
15+
.nullish(),
16+
subjectIdDisplayLength: z.number().nullish()
1617
});
1718

1819
export type GroupType = z.infer<typeof $GroupType>;

0 commit comments

Comments
 (0)