Skip to content

Commit 5696afd

Browse files
Merge pull request #1424 from InseeFr/fix/reset-codes-list-form
fix: reset codes list form
2 parents 4ed0b61 + 5b691ee commit 5696afd

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/packages/modules-ddi/physical-instances/components/CodeRepresentation/CodeRepresentation.reducer.spec.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,28 @@ describe("codeRepresentationReducer", () => {
276276
expect(result.showDataTable).toBe(false);
277277
expect(result.codes).toEqual([]);
278278
});
279+
280+
it("should reset showReuseSelect to false when initializing from code list", () => {
281+
const stateWithReuseSelect: CodeRepresentationState = {
282+
...initialState,
283+
showReuseSelect: true,
284+
selectedCodeListId: "some-id",
285+
};
286+
const action: CodeRepresentationAction = {
287+
type: "INIT_FROM_CODE_LIST",
288+
payload: {
289+
label: "New List",
290+
codes: [],
291+
showDataTable: true,
292+
},
293+
};
294+
295+
const result = codeRepresentationReducer(stateWithReuseSelect, action);
296+
297+
expect(result.showReuseSelect).toBe(false);
298+
expect(result.selectedCodeListId).toBeNull();
299+
expect(result.showDataTable).toBe(true);
300+
});
279301
});
280302

281303
describe("INIT_REUSED_CODE_LIST", () => {
@@ -308,16 +330,16 @@ describe("codeRepresentationReducer", () => {
308330
expect(result.showReuseSelect).toBe(true);
309331
});
310332

311-
it("should preserve other state properties", () => {
333+
it("should reset state to initial values except for selectedCodeListId and showReuseSelect", () => {
312334
const action: CodeRepresentationAction = {
313335
type: "INIT_REUSED_CODE_LIST",
314336
payload: { selectedCodeListId: "agency-list-id" },
315337
};
316338

317339
const result = codeRepresentationReducer(stateWithCodes, action);
318340

319-
expect(result.codes).toEqual(stateWithCodes.codes);
320-
expect(result.codeListLabel).toBe(stateWithCodes.codeListLabel);
341+
expect(result.codes).toEqual([]);
342+
expect(result.codeListLabel).toBe("");
321343
});
322344
});
323345

src/packages/modules-ddi/physical-instances/components/CodeRepresentation/CodeRepresentation.reducer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,17 @@ export const codeRepresentationReducer = (
8484

8585
case "INIT_FROM_CODE_LIST":
8686
return {
87-
...state,
87+
...initialState,
8888
codeListLabel: action.payload.label,
8989
codes: action.payload.codes,
9090
showDataTable: action.payload.showDataTable,
9191
};
9292

9393
case "INIT_REUSED_CODE_LIST":
9494
return {
95-
...state,
95+
...initialState,
9696
selectedCodeListId: action.payload.selectedCodeListId,
9797
showReuseSelect: true,
98-
showDataTable: false,
9998
};
10099

101100
default:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const CodeRepresentation = ({
4444
});
4545

4646
const { codeListLabel, codes, showDataTable, showReuseSelect, selectedCodeListId } = state;
47-
4847
useEffect(() => {
4948
if (codeList) {
5049
// Cas où on a une codeList complète (création ou liste existante chargée)

0 commit comments

Comments
 (0)