Unverified Commit decc3cb0 authored by Dannon's avatar Dannon Committed by GitHub
Browse files

Merge pull request #14307 from davelopez/22.05_fix_history_switch_defaul_sorting

[22.05] Sort histories in history switcher by most recently updated
parents c811c17c c87a9a37
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
            :per-page="perPage"
            :current-page="currentPage"
            :selectable="true"
            :sort-by.sync="sortBy"
            :sort-desc.sync="sortDesc"
            :sort-compare="currentFirstSortCompare"
            select-mode="single"
            selected-variant="success"
            @row-selected="switchToHistory"
@@ -58,6 +61,8 @@ export default {
            filter: null,
            currentPage: 1,
            totalRows: 0,
            sortBy: "update_time",
            sortDesc: true,
        };
    },
    computed: {
@@ -92,6 +97,17 @@ export default {
            this.totalRows = filteredItems.length;
            this.currentPage = 1;
        },
        /** Make the current history appear always first when sorting. */
        currentFirstSortCompare(a, b, key, sortDesc) {
            if (a.id == this.currentHistoryId) {
                return sortDesc ? 1 : -1;
            } else if (b.id == this.currentHistoryId) {
                return sortDesc ? -1 : 1;
            } else {
                // Fallback to default sorting
                return false;
            }
        },
    },
};
</script>