Skip to content

Commit 6cec23d

Browse files
add computed owned to useWorkflowInstance, and replace in components
1 parent ae7ec2e commit 6cec23d

4 files changed

Lines changed: 13 additions & 29 deletions

File tree

client/src/components/Workflow/WorkflowAnnotation.vue

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import { faClock } from "@fortawesome/free-regular-svg-icons";
33
import { faExclamation, faHdd } from "@fortawesome/free-solid-svg-icons";
44
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
55
import { BBadge } from "bootstrap-vue";
6-
import { storeToRefs } from "pinia";
76
import { computed, ref } from "vue";
87
9-
import { isRegisteredUser } from "@/api";
108
import { useMarkdown } from "@/composables/markdown";
119
import { useWorkflowInstance } from "@/composables/useWorkflowInstance";
1210
import { useHistoryStore } from "@/stores/historyStore";
13-
import { useUserStore } from "@/stores/userStore";
1411
1512
import Heading from "../Common/Heading.vue";
1613
import TextSummary from "../Common/TextSummary.vue";
@@ -32,16 +29,7 @@ const props = withDefaults(defineProps<Props>(), {
3229
invocationUpdateTime: undefined,
3330
});
3431
35-
const { workflow } = useWorkflowInstance(props.workflowId);
36-
37-
const { currentUser } = storeToRefs(useUserStore());
38-
const owned = computed(() => {
39-
if (isRegisteredUser(currentUser.value) && workflow.value) {
40-
return currentUser.value.username === workflow.value.owner;
41-
} else {
42-
return false;
43-
}
44-
});
32+
const { workflow, owned } = useWorkflowInstance(props.workflowId);
4533
4634
const description = computed(() => {
4735
if (workflow.value?.annotation) {

client/src/components/Workflow/WorkflowNavigationTitle.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { storeToRefs } from "pinia";
66
import { computed, ref } from "vue";
77
import { RouterLink } from "vue-router";
88
9-
import { isRegisteredUser } from "@/api";
109
import type { WorkflowInvocationElementView } from "@/api/invocations";
1110
import type { WorkflowSummary } from "@/api/workflows";
1211
import { useWorkflowInstance } from "@/composables/useWorkflowInstance";
@@ -37,16 +36,9 @@ const emit = defineEmits<{
3736
(e: "on-execute"): void;
3837
}>();
3938
40-
const { workflow, loading, error } = useWorkflowInstance(props.workflowId);
39+
const { workflow, loading, error, owned } = useWorkflowInstance(props.workflowId);
4140
42-
const { currentUser, isAnonymous } = storeToRefs(useUserStore());
43-
const owned = computed(() => {
44-
if (isRegisteredUser(currentUser.value) && workflow.value) {
45-
return currentUser.value.username === workflow.value.owner;
46-
} else {
47-
return false;
48-
}
49-
});
41+
const { isAnonymous } = storeToRefs(useUserStore());
5042
5143
const importErrorMessage = ref<string | null>(null);
5244
const importedWorkflow = ref<WorkflowSummary | null>(null);

client/src/components/WorkflowInvocationState/WorkflowInvocationShare.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const props = defineProps<{
2323
const modalToggle = ref(false);
2424
2525
// Workflow and History refs
26-
const { workflow, loading: workflowLoading, error: workflowError } = useWorkflowInstance(props.workflowId);
26+
const { workflow, loading, error, owned } = useWorkflowInstance(props.workflowId);
2727
const historyStore = useHistoryStore();
2828
2929
/** The link to the invocation. */
@@ -58,7 +58,7 @@ async function makeInvocationShareable() {
5858
</script>
5959

6060
<template>
61-
<div>
61+
<div v-if="owned">
6262
<BButton
6363
v-b-tooltip.noninteractive.hover
6464
title="Share Invocation"
@@ -76,11 +76,11 @@ async function makeInvocationShareable() {
7676
title-tag="h2"
7777
ok-title="Make Workflow and History Shareable, and Copy Link"
7878
@ok="makeInvocationShareable">
79-
<BAlert v-if="workflowError" variant="danger" show>
80-
{{ workflowError }}
79+
<BAlert v-if="error" variant="danger" show>
80+
{{ error }}
8181
</BAlert>
8282

83-
<LoadingSpan v-else-if="workflowLoading" message="Loading details for invocation" />
83+
<LoadingSpan v-else-if="loading" message="Loading details for invocation" />
8484

8585
<div v-else-if="!!workflow">
8686
<p v-localize>

client/src/composables/useWorkflowInstance.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { computed, ref } from "vue";
22

3+
import { useUserStore } from "@/stores/userStore";
34
import { useWorkflowStore } from "@/stores/workflowStore";
45
import { errorMessageAsString } from "@/utils/simple-error";
56

@@ -9,6 +10,9 @@ export function useWorkflowInstance(workflowId: string) {
910
const loading = ref(false);
1011
const error = ref<string | null>(null);
1112

13+
const userStore = useUserStore();
14+
const owned = computed(() => workflow.value && userStore.matchesCurrentUsername(workflow.value.owner));
15+
1216
async function getWorkflowInstance() {
1317
if (!workflow.value) {
1418
loading.value = true;
@@ -23,5 +27,5 @@ export function useWorkflowInstance(workflowId: string) {
2327
}
2428
getWorkflowInstance();
2529

26-
return { workflow, loading, error };
30+
return { workflow, loading, error, owned };
2731
}

0 commit comments

Comments
 (0)