Skip to content

Commit 0d4e000

Browse files
feat: group and study unit (#1408)
* feat: display Groups and Study Unit inputs * fix: improve DDI pages * fix: format code
1 parent 45a9047 commit 0d4e000

29 files changed

+954
-414
lines changed

src/packages/modules-ddi/hooks/useCreatePhysicalInstance.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { useAppContext } from "../../application/app-context";
55
interface CreatePhysicalInstanceParams {
66
physicalInstanceLabel: string;
77
dataRelationshipName: string;
8+
groupId: string;
9+
groupAgency: string;
10+
studyUnitId: string;
11+
studyUnitAgency: string;
812
}
913

1014
interface TopLevelReference {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { DDIApi } from "../../sdk";
3+
4+
export interface StudyUnit {
5+
ID: string;
6+
Agency: string;
7+
Version: string;
8+
Citation: {
9+
Title: {
10+
String: {
11+
"@xml:lang": string;
12+
"#text": string;
13+
};
14+
};
15+
};
16+
}
17+
18+
interface GroupDetailsResponse {
19+
Group: Array<{
20+
ID: string;
21+
Agency: string;
22+
StudyUnitReference: Array<{
23+
Agency: string;
24+
ID: string;
25+
Version: string;
26+
TypeOfObject: string;
27+
}>;
28+
}>;
29+
StudyUnit: StudyUnit[];
30+
}
31+
32+
export function useGroupDetails(agencyId: string | null, groupId: string | null) {
33+
return useQuery<GroupDetailsResponse>({
34+
queryKey: ["group", agencyId, groupId],
35+
queryFn: () => DDIApi.getGroup(agencyId!, groupId!),
36+
enabled: !!agencyId && !!groupId,
37+
});
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { DDIApi } from "../../sdk";
3+
4+
export interface Group {
5+
id: string;
6+
label: string;
7+
versionDate: string;
8+
agency: string;
9+
}
10+
11+
export function useGroups() {
12+
return useQuery<Group[]>({
13+
queryKey: ["groups"],
14+
queryFn: () => DDIApi.getGroups(),
15+
});
16+
}

src/packages/modules-ddi/hooks/usePublishPhysicalInstance.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export function usePublishPhysicalInstance() {
1818
queryClient.invalidateQueries({
1919
queryKey: ["physicalInstanceById", variables.agencyId, variables.id],
2020
});
21+
// Invalider le cache des code lists pour qu'elles soient disponibles
22+
// immédiatement dans le sélecteur "Réutiliser une code list"
23+
queryClient.invalidateQueries({
24+
queryKey: ["codesLists"],
25+
});
2126
},
2227
});
2328
}

src/packages/modules-ddi/hooks/useUpdatePhysicalInstance.spec.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("useUpdatePhysicalInstance", () => {
5757
});
5858
});
5959

60-
it("should invalidate query cache on successful mutation", async () => {
60+
it("should not invalidate query cache to preserve local variables", async () => {
6161
const mockPatch = vi.fn().mockResolvedValue({});
6262
(DDIApi.patchPhysicalInstance as any) = mockPatch;
6363

@@ -78,11 +78,8 @@ describe("useUpdatePhysicalInstance", () => {
7878

7979
await result.current.mutateAsync(testData);
8080

81-
await waitFor(() => {
82-
expect(invalidateQueriesSpy).toHaveBeenCalledWith({
83-
queryKey: ["physicalInstanceById", "test-agency-456", "test-id-123"],
84-
});
85-
});
81+
// Le cache ne doit pas être invalidé pour préserver les variables locales non sauvegardées
82+
expect(invalidateQueriesSpy).not.toHaveBeenCalled();
8683
});
8784

8885
it("should handle API errors correctly", async () => {
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from "@tanstack/react-query";
1+
import { useMutation } from "@tanstack/react-query";
22
import { DDIApi } from "../../sdk";
33

44
interface UpdatePhysicalInstanceParams {
@@ -7,20 +7,18 @@ interface UpdatePhysicalInstanceParams {
77
data: {
88
physicalInstanceLabel: string;
99
dataRelationshipName: string;
10+
groupId: string;
11+
groupAgency: string;
12+
studyUnitId: string;
13+
studyUnitAgency: string;
1014
};
1115
}
1216

1317
export function useUpdatePhysicalInstance() {
14-
const queryClient = useQueryClient();
15-
1618
return useMutation({
1719
mutationFn: ({ id, agencyId, data }: UpdatePhysicalInstanceParams) =>
1820
DDIApi.patchPhysicalInstance(agencyId, id, data),
19-
onSuccess: (_, variables) => {
20-
// Invalider le cache pour rafraîchir les données
21-
queryClient.invalidateQueries({
22-
queryKey: ["physicalInstanceById", variables.agencyId, variables.id],
23-
});
24-
},
21+
// Ne pas invalider le cache ici car cela écraserait les variables locales
22+
// non sauvegardées. Le titre est mis à jour localement via le state du composant.
2523
});
2624
}

src/packages/modules-ddi/i18n/locales/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"create": "Create",
66
"errorMessage": "An error occurred during creation",
77
"errorTitle": "Creation error",
8+
"group": "Group",
89
"label": "Label",
10+
"selectGroup": "Select a group",
11+
"selectStudyUnit": "Select a study unit",
12+
"studyUnit": "Study Unit",
913
"successMessage": "Your changes have been successfully saved",
1014
"successTitle": "Creation successful",
1115
"title": "Create a new physical instance"
@@ -132,6 +136,8 @@
132136
},
133137
"variableUpdateSuccess": "Variable updated",
134138
"variableUpdateSuccessDetail": "Variable successfully updated. Remember to save",
139+
"previousVariable": "Previous variable",
140+
"nextVariable": "Next variable",
135141
"totalVariables": "Total: {{count}} variable(s)",
136142
"unsavedChangesTitle": "Unsaved changes",
137143
"unsavedChangesMessage": "You have unsaved changes. Are you sure you want to leave this page?",

src/packages/modules-ddi/i18n/locales/fr.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"create": "Créer",
66
"errorMessage": "Une erreur est survenue lors de la création",
77
"errorTitle": "Erreur de création",
8+
"group": "Groupe",
89
"label": "Libellé",
10+
"selectGroup": "Sélectionnez un groupe",
11+
"selectStudyUnit": "Sélectionnez une étude",
12+
"studyUnit": "Étude",
913
"successMessage": "Vos modifications ont été sauvegardées avec succès",
1014
"successTitle": "Création réussie",
1115
"title": "Créer un nouveau fichier de données"
@@ -131,6 +135,8 @@
131135
},
132136
"variableUpdateSuccess": "Variable mise à jour",
133137
"variableUpdateSuccessDetail": "Variable mise à jour avec succès. Pensez à sauvegarder",
138+
"previousVariable": "Variable précédente",
139+
"nextVariable": "Variable suivante",
134140
"variablesTable": "Tableau des variables",
135141
"totalVariables": "Total : {{count}} variable(s)",
136142
"unsavedChangesTitle": "Modifications non sauvegardées",

src/packages/modules-ddi/physical-instances/components/CodeRepresentation/CodeListDataTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export const CodeListDataTable = ({
147147
<InputText
148148
id="code-list-label"
149149
name="codeListLabel"
150+
autoComplete="off"
150151
value={codeListLabel}
151152
onChange={(e) => onCodeListLabelChange(e.target.value)}
152153
/>

src/packages/modules-ddi/physical-instances/components/CodeRepresentation/ReuseCodeListSelect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const ReuseCodeListSelect = ({
2222

2323
if (isLoadingCodesLists) {
2424
return (
25-
<div className="flex align-items-center gap-2">
26-
<ProgressSpinner style={{ width: "20px", height: "20px" }} strokeWidth="4" />
25+
<div className="flex gap-2">
26+
<ProgressSpinner style={{ width: "20px", height: "20px", margin: "0" }} strokeWidth="4" />
2727
<span>{t("physicalInstance.view.code.loadingCodesLists")}</span>
2828
</div>
2929
);

0 commit comments

Comments
 (0)