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.
This commit is contained in:
parent
47361cdc69
commit
07576f3225
@ -32,14 +32,20 @@ export const useJobs = defineStore('jobs', {
|
|||||||
actions: {
|
actions: {
|
||||||
setActiveJobID(jobID) {
|
setActiveJobID(jobID) {
|
||||||
this.$patch({
|
this.$patch({
|
||||||
activeJob: {id: jobID},
|
activeJob: {id: jobID, settings: {}, metadata: {}},
|
||||||
activeJobID: jobID,
|
activeJobID: jobID,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setActiveJob(job) {
|
setActiveJob(job) {
|
||||||
this.$patch({
|
// The "function" form of $patch is necessary here, as otherwise it'll
|
||||||
activeJob: job,
|
// merge `job` into `state.activeJob`. As a result, it won't touch missing
|
||||||
activeJobID: job.id,
|
// 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() {
|
deselectAllJobs() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user