Commit ab08b143 authored by guerler's avatar guerler
Browse files

Fix history action names, revise handling, reduce requests

parent f9a07649
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ export class HistoryPanelProxy {
    }
    switchToHistory(historyId) {
        this.model.id = historyId;
        store.dispatch("history/setCurrentHistoryId", historyId);
        store.dispatch("history/setCurrentHistory", historyId);
    }
    async buildCollection(collectionType, selection, hideSourceItems, fromRulesInput = false) {
        let selectionContent = null;
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ export default {
            "createNewHistory",
            "updateHistory",
            "deleteHistory",
            "setCurrentHistoryId",
            "setCurrentHistory",
            "setHistory",
            "loadHistories",
            "secureHistory",
@@ -73,7 +73,7 @@ export default {
                setHistory: this.setHistory,

                // select new history, basically just needs the id
                setCurrentHistory: (h) => this.setCurrentHistoryId(h.id),
                setCurrentHistory: (h) => this.setCurrentHistory(h.id),

                // create new history then select it
                createNewHistory: this.createNewHistory,
+14 −23
Original line number Diff line number Diff line
@@ -75,11 +75,9 @@ const getters = {
    },
};

// Holds promises for in-flight loads
const promises = {
    load: null,
    byId: new Map(),
};
// flags to keep track of loading states
const isLoadingHistory = new Map();
let isLoadingHistories = false;

const actions = {
    async copyHistory({ dispatch }, { history, name, copyAll }) {
@@ -95,7 +93,7 @@ const actions = {
        const deletedHistory = await deleteHistoryById(history.id, purge);
        commit("deleteHistory", deletedHistory);
        if (getters.firstHistoryId) {
            return dispatch("setCurrentHistoryId", getters.firstHistoryId);
            return dispatch("setCurrentHistory", getters.firstHistoryId);
        } else {
            return dispatch("createNewHistory");
        }
@@ -104,9 +102,9 @@ const actions = {
        getCurrentHistoryFromServer().then((history) => dispatch("selectHistory", history));
    },
    loadHistories({ commit }) {
        if (!promises.load) {
        if (!isLoadingHistories) {
            commit("setHistoriesLoading", true);
            promises.load = getHistoryList()
            isLoadingHistories = getHistoryList()
                .then((list) => {
                    commit("setHistories", list);
                })
@@ -114,31 +112,24 @@ const actions = {
                    console.warn("loadHistories error", err);
                })
                .finally(() => {
                    promises.load = null;
                    isLoadingHistories = null;
                    commit("setHistoriesLoading", false);
                });
        }
    },
    loadHistoryById({ commit, getters, dispatch }, id) {
        if (!promises.byId.has(id)) {
            // immediately set if we have something current
            const existing = getters.getHistoryById(id);
            if (existing) {
                commit("setHistory", existing);
            }

            // but also check for updates
    loadHistoryById({ dispatch }, id) {
        if (!isLoadingHistory.has(id)) {
            const p = getHistoryById(id)
                .then((history) => {
                    dispatch("selectHistory", history);
                    dispatch("setHistory", history);
                })
                .catch((err) => {
                    console.warn("loadHistoryById error", id, err);
                })
                .finally(() => {
                    promises.byId.delete(id);
                    isLoadingHistory.delete(id);
                });
            promises.byId.set(id, p);
            isLoadingHistory.set(id, p);
        }
    },
    resetHistory({ commit }) {
@@ -153,10 +144,10 @@ const actions = {
        commit("setHistory", history);
        commit("setCurrentHistoryId", history.id);
    },
    async setCurrentHistoryId({ dispatch, getters }, id) {
    async setCurrentHistory({ dispatch, getters }, id) {
        if (id !== getters.currentHistoryId) {
            const changedHistory = await setCurrentHistoryOnServer(id);
            dispatch("loadHistoryById", changedHistory.id);
            dispatch("selectHistory", changedHistory);
        }
    },
    setHistory({ commit }, history) {