|
1 | 1 | <script lang="ts"> |
2 | 2 | import {queryAuthInfo} from '$lib/queries/serverQueries'; |
3 | | - import {queryTaskManifest} from '$lib/queries/taskQueries'; |
4 | | - import {Loading, Popover, ProgressBar} from 'carbon-components-svelte'; |
| 3 | + import {cancelTaskMutation, queryTaskManifest} from '$lib/queries/taskQueries'; |
| 4 | + import {Loading, Modal, Popover, ProgressBar} from 'carbon-components-svelte'; |
5 | 5 | import type {ProgressBarProps} from 'carbon-components-svelte/types/ProgressBar/ProgressBar.svelte'; |
| 6 | + import {CloseFilled} from 'carbon-icons-svelte'; |
6 | 7 | import Checkmark from 'carbon-icons-svelte/lib/Checkmark.svelte'; |
7 | 8 | import {hoverTooltip} from './common/HoverTooltip'; |
8 | 9 |
|
|
21 | 22 | const taskToProgressStatus: {[taskStatus: string]: ProgressBarProps['status']} = { |
22 | 23 | pending: 'active', |
23 | 24 | completed: 'finished', |
24 | | - error: 'error' |
| 25 | + error: 'error', |
| 26 | + cancelled: 'error' |
25 | 27 | }; |
26 | 28 |
|
| 29 | + const cancelTask = cancelTaskMutation(); |
| 30 | + let cancelTaskId: string | undefined = undefined; |
| 31 | + let cancelTaskName: string | undefined = undefined; |
| 32 | + function cancelTaskAccepted() { |
| 33 | + if (cancelTaskId == null) return; |
| 34 | + $cancelTask.mutate([cancelTaskId]); |
| 35 | + cancelTaskId = undefined; |
| 36 | + } |
| 37 | +
|
27 | 38 | const authInfo = queryAuthInfo(); |
28 | 39 | $: canRunTasks = |
29 | 40 | $authInfo.data?.access.dataset.compute_signals || $authInfo.data?.access.create_dataset; |
|
78 | 89 | task.total_progress != null && task.total_len != null |
79 | 90 | ? task.total_progress / task.total_len |
80 | 91 | : undefined} |
81 | | - {@const message = task.error ?? task.message} |
| 92 | + {@const message = |
| 93 | + task.status != 'cancelled' ? task.error ?? task.message : 'Task cancelled.'} |
82 | 94 | <div class="relative border-b-2 border-slate-200 p-4 text-left last:border-b-0"> |
83 | | - <div class="text-s flex flex-row"> |
| 95 | + <div class="text-s flex flex-row items-center"> |
84 | 96 | <div class="mr-2">{task.name}</div> |
| 97 | + {#if task.status === 'pending'} |
| 98 | + <div use:hoverTooltip={{text: 'Cancel task'}}> |
| 99 | + <button |
| 100 | + on:click|stopPropagation={() => { |
| 101 | + cancelTaskId = id; |
| 102 | + cancelTaskName = task.name; |
| 103 | + }}><CloseFilled /></button |
| 104 | + > |
| 105 | + </div> |
| 106 | + {/if} |
85 | 107 | </div> |
86 | | - <button>Cancel button</button> |
87 | 108 | <div class="progress-container mt-3"> |
88 | 109 | <ProgressBar |
89 | 110 | labelText={message || ''} |
|
102 | 123 | </div> |
103 | 124 | {/if} |
104 | 125 |
|
| 126 | +<Modal |
| 127 | + size="xs" |
| 128 | + open={cancelTaskId != null} |
| 129 | + modalHeading="Cancel task" |
| 130 | + primaryButtonText="Confirm" |
| 131 | + secondaryButtonText="Cancel" |
| 132 | + selectorPrimaryFocus=".bx--btn--primary" |
| 133 | + on:submit={() => cancelTaskAccepted()} |
| 134 | + on:click:button--secondary={() => { |
| 135 | + cancelTaskId = undefined; |
| 136 | + }} |
| 137 | + on:close={(cancelTaskId = undefined)} |
| 138 | +> |
| 139 | + <div class="italic"> |
| 140 | + {cancelTaskName} |
| 141 | + </div> |
| 142 | + <p class="mt-4">Are you sure you want to cancel this task?</p> |
| 143 | +</Modal> |
| 144 | + |
105 | 145 | <style lang="postcss"> |
106 | 146 | :global(.progress-container .bx--progress-bar__label) { |
107 | 147 | @apply text-xs; |
|
0 commit comments