-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathInvocationScrollList.vue
More file actions
163 lines (143 loc) · 5.14 KB
/
InvocationScrollList.vue
File metadata and controls
163 lines (143 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<script setup lang="ts">
import { faClock } from "@fortawesome/free-regular-svg-icons";
import { faHdd, faSitemap } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useRoute, useRouter } from "vue-router/composables";
import type { WorkflowInvocation } from "@/api/invocations";
import { getData } from "@/components/Grid/configs/invocations";
import { useHistoryStore } from "@/stores/historyStore";
import { useInvocationStore } from "@/stores/invocationStore";
import { useUserStore } from "@/stores/userStore";
import { useWorkflowStore } from "@/stores/workflowStore";
import GCard from "@/components/Common/GCard.vue";
import Heading from "@/components/Common/Heading.vue";
import ScrollList from "@/components/ScrollList/ScrollList.vue";
const currentUser = computed(() => useUserStore().currentUser);
const invocationStore = useInvocationStore();
const { sortedStoredInvocations, scrollListScrollTop, totalInvocationCount } = storeToRefs(invocationStore);
interface Props {
inPanel?: boolean;
limit?: number;
}
const props = withDefaults(defineProps<Props>(), {
inPanel: false,
limit: 20,
});
const emit = defineEmits(["invocation-clicked"]);
const stateClasses: Record<string, string> = {
ready: "waiting",
scheduled: "ok",
completed: "ok",
failed: "error",
};
async function loadInvocations(offset: number, limit: number) {
if (!currentUser.value || currentUser.value.isAnonymous) {
return { items: [], total: 0 };
}
const extraProps = { user_id: currentUser.value.id };
const [data, totalMatches] = await getData(offset, limit, "", "create_time", true, extraProps);
for (const item of data) {
invocationStore.updateInvocation(item.id, item);
}
totalInvocationCount.value = totalMatches ?? 0;
return { items: data, total: totalMatches! };
}
function historyName(historyId: string) {
const historyStore = useHistoryStore();
return historyStore.getHistoryNameById(historyId);
}
function stateClass(state: WorkflowInvocation["state"]) {
if (stateClasses[state]) {
return `node-header-invocation header-${stateClasses[state]}`;
}
return "";
}
function workflowName(workflowId: string) {
const workflowStore = useWorkflowStore();
return workflowStore.getStoredWorkflowNameByInstanceId(workflowId);
}
const route = useRoute();
const router = useRouter();
const currentItemId = computed(() => {
const path = route.path;
const match = path.match(/\/workflows\/invocations\/([a-zA-Z0-9]+)/);
return match ? match[1] : undefined;
});
function cardClicked(invocation: WorkflowInvocation) {
if (props.inPanel) {
emit("invocation-clicked");
}
router.push(`/workflows/invocations/${invocation.id}`);
}
function getInvocationBadges(invocation: WorkflowInvocation) {
return [
{
id: "state",
label: invocation.state,
title: "",
class: stateClass(invocation.state),
visible: true,
},
];
}
</script>
<template>
<ScrollList
:loader="loadInvocations"
:item-key="(invocation) => invocation.id"
:in-panel="props.inPanel"
:prop-items="sortedStoredInvocations"
:prop-total-count="totalInvocationCount"
adjust-for-total-count-changes
name="invocation"
name-plural="invocations"
:load-disabled="!currentUser || currentUser.isAnonymous"
:prop-scroll-top.sync="scrollListScrollTop">
<template v-slot:item="{ item: invocation }">
<GCard
:id="`invocation-${invocation.id}`"
clickable
button
:current="invocation.id === currentItemId"
:active="invocation.id === currentItemId"
:badges="getInvocationBadges(invocation)"
:title="workflowName(invocation.workflow_id)"
:title-icon="{ icon: faSitemap }"
:title-n-lines="2"
title-size="text"
:update-time="invocation.create_time"
update-time-title="Invoked"
:update-time-icon="faClock"
@title-click="workflowName(invocation.workflow_id)"
@click="() => cardClicked(invocation)">
<template v-slot:description>
<Heading class="m-0" size="text">
<FontAwesomeIcon :icon="faHdd" fixed-width />
<small class="text-muted truncate-n-lines two-lines">
{{ historyName(invocation.history_id) }}
</small>
</Heading>
</template>
</GCard>
</template>
</ScrollList>
</template>
<style scoped lang="scss">
.truncate-n-lines {
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-word;
overflow-wrap: break-word;
&.three-lines {
-webkit-line-clamp: 3;
line-clamp: 3;
}
&.two-lines {
-webkit-line-clamp: 2;
line-clamp: 2;
}
}
</style>