mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 16:02:28 +00:00
c15b9abe5e
* feat: add fileset resource type support
Add a new "fileset" resource type that represents a collection of files
stored as a relpath→content map. This enables resource types to manage
multiple files (e.g., config directories, template sets) instead of just
a single file.
Backend:
- Add is_fileset column to resource_type table
- Update CRUD operations and workspace duplication to handle is_fileset
- Add integration tests for fileset resource types
Frontend:
- Add FilesetEditor component with file explorer + Monaco editor
- Extract shared FileExplorer component from RawAppSidebar (dedup)
- Add fileset toggle to EditableSchemaWrapper
- Show fileset editor in ResourceEditor and ApiConnectForm
- Show folder icon for fileset resource types in IconedResourceType
CLI:
- Support fileset resources in sync pull (expand to .fileset/ directory)
- Support fileset resources in sync push (reconstruct from directory)
- Handle !inline_fileset YAML tag in resource resolution
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* sqlx
* 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>
* fix: address code review findings for fileset feature
- Use sqlb.set() instead of set_str() for boolean is_fileset field
to avoid quoting (SET is_fileset = TRUE not 'TRUE')
- Add JSDoc comment to isFilesetResource explaining it matches
children inside .fileset/ directories, not the directory itself
- Update OpenAPI spec for file_resource_type_to_file_ext_map endpoint
to document the new response schema with format_extension and
is_fileset fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address second round of review findings
- Remove bidirectional $effect sync in RawAppSidebar; bind FileExplorer
directly to files prop with {} default
- Avoid creating new files object on every keystroke in FilesetEditor;
merge editContent → args in a single effect without intermediate spread
- Simplify no-op `?? undefined` in addResourceType
- Add backend validation: reject create_resource_type when both
is_fileset and format_extension are set
- Fix fileset alert title showing undefined format extension
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: exclude app_theme resources from workspace tab
Theme resources (app_theme) were showing on the workspace tab alongside
regular resources. Now they are excluded from the workspace tab
(like cache and state) and the theme tab loads only app_theme resources.
Also includes review fixes:
- Remove bidirectional $effect sync in RawAppSidebar
- Avoid spreading new files object on every keystroke in FilesetEditor
- Simplify ?? undefined no-op
- Add backend validation for is_fileset + format_extension conflict
- Fix fileset alert title
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: restore full-width file tree items in raw app sidebar
FileExplorer's tree container was missing w-full, causing items to not
stretch inside PanelSection's items-start flex container.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: prevent iframe from overriding file selection after file creation
When files change in the sidebar, setFilesInIframe sends the new files
to the iframe which responds with setActiveDocument defaulting to
App.tsx, overriding the user's selection. Now we ignore setActiveDocument
messages for 500ms after sending setFiles to the iframe.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Revert "fix: prevent iframe from overriding file selection after file creation"
This reverts commit 7f3ddd7edd.
* fix: suppress iframe setActiveDocument during file population
Use setFilesAndSelectInIframe in populateFiles to keep the current
document selected when re-sending files. Suppress setActiveDocument
for 500ms after population to prevent the iframe from defaulting
back to App.tsx on focus changes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
294 lines
8.2 KiB
Svelte
294 lines
8.2 KiB
Svelte
<script lang="ts">
|
|
import Button from './common/button/Button.svelte'
|
|
import { Plus, File, Folder, FolderOpen } from 'lucide-svelte'
|
|
import FileTreeNode from './raw_apps/FileTreeNode.svelte'
|
|
import type { TreeNode } from './raw_apps/fileTreeUtils'
|
|
import { buildFileTree } from './raw_apps/fileTreeUtils'
|
|
|
|
interface Props {
|
|
/** File path → content map. Keys use / prefix (e.g. /index.html). */
|
|
files: Record<string, string>
|
|
/** Currently selected path (/-prefixed). Read-only; changes via onSelectPath callback. */
|
|
selectedPath?: string | undefined
|
|
/** Called when user clicks a path (file or folder). */
|
|
onSelectPath?: (path: string) => void
|
|
/** Extra tree nodes appended after the main tree (e.g. read-only wmill.ts). */
|
|
extraNodes?: TreeNode[]
|
|
/** Show a root / entry at the top of the tree. */
|
|
showRoot?: boolean
|
|
/** Hide the built-in header (useful when parent provides its own). */
|
|
hideHeader?: boolean
|
|
}
|
|
|
|
let {
|
|
files = $bindable({}),
|
|
selectedPath = undefined,
|
|
onSelectPath,
|
|
extraNodes,
|
|
showRoot = false,
|
|
hideHeader = false
|
|
}: Props = $props()
|
|
|
|
let pendingNewFilePath: string | undefined = $state(undefined)
|
|
let pathToEdit: string | undefined = $state(undefined)
|
|
// Empty folders exist only in the UI until a file is created inside them
|
|
let emptyFolders: string[] = $state([])
|
|
|
|
const fileTree = $derived(
|
|
buildFileTree([
|
|
...Object.keys(files ?? {}),
|
|
...emptyFolders,
|
|
...(pendingNewFilePath ? [pendingNewFilePath] : [])
|
|
])
|
|
)
|
|
|
|
function getUniquePath(basePath: string): string {
|
|
const existingPaths = new Set(
|
|
[...Object.keys(files ?? {}), ...emptyFolders, pendingNewFilePath].filter(Boolean)
|
|
)
|
|
|
|
if (!existingPaths.has(basePath)) return basePath
|
|
|
|
const isFolder = basePath.endsWith('/')
|
|
let pathWithoutTrailing = isFolder ? basePath.slice(0, -1) : basePath
|
|
const lastSlash = pathWithoutTrailing.lastIndexOf('/')
|
|
const parentPath = pathWithoutTrailing.substring(0, lastSlash + 1)
|
|
const fileName = pathWithoutTrailing.substring(lastSlash + 1)
|
|
|
|
let nameWithoutExt: string
|
|
let ext: string
|
|
if (isFolder) {
|
|
nameWithoutExt = fileName
|
|
ext = ''
|
|
} else {
|
|
const dotIndex = fileName.lastIndexOf('.')
|
|
nameWithoutExt = dotIndex > 0 ? fileName.substring(0, dotIndex) : fileName
|
|
ext = dotIndex > 0 ? fileName.substring(dotIndex) : ''
|
|
}
|
|
|
|
let counter = 1
|
|
let candidate: string
|
|
do {
|
|
const newName = `${nameWithoutExt} (${counter})${ext}`
|
|
candidate = isFolder ? `${parentPath}${newName}/` : `${parentPath}${newName}`
|
|
counter++
|
|
} while (existingPaths.has(candidate))
|
|
return candidate
|
|
}
|
|
|
|
function handleFileClick(path: string) {
|
|
onSelectPath?.(path)
|
|
}
|
|
|
|
function handleAddFile(folderPath: string) {
|
|
const normalizedFolder = folderPath.endsWith('/') ? folderPath : folderPath + '/'
|
|
const basePath = normalizedFolder + 'newfile.txt'
|
|
const newPath = getUniquePath(basePath)
|
|
pendingNewFilePath = newPath
|
|
pathToEdit = newPath
|
|
}
|
|
|
|
export function handleAddRootFile() {
|
|
let basePath: string
|
|
if (selectedPath && selectedPath !== '/') {
|
|
if (selectedPath.endsWith('/')) {
|
|
basePath = selectedPath + 'newfile.txt'
|
|
} else {
|
|
const pathParts = selectedPath.split('/').filter(Boolean)
|
|
const parentPath =
|
|
pathParts.length > 1 ? '/' + pathParts.slice(0, -1).join('/') + '/' : '/'
|
|
basePath = parentPath + 'newfile.txt'
|
|
}
|
|
} else {
|
|
basePath = '/newfile.txt'
|
|
}
|
|
const newPath = getUniquePath(basePath)
|
|
pendingNewFilePath = newPath
|
|
pathToEdit = newPath
|
|
}
|
|
|
|
function handleAddFolder(folderPath: string) {
|
|
const normalizedFolder = folderPath.endsWith('/') ? folderPath : folderPath + '/'
|
|
const basePath = normalizedFolder + 'newfolder/'
|
|
const newPath = getUniquePath(basePath)
|
|
pendingNewFilePath = newPath
|
|
pathToEdit = newPath
|
|
}
|
|
|
|
export function handleAddRootFolder() {
|
|
let basePath: string
|
|
if (selectedPath && selectedPath !== '/') {
|
|
if (selectedPath.endsWith('/')) {
|
|
basePath = selectedPath + 'newfolder/'
|
|
} else {
|
|
const pathParts = selectedPath.split('/').filter(Boolean)
|
|
const parentPath =
|
|
pathParts.length > 1 ? '/' + pathParts.slice(0, -1).join('/') + '/' : '/'
|
|
basePath = parentPath + 'newfolder/'
|
|
}
|
|
} else {
|
|
basePath = '/newfolder/'
|
|
}
|
|
const newPath = getUniquePath(basePath)
|
|
pendingNewFilePath = newPath
|
|
pathToEdit = newPath
|
|
}
|
|
|
|
function handleRename(oldPath: string, newName: string) {
|
|
const isFolder = oldPath.endsWith('/')
|
|
const pathParts = oldPath.split('/').filter(Boolean)
|
|
const parentPath = '/' + pathParts.slice(0, -1).join('/')
|
|
let newPath = parentPath === '/' ? '/' + newName : parentPath + '/' + newName
|
|
if (isFolder && !newPath.endsWith('/')) {
|
|
newPath = newPath + '/'
|
|
}
|
|
|
|
const isPendingNew = pendingNewFilePath === oldPath
|
|
|
|
if (!isPendingNew && oldPath === newPath) {
|
|
pathToEdit = undefined
|
|
return
|
|
}
|
|
|
|
const nfiles = { ...files }
|
|
|
|
if (isFolder) {
|
|
if (isPendingNew) {
|
|
// New empty folder — track in UI until a file is created inside
|
|
emptyFolders = [...emptyFolders, newPath]
|
|
pendingNewFilePath = undefined
|
|
} else {
|
|
// Rename all children under old folder path
|
|
for (const key of Object.keys(nfiles)) {
|
|
if (key === oldPath || key.startsWith(oldPath)) {
|
|
const newKey = newPath + key.substring(oldPath.length)
|
|
nfiles[newKey] = nfiles[key]
|
|
delete nfiles[key]
|
|
}
|
|
}
|
|
// Also rename in emptyFolders
|
|
emptyFolders = emptyFolders.map((f) =>
|
|
f === oldPath || f.startsWith(oldPath)
|
|
? newPath + f.substring(oldPath.length)
|
|
: f
|
|
)
|
|
}
|
|
} else {
|
|
if (isPendingNew) {
|
|
nfiles[newPath] = ''
|
|
pendingNewFilePath = undefined
|
|
} else {
|
|
nfiles[newPath] = nfiles[oldPath]
|
|
delete nfiles[oldPath]
|
|
}
|
|
// Remove empty folders that are now implicitly defined by this file path
|
|
emptyFolders = emptyFolders.filter((f) => !newPath.startsWith(f))
|
|
}
|
|
|
|
files = nfiles
|
|
pathToEdit = undefined
|
|
onSelectPath?.(newPath)
|
|
}
|
|
|
|
function handleDelete(path: string) {
|
|
const isFolder = path.endsWith('/')
|
|
const nfiles = { ...files }
|
|
|
|
if (isFolder) {
|
|
for (const key of Object.keys(nfiles)) {
|
|
if (key === path || key.startsWith(path)) {
|
|
delete nfiles[key]
|
|
}
|
|
}
|
|
emptyFolders = emptyFolders.filter((f) => f !== path && !f.startsWith(path))
|
|
} else {
|
|
delete nfiles[path]
|
|
}
|
|
|
|
files = nfiles
|
|
|
|
if (selectedPath === path || (isFolder && selectedPath?.startsWith(path))) {
|
|
const remaining = Object.keys(nfiles)
|
|
if (remaining.length > 0) {
|
|
onSelectPath?.(remaining[0])
|
|
} else {
|
|
onSelectPath?.(showRoot ? '/' : '')
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{#if !hideHeader}
|
|
<div class="p-2 border-b flex items-center justify-between">
|
|
<span class="text-xs font-semibold text-emphasis">Files</span>
|
|
<div class="flex gap-1">
|
|
<Button
|
|
onClick={handleAddRootFile}
|
|
title="Add file"
|
|
unifiedSize="xs"
|
|
variant="subtle"
|
|
btnClasses="px-1 gap-0.5"
|
|
>
|
|
<Plus size={12} />
|
|
<File size={12} />
|
|
</Button>
|
|
<Button
|
|
onClick={handleAddRootFolder}
|
|
title="Add folder"
|
|
unifiedSize="xs"
|
|
variant="subtle"
|
|
btnClasses="px-1 gap-0.5"
|
|
>
|
|
<Plus size={12} />
|
|
<Folder size={12} />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
<div class="flex-1 overflow-y-auto py-1 w-full">
|
|
{#if showRoot}
|
|
<button
|
|
onclick={() => onSelectPath?.('/')}
|
|
class="w-full flex items-center gap-1 px-2 py-1 text-xs hover:bg-surface-hover transition-colors rounded text-left {selectedPath ===
|
|
'/'
|
|
? 'bg-surface-accent-selected'
|
|
: ''}"
|
|
>
|
|
<FolderOpen size={12} class="flex-shrink-0 text-secondary" />
|
|
<span
|
|
class="truncate text-primary font-normal {selectedPath === '/' ? 'text-accent' : ''}"
|
|
>/</span
|
|
>
|
|
</button>
|
|
{/if}
|
|
{#each fileTree as node (node.path)}
|
|
<FileTreeNode
|
|
{node}
|
|
onFileClick={handleFileClick}
|
|
onAddFile={handleAddFile}
|
|
onAddFolder={handleAddFolder}
|
|
onRename={handleRename}
|
|
onDelete={handleDelete}
|
|
{selectedPath}
|
|
{pathToEdit}
|
|
onRequestEdit={(path) => (pathToEdit = path)}
|
|
onCancelEdit={() => {
|
|
pathToEdit = undefined
|
|
pendingNewFilePath = undefined
|
|
}}
|
|
/>
|
|
{/each}
|
|
{#if extraNodes}
|
|
{#each extraNodes as node (node.path)}
|
|
<FileTreeNode
|
|
{node}
|
|
noEdit
|
|
onFileClick={handleFileClick}
|
|
onAddFile={handleAddFile}
|
|
onAddFolder={handleAddFolder}
|
|
{selectedPath}
|
|
/>
|
|
{/each}
|
|
{/if}
|
|
</div>
|