From d09f9cca293271f1dc54584300e077f9e781caf0 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 3 Sep 2024 18:10:06 -0500 Subject: [PATCH] add `getContentItemState` function --- .../History/Content/ContentItem.vue | 22 ++--------------- .../History/Content/model/states.ts | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/client/src/components/History/Content/ContentItem.vue b/client/src/components/History/Content/ContentItem.vue index 04f3c7d0729f..58ba0da9a58a 100644 --- a/client/src/components/History/Content/ContentItem.vue +++ b/client/src/components/History/Content/ContentItem.vue @@ -20,7 +20,7 @@ import { useEventStore } from "@/stores/eventStore"; import { clearDrag } from "@/utils/setDrag"; import { JobStateSummary } from "./Collection/JobStateSummary"; -import { HIERARCHICAL_COLLECTION_JOB_STATES, type StateMap, STATES } from "./model/states"; +import { getContentItemState, type StateMap, STATES } from "./model/states"; import CollectionDescription from "./Collection/CollectionDescription.vue"; import ContentOptions from "./ContentOptions.vue"; @@ -135,25 +135,7 @@ const state = computed(() => { if (props.isPlaceholder) { return "placeholder"; } - if (props.item.accessible === false) { - return "inaccessible"; - } - if (props.item.populated_state === "failed") { - return "failed_populated_state"; - } - if (props.item.populated_state === "new") { - return "new_populated_state"; - } - if (props.item.job_state_summary) { - for (const jobState of HIERARCHICAL_COLLECTION_JOB_STATES) { - if (props.item.job_state_summary[jobState] > 0) { - return jobState; - } - } - } else if (props.item.state) { - return props.item.state; - } - return "ok"; + return getContentItemState(props.item); }); const dataState = computed(() => { diff --git a/client/src/components/History/Content/model/states.ts b/client/src/components/History/Content/model/states.ts index 5a201ed9b085..bc3195cbf348 100644 --- a/client/src/components/History/Content/model/states.ts +++ b/client/src/components/History/Content/model/states.ts @@ -1,3 +1,4 @@ +import { isHDCA } from "@/api"; import { type components } from "@/api/schema"; type DatasetState = components["schemas"]["DatasetState"]; @@ -146,3 +147,26 @@ export const HIERARCHICAL_COLLECTION_JOB_STATES = [ "queued", "new", ] as const; + +export function getContentItemState(item: any) { + if (isHDCA(item)) { + if (item.populated_state === "failed") { + return "failed_populated_state"; + } + if (item.populated_state === "new") { + return "new_populated_state"; + } + if (item.job_state_summary) { + for (const jobState of HIERARCHICAL_COLLECTION_JOB_STATES) { + if (item.job_state_summary[jobState] > 0) { + return jobState; + } + } + } + } else if (item.accessible === false) { + return "inaccessible"; + } else if (item.state) { + return item.state; + } + return "ok"; +}