mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 16:02:28 +00:00
fix: resolve svelte warnings and type error in fileset components
- Fix state_referenced_locally warnings in FilesetEditor by computing initial values before creating $state - Fix Promise<boolean> type error in +page.svelte by making resourceNameIsFileset/resourceNameToFileExt synchronous lookups with eager map loading Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,18 +8,16 @@
|
||||
|
||||
let { args = $bindable({}) }: Props = $props()
|
||||
|
||||
// Internal files map uses /-prefixed keys (matching tree node paths)
|
||||
let files: Record<string, string> = $state(
|
||||
Object.fromEntries(
|
||||
Object.entries(args ?? {}).map(([k, v]) => ['/' + k, String(v ?? '')])
|
||||
)
|
||||
// Internal files map uses /-prefixed keys (matching tree node paths).
|
||||
// Compute initial files + selection together to avoid referencing $state outside reactive context.
|
||||
const initialFiles = Object.fromEntries(
|
||||
Object.entries(args ?? {}).map(([k, v]) => ['/' + k, String(v ?? '')])
|
||||
)
|
||||
const initialFile = Object.keys(initialFiles).find((k) => !k.endsWith('/'))
|
||||
|
||||
// Initialize selection synchronously so SimpleEditor mounts with correct content
|
||||
const initialKeys = Object.keys(files)
|
||||
const initialFile = initialKeys.find((k) => !k.endsWith('/'))
|
||||
let selectedPath: string | undefined = $state(initialFile ?? (initialKeys.length > 0 ? '/' : '/'))
|
||||
let editContent: string = $state(initialFile ? (files[initialFile] ?? '') : '')
|
||||
let files: Record<string, string> = $state(initialFiles)
|
||||
let selectedPath: string | undefined = $state(initialFile ?? '/')
|
||||
let editContent: string = $state(initialFile ? (initialFiles[initialFile] ?? '') : '')
|
||||
|
||||
// The selected file path (/-prefixed, not a folder)
|
||||
const selectedFileKey: string | undefined = $derived.by(() => {
|
||||
|
||||
@@ -477,16 +477,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function resourceNameToFileExt(resourceName: string) {
|
||||
await loadResourceNameToFileExtMap()
|
||||
function resourceNameToFileExt(resourceName: string): string | undefined {
|
||||
return resourceNameToFileExtMap?.[resourceName]
|
||||
}
|
||||
|
||||
async function resourceNameIsFileset(resourceName: string) {
|
||||
await loadResourceNameToFileExtMap()
|
||||
function resourceNameIsFileset(resourceName: string): boolean {
|
||||
return resourceNameToIsFilesetMap?.[resourceName] ?? false
|
||||
}
|
||||
|
||||
// Eagerly load the map
|
||||
loadResourceNameToFileExtMap()
|
||||
|
||||
// Current resources based on tab
|
||||
let currentResources = $derived(
|
||||
tab == 'cache' ? cacheResources : tab == 'states' ? stateResources : resources
|
||||
|
||||
Reference in New Issue
Block a user