From 07576f3225e213e134bff92249066624042deab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 12 May 2022 10:55:42 +0200 Subject: [PATCH] Web: ensure switching active jobs doesn't retain previous job data Pinia's `$patch()` function will merge the given state with the current state, instead of doing a replacement. As a result, going from an active job with metadata fields `A` and `B`, to a job with metadata fields `B` and `C` would actually have fields `A`, `B`, and `C` in the Pinia store. This is resolved by replacing the `$patch(object)` with `$patch(function)` and having that function replace the entire job. --- web/app/src/stores/jobs.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/app/src/stores/jobs.js b/web/app/src/stores/jobs.js index 2267cdc4..12a98835 100644 --- a/web/app/src/stores/jobs.js +++ b/web/app/src/stores/jobs.js @@ -32,14 +32,20 @@ export const useJobs = defineStore('jobs', { actions: { setActiveJobID(jobID) { this.$patch({ - activeJob: {id: jobID}, + activeJob: {id: jobID, settings: {}, metadata: {}}, activeJobID: jobID, }); }, setActiveJob(job) { - this.$patch({ - activeJob: job, - activeJobID: job.id, + // The "function" form of $patch is necessary here, as otherwise it'll + // merge `job` into `state.activeJob`. As a result, it won't touch missing + // keys, which means that metadata fields that existed on the previous job + // but not on the new one will still linger around. By passing a function + // to `$patch` this is resolved. + this.$patch((state) => { + state.activeJob = job; + state.activeJobID = job.id; + state.hasChanged = true; }); }, deselectAllJobs() {