Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Start Workflow input preview, add error alert for invalid input #2338

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/i18n/locales/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ export const Strings = {
state: 'State',
attempt: 'Attempt',
message: 'Message',
'upload-json': 'Upload JSON',
'input-valid-json': 'Input must be valid JSON',
} as const;
37 changes: 20 additions & 17 deletions src/lib/pages/start-workflow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Input from '$lib/holocene/input/input.svelte';
import Label from '$lib/holocene/label.svelte';
import Link from '$lib/holocene/link.svelte';
import Tooltip from '$lib/holocene/tooltip.svelte';
import { translate } from '$lib/i18n/translate';
import { getPollers } from '$lib/services/pollers-service';
import {
Expand Down Expand Up @@ -140,10 +141,22 @@
inputRetrieved = Date.now();
};

const inputIsJSON = (input: string) => {
try {
JSON.parse(input);
return true;
} catch (e) {
return false;
}
};

$: inputValid = !input || inputIsJSON(input);

$: enableStart =
!!workflowId &&
!!taskQueue &&
!!workflowType &&
!!inputValid &&
!workflowCreateDisabled($page);

$: checkTaskQueue(taskQueueParam);
Expand Down Expand Up @@ -222,25 +235,12 @@
<div
class="flex w-full flex-col items-end justify-between gap-4 md:flex-row"
>
{#if initialInput}
<div class="flex w-full flex-col gap-2 md:w-1/2">
<Label
class="text-subtle"
for="workflow-example-input"
label={translate('workflows.example-input')}
/>
<CodeBlock
id="workflow-initial-input"
minHeight={120}
content={initialInput}
copyable
/>
</div>
{/if}
<div class="flex w-full flex-col gap-2 {initialInput && 'md:w-1/2'}">
<div class="flex w-full flex-col gap-2">
<div class="flex w-full items-end justify-between">
<Label for="workflow-input" label={translate('workflows.input')} />
<FileInput id="start-workflow-input-file-upload" {onUpload} />
<Tooltip text={translate('common.upload-json')} left>
<FileInput id="start-workflow-input-file-upload" {onUpload} />
</Tooltip>
</div>
{#key inputRetrieved}
<CodeBlock
Expand All @@ -252,6 +252,9 @@
copyable={false}
/>
{/key}
{#if !inputValid}
<Alert intent="error" title={translate('common.input-valid-json')} />
{/if}
</div>
</div>
{#if viewAdvancedOptions}
Expand Down
Loading