Unverified Commit 6d31292a authored by Ahmed Awan's avatar Ahmed Awan Committed by mvdbeek
Browse files

use `StoredWorkflowDetailed` instead of `Workflow` type from store

We really need a less specific type to be used here, and this will be possible once routes like `api/workflows` index are modernized.
parent 7f7eed27
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -15,11 +15,11 @@ import { storeToRefs } from "pinia";
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";

import type { WorkflowInvocationElementView } from "@/api/invocations";
import type { StoredWorkflowDetailed } from "@/api/workflows";
import { useDatatypesMapper } from "@/composables/datatypesMapper";
import { useInvocationGraph } from "@/composables/useInvocationGraph";
import { useWorkflowStateStore } from "@/stores/workflowEditorStateStore";
import type { Step } from "@/stores/workflowStepStore";
import type { Workflow } from "@/stores/workflowStore";

import Heading from "@/components/Common/Heading.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
@@ -33,7 +33,7 @@ interface Props {
    /** The invocation to display */
    invocation: WorkflowInvocationElementView;
    /** The workflow which was run */
    workflow: Workflow;
    workflow: StoredWorkflowDetailed;
    /** Whether the invocation is terminal */
    isTerminal: boolean;
    /** The zoom level for the graph */
@@ -120,7 +120,7 @@ const initialPosition = computed(() => ({
}));

function activeStepFor(activeNodeId: number): Step {
    return props.workflow.steps[activeNodeId] as Step;
    return props.workflow.steps[activeNodeId] as unknown as Step;
}

/** Updates and loads the invocation graph */
+11 −6
Original line number Diff line number Diff line
<script setup lang="ts">
import { BModal } from "bootstrap-vue";
import { reactive, ref } from "vue";
import { computed, reactive, ref } from "vue";

import type { StoredWorkflowDetailed } from "@/api/workflows";
import type { Workflow } from "@/components/Workflow/workflows.services";

import type { SelectedWorkflow } from "./types";
@@ -40,6 +41,10 @@ const emit = defineEmits<{
    (e: "insertWorkflowSteps", id: string, stepCount: number): void;
}>();

/** `props.workflows` typed as `StoredWorkflowDetailed[]` because that is the type expected by `WorkflowCard` */
const detailedWorkflows = computed(() => props.workflows as unknown as StoredWorkflowDetailed[]);
// TODO: Ideally, components like `WorkflowCard` should accept a less specific type, like `Workflow` instead of `StoredWorkflowDetailed`

const modalOptions = reactive({
    rename: {
        id: "",
@@ -70,19 +75,19 @@ function onPreview(id: string) {
}

// TODO: clean-up types, as soon as better Workflow type is available
function onInsert(workflow: Workflow) {
    emit("insertWorkflow", workflow.latest_workflow_id as any, workflow.name as any);
function onInsert(workflow: StoredWorkflowDetailed) {
    emit("insertWorkflow", (workflow as any).latest_workflow_id, workflow.name);
}

function onInsertSteps(workflow: Workflow) {
    emit("insertWorkflowSteps", workflow.id as any, workflow.number_of_steps as any);
function onInsertSteps(workflow: StoredWorkflowDetailed) {
    emit("insertWorkflowSteps", workflow.id, workflow.number_of_steps as any);
}
</script>

<template>
    <div class="workflow-card-list" :class="{ grid: props.gridView }">
        <WorkflowCard
            v-for="workflow in props.workflows"
            v-for="workflow in detailedWorkflows"
            :key="workflow.id"
            :workflow="workflow"
            :selectable="!publishedView && !editorView"
+2 −3
Original line number Diff line number Diff line
@@ -14,10 +14,9 @@ import { BBadge, BButton } from "bootstrap-vue";
import { computed } from "vue";
import { useRouter } from "vue-router/composables";

import type { Creator } from "@/api/workflows";
import type { Creator, StoredWorkflowDetailed } from "@/api/workflows";
import { useToast } from "@/composables/toast";
import { useUserStore } from "@/stores/userStore";
import type { Workflow } from "@/stores/workflowStore";
import { copy } from "@/utils/clipboard";
import { isUrl } from "@/utils/url";

@@ -31,7 +30,7 @@ interface BadgeData {
}

interface Props {
    workflow: Workflow;
    workflow: StoredWorkflowDetailed;
    publishedView: boolean;
    noEditTime?: boolean;
    filterable?: boolean;
+7 −4
Original line number Diff line number Diff line
@@ -7,13 +7,13 @@ import { type AxiosError } from "axios";
import { BAlert, BButton, BCard } from "bootstrap-vue";
import { computed, nextTick, onMounted, ref, watch } from "vue";

import { type WorkflowSummary } from "@/api/workflows";
import { type StoredWorkflowDetailed, type WorkflowSummary } from "@/api/workflows";
import { fromSimple } from "@/components/Workflow/Editor/modules/model";
import { getWorkflowFull, getWorkflowInfo } from "@/components/Workflow/workflows.services";
import { useDatatypesMapper } from "@/composables/datatypesMapper";
import { provideScopedWorkflowStores } from "@/composables/workflowStores";
import { useUserStore } from "@/stores/userStore";
import type { Workflow } from "@/stores/workflowStore";
import type { Steps } from "@/stores/workflowStepStore";
import { assertDefined } from "@/utils/assertions";
import { withPrefix } from "@/utils/redirect";

@@ -60,7 +60,7 @@ const { stateStore } = provideScopedWorkflowStores(props.id);
const loading = ref(true);
const errorMessage = ref("");
const workflowInfo = ref<WorkflowSummary>();
const workflow = ref<Workflow | null>(null);
const workflow = ref<StoredWorkflowDetailed | null>(null);

const hasError = computed(() => !!errorMessage.value);

@@ -91,6 +91,9 @@ const editButtonTitle = computed(() => {
    }
});

/** Workflow steps force typed as `Steps` from the `workflowStepStore` */
const workflowSteps = computed(() => (workflow.value?.steps as unknown as Steps) ?? []);

function logInTitle(title: string) {
    if (userStore.isAnonymous) {
        return `Log in to ${title}`;
@@ -233,7 +236,7 @@ onMounted(async () => {
                    <WorkflowGraph
                        v-if="workflow && datatypesMapper"
                        ref="workflowGraph"
                        :steps="workflow.steps"
                        :steps="workflowSteps"
                        :datatypes-mapper="datatypesMapper"
                        :initial-position="initialPosition"
                        :show-minimap="props.showMinimap"
+3 −3
Original line number Diff line number Diff line
@@ -8,9 +8,9 @@ import { RouterLink } from "vue-router";

import { isRegisteredUser } from "@/api";
import type { WorkflowInvocationElementView } from "@/api/invocations";
import type { StoredWorkflowDetailed } from "@/api/workflows";
import { useWorkflowInstance } from "@/composables/useWorkflowInstance";
import { useUserStore } from "@/stores/userStore";
import type { Workflow } from "@/stores/workflowStore";
import localize from "@/utils/localization";
import { errorMessageAsString } from "@/utils/simple-error";

@@ -48,7 +48,7 @@ const owned = computed(() => {
});

const importErrorMessage = ref<string | null>(null);
const importedWorkflow = ref<Workflow | null>(null);
const importedWorkflow = ref<StoredWorkflowDetailed | null>(null);
const workflowImportedAttempted = ref(false);

async function onImport() {
@@ -57,7 +57,7 @@ async function onImport() {
    }
    try {
        const wf = await copyWorkflow(workflow.value.id, workflow.value.owner);
        importedWorkflow.value = wf as unknown as Workflow;
        importedWorkflow.value = wf as unknown as StoredWorkflowDetailed;
    } catch (error) {
        importErrorMessage.value = errorMessageAsString(error, "Failed to import workflow");
    } finally {
Loading