Skip to content

Commit

Permalink
Merge branch 'release_23.1' into release_23.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Feb 18, 2024
2 parents 29f7a29 + 3308279 commit b83b8bb
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions client/src/store/historyStore/datasetStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Vue from "vue";
import { urlData } from "utils/url";

const state = {
items: {},
};

const getters = {
getDataset:
(state) =>
({ id }) => {
return state.items[id] || { hid: 0, name: "Wait..." };
},
};

const actions = {
fetchDataset: async ({ state, commit }, { id }) => {
if (!state.items[id]) {
const url = `/api/datasets/${id}`;
const dataset = await urlData({ url });
commit("saveDataset", { id, dataset });
}
},
};

const mutations = {
/**
* Adds a new dataset.
* @param {Array} dataset as returned by the datasets api (detailed serialization)
*/
saveDataset: (state, { id, dataset }) => {
Vue.set(state.items, id, dataset);
},
/**
* Updates existing datasets. This is called by the history changed items store.
* @param {Array} payload as returned by the history contents api (detailed serialization)
*/
saveDatasets: (state, { payload }) => {
payload.forEach((item) => {
if (item.history_content_type == "dataset") {
const id = item.id;
if (state.items[id]) {
const localItem = state.items[id];
Object.keys(item).forEach((key) => {
localItem[key] = item[key];
});
}
}
});
},
};

export const datasetStore = {
state,
getters,
actions,
mutations,
};

0 comments on commit b83b8bb

Please sign in to comment.