diff --git a/src/lib/components/payload-input.svelte b/src/lib/components/payload-input.svelte index 6d9dd4fbb..3e72c419b 100644 --- a/src/lib/components/payload-input.svelte +++ b/src/lib/components/payload-input.svelte @@ -10,9 +10,11 @@ import Alert from '$lib/holocene/alert.svelte'; import Card from '$lib/holocene/card.svelte'; import CodeBlock from '$lib/holocene/code-block.svelte'; + import FileInput from '$lib/holocene/file-input.svelte'; import Label from '$lib/holocene/label.svelte'; import RadioGroup from '$lib/holocene/radio-input/radio-group.svelte'; import RadioInput from '$lib/holocene/radio-input/radio-input.svelte'; + import Tooltip from '$lib/holocene/tooltip.svelte'; import { translate } from '$lib/i18n/translate'; export let input: string; @@ -21,16 +23,22 @@ export let resetValues = false; let codeBlock: CodeBlock; + let uploaded = false; + + $: error = !isValidInput(input); + + $: { + if (resetValues) { + clearValues(); + } + } const handleInputChange = (event: CustomEvent): void => { input = event.detail; }; const isValidInput = (value: string) => { - if (!input) { - return true; - } - + if (!input) return true; try { JSON.parse(value); return true; @@ -39,27 +47,29 @@ } }; - $: error = !isValidInput(input); - const clearValues = () => { $encoding = 'json/plain'; input = ''; codeBlock?.resetView(input); - input = ''; + uploaded = false; }; - $: { - if (resetValues) { - clearValues(); - } - } + const onUpload = (uploadInput: string) => { + input = uploadInput; + uploaded = true; + }; onDestroy(() => { clearValues(); }); -
Input
+
+
Input
+ + {translate('workflows.signal-payload-input-label-hint')} + +
@@ -70,27 +80,26 @@ label="json/protobuf" /> - + + +
-
-
- + {#key uploaded} + + {/key} {#if error} {/if} diff --git a/src/lib/holocene/file-input.svelte b/src/lib/holocene/file-input.svelte index f9935c4fe..cef2e76ef 100644 --- a/src/lib/holocene/file-input.svelte +++ b/src/lib/holocene/file-input.svelte @@ -7,7 +7,7 @@ export let accept = '.json'; export let onUpload: (input: string) => void; - const onFileSelect = async (e: Event) => { + const onFileSelect = (e: Event) => { const target = e.target as HTMLInputElement; const file = target?.files?.[0]; const reader = new FileReader(); diff --git a/src/lib/i18n/locales/en/workflows.ts b/src/lib/i18n/locales/en/workflows.ts index 1fd5a4cdc..25c7ac28e 100644 --- a/src/lib/i18n/locales/en/workflows.ts +++ b/src/lib/i18n/locales/en/workflows.ts @@ -103,7 +103,7 @@ export const Strings = { 'Are you sure you want to terminate this workflow? This action cannot be undone.', 'signal-modal-title': 'Send a Signal', 'signal-name-label': 'Signal name', - 'signal-payload-input-label': 'Payload', + 'signal-payload-input-label': 'Data', 'signal-payload-input-label-hint': '(only single JSON payload supported)', 'cancel-request-sent': 'Cancel Request Sent', 'cancel-request-sent-description': diff --git a/src/lib/pages/start-workflow.svelte b/src/lib/pages/start-workflow.svelte index aff54e536..27ed2601a 100644 --- a/src/lib/pages/start-workflow.svelte +++ b/src/lib/pages/start-workflow.svelte @@ -13,10 +13,8 @@ import AddSearchAttributes from '$lib/components/workflow/add-search-attributes.svelte'; import Alert from '$lib/holocene/alert.svelte'; import Button from '$lib/holocene/button.svelte'; - import FileInput from '$lib/holocene/file-input.svelte'; import Input from '$lib/holocene/input/input.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 { @@ -110,7 +108,6 @@ workflowType: type, }); input = initialValues.input; - $encoding = initialValues.encoding as PayloadInputEncoding; inputRetrieved = Date.now(); if (initialValues?.searchAttributes) { const customSAKeys = Object.keys($customSearchAttributes); @@ -136,11 +133,6 @@ }); }; - const onUpload = (uploadInput: string) => { - input = uploadInput; - inputRetrieved = Date.now(); - }; - const inputIsJSON = (input: string) => { try { JSON.parse(input); @@ -233,11 +225,7 @@ on:blur={(e) => onInputChange(e, 'workflowType')} /> {#key inputRetrieved} - - - - - + {/key} {#if viewAdvancedOptions} diff --git a/src/lib/services/workflow-service.ts b/src/lib/services/workflow-service.ts index a7046f055..8203d7f0b 100644 --- a/src/lib/services/workflow-service.ts +++ b/src/lib/services/workflow-service.ts @@ -35,7 +35,6 @@ import type { ListWorkflowExecutionsResponse, WorkflowExecution, } from '$lib/types/workflows'; -import { atob } from '$lib/utilities/atob'; import { cloneAllPotentialPayloadsWithCodec, type PotentiallyDecodable, @@ -554,7 +553,6 @@ export const fetchInitialValuesForStartWorkflow = async ({ workflowId?: string; }): Promise<{ input: string; - encoding: string; searchAttributes: Record | undefined; }> => { const handleError: ErrorCallback = (err) => { @@ -562,7 +560,6 @@ export const fetchInitialValuesForStartWorkflow = async ({ }; const emptyValues = { input: '', - encoding: 'json/plain', searchAttributes: undefined, }; try { @@ -602,15 +599,8 @@ export const fetchInitialValuesForStartWorkflow = async ({ )) as PotentiallyDecodable; const input = stringifyWithBigInt(convertedAttributes?.payloads[0]); - const encoding = atob( - String( - convertedAttributes?.payloads[0]?.metadata?.encoding ?? 'json/plain', - ), - ); - return { input, - encoding, searchAttributes: workflow?.searchAttributes?.indexedFields, }; } catch (e) { diff --git a/src/lib/utilities/decode-payload.ts b/src/lib/utilities/decode-payload.ts index ec96a7e8b..11238469e 100644 --- a/src/lib/utilities/decode-payload.ts +++ b/src/lib/utilities/decode-payload.ts @@ -59,18 +59,15 @@ export function decodePayload( return payload; } - const encoding = atob(String(payload?.metadata?.encoding ?? '')); - - if (encoding?.startsWith('json/')) { - try { - const data = parseWithBigInt(atob(String(payload?.data ?? ''))); - return returnDataOnly ? data : { ...payload, data }; - } catch (_e) { - console.warn('Could not parse payload: ', _e); - // Couldn't correctly decode this just let the user deal with the data as is - } + try { + const data = parseWithBigInt(atob(String(payload?.data ?? ''))); + return returnDataOnly ? data : { ...payload, data }; + } catch (_e) { + console.warn('Could not parse payload: ', _e); + // Couldn't correctly decode this just let the user deal with the data as is } + const encoding = atob(String(payload?.metadata?.encoding ?? '')); if (encoding === 'binary/null') { return returnDataOnly ? null : { ...payload, data: null }; }