Skip to content

Commit

Permalink
Assure que les pages sont ordonnées avant de changer d'onglets (#877)
Browse files Browse the repository at this point in the history
* make sure pages are ordered when changing pages tabs

* create a computed for ordered pages

* sort audit pages in store

* update changelog
  • Loading branch information
bellangerq authored Nov 22, 2024
1 parent e3b6b52 commit f7f5609
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Tous les changements notables de Ara sont documentés ici avec leur date, leur c

### Corrections 🐛

- Corrige le problème des filtres des critères qui décalait l’ordre des pages de l’échantillon sur la page d’audit ([#877](https://github.com/DISIC/Ara/pull/877))
- Corrige la "fausse" mise à jour des paramètres de l’audit quand on quitte la page sans sauvegarder ([#875](https://github.com/DISIC/Ara/pull/875))

## 21/11/2024
Expand Down
16 changes: 7 additions & 9 deletions confiture-web-app/src/pages/audit/AuditGenerationPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { sortBy } from "lodash-es";
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { onBeforeRouteLeave, useRoute } from "vue-router";
Expand Down Expand Up @@ -82,7 +81,9 @@ function updateCurrentPageId(i: number) {
auditStore.updateCurrentPageId(
i === 0
? auditStore.currentAudit?.transverseElementsPage.id ?? null
: auditStore.currentAudit?.pages.at(i - 1)?.id ?? null
: auditStore.currentAudit?.pages
? auditStore.currentAudit?.pages.at(i - 1)?.id ?? null
: null
);
}
Expand Down Expand Up @@ -218,13 +219,10 @@ const tabsData = computed((): TabData[] => {
...(transversePage
? [{ label: transversePage?.name, data: transversePage }]
: []),
...sortBy(
auditStore.currentAudit?.pages.map((p) => ({
label: p.name,
data: p
})) ?? [],
(p) => p.data.order
)
...(auditStore.currentAudit?.pages.map((p) => ({
label: p.name,
data: p
})) ?? [])
];
});
</script>
Expand Down
14 changes: 11 additions & 3 deletions confiture-web-app/src/store/audit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ky from "ky";
import { sortBy } from "lodash-es";
import { defineStore } from "pinia";

import {
Expand Down Expand Up @@ -60,13 +61,20 @@ export const useAuditStore = defineStore("audit", {
return response;
},

setAudit(id: string, audit: Audit) {
this.entities[id] = {
...audit,
pages: sortBy(audit.pages, "order")
};
},

async fetchAudit(editUniqueId: string) {
this.currentAuditId = editUniqueId;
const data = (await ky
.get(`/api/audits/${editUniqueId}`)
.json()) as Audit;

this.entities[editUniqueId] = data;
this.setAudit(editUniqueId, data);
},

async fetchAuditIfNeeded(editUniqueId: string) {
Expand All @@ -86,7 +94,7 @@ export const useAuditStore = defineStore("audit", {
json: data
})
.json()) as Audit;
this.entities[uniqueId] = response;
this.setAudit(uniqueId, response);
return response;
},

Expand Down Expand Up @@ -163,7 +171,7 @@ export const useAuditStore = defineStore("audit", {
const response = (await ky
.put(`/api/audits/${uniqueId}/publish`)
.json()) as Audit;
this.entities[uniqueId] = response;
this.setAudit(uniqueId, response);
return response;
},

Expand Down

0 comments on commit f7f5609

Please sign in to comment.