{/if}
+ {#if property && shouldDisplayPlaceholderForProperty(property)}
+
+ {/if}
+
+ import { computeKind } from '$lib/utils'
import Label from './Label.svelte'
import RadioButton from './RadioButton.svelte'
import ResourceTypePicker from './ResourceTypePicker.svelte'
@@ -21,7 +22,13 @@
export let noExtra = false
export let dateFormat: string | undefined
- let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' = computeKind()
+ let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' = computeKind(
+ enum_,
+ contentEncoding,
+ pattern,
+ format
+ )
+
let patternStr: string = pattern ?? ''
let resource: string | undefined
@@ -64,24 +71,6 @@
}
}
- function computeKind(): 'base64' | 'none' | 'pattern' | 'enum' | 'resource' | 'format' {
- if (enum_ != undefined) {
- return 'enum'
- }
- if (contentEncoding == 'base64') {
- return 'base64'
- }
- if (pattern != undefined) {
- return 'pattern'
- }
- if (format != undefined && format != '') {
- if (format.startsWith('resource')) {
- return 'resource'
- }
- return 'format'
- }
- return 'none'
- }
const presetOptions = [
{ label: 'ISO Format', format: 'yyyy-MM-dd' },
{ label: 'US Format', format: 'MM/dd/yyyy' },
diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecEditor.svelte
index a1ba8ff98a..2154e31963 100644
--- a/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecEditor.svelte
+++ b/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecEditor.svelte
@@ -52,7 +52,9 @@
...componentInput,
type: 'evalv2',
expr: expr,
- connections: [{ componentId: connection.componentId, id: connection.path.split('.')[0].split('[')[0] }]
+ connections: [
+ { componentId: connection.componentId, id: connection.path.split('.')[0].split('[')[0] }
+ ]
}
evalV2editor?.setCode(expr)
$app = $app
diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts
index b379e2d0c6..e6fcff7a1a 100644
--- a/frontend/src/lib/utils.ts
+++ b/frontend/src/lib/utils.ts
@@ -851,3 +851,49 @@ export function getLocalSetting(name: string) {
return undefined
}
}
+
+export function computeKind(
+ enum_: string[] | undefined,
+ contentEncoding: 'base64' | 'binary' | undefined,
+ pattern: string | undefined,
+ format: string | undefined
+): 'base64' | 'none' | 'pattern' | 'enum' | 'resource' | 'format' {
+ if (enum_ != undefined) {
+ return 'enum'
+ }
+ if (contentEncoding == 'base64') {
+ return 'base64'
+ }
+ if (pattern != undefined) {
+ return 'pattern'
+ }
+ if (format != undefined && format != '') {
+ if (format?.startsWith('resource')) {
+ return 'resource'
+ }
+ return 'format'
+ }
+ return 'none'
+}
+
+// Used to check whether a placeholder should be displayed in the input field, based on the schema
+export function shouldDisplayPlaceholder(
+ type: string | undefined,
+ format: string | undefined,
+ enum_: string[] | undefined,
+ contentEncoding: 'base64' | 'binary' | undefined,
+ pattern: string | undefined
+): boolean {
+ if (type === 'string') {
+ const kind = computeKind(enum_, contentEncoding, pattern, format)
+
+ if (kind === 'format' && format) {
+ const whiteList = ['email', 'hostname', 'ipv4', 'uri', 'uuid']
+ return whiteList.includes(format)
+ }
+
+ return kind === 'none' || kind === 'pattern'
+ }
+
+ return type === 'number' || type === 'integer' || type === undefined
+}
diff --git a/frontend/src/routes/(root)/(logged)/scripts/add/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/add/+page.svelte
index 6546abadd2..8f2b461bc8 100644
--- a/frontend/src/routes/(root)/(logged)/scripts/add/+page.svelte
+++ b/frontend/src/routes/(root)/(logged)/scripts/add/+page.svelte
@@ -5,7 +5,7 @@
import { defaultScripts, workspaceStore } from '$lib/stores'
import ScriptBuilder from '$lib/components/ScriptBuilder.svelte'
import type { Schema } from '$lib/common'
- import { decodeState, emptySchema } from '$lib/utils'
+ import { decodeState, emptySchema, emptyString } from '$lib/utils'
import { goto } from '$app/navigation'
import UnsavedConfirmationModal from '$lib/components/common/confirmationModal/UnsavedConfirmationModal.svelte'
@@ -57,7 +57,9 @@
workspace: $workspaceStore!,
path: templatePath
})
- script.summary = `Copy of ${template.summary}`
+
+ // Only copy the summary if it's not empty
+ script.summary = !emptyString(template.summary) ? `Copy of ${template.summary}` : ''
script.description = template.description
script.content = template.content
script.schema = template.schema