import { computed, ref, watch, type Ref } from "vue"; import { useSettingsStore, type ResourceRevision } from "@/stores/settings"; import { workflowRevisions } from "./workflow-revisions"; const KIND = "workflow-definitions"; /** The history of workflow `id`, kept current as the definitions change. */ export function useWorkflowHistory(id: Ref) { const store = useSettingsStore(); const all = ref([]); const error = ref(""); async function reload(): Promise { try { all.value = await store.history(KIND); error.value = ""; } catch (err) { error.value = err instanceof Error ? err.message : "Could not load history"; } } watch(() => store.stateFor(KIND).resource?.version, () => void reload(), { immediate: true }); const revisions = computed(() => workflowRevisions(id.value, all.value)); return { revisions, error, reload }; }