|
1 | 1 | <script lang="ts"> |
2 | | - import { InputService, type RunnableType, type Job } from '$lib/gen/index.js' |
3 | | - import { workspaceStore } from '$lib/stores.js' |
| 2 | + import { type RunnableType, type Job } from '$lib/gen/index.js' |
4 | 3 | import { sendUserToast } from '$lib/utils.js' |
5 | | - import JobSchemaPicker from '$lib/components/schema/JobSchemaPicker.svelte' |
6 | 4 | import RunningJobSchemaPicker from '$lib/components/schema/RunningJobSchemaPicker.svelte' |
7 | 5 | import { createEventDispatcher, onDestroy } from 'svelte' |
8 | 6 | import JobLoader from './runs/JobLoader.svelte' |
9 | 7 | import { DataTable } from '$lib/components/table' |
10 | | - import InfiniteList from './InfiniteList.svelte' |
| 8 | + import HistoricList from './HistoricList.svelte' |
11 | 9 |
|
12 | 10 | export let runnableId: string | undefined = undefined |
13 | 11 | export let runnableType: RunnableType | undefined = undefined |
14 | 12 | export let loading: boolean = false |
| 13 | + export let selected: string | undefined = undefined |
15 | 14 |
|
| 15 | + let historicList: HistoricList | undefined = undefined |
16 | 16 | const dispatch = createEventDispatcher() |
17 | 17 |
|
18 | 18 | let jobs: Job[] = [] |
19 | 19 | let hasMoreCurrentRuns = false |
20 | 20 | let page = 1 |
21 | | - let infiniteList: InfiniteList | undefined = undefined |
22 | | - let loadInputsPageFn: ((page: number, perPage: number) => Promise<any>) | undefined = undefined |
23 | | -
|
24 | | - let cachedArgs: Record<string, any> = {} |
25 | | - function initLoadInputs() { |
26 | | - loadInputsPageFn = async (page: number, perPage: number) => { |
27 | | - const inputs = await InputService.getInputHistory({ |
28 | | - workspace: $workspaceStore!, |
29 | | - runnableId, |
30 | | - runnableType, |
31 | | - page, |
32 | | - perPage, |
33 | | - includePreview: true |
34 | | - }) |
35 | | -
|
36 | | - const inputsWithPayload = await Promise.all( |
37 | | - inputs.map(async (input) => { |
38 | | - if (cachedArgs[input.id]) { |
39 | | - return { |
40 | | - ...input, |
41 | | - payloadData: cachedArgs[input.id] |
42 | | - } |
43 | | - } |
44 | | - const payloadData = await loadArgsFromHistory(input.id, undefined, false) |
45 | | - if (payloadData === 'WINDMILL_TOO_BIG') { |
46 | | - return { |
47 | | - ...input, |
48 | | - payloadData: 'WINDMILL_TOO_BIG', |
49 | | - getFullPayload: () => loadArgsFromHistory(input.id, undefined, true) |
50 | | - } |
51 | | - } |
52 | | - cachedArgs[input.id] = payloadData |
53 | | - return { |
54 | | - ...input, |
55 | | - payloadData |
56 | | - } |
57 | | - }) |
58 | | - ) |
59 | | - return inputsWithPayload |
60 | | - } |
61 | | - infiniteList?.setLoader(loadInputsPageFn) |
62 | | - } |
63 | 21 |
|
64 | 22 | async function handleSelected(data: any) { |
65 | 23 | if (selected === data.id) { |
|
69 | 27 | selected = data.id |
70 | 28 | if (data.payloadData === 'WINDMILL_TOO_BIG') { |
71 | 29 | const fullPayload = await data.getFullPayload?.() |
72 | | - dispatch('select', fullPayload) |
| 30 | + dispatch('select', { args: fullPayload, jobId: data.id }) |
73 | 31 | } else { |
74 | | - dispatch('select', structuredClone(data.payloadData)) |
| 32 | + dispatch('select', { args: structuredClone(data.payloadData), jobId: data.id }) |
75 | 33 | } |
76 | 34 | } |
77 | 35 |
|
78 | | - let selected: string | undefined = undefined |
79 | | -
|
80 | 36 | onDestroy(() => { |
81 | 37 | resetSelected(true) |
82 | 38 | }) |
83 | 39 |
|
84 | | - async function loadArgsFromHistory( |
85 | | - id: string | undefined, |
86 | | - input: boolean | undefined, |
87 | | - allowLarge: boolean |
88 | | - ): Promise<any> { |
89 | | - if (!id) return |
90 | | - const payloadData = await InputService.getArgsFromHistoryOrSavedInput({ |
91 | | - jobOrInputId: id, |
92 | | - workspace: $workspaceStore!, |
93 | | - input, |
94 | | - allowLarge |
95 | | - }) |
96 | | - return payloadData |
97 | | - } |
98 | | -
|
99 | 40 | function handleKeydown(event: KeyboardEvent) { |
100 | 41 | if (event.key === 'Escape' && selected) { |
101 | 42 | resetSelected(true) |
|
113 | 54 | let jobHovered: string | undefined = undefined |
114 | 55 |
|
115 | 56 | export function refresh() { |
116 | | - if (infiniteList) { |
117 | | - infiniteList.loadData('refresh') |
118 | | - } |
| 57 | + historicList?.refresh() |
119 | 58 | } |
120 | 59 |
|
121 | 60 | export function resetSelected(dispatchEvent?: boolean) { |
122 | | - console.log('resetSelected') |
123 | 61 | selected = undefined |
124 | 62 | if (dispatchEvent) { |
125 | 63 | dispatch('select', undefined) |
126 | 64 | } |
127 | 65 | } |
128 | 66 |
|
129 | | - $: !loading && refresh() |
130 | | - $: $workspaceStore && runnableId && runnableType && infiniteList && initLoadInputs() |
| 67 | + function getJobKinds(runnableType: RunnableType | undefined) { |
| 68 | + if (runnableType === 'FlowPath') { |
| 69 | + return 'flow,flowpreview' |
| 70 | + } else if (runnableType === 'ScriptPath') { |
| 71 | + return 'script,preview' |
| 72 | + } else if (runnableType === 'ScriptHash') { |
| 73 | + return 'script,preview' |
| 74 | + } |
| 75 | + return 'all' |
| 76 | + } |
131 | 77 | </script> |
132 | 78 |
|
133 | 79 | <svelte:window on:keydown={handleKeydown} /> |
|
137 | 83 | bind:jobs |
138 | 84 | path={runnableId} |
139 | 85 | isSkipped={false} |
140 | | - jobKindsCat="all" |
| 86 | + jobKinds={getJobKinds(runnableType)} |
141 | 87 | user={null} |
142 | 88 | label={null} |
143 | 89 | folder={null} |
|
153 | 99 | /> |
154 | 100 | {/if} |
155 | 101 |
|
156 | | -<div class="h-full w-full flex flex-col gap-4"> |
| 102 | +<div class="h-full max-h-full min-h-0 w-full flex flex-col gap-4"> |
157 | 103 | <div class="grow-0" data-schema-picker> |
158 | 104 | <DataTable size="xs" bind:currentPage={page} hasMore={hasMoreCurrentRuns} tableFixed={true}> |
159 | 105 | {#if loading && (jobs == undefined || jobs?.length == 0)} |
|
187 | 133 | </div> |
188 | 134 |
|
189 | 135 | <div class="min-h-0 grow" data-schema-picker> |
190 | | - <InfiniteList |
191 | | - bind:this={infiniteList} |
192 | | - selectedItemId={selected} |
| 136 | + <HistoricList |
| 137 | + bind:this={historicList} |
193 | 138 | on:error={(e) => handleError(e.detail)} |
194 | 139 | on:select={(e) => handleSelected(e.detail)} |
195 | | - > |
196 | | - <svelte:fragment slot="columns"> |
197 | | - <colgroup> |
198 | | - <col class="w-8" /> |
199 | | - <col class="w-16" /> |
200 | | - <col /> |
201 | | - </colgroup> |
202 | | - </svelte:fragment> |
203 | | - <svelte:fragment let:item let:hover> |
204 | | - <JobSchemaPicker |
205 | | - job={item} |
206 | | - selected={selected === item.id} |
207 | | - hovering={hover} |
208 | | - payloadData={item.payloadData} |
209 | | - /> |
210 | | - </svelte:fragment> |
211 | | - <svelte:fragment slot="empty"> |
212 | | - <div class="text-center text-tertiary text-xs py-2"> |
213 | | - {runnableId ? 'No previous inputs' : 'Save draft to see previous runs'} |
214 | | - </div> |
215 | | - </svelte:fragment> |
216 | | - </InfiniteList> |
| 140 | + {runnableId} |
| 141 | + {runnableType} |
| 142 | + {selected} |
| 143 | + /> |
217 | 144 | </div> |
218 | 145 | </div> |
0 commit comments