Commit 398f7731 authored by davelopez's avatar davelopez
Browse files

Add mixin to reuse extended history properties

The computed properties in the mixin avoid console errors when the history properties haven't been loaded yet.
parent c88e1a15
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
            class="rounded-0 text-decoration-none"
            @click="onDashboard">
            <icon icon="database" />
            <span>{{ history.size | niceFileSize }}</span>
            <span>{{ historySize | niceFileSize }}</span>
        </b-button>
        <b-button-group>
            <b-button
@@ -19,10 +19,10 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('')">
                <span class="fa fa-map-marker" />
                <span>{{ history.contents_active.active }}</span>
                <span>{{ numItemsActive }}</span>
            </b-button>
            <b-button
                v-if="history.contents_active.deleted"
                v-if="numItemsDeleted"
                v-b-tooltip.hover
                title="Show deleted"
                variant="link"
@@ -30,10 +30,10 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('deleted:true')">
                <icon icon="trash" />
                <span>{{ history.contents_active.deleted }}</span>
                <span>{{ numItemsDeleted }}</span>
            </b-button>
            <b-button
                v-if="history.contents_active.hidden"
                v-if="numItemsHidden"
                v-b-tooltip.hover
                title="Show hidden"
                variant="link"
@@ -41,7 +41,7 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('visible:false')">
                <icon icon="eye-slash" />
                <span>{{ history.contents_active.hidden }}</span>
                <span>{{ numItemsHidden }}</span>
            </b-button>
            <b-button
                v-b-tooltip.hover
@@ -60,6 +60,7 @@
import { backboneRoute } from "components/plugins/legacyNavigation";
import prettyBytes from "pretty-bytes";
import { formatDistanceToNowStrict } from "date-fns";
import { usesDetailedHistoryMixin } from "./usesDetailedHistoryMixin.js";

export default {
    filters: {
@@ -67,6 +68,7 @@ export default {
            return prettyBytes(rawSize);
        },
    },
    mixins: [usesDetailedHistoryMixin],
    props: {
        history: { type: Object, required: true },
        lastChecked: { type: Date, default: null },
+6 −4
Original line number Diff line number Diff line
@@ -13,16 +13,16 @@
            <b-dropdown-text id="history-op-all-content">
                <span v-localize>With entire history...</span>
            </b-dropdown-text>
            <b-dropdown-item v-if="history.contents_active.active" data-description="copy datasets" @click="onCopy">
            <b-dropdown-item v-if="numItemsActive" data-description="copy datasets" @click="onCopy">
                <span v-localize>Copy Datasets</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.hidden" v-b-modal:show-all-hidden-content>
            <b-dropdown-item v-if="numItemsHidden" v-b-modal:show-all-hidden-content>
                <span v-localize>Unhide All Hidden Content</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.hidden" v-b-modal:delete-all-hidden-content>
            <b-dropdown-item v-if="numItemsHidden" v-b-modal:delete-all-hidden-content>
                <span v-localize>Delete All Hidden Content</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.deleted" v-b-modal:purge-all-deleted-content>
            <b-dropdown-item v-if="numItemsDeleted" v-b-modal:purge-all-deleted-content>
                <span v-localize>Purge All Deleted Content</span>
            </b-dropdown-item>
        </b-dropdown>
@@ -43,8 +43,10 @@
<script>
import { unhideAllHiddenContent, deleteAllHiddenContent, purgeAllDeletedContent } from "components/History/model/crud";
import { iframeRedirect } from "components/plugins/legacyNavigation";
import { usesDetailedHistoryMixin } from "../usesDetailedHistoryMixin.js";

export default {
    mixins: [usesDetailedHistoryMixin],
    props: {
        history: { type: Object, required: true },
    },
+24 −0
Original line number Diff line number Diff line
/**
 * VueJS mixin exposing extended properties for a history in a safe way.
 * If the values haven't been loaded yet the computed properties will return 0 instead of undefined.
 */
export const usesDetailedHistoryMixin = {
    computed: {
        /** The total size in bytes of the sum of all the items in this history. */
        historySize() {
            return this.history.size || 0;
        },
        /** The number of items currently active (usable). */
        numItemsActive() {
            return this.history.contents_active?.active || 0;
        },
        /** The number of items deleted and/or purged. */
        numItemsDeleted() {
            return this.history.contents_active?.deleted || 0;
        },
        /** The number of items hidden. */
        numItemsHidden() {
            return this.history.contents_active?.hidden || 0;
        },
    },
};