diff --git a/frontend/src/lib/components/LightweightArgInput.svelte b/frontend/src/lib/components/LightweightArgInput.svelte index 0dc9e2d892..5e709893ff 100644 --- a/frontend/src/lib/components/LightweightArgInput.svelte +++ b/frontend/src/lib/components/LightweightArgInput.svelte @@ -96,18 +96,15 @@ $: render && changeDefaultValue(inputCat, defaultValue) - $: rawValue && evalRawValueToValue() + $: (rawValue || inputCat === 'object') && evalRawValueToValue() $: validateInput(pattern, value, required) - $: { - if (inputCat === 'object') { - evalValueToRaw() - } - } - function evalRawValueToValue() { - if (rawValue) { + if (!rawValue || rawValue === '') { + value = undefined + error = '' + } else { try { value = JSON.parse(rawValue) error = '' @@ -124,7 +121,7 @@ } else { // If value is undefined, set rawValue to empty object // This is to prevent the textarea from being empty - rawValue = '{}' + rawValue = '' } } diff --git a/frontend/src/lib/components/StringTypeNarrowing.svelte b/frontend/src/lib/components/StringTypeNarrowing.svelte index 0a2d2a118f..8ca87357e2 100644 --- a/frontend/src/lib/components/StringTypeNarrowing.svelte +++ b/frontend/src/lib/components/StringTypeNarrowing.svelte @@ -27,12 +27,8 @@ export let overrideAllowKindChange: boolean = true export let originalType: string | undefined = undefined - let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' = computeKind( - enum_, - contentEncoding, - pattern, - format - ) + let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' | 'date-time' = + computeKind(enum_, contentEncoding, pattern, format) const allowKindChange = overrideAllowKindChange || originalType === 'string' @@ -55,6 +51,15 @@ // 'jsonpointer', ] + const FIELD_SETTINGS = [ + ['None', 'none'], + ['File', 'base64', 'Encoded as Base 64'], + ['Enum', 'enum'], + ['Datetime', 'date-time'], + ['Format', 'format'], + ['Pattern', 'pattern'] + ] + $: format = kind == 'resource' ? (resource != undefined ? `resource-${resource}` : 'resource') : format $: pattern = patternStr == '' ? undefined : patternStr @@ -111,6 +116,9 @@ if (e.detail != 'enum') { enum_ = undefined } + if (e.detail == 'date-time') { + format = 'date-time' + } if (e.detail == 'none') { pattern = undefined format = undefined @@ -122,7 +130,7 @@ } }} > - {#each [['None', 'none'], ['File', 'base64', 'Encoded as Base 64'], ['Enum', 'enum'], ['Format', 'format'], ['Pattern', 'pattern']] as x} + {#each FIELD_SETTINGS as x} {/each} diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 876d60bce2..896e3a73a4 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -495,7 +495,7 @@ export function isObject(obj: any) { export function debounce(func: (...args: any[]) => any, wait: number) { let timeout: any - return function(...args: any[]) { + return function (...args: any[]) { // @ts-ignore const context = this clearTimeout(timeout) @@ -505,7 +505,7 @@ export function debounce(func: (...args: any[]) => any, wait: number) { export function throttle(func: (...args: any[]) => T, wait: number) { let timeout: any - return function(...args: any[]) { + return function (...args: any[]) { if (!timeout) { timeout = setTimeout(() => { timeout = null @@ -721,7 +721,7 @@ export async function tryEvery({ try { await tryCode() break - } catch (err) { } + } catch (err) {} i++ } if (i >= times) { @@ -883,7 +883,7 @@ export function computeKind( contentEncoding: 'base64' | 'binary' | undefined, pattern: string | undefined, format: string | undefined -): 'base64' | 'none' | 'pattern' | 'enum' | 'resource' | 'format' { +): 'base64' | 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'date-time' { if (enum_ != undefined) { return 'enum' } @@ -893,6 +893,9 @@ export function computeKind( if (pattern != undefined) { return 'pattern' } + if (format == 'date-time') { + return 'date-time' + } if (format != undefined && format != '') { if (format?.startsWith('resource')) { return 'resource' @@ -950,10 +953,7 @@ export function isDeployable( return false } - if ( - deployUiSettings.include_type != undefined && - !deployUiSettings.include_type.includes(type) - ) { + if (deployUiSettings.include_type != undefined && !deployUiSettings.include_type.includes(type)) { return false } @@ -972,4 +972,3 @@ export const ALL_DEPLOYABLE: WorkspaceDeployUISettings = { include_path: [], include_type: ['script', 'flow', 'app', 'resource', 'variable', 'secret'] } -