Skip to content

Commit

Permalink
add getContentItemState function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Sep 3, 2024
1 parent 24a2921 commit d09f9cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
22 changes: 2 additions & 20 deletions client/src/components/History/Content/ContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -135,25 +135,7 @@ const state = computed<keyof StateMap>(() => {
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(() => {
Expand Down
24 changes: 24 additions & 0 deletions client/src/components/History/Content/model/states.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isHDCA } from "@/api";
import { type components } from "@/api/schema";

type DatasetState = components["schemas"]["DatasetState"];
Expand Down Expand Up @@ -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";
}

0 comments on commit d09f9cc

Please sign in to comment.