mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-23 00:00:33 +00:00
fix: reset button for preprocessor scripts now uses preprocessor signature
- Added selectedTab prop to EditorBar component to track active tab - Modified clearContent function to use preprocessor signature when on preprocessor tab - Added getPreprocessorCode helper function to return appropriate preprocessor template - Updated ScriptEditor to pass selectedTab to EditorBar - Updated WorkspaceScriptPicker and PickHubScript type definitions to support preprocessor kind Fixes #6594 Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
import type { Schema, SchemaProperty, SupportedLanguage } from '$lib/common'
|
||||
import ScriptVersionHistory from './ScriptVersionHistory.svelte'
|
||||
import type DiffEditor from './DiffEditor.svelte'
|
||||
import { getResetCode } from '$lib/script_helpers'
|
||||
import { getResetCode, TS_PREPROCESSOR_MODULE_CODE, PYTHON_PREPROCESSOR_MODULE_CODE, TS_PREPROCESSOR_SCRIPT_INTRO, PYTHON_PREPROCESSOR_SCRIPT_INTRO } from '$lib/script_helpers'
|
||||
import Popover from './Popover.svelte'
|
||||
import ResourceEditorDrawer from './ResourceEditorDrawer.svelte'
|
||||
import type { EditorBarUi } from './custom_ui'
|
||||
@@ -66,7 +66,7 @@
|
||||
}
|
||||
iconOnly?: boolean
|
||||
validCode?: boolean
|
||||
kind?: 'script' | 'trigger' | 'approval'
|
||||
kind?: 'script' | 'trigger' | 'approval' | 'preprocessor'
|
||||
template?: 'pgsql' | 'mysql' | 'script' | 'docker' | 'powershell' | 'bunnative'
|
||||
collabMode?: boolean
|
||||
collabLive?: boolean
|
||||
@@ -83,6 +83,7 @@
|
||||
right?: import('svelte').Snippet
|
||||
openAiChat?: boolean
|
||||
moduleId?: string
|
||||
selectedTab?: 'main' | 'preprocessor'
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -107,7 +108,8 @@
|
||||
showHistoryDrawer = $bindable(false),
|
||||
right,
|
||||
openAiChat = false,
|
||||
moduleId = undefined
|
||||
moduleId = undefined,
|
||||
selectedTab = 'main'
|
||||
}: Props = $props()
|
||||
|
||||
let contextualVariablePicker: ItemPicker | undefined = $state()
|
||||
@@ -351,11 +353,34 @@
|
||||
|
||||
function clearContent() {
|
||||
if (editor) {
|
||||
const resetCode = getResetCode(lang, kind as Script['kind'], template)
|
||||
editor.setCode(resetCode)
|
||||
// If we're on the preprocessor tab or the kind is preprocessor, use preprocessor signature
|
||||
if (selectedTab === 'preprocessor' || kind === 'preprocessor') {
|
||||
const preprocessorCode = getPreprocessorCode(lang)
|
||||
if (preprocessorCode) {
|
||||
editor.setCode(preprocessorCode)
|
||||
} else {
|
||||
// Fallback to regular reset code if no preprocessor code is available
|
||||
const resetCode = getResetCode(lang, 'script', template)
|
||||
editor.setCode(resetCode)
|
||||
}
|
||||
} else {
|
||||
const resetCode = getResetCode(lang, kind as Script['kind'], template)
|
||||
editor.setCode(resetCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPreprocessorCode(language: SupportedLanguage | 'bunnative' | undefined): string | undefined {
|
||||
if (language === 'deno' || language === 'bun') {
|
||||
return `${TS_PREPROCESSOR_SCRIPT_INTRO}${TS_PREPROCESSOR_MODULE_CODE}`
|
||||
} else if (language === 'python3') {
|
||||
return `${PYTHON_PREPROCESSOR_SCRIPT_INTRO}${PYTHON_PREPROCESSOR_MODULE_CODE}`
|
||||
} else if (language === 'nativets' || language === 'bunnative') {
|
||||
return `${TS_PREPROCESSOR_SCRIPT_INTRO}${TS_PREPROCESSOR_MODULE_CODE}`
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function windmillPathToCamelCaseName(path: string): string {
|
||||
const parts = path.split('/')
|
||||
const lastPart = parts[parts.length - 1]
|
||||
|
||||
@@ -510,6 +510,7 @@
|
||||
: undefined}
|
||||
{diffMode}
|
||||
bind:showHistoryDrawer
|
||||
{selectedTab}
|
||||
>
|
||||
{#snippet right()}
|
||||
{@render editor_bar_right?.()}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import { Loader2 } from 'lucide-svelte'
|
||||
|
||||
interface Props {
|
||||
kind?: HubScriptKind & string
|
||||
kind?: (HubScriptKind | 'preprocessor') & string
|
||||
filter?: string
|
||||
syncQuery?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import NoItemFound from '$lib/components/home/NoItemFound.svelte'
|
||||
|
||||
export let kind: 'script' | 'trigger' | 'approval' | 'failure' = 'script'
|
||||
export let kind: 'script' | 'trigger' | 'approval' | 'failure' | 'preprocessor' = 'script'
|
||||
export let isTemplate: boolean | undefined = undefined
|
||||
export let displayLock = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user