Skip to content

Commit

Permalink
feat(frontend): Add action bar to run details (#684)
Browse files Browse the repository at this point in the history
* feat(frontend): Add action bar to run details
  • Loading branch information
adam-kov committed Oct 4, 2022
1 parent 91ce66e commit 4e472f5
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 134 deletions.
19 changes: 13 additions & 6 deletions frontend/src/lib/components/common/actionRow/ActionRow.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<script lang="ts">
export let applyPageWidth = false
let classes = 'max-w-6xl mx-auto px-4 sm:px-6 md:px-8'
export let stickToTop = false
$: wide = applyPageWidth ? 'max-w-6xl mx-auto px-4 sm:px-6 md:px-8 ' : ''
let scrollY: number
</script>

<div class={'bg-white py-3 ' + $$props.class}>
<div
class={'w-full flex flex-wrap justify-between items-center gap-4 ' +
(applyPageWidth ? classes : '')}
>
<svelte:window bind:scrollY />

<div
class={'bg-white py-3 ' +
(stickToTop ? 'sticky top-0 ' + (scrollY >= 30 ? 'border-b ' : '') : '') +
$$props.class}
>
<div class={'w-full flex flex-wrap justify-between items-center gap-4 ' + wide}>
<div class="flex flex-wrap items-center gap-2">
{#if $$slots.left}
<slot name="left" />
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/routes/flows/get/[...path].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
let path = $page.params.path
let shareModal: ShareModal
let scrollY: number
$: {
if ($workspaceStore && $userStore) {
Expand Down Expand Up @@ -90,10 +89,8 @@
}
</script>

<svelte:window bind:scrollY />

{#if flow}
<ActionRow applyPageWidth class={'sticky top-0 ' + (scrollY >= 30 ? 'border-b' : '')}>
<ActionRow applyPageWidth stickToTop>
<svelte:fragment slot="left">
<Button
href="/flows/run/{path}"
Expand Down Expand Up @@ -241,11 +238,13 @@
corresponding jsonschema as payload. To create a permanent token, go to your user setting
by clicking your username on the top-left.</Tooltip
>
<pre><code
<pre
><code
><a href="/api/w/{$workspaceStore}/jobs/run/f/{flow?.path}"
>/api/w/{$workspaceStore}/jobs/run/f/{flow?.path}</a
></code
></pre>
></pre
>
</div>
<div>
<h2 class="text-gray-700 pb-1 mb-3 border-b">Flow</h2>
Expand Down
187 changes: 69 additions & 118 deletions frontend/src/routes/run/[...run].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Icon from 'svelte-awesome'
import { check } from 'svelte-awesome/icons'
import {
faBolt,
faRefresh,
faCircle,
faTimes,
faTrash,
Expand All @@ -38,7 +38,6 @@
} from '@fortawesome/free-solid-svg-icons'
import Tooltip from '$lib/components/Tooltip.svelte'
import DisplayResult from '$lib/components/DisplayResult.svelte'
import { userStore, workspaceStore } from '$lib/stores'
import CenteredPage from '$lib/components/CenteredPage.svelte'
import FlowStatusViewer from '$lib/components/FlowStatusViewer.svelte'
Expand All @@ -48,7 +47,7 @@
import HighlightCode from '$lib/components/HighlightCode.svelte'
import TestJobLoader from '$lib/components/TestJobLoader.svelte'
import LogViewer from '$lib/components/LogViewer.svelte'
import { Button } from '$lib/components/common'
import { Button, ActionRow } from '$lib/components/common'
let workspace_id_query: string | undefined = $page.url.searchParams.get('workspace') ?? undefined
let workspace_id: string | undefined
Expand Down Expand Up @@ -108,6 +107,73 @@
bind:job
/>

{#if job?.job_kind === 'script' || job?.job_kind === 'flow'}
<ActionRow applyPageWidth stickToTop>
<svelte:fragment slot="left">
{@const stem = `/${job?.job_kind}s`}
{@const isScript = job?.job_kind === 'script'}
{@const route = isScript ? job?.script_hash : job?.script_path}
{@const runHref = `${stem}/run/${route}${
job?.args ? '?args=' + encodeURIComponent(encodeState(job?.args)) : ''
}`}
{@const editHref = `${stem}/edit/${route}${isScript ? '?step=2' : ''}`}
{@const isRunning = job && 'running' in job && job.running}
{#if isRunning}
<Button
color="red"
size="xs"
startIcon={{ icon: faTimesCircle }}
on:click|once={() => {
if (job?.id) {
cancelJob(job?.id)
}
}}
>
Cancel
</Button>
{/if}
<Button
href={runHref}
disabled={isRunning}
color="blue"
size="xs"
startIcon={{ icon: faRefresh }}>Run again</Button
>
{#if canWrite(job?.script_path ?? '', {}, $userStore)}
<Button href={editHref} color="blue" size="xs" startIcon={{ icon: faEdit }}>Edit</Button>
{/if}
</svelte:fragment>
<svelte:fragment slot="right">
{@const stem = `/${job?.job_kind}s`}
{@const isScript = job?.job_kind === 'script'}
{@const runsHref = `/runs/${job?.script_path}${!isScript ? '?jobKind=flow' : ''}`}
{@const viewHref = `${stem}/get/${isScript ? job?.script_hash : job?.script_path}`}
{#if job && 'deleted' in job && !job?.deleted && ($userStore?.is_admin ?? false)}
<Button
variant="border"
color="red"
size="xs"
startIcon={{ icon: faTrash }}
on:click={() => job?.id && deleteCompletedJob(job.id)}
>
Delete
</Button>
{/if}
<Button href={runsHref} variant="border" color="blue" size="xs" startIcon={{ icon: faList }}>
View runs
</Button>
<Button
href={viewHref}
variant="border"
color="blue"
size="xs"
startIcon={{ icon: faScroll }}
>
View {job?.job_kind}
</Button>
</svelte:fragment>
</ActionRow>
{/if}
<CenteredPage>
<div class="flex flex-row flex-wrap justify-between items-center gap-4 pb-4">
<h1>
Expand Down Expand Up @@ -173,121 +239,6 @@
{/if}
</div>
</h1>
<div class="flex flex-wrap gap-2">
{#if job && 'deleted' in job && !job?.deleted && ($userStore?.is_admin ?? false)}
<Button
variant="border"
color="red"
size="sm"
startIcon={{ icon: faTrash }}
on:click={() => {
if (job?.id) {
deleteCompletedJob(job?.id)
}
}}
>
Delete
</Button>
{/if}
{#if job && 'running' in job && job.running}
<Button
variant="border"
color="red"
size="sm"
startIcon={{ icon: faTimesCircle }}
on:click|once={() => {
if (job?.id) {
cancelJob(job?.id)
}
}}
>
Cancel
</Button>
{/if}
{#if job?.job_kind == 'script'}
{#if canWrite(job?.script_path ?? '', {}, $userStore)}
<Button
href="/scripts/edit/{job?.script_hash}?step=2"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faEdit }}
>
Edit
</Button>
{/if}
<Button
href="/scripts/get/{job?.script_hash}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faScroll }}
>
View script
</Button>
<Button
href="/runs/{job?.script_path}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faList }}
>
View runs
</Button>
<Button
href="/scripts/run/{job?.script_hash}{job?.args
? `?args=${encodeURIComponent(encodeState(job?.args))}`
: ''}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faBolt }}
>
Run again
</Button>
{:else if job?.job_kind == 'flow'}
{#if canWrite(job?.script_path ?? '', {}, $userStore)}
<Button
href="/flows/edit/{job?.script_path}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faEdit }}
>
Edit
</Button>
{/if}
<Button
href="/flows/get/{job?.script_path}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faScroll }}
>
View flow
</Button>
<Button
href="/runs/{job?.script_path}?jobKind=flow"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faList }}
>
View runs
</Button>
<Button
href="/flows/run/{job?.script_path}{job?.args
? `?args=${encodeURIComponent(encodeState(job?.args))}`
: ''}"
variant="border"
color="blue"
size="sm"
startIcon={{ icon: faBolt }}
>
Run again
</Button>
{/if}
</div>
</div>
{#if job && 'deleted' in job && job?.deleted}
<div class="bg-red-100 border-l-4 border-red-600 text-orange-700 p-4" role="alert">
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/routes/scripts/get/[...hash].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
let can_write = false
let deploymentInProgress = false
let intervalId: NodeJS.Timer
let scrollY: number
let shareModal: ShareModal
Expand Down Expand Up @@ -127,10 +126,8 @@
})
</script>

<svelte:window bind:scrollY />

{#if script}
<ActionRow applyPageWidth class={'sticky top-0 ' + (scrollY >= 30 ? 'border-b' : '')}>
<ActionRow applyPageWidth stickToTop>
<svelte:fragment slot="left">
<Button
href={`/scripts/run/${script.hash}`}
Expand Down

0 comments on commit 4e472f5

Please sign in to comment.