mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
feat: publish a folder sub-path to the Hub as its own project (#12081)
* feat: accept nested folder paths for Hub project publish and import A Hub project can be published from, and imported into, a sub-path of a folder (`hub/billing`, i.e. items under `f/hub/billing/...`). The backend folder check and the import wizard's folder check accept `/`-separated segments; an import into a nested destination creates only the base folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: describe nested folder source keys on HubPublishCtx Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: choose a folder sub-path when publishing to or importing from the Hub Publishing keeps each item's sub-path under the project slug instead of flattening items outside `f/<slug>/` to their last segment, so a nested source folder is bundled like a root one. The publish drawer gets a scope select listing the folder's sub-paths, and the import wizard an optional sub-path field next to the folder picker. A nested project's name defaults to its last segment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: pick the Hub publish scope from a folder tree, drop nested import Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: show sub-folders already published to the Hub in the publish drawer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: open the Hub publish drawer on the folder's projects, tree only for a new one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: let the last sub-folder become a Hub project and keep other projects' items out of updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: open sub-folder Hub projects from a list and block only nested projects on update Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: render the Hub project list with ListRow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * revert: keep the Hub project list as bordered card rows like the drawer's other lists Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3d0ca92ef2
commit
23fbf1edfe
@@ -57,12 +57,16 @@ struct HubScope {
|
||||
folder: Option<String>,
|
||||
}
|
||||
|
||||
/// A base folder name, or one followed by `/`-separated sub-path segments
|
||||
/// (`hub/billing`): every segment non-empty, so no leading, trailing or doubled `/`.
|
||||
fn validate_folder(folder: &str) -> Result<(), Error> {
|
||||
let ok = !folder.is_empty()
|
||||
&& folder.len() <= 255
|
||||
&& folder
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-');
|
||||
let ok = folder.len() <= 255
|
||||
&& folder.split('/').all(|seg| {
|
||||
!seg.is_empty()
|
||||
&& seg
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-')
|
||||
});
|
||||
if ok {
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -118,10 +122,11 @@ impl std::fmt::Display for ProjectSlug {
|
||||
/// Handlers can only reach the Hub via this extractor's methods, so a new
|
||||
/// endpoint cannot forget the admin check or folder validation.
|
||||
///
|
||||
/// A workspace can publish one Hub project per folder. The stable, never-mutated
|
||||
/// link key is `workspace_id:folder_name` (folder name is the path segment and is
|
||||
/// A workspace can publish one Hub project per folder or folder sub-path. The
|
||||
/// stable, never-mutated link key is `workspace_id:folder` (`folder` is the base
|
||||
/// folder name, optionally followed by `/`-separated sub-path segments, and is
|
||||
/// never renamed — only display_name changes). `:` is safe: neither workspace ids
|
||||
/// nor folder names (alphanumeric, underscore, hyphen) contain it.
|
||||
/// nor folder paths (alphanumeric, underscore, hyphen, `/`) contain it.
|
||||
struct HubPublishCtx {
|
||||
source_id: Option<String>,
|
||||
token: String,
|
||||
@@ -740,7 +745,28 @@ async fn forward_to_hub<T: Serialize>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::is_public_hub;
|
||||
use super::{is_public_hub, validate_folder};
|
||||
|
||||
#[test]
|
||||
fn folder_accepts_nested_sub_paths() {
|
||||
for ok in ["hub", "my-folder_2", "hub/billing", "hub/billing/v-2"] {
|
||||
assert!(validate_folder(ok).is_ok(), "{ok} should be valid");
|
||||
}
|
||||
let too_long = format!("a/{}", "b".repeat(254));
|
||||
for bad in [
|
||||
"",
|
||||
"/hub",
|
||||
"hub/",
|
||||
"hub//billing",
|
||||
"hub/../x",
|
||||
"hub/./x",
|
||||
"hub/bil ling",
|
||||
"hub\\billing",
|
||||
too_long.as_str(),
|
||||
] {
|
||||
assert!(validate_folder(bad).is_err(), "{bad} should be rejected");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_hub_recognized_in_every_spelling() {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
<script lang="ts" module>
|
||||
const treeOpenState = new Map<string, boolean>()
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Folder, Loader2, User } from 'lucide-svelte'
|
||||
import { Badge } from './common'
|
||||
@@ -6,6 +10,8 @@
|
||||
import Tooltip from './Tooltip.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { Kind } from '$lib/utils_deployable'
|
||||
import TreeViewRoot from './home/TreeViewRoot.svelte'
|
||||
import type { ItemType } from './home/treeViewUtils'
|
||||
|
||||
interface DeployableItem {
|
||||
key: string
|
||||
@@ -25,6 +31,11 @@
|
||||
|
||||
interface Props {
|
||||
items: DeployableItem[]
|
||||
/** Show the items as the home page's folder tree, each folder row selecting
|
||||
* everything under it, instead of grouped by top-level folder. */
|
||||
nested?: boolean
|
||||
/** With `nested`, appended to a folder row's item count, given its full path prefix. */
|
||||
folderDetail?: Snippet<[string]>
|
||||
selectedItems: string[]
|
||||
selectablePredicate?: (item: DeployableItem) => boolean
|
||||
/** Selectable on its own row, but never swept in by a bulk action (the group
|
||||
@@ -68,6 +79,8 @@
|
||||
|
||||
let {
|
||||
items,
|
||||
nested = false,
|
||||
folderDetail,
|
||||
selectedItems,
|
||||
selectablePredicate = () => true,
|
||||
bulkExcluded = () => false,
|
||||
@@ -138,15 +151,34 @@
|
||||
// selection frozen, so they don't count toward the group's tri-state. Bulk-excluded
|
||||
// rows are left out too — the group checkbox is a bulk action, so it must neither
|
||||
// select them nor let them hold its tri-state short of full.
|
||||
function groupSelectable(group: DeployGroup): DeployableItem[] {
|
||||
return group.items.filter(
|
||||
function bulkSelectable(list: DeployableItem[]): DeployableItem[] {
|
||||
return list.filter(
|
||||
(i) =>
|
||||
selectablePredicate(i) && !bulkExcluded(i) && deploymentStatus[i.key]?.status !== 'deployed'
|
||||
)
|
||||
}
|
||||
function groupSelectable(group: DeployGroup): DeployableItem[] {
|
||||
return bulkSelectable(group.items)
|
||||
}
|
||||
|
||||
function toggleGroup(group: DeployGroup) {
|
||||
const selectable = groupSelectable(group)
|
||||
// The tree keys its leaves by `type`; the rows keep every other field as they are.
|
||||
let treeItems = $derived(
|
||||
nested ? (items.map((i) => ({ ...i, type: i.kind })) as unknown as ItemType[]) : []
|
||||
)
|
||||
// While selecting, top-level folders start open and sub-folders closed; without a
|
||||
// selection to make, the tree opens fully, since every row may carry an action.
|
||||
// Held at module level so a toggle survives the remount the Hub drawer does when the
|
||||
// selection changes its scope.
|
||||
const treeOpen = {
|
||||
isOpen: (prefix: string) => treeOpenState.get(prefix) ?? prefix.split('/').length === 2,
|
||||
setOpen: (prefix: string, open: boolean) => void treeOpenState.set(prefix, open)
|
||||
}
|
||||
function underPrefix(prefix: string): DeployableItem[] {
|
||||
return items.filter((i) => i.path.startsWith(prefix + '/'))
|
||||
}
|
||||
|
||||
function toggleGroup(group: Pick<DeployGroup, 'items'>) {
|
||||
const selectable = bulkSelectable(group.items)
|
||||
const target = !selectable.every((i) => selectedItems.includes(i.key))
|
||||
// Snapshot which items need flipping before mutating: onToggleItem updates
|
||||
// the parent's selection, which feeds back into `selectedItems` mid-loop.
|
||||
@@ -157,6 +189,88 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet itemRow(item: DeployableItem, depth: number, subPath: string)}
|
||||
{@const isSelectable = selectablePredicate(item)}
|
||||
{@const isSelected = selectedItems.includes(item.key)}
|
||||
{@const status = deploymentStatus[item.key]}
|
||||
{@const isDeployed = status?.status === 'deployed'}
|
||||
{@const blockedReason = !isSelectable && !isDeployed ? selectBlockedReason?.(item) : undefined}
|
||||
<!-- A resource is titled by its path, except an agent, titled by its summary. -->
|
||||
{@const showPath =
|
||||
isAgent?.(item) ||
|
||||
(item.kind !== 'resource' && item.kind !== 'variable' && item.kind !== 'resource_type')}
|
||||
|
||||
<Row
|
||||
isSelectable={!hideSelection && isSelectable && !isDeployed}
|
||||
selectDisabledReason={blockedReason}
|
||||
selectOnRowClick={!hideSelection}
|
||||
alignWithSelectable={!hideSelection}
|
||||
disabled={!hideSelection && (blockedReason ? false : !isSelectable)}
|
||||
selected={isSelected && !isDeployed}
|
||||
onSelect={() => handleSelect(item)}
|
||||
path={showPath ? item.path : ''}
|
||||
marked={undefined}
|
||||
kind={isAgent?.(item) ? 'agent' : item.kind}
|
||||
triggerKind={item.triggerKind}
|
||||
canFavorite={false}
|
||||
workspaceId=""
|
||||
{depth}
|
||||
>
|
||||
{#snippet customSummary()}
|
||||
{#if itemSummary}
|
||||
{@render itemSummary(item)}
|
||||
{:else}
|
||||
{item.path}
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet pathDisplay()}
|
||||
{#if itemPath}
|
||||
{@render itemPath(item)}
|
||||
{:else}
|
||||
{showPath ? subPath : ''}
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet actions()}
|
||||
{#if itemActions}
|
||||
{@render itemActions(item)}
|
||||
{/if}
|
||||
<!-- Deployment status always shown -->
|
||||
{#if status}
|
||||
{#if status.status === 'loading'}
|
||||
<Loader2 class="animate-spin" />
|
||||
{:else if status.status === 'deployed'}
|
||||
<Badge color="green">Deployed</Badge>
|
||||
{:else if status.status === 'failed'}
|
||||
<div class="inline-flex gap-1">
|
||||
<Badge color="red">Failed</Badge>
|
||||
<Tooltip>{status.error}</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Row>
|
||||
{/snippet}
|
||||
|
||||
{#snippet treeLeaf(leaf: ItemType, depth: number)}
|
||||
{@const item = leaf as unknown as DeployableItem}
|
||||
{@render itemRow(item, depth, item.path.split('/').pop() ?? item.path)}
|
||||
{/snippet}
|
||||
|
||||
{#snippet prefixCheckbox(prefix: string)}
|
||||
{@const under = underPrefix(prefix)}
|
||||
{@const selectable = bulkSelectable(under)}
|
||||
{@const selectedCount = selectable.filter((i) => selectedItems.includes(i.key)).length}
|
||||
<Checkbox
|
||||
checked={selectable.length > 0 && selectedCount === selectable.length}
|
||||
indeterminate={selectedCount > 0 && selectedCount < selectable.length}
|
||||
disabled={selectable.length === 0}
|
||||
title={selectedCount === selectable.length
|
||||
? `Deselect all in ${prefix}`
|
||||
: `Select all in ${prefix}`}
|
||||
onChange={() => toggleGroup({ items: under })}
|
||||
/>
|
||||
{/snippet}
|
||||
|
||||
<div class="flex flex-col h-full">
|
||||
<!-- Header section -->
|
||||
{#if header}
|
||||
@@ -197,7 +311,20 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if items.length > 0}
|
||||
{#if items.length > 0 && nested}
|
||||
<div class="overflow-y-auto">
|
||||
<TreeViewRoot
|
||||
items={treeItems}
|
||||
collapseAll={!hideSelection}
|
||||
openMemory={treeOpen}
|
||||
showCode={() => {}}
|
||||
sortCompare={(a, b) => a.path.localeCompare(b.path)}
|
||||
leaf={treeLeaf}
|
||||
ownerLead={hideSelection ? undefined : prefixCheckbox}
|
||||
ownerDetail={folderDetail}
|
||||
/>
|
||||
</div>
|
||||
{:else if items.length > 0}
|
||||
<!-- Items list -->
|
||||
<div class="overflow-y-auto">
|
||||
<div class="border rounded-md bg-surface-tertiary">
|
||||
@@ -248,73 +375,15 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#each group.items as item (item.key)}
|
||||
{@const isSelectable = selectablePredicate(item)}
|
||||
{@const isSelected = selectedItems.includes(item.key)}
|
||||
{@const status = deploymentStatus[item.key]}
|
||||
{@const isDeployed = status?.status === 'deployed'}
|
||||
{@const blockedReason =
|
||||
!isSelectable && !isDeployed ? selectBlockedReason?.(item) : undefined}
|
||||
<!-- A resource is titled by its path, except an agent, titled by its summary. -->
|
||||
{@const showPath =
|
||||
isAgent?.(item) ||
|
||||
(item.kind !== 'resource' &&
|
||||
item.kind !== 'variable' &&
|
||||
item.kind !== 'resource_type')}
|
||||
<!-- The group header already names the folder — the path line only
|
||||
carries what's below it. -->
|
||||
{@const subPath =
|
||||
group.key && item.path.startsWith(group.key + '/')
|
||||
{@render itemRow(
|
||||
item,
|
||||
0,
|
||||
showGroupHeaders && group.key && item.path.startsWith(group.key + '/')
|
||||
? item.path.slice(group.key.length + 1)
|
||||
: item.path}
|
||||
|
||||
<Row
|
||||
isSelectable={!hideSelection && isSelectable && !isDeployed}
|
||||
selectDisabledReason={blockedReason}
|
||||
selectOnRowClick={!hideSelection}
|
||||
alignWithSelectable={!hideSelection}
|
||||
disabled={!hideSelection && (blockedReason ? false : !isSelectable)}
|
||||
selected={isSelected && !isDeployed}
|
||||
onSelect={() => handleSelect(item)}
|
||||
path={showPath ? item.path : ''}
|
||||
marked={undefined}
|
||||
kind={isAgent?.(item) ? 'agent' : item.kind}
|
||||
triggerKind={item.triggerKind}
|
||||
canFavorite={false}
|
||||
workspaceId=""
|
||||
>
|
||||
{#snippet customSummary()}
|
||||
{#if itemSummary}
|
||||
{@render itemSummary(item)}
|
||||
{:else}
|
||||
{item.path}
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet pathDisplay()}
|
||||
{#if itemPath}
|
||||
{@render itemPath(item)}
|
||||
{:else}
|
||||
{showPath ? (showGroupHeaders ? subPath : item.path) : ''}
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet actions()}
|
||||
{#if itemActions}
|
||||
{@render itemActions(item)}
|
||||
{/if}
|
||||
<!-- Deployment status always shown -->
|
||||
{#if status}
|
||||
{#if status.status === 'loading'}
|
||||
<Loader2 class="animate-spin" />
|
||||
{:else if status.status === 'deployed'}
|
||||
<Badge color="green">Deployed</Badge>
|
||||
{:else if status.status === 'failed'}
|
||||
<div class="inline-flex gap-1">
|
||||
<Badge color="red">Failed</Badge>
|
||||
<Tooltip>{status.error}</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Row>
|
||||
: item.path
|
||||
)}
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
detail: Snippet
|
||||
/** Controls rendered next to the name. Clicks on them do not toggle the row. */
|
||||
actions?: Snippet
|
||||
/** Always-visible control before the icon (e.g. a checkbox). Clicks on it do not
|
||||
* toggle the row. */
|
||||
lead?: Snippet
|
||||
/** Always-visible controls before the chevron. They stop their own clicks. */
|
||||
trailing?: Snippet
|
||||
/** False for a row known to group nothing: it renders without a chevron and does not toggle. */
|
||||
@@ -35,6 +38,7 @@
|
||||
toggleLabel,
|
||||
detail,
|
||||
actions,
|
||||
lead,
|
||||
trailing,
|
||||
expandable = true
|
||||
}: Props = $props()
|
||||
@@ -54,6 +58,11 @@
|
||||
class="flex flex-row items-center gap-4"
|
||||
style={indent > 0 ? `padding-left: ${indent}px;` : ''}
|
||||
>
|
||||
{#if lead}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="flex" onclick={(e) => e.stopPropagation()}>{@render lead()}</div>
|
||||
{/if}
|
||||
<Icon size={16} class="text-secondary shrink-0" />
|
||||
<div>
|
||||
<div class="flex flex-row items-center gap-1">
|
||||
|
||||
@@ -64,10 +64,15 @@
|
||||
leaf?: Snippet<[ItemType, number]>
|
||||
// Remembers which nodes the user opened by hand, so they reopen on the next visit
|
||||
// while expand/collapse-all is in its collapsed state.
|
||||
openMemory?: TreeOpenMemory
|
||||
openMemory?: Pick<TreeOpenMemory, 'isOpen' | 'setOpen'>
|
||||
// Adds a "Manage folder" menu ("View folder" for a non-owner) to top-level folder rows.
|
||||
// Subfolders are path segments, not folders with permissions of their own, so get none.
|
||||
onManageFolder?: (folderName: string) => void
|
||||
// An always-visible control before a folder/user row's icon, given the node's
|
||||
// full path prefix (e.g. a checkbox selecting everything under it).
|
||||
ownerLead?: Snippet<[string]>
|
||||
// Appended to a folder/user row's item count, given the node's full path prefix.
|
||||
ownerDetail?: Snippet<[string]>
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -88,7 +93,9 @@
|
||||
indent = 0,
|
||||
leaf,
|
||||
openMemory,
|
||||
onManageFolder
|
||||
onManageFolder,
|
||||
ownerLead,
|
||||
ownerDetail
|
||||
}: Props = $props()
|
||||
|
||||
const unruled = inUnruledList()
|
||||
@@ -335,6 +342,12 @@
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#snippet ownerLeadForNode()}
|
||||
{#if nodePrefix != undefined}
|
||||
{@render ownerLead?.(nodePrefix)}
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#if isFolder(item) || isUser(item)}
|
||||
<div>
|
||||
<TreeOwnerRow
|
||||
@@ -345,6 +358,7 @@
|
||||
expandable={!empty || opened}
|
||||
indent={visualDepth * 16}
|
||||
actions={onManageFolder && depth === 0 && isFolder(item) ? manageFolderMenu : undefined}
|
||||
lead={ownerLead && nodePrefix != undefined ? ownerLeadForNode : undefined}
|
||||
trailing={badgeRoot ? folderBadge : undefined}
|
||||
>
|
||||
{#snippet detail()}
|
||||
@@ -362,6 +376,9 @@
|
||||
{:else}
|
||||
({pluralize(loadedHere, ' item')})
|
||||
{/if}
|
||||
{#if ownerDetail && nodePrefix != undefined}
|
||||
{@render ownerDetail(nodePrefix)}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</TreeOwnerRow>
|
||||
<!-- ResizeObserver, not a slide: a freshly-opened owner fetches its rows, so its height
|
||||
@@ -400,6 +417,8 @@
|
||||
{indent}
|
||||
{leaf}
|
||||
{onManageFolder}
|
||||
{ownerLead}
|
||||
{ownerDetail}
|
||||
/>
|
||||
{/each}
|
||||
{#if effectiveMax < item.items.length}
|
||||
|
||||
@@ -52,9 +52,13 @@
|
||||
// See TreeView's `leaf`.
|
||||
leaf?: Snippet<[ItemType, number]>
|
||||
// See TreeView's `openMemory`.
|
||||
openMemory?: TreeOpenMemory
|
||||
openMemory?: Pick<TreeOpenMemory, 'isOpen' | 'setOpen'>
|
||||
// See TreeView's `onManageFolder`.
|
||||
onManageFolder?: (folderName: string) => void
|
||||
// See TreeView's `ownerLead`.
|
||||
ownerLead?: Snippet<[string]>
|
||||
// See TreeView's `ownerDetail`.
|
||||
ownerDetail?: Snippet<[string]>
|
||||
// Inject folders `ownerCounts` calls empty, as "0 items". Off under a kind filter,
|
||||
// where those counts are per kind and every folder lacking that kind would show.
|
||||
keepEmptyFolders?: boolean
|
||||
@@ -85,6 +89,8 @@
|
||||
leaf,
|
||||
openMemory,
|
||||
onManageFolder,
|
||||
ownerLead,
|
||||
ownerDetail,
|
||||
keepEmptyFolders = false,
|
||||
keptFolders
|
||||
}: Props = $props()
|
||||
@@ -295,6 +301,8 @@
|
||||
{leaf}
|
||||
{openMemory}
|
||||
{onManageFolder}
|
||||
{ownerLead}
|
||||
{ownerDetail}
|
||||
/>
|
||||
{/snippet}
|
||||
|
||||
|
||||
@@ -23,18 +23,22 @@
|
||||
import RawAppRecordSession from './RawAppRecordSession.svelte'
|
||||
import AssetGraphCanvas from '$lib/components/assets/AssetGraph/AssetGraphCanvas.svelte'
|
||||
import {
|
||||
ArrowLeft,
|
||||
Check,
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
Cloud,
|
||||
Code2,
|
||||
Database,
|
||||
Eye,
|
||||
ExternalLink,
|
||||
FolderTree,
|
||||
Image as ImageIcon,
|
||||
Info,
|
||||
LayoutDashboard,
|
||||
Loader2,
|
||||
Play,
|
||||
Plus,
|
||||
RotateCcw,
|
||||
TriangleAlert,
|
||||
X,
|
||||
@@ -43,19 +47,113 @@
|
||||
import BarsStaggered from '$lib/components/icons/BarsStaggered.svelte'
|
||||
import ConfirmationModal from '../common/confirmationModal/ConfirmationModal.svelte'
|
||||
import Popover from '$lib/components/Popover.svelte'
|
||||
import { untrack } from 'svelte'
|
||||
|
||||
// Folder name (no `f/`) this project is scoped to; provided by the /folders launcher.
|
||||
let { folder: folderProp }: { folder: string } = $props()
|
||||
|
||||
// The whole folder or one of its sub-paths (`hub/billing`); each is its own Hub project.
|
||||
let scope = $state(untrack(() => folderProp))
|
||||
|
||||
// All deploy state lives in a session keyed by (workspace, folder): switching
|
||||
// either replaces the instance (and the {#key} below remounts the UI, closing
|
||||
// drawers), so nothing here needs resetting by hand.
|
||||
const deployHub = useDeployToHubSession({
|
||||
workspace: () => $workspaceStore,
|
||||
folder: () => folderProp,
|
||||
folder: () => scope,
|
||||
listFolder: () => folderProp,
|
||||
hasEeLicense: () => !!$enterpriseLicense
|
||||
})
|
||||
|
||||
// Until a scope has a Hub project, its selection decides which project it is.
|
||||
// Waiting on `hubChecked` keeps an existing project from being left before it is found.
|
||||
$effect(() => {
|
||||
const s = deployHub.session
|
||||
if (!s || s.phase !== 'predeploy' || s.effectiveSlug || !s.hubChecked) return
|
||||
if (s.selectedItems.length && s.selectionScope !== s.folder) scope = s.selectionScope
|
||||
})
|
||||
|
||||
type HubProject = { folder: string; status: string; name: string }
|
||||
// The folder's Hub projects (the whole folder and any sub-paths), found once when the
|
||||
// drawer opens; undefined until then. None: the tree. Only the whole folder: that
|
||||
// project, as on main. Any sub-path project: a list to pick from, the one place to
|
||||
// start another.
|
||||
let projects = $state<HubProject[] | undefined>(undefined)
|
||||
let showList = $state(false)
|
||||
const wholeIsProject = $derived(!!projects?.some((p) => p.folder === folderProp))
|
||||
const hasSubProjects = $derived(!!projects?.some((p) => p.folder !== folderProp))
|
||||
|
||||
function statusOf(s: DeployToHubSession): string {
|
||||
return s.liveOnHub || s.phase === 'live'
|
||||
? 'live'
|
||||
: s.phase === 'under_review'
|
||||
? 'under_review'
|
||||
: 'draft'
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const s = deployHub.session
|
||||
if (projects || !s || s.folder !== folderProp || !s.hubChecked || !s.subProjectsChecked) return
|
||||
const found: HubProject[] = [
|
||||
...(s.effectiveSlug
|
||||
? [{ folder: folderProp, status: statusOf(s), name: s.hubName || s.hubSlug }]
|
||||
: []),
|
||||
...s.subProjects
|
||||
]
|
||||
projects = found
|
||||
showList = s.subProjects.length > 0
|
||||
})
|
||||
|
||||
// The open project keeps its list entry current: one created here joins the list,
|
||||
// and a submit or approval shows up when going back to it.
|
||||
$effect(() => {
|
||||
const s = deployHub.session
|
||||
if (!s?.effectiveSlug) return
|
||||
const entry = { folder: s.folder, status: statusOf(s), name: s.hubName || s.hubSlug }
|
||||
untrack(() => {
|
||||
if (!projects) return
|
||||
const cur = projects.find((p) => p.folder === entry.folder)
|
||||
if (cur?.status === entry.status && cur.name === entry.name) return
|
||||
projects = [...projects.filter((p) => p.folder !== entry.folder), entry].sort((a, b) =>
|
||||
a.folder.localeCompare(b.folder)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
// No project takes in items another one holds. A new one is kept out of every
|
||||
// project; an existing one only out of projects nested inside it, never out of its
|
||||
// own items because a project above it was published later.
|
||||
$effect(() => {
|
||||
const s = deployHub.session
|
||||
if (!s || !projects) return
|
||||
const folders = projects.map((p) => p.folder)
|
||||
s.blockedFolders = s.effectiveSlug
|
||||
? folders.filter((f) => f.startsWith(`${s.folder}/`))
|
||||
: folders
|
||||
})
|
||||
|
||||
// Once the folder has projects, a new one is a sub-path: the whole folder would
|
||||
// take in their items.
|
||||
function needsSubFolder(s: DeployToHubSession): boolean {
|
||||
return !s.effectiveSlug && s.folder === folderProp && !!projects?.length
|
||||
}
|
||||
|
||||
function startNewProject() {
|
||||
showList = false
|
||||
scope = folderProp
|
||||
}
|
||||
function openProject(folder: string) {
|
||||
showList = false
|
||||
scope = folder
|
||||
}
|
||||
function statusBadge(status: string): { color: 'green' | 'yellow' | 'gray'; label: string } {
|
||||
return status === 'live'
|
||||
? { color: 'green', label: 'Live on Hub' }
|
||||
: status === 'under_review'
|
||||
? { color: 'yellow', label: 'In review on Hub' }
|
||||
: { color: 'gray', label: 'Draft on Hub' }
|
||||
}
|
||||
|
||||
let recordDrawer = $state<Drawer | undefined>()
|
||||
let appRecordDrawer = $state<Drawer | undefined>()
|
||||
let appRecordTarget = $state<DeployItem | undefined>(undefined)
|
||||
@@ -153,7 +251,59 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if deployHub.session}
|
||||
{#snippet subProjectNote(prefix: string)}
|
||||
{@const sp = projects?.find((p) => `f/${p.folder}` === prefix)}
|
||||
{#if sp}
|
||||
{@const b = statusBadge(sp.status)}
|
||||
<Badge small color={b.color} wrapperClass="ml-1">
|
||||
<Cloud size={10} class="mr-1" />
|
||||
{b.label}
|
||||
</Badge>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#if !projects}
|
||||
<div class="flex items-center gap-2 py-8 text-xs text-secondary">
|
||||
<Loader2 size={14} class="animate-spin" /> Looking for Hub projects…
|
||||
</div>
|
||||
{:else if showList}
|
||||
<div class="flex flex-col gap-3 max-w-2xl">
|
||||
<span class="text-sm font-semibold text-emphasis">Hub projects from this folder</span>
|
||||
<span class="text-xs text-primary">Pick a project to update, record or submit.</span>
|
||||
<div class="flex flex-col border rounded-md bg-surface-tertiary divide-y">
|
||||
{#each projects as p (p.folder)}
|
||||
{@const b = statusBadge(p.status)}
|
||||
<button
|
||||
class="flex items-center gap-3 px-4 py-3 text-left hover:bg-surface-hover"
|
||||
onclick={() => openProject(p.folder)}
|
||||
>
|
||||
<FolderTree size={16} class="text-secondary shrink-0" />
|
||||
<span class="flex flex-col gap-0.5 min-w-0">
|
||||
<span class="text-xs font-semibold text-emphasis truncate">{p.name}</span>
|
||||
<span class="text-2xs font-mono text-secondary truncate">f/{p.folder}/</span>
|
||||
</span>
|
||||
<Badge small color={b.color} wrapperClass="ml-auto">
|
||||
<Cloud size={10} class="mr-1" />
|
||||
{b.label}
|
||||
</Badge>
|
||||
<ChevronRight size={16} class="text-secondary shrink-0" />
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{#if !wholeIsProject}
|
||||
<div class="flex">
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: Plus }}
|
||||
onclick={startNewProject}
|
||||
>
|
||||
New project from another sub-folder
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if deployHub.session}
|
||||
<ConfirmationModal
|
||||
open={discardTarget !== undefined}
|
||||
title="Discard update"
|
||||
@@ -175,6 +325,10 @@
|
||||
<div>
|
||||
<WorkspaceDeployLayout
|
||||
items={s.items}
|
||||
nested
|
||||
folderDetail={subProjectNote}
|
||||
selectablePredicate={(i) => !s.isBlocked(i.path)}
|
||||
selectBlockedReason={() => 'Already part of another Hub project'}
|
||||
selectedItems={s.selectedItemKeys}
|
||||
deploymentStatus={s.deploymentStatus}
|
||||
hideSelection={s.phase !== 'predeploy'}
|
||||
@@ -224,6 +378,16 @@
|
||||
</li>
|
||||
</ol>
|
||||
<div class="flex flex-wrap items-center gap-2 pt-4">
|
||||
{#if hasSubProjects}
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
variant="subtle"
|
||||
iconOnly
|
||||
startIcon={{ icon: ArrowLeft }}
|
||||
title="Back to Hub projects"
|
||||
onclick={() => (showList = true)}
|
||||
/>
|
||||
{/if}
|
||||
{#if s.phase === 'predeploy'}
|
||||
<span class="text-sm font-semibold text-primary">
|
||||
Step 1: Bundle your project
|
||||
@@ -256,6 +420,7 @@
|
||||
variant="accent"
|
||||
loading={s.deploying || s.triggersLoading}
|
||||
disabled={s.selectedItems.length === 0 ||
|
||||
needsSubFolder(s) ||
|
||||
s.triggersLoading ||
|
||||
s.triggerDiscoveryFailed}
|
||||
startIcon={{ icon: Cloud }}
|
||||
@@ -325,6 +490,14 @@
|
||||
<span class="font-mono">{s.selectedFolder}/</span>.
|
||||
{s.selectedItems.length} of {s.filteredWorkspaceItems.length} items selected.
|
||||
</span>
|
||||
{#if needsSubFolder(s) && s.selectedItems.length}
|
||||
<span
|
||||
class="flex items-center gap-1.5 text-xs text-yellow-700 dark:text-yellow-400"
|
||||
>
|
||||
<TriangleAlert size={12} class="shrink-0" />
|
||||
Select items inside one sub-folder: the whole folder already holds other Hub projects.
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs">
|
||||
<span class="font-semibold text-primary shrink-0">
|
||||
@@ -766,7 +939,8 @@
|
||||
<div class="flex flex-col gap-3">
|
||||
<p class="text-xs text-secondary">
|
||||
Run this {s.recordTarget?.kind} once with the inputs below. The full execution — args, logs,
|
||||
intermediate step outputs and final result — is saved as a <b>replayable recording</b>
|
||||
intermediate step outputs and final result — is saved as a
|
||||
<b>replayable recording</b>
|
||||
shown on the Hub page. Visitors can step through it to see how the {s.recordTarget
|
||||
?.kind} works without running anything themselves.
|
||||
</p>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
canRecordSession,
|
||||
commonFolderPath,
|
||||
folderSubPaths,
|
||||
inputResourceTypes,
|
||||
mergeAppTableOrigin,
|
||||
type DeployItem
|
||||
@@ -62,3 +64,26 @@ describe('inputResourceTypes', () => {
|
||||
expect(inputResourceTypes(schema, new Set())).toEqual(all)
|
||||
})
|
||||
})
|
||||
|
||||
describe('folderSubPaths', () => {
|
||||
it('lists every sub-path that holds an item, at every depth', () => {
|
||||
expect(
|
||||
folderSubPaths(
|
||||
['f/hub/top', 'f/hub/billing/utils/x', 'f/hub/notifications/send', 'f/other/a/b'],
|
||||
'hub'
|
||||
)
|
||||
).toEqual(['hub/billing', 'hub/billing/utils', 'hub/notifications'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('commonFolderPath', () => {
|
||||
it('is the deepest sub-path holding every selected item', () => {
|
||||
expect(commonFolderPath(['f/hub/billing/charge', 'f/hub/billing/utils/format'])).toBe(
|
||||
'hub/billing'
|
||||
)
|
||||
expect(commonFolderPath(['f/hub/billing/utils/format'])).toBe('hub/billing/utils')
|
||||
expect(commonFolderPath(['f/hub/billing/charge', 'f/hub/notifications/send'])).toBe('hub')
|
||||
expect(commonFolderPath(['f/hub/billing/charge', 'f/hub/readme_bot'])).toBe('hub')
|
||||
expect(commonFolderPath([])).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,3 +82,37 @@ export function mergeAppTableOrigin(
|
||||
})
|
||||
return changed ? merged : draftItems
|
||||
}
|
||||
|
||||
/**
|
||||
* Every sub-path of `folder` that holds at least one item, at every depth, sorted:
|
||||
* `hub` with `f/hub/billing/utils/x` gives `['hub/billing', 'hub/billing/utils']`.
|
||||
*/
|
||||
export function folderSubPaths(paths: string[], folder: string): string[] {
|
||||
const prefix = `f/${folder}/`
|
||||
const out = new Set<string>()
|
||||
for (const p of paths) {
|
||||
if (!p.startsWith(prefix)) continue
|
||||
const dirs = p.slice(prefix.length).split('/').slice(0, -1)
|
||||
for (let i = 1; i <= dirs.length; i++) out.add(`${folder}/${dirs.slice(0, i).join('/')}`)
|
||||
}
|
||||
return [...out].sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* The deepest folder sub-path holding every selected `f/...` path: `f/hub/billing/a`
|
||||
* and `f/hub/billing/utils/b` give `hub/billing`. `undefined` for an empty selection.
|
||||
*/
|
||||
export function commonFolderPath(paths: string[]): string | undefined {
|
||||
let common: string[] | undefined
|
||||
for (const p of paths) {
|
||||
const dirs = p.split('/').slice(1, -1)
|
||||
if (!common) {
|
||||
common = dirs
|
||||
continue
|
||||
}
|
||||
let n = 0
|
||||
while (n < common.length && n < dirs.length && common[n] === dirs[n]) n++
|
||||
common = common.slice(0, n)
|
||||
}
|
||||
return common?.length ? common.join('/') : undefined
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ import type { Kind } from '$lib/utils_deployable'
|
||||
import {
|
||||
canRecord,
|
||||
canRecordSession,
|
||||
commonFolderPath,
|
||||
folderSubPaths,
|
||||
inputResourceTypes,
|
||||
mergeAppTableOrigin,
|
||||
HIDDEN_RESOURCE_TYPES,
|
||||
@@ -141,6 +143,9 @@ export class DeployToHubSession {
|
||||
readonly folder: string
|
||||
/** `f/`-prefixed folder path the project is scoped to. */
|
||||
readonly selectedFolder: string
|
||||
/** The base folder whose items are offered for selection; `folder` is it or one of
|
||||
* its sub-paths. */
|
||||
readonly listFolder: string
|
||||
|
||||
#disposed = false
|
||||
#deps: SessionDeps
|
||||
@@ -265,11 +270,22 @@ export class DeployToHubSession {
|
||||
#previewItemCache = new Map<string, Promise<FetchedItem | undefined>>()
|
||||
#previewTypeCache = new Map<string, Promise<string | undefined>>()
|
||||
|
||||
constructor(workspace: string, folder: string, deps: SessionDeps) {
|
||||
constructor(
|
||||
workspace: string,
|
||||
folder: string,
|
||||
deps: SessionDeps,
|
||||
listFolder: string = folder,
|
||||
seed?: { items: DeployItem[]; deselected: Set<string> }
|
||||
) {
|
||||
this.workspace = workspace
|
||||
this.folder = folder
|
||||
this.selectedFolder = `f/${folder}`
|
||||
this.listFolder = listFolder
|
||||
this.#deps = deps
|
||||
if (seed) {
|
||||
this.workspaceItems = seed.items
|
||||
this.manualDeselected = seed.deselected
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
@@ -301,8 +317,22 @@ export class DeployToHubSession {
|
||||
}
|
||||
}
|
||||
|
||||
/** Set once the Hub has said whether this scope already has a project. */
|
||||
hubChecked = $state(false)
|
||||
/** Sub-paths of the base folder that are Hub projects of their own. */
|
||||
subProjects = $state<{ folder: string; status: string; name: string }[]>([])
|
||||
/** Set once `subProjects` has been looked up. */
|
||||
subProjectsChecked = $state(false)
|
||||
#subProjectsLoaded = false
|
||||
/** Folders already published as other projects: their items cannot join this one. */
|
||||
blockedFolders = $state<string[]>([])
|
||||
isBlocked = (path: string) => this.blockedFolders.some((f) => path.startsWith(`f/${f}/`))
|
||||
// A scope with a Hub project offers only its own items, so an update cannot drift
|
||||
// into another scope's project; until then the whole base folder is offered.
|
||||
filteredWorkspaceItems = $derived(
|
||||
this.workspaceItems.filter((i) => i.path.startsWith(this.selectedFolder + '/'))
|
||||
this.workspaceItems.filter((i) =>
|
||||
i.path.startsWith(`f/${this.effectiveSlug ? this.folder : this.listFolder}/`)
|
||||
)
|
||||
)
|
||||
// Derived (not merged at load time) so it settles regardless of which of the
|
||||
// racing loads (#loadWorkspace / rehydrateFromHub) finishes last.
|
||||
@@ -312,13 +342,24 @@ export class DeployToHubSession {
|
||||
)
|
||||
selectedItems = $derived(
|
||||
this.phase === 'predeploy'
|
||||
? this.filteredWorkspaceItems.filter((i) => !this.manualDeselected.has(i.key))
|
||||
? this.filteredWorkspaceItems.filter(
|
||||
(i) => !this.manualDeselected.has(i.key) && !this.isBlocked(i.path)
|
||||
)
|
||||
: []
|
||||
)
|
||||
selectedItemKeys = $derived(this.selectedItems.map((i) => i.key))
|
||||
allSelected = $derived(
|
||||
this.phase === 'predeploy' &&
|
||||
this.selectedItemKeys.length === this.filteredWorkspaceItems.length
|
||||
this.selectedItemKeys.length ===
|
||||
this.filteredWorkspaceItems.filter((i) => !this.isBlocked(i.path)).length
|
||||
)
|
||||
/** The project the selection describes: the whole base folder while everything is
|
||||
* selected and no other project holds part of it, else the deepest sub-path holding
|
||||
* all of it. */
|
||||
selectionScope = $derived.by(() =>
|
||||
this.allSelected && !this.blockedFolders.length
|
||||
? this.listFolder
|
||||
: (commonFolderPath(this.selectedItems.map((i) => i.path)) ?? this.folder)
|
||||
)
|
||||
// A raw app's recorded session counts towards the project's recordings just as
|
||||
// a script's captured run does — both are what a visitor replays.
|
||||
@@ -596,6 +637,36 @@ export class DeployToHubSession {
|
||||
}
|
||||
}
|
||||
|
||||
// ponytail: one lookup per sub-path; a by-prefix Hub query if folders grow deep.
|
||||
async loadSubProjects() {
|
||||
if (this.#subProjectsLoaded) return
|
||||
this.#subProjectsLoaded = true
|
||||
const subs = folderSubPaths(
|
||||
this.workspaceItems.map((i) => i.path),
|
||||
this.listFolder
|
||||
)
|
||||
const found = await Promise.all(
|
||||
subs.map(async (folder) => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/w/${this.workspace}/hub/project?folder=${encodeURIComponent(folder)}`,
|
||||
{ credentials: 'include', headers: { accept: 'application/json' } }
|
||||
)
|
||||
if (!res.ok) return undefined
|
||||
const p = await res.json()
|
||||
return p?.slug
|
||||
? { folder, status: String(p.status ?? 'draft'), name: String(p.name || p.slug) }
|
||||
: undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
})
|
||||
)
|
||||
if (this.#disposed) return
|
||||
this.subProjects = found.filter((p) => p !== undefined)
|
||||
this.subProjectsChecked = true
|
||||
}
|
||||
|
||||
async rehydrateFromHub() {
|
||||
try {
|
||||
const res = await fetch(`/api/w/${this.workspace}/hub/project${this.#folderQs()}`, {
|
||||
@@ -638,7 +709,10 @@ export class DeployToHubSession {
|
||||
} satisfies DeployItem
|
||||
})
|
||||
this.hubItemIds = ids
|
||||
} catch {}
|
||||
} catch {
|
||||
} finally {
|
||||
if (!this.#disposed) this.hubChecked = true
|
||||
}
|
||||
}
|
||||
|
||||
/** Kick off schedule-preview fetches for any relevant schedule trigger missing one. */
|
||||
@@ -689,7 +763,14 @@ export class DeployToHubSession {
|
||||
const triggerVars = this.#triggerVarPaths(this.relevantTriggers)
|
||||
let cancelled = false
|
||||
const timer = setTimeout(() => {
|
||||
buildProjectBundle(seed, slug, this.#cachedBundleDeps(), triggerResources, triggerVars)
|
||||
buildProjectBundle(
|
||||
seed,
|
||||
slug,
|
||||
this.#cachedBundleDeps(),
|
||||
triggerResources,
|
||||
triggerVars,
|
||||
this.folder
|
||||
)
|
||||
.then((b) => {
|
||||
if (cancelled) return
|
||||
this.bundlePreview = b
|
||||
@@ -887,7 +968,7 @@ export class DeployToHubSession {
|
||||
|
||||
/** Prefill bundle metadata and start migration detection (bundle drawer opening). */
|
||||
prepareBundle() {
|
||||
this.hubName = this.hubName || this.folder
|
||||
this.hubName = this.hubName || (this.folder.split('/').pop() ?? this.folder)
|
||||
void this.regenerateMigrations()
|
||||
}
|
||||
|
||||
@@ -1062,7 +1143,8 @@ export class DeployToHubSession {
|
||||
): Promise<void> {
|
||||
const pathMap = buildPathMap(
|
||||
relevant.map((t) => t.path),
|
||||
slug
|
||||
slug,
|
||||
this.folder
|
||||
)
|
||||
const triggers: Array<Record<string, unknown>> = []
|
||||
const skipped: string[] = []
|
||||
@@ -1157,7 +1239,8 @@ export class DeployToHubSession {
|
||||
slug,
|
||||
this.#buildBundleDeps(),
|
||||
triggerResources,
|
||||
triggerVars
|
||||
triggerVars,
|
||||
this.folder
|
||||
)
|
||||
// Full path map (incl. unresolved) so a trigger's resource path is always
|
||||
// relocated — never leaks the publisher's original private path to the Hub.
|
||||
@@ -1858,6 +1941,8 @@ export class DeployToHubSession {
|
||||
export function useDeployToHubSession(args: {
|
||||
workspace: () => string | undefined
|
||||
folder: () => string
|
||||
/** The base folder offered for selection; `folder` is it or one of its sub-paths. */
|
||||
listFolder: () => string
|
||||
hasEeLicense: () => boolean
|
||||
}) {
|
||||
let session = $state<DeployToHubSession | undefined>()
|
||||
@@ -1865,13 +1950,28 @@ export function useDeployToHubSession(args: {
|
||||
$effect(() => {
|
||||
const workspace = args.workspace()
|
||||
const folder = args.folder()
|
||||
const listFolder = args.listFolder()
|
||||
if (!workspace) return
|
||||
untrack(() => {
|
||||
if (session && session.workspace === workspace && session.folder === folder) return
|
||||
session?.dispose()
|
||||
const next = new DeployToHubSession(workspace, folder, {
|
||||
hasEeLicense: args.hasEeLicense
|
||||
})
|
||||
const prev = session
|
||||
// A scope change made by editing the selection keeps that selection.
|
||||
const seed =
|
||||
prev &&
|
||||
prev.workspace === workspace &&
|
||||
prev.listFolder === listFolder &&
|
||||
prev.phase === 'predeploy' &&
|
||||
!prev.effectiveSlug
|
||||
? { items: prev.workspaceItems, deselected: prev.manualDeselected }
|
||||
: undefined
|
||||
prev?.dispose()
|
||||
const next = new DeployToHubSession(
|
||||
workspace,
|
||||
folder,
|
||||
{ hasEeLicense: args.hasEeLicense },
|
||||
listFolder,
|
||||
seed
|
||||
)
|
||||
session = next
|
||||
next.load()
|
||||
})
|
||||
@@ -1889,16 +1989,27 @@ export function useDeployToHubSession(args: {
|
||||
})
|
||||
})
|
||||
|
||||
// Leaving/entering predeploy invalidates manual selection tweaks.
|
||||
// Leaving/entering predeploy invalidates manual selection tweaks; a new session
|
||||
// keeps the selection it was seeded with.
|
||||
let phaseSeen: { s: DeployToHubSession; phase: Phase } | undefined
|
||||
$effect(() => {
|
||||
const s = session
|
||||
if (!s) return
|
||||
s.phase
|
||||
const phase = s.phase
|
||||
untrack(() => {
|
||||
s.manualDeselected = new Set()
|
||||
if (phaseSeen?.s === s && phaseSeen.phase !== phase) s.manualDeselected = new Set()
|
||||
phaseSeen = { s, phase }
|
||||
})
|
||||
})
|
||||
|
||||
// The base folder looks up which of its sub-paths are published on their own, once
|
||||
// its items have loaded.
|
||||
$effect(() => {
|
||||
const s = session
|
||||
if (s && s.hubChecked && !s.loading && s.folder === s.listFolder)
|
||||
untrack(() => void s.loadSubProjects())
|
||||
})
|
||||
|
||||
// Schedule previews for relevant schedule triggers (deduped in the session).
|
||||
$effect(() => {
|
||||
session?.ensureSchedulePreviews()
|
||||
|
||||
@@ -129,6 +129,20 @@ describe('buildPathMap', () => {
|
||||
expect(m.get('f/proj/a/x')).toBe('f/proj/a/x')
|
||||
expect(m.get('f/proj/b/x')).toBe('f/proj/b/x')
|
||||
})
|
||||
it('keeps the sub-path of every item in a nested source folder', () => {
|
||||
const m = buildPathMap(
|
||||
['f/hub/billing/charge', 'f/hub/billing/utils/format', 'f/hub/billing/stripe/format'],
|
||||
'billing',
|
||||
'hub/billing'
|
||||
)
|
||||
expect(m.get('f/hub/billing/charge')).toBe('f/billing/charge')
|
||||
expect(m.get('f/hub/billing/utils/format')).toBe('f/billing/utils/format')
|
||||
expect(m.get('f/hub/billing/stripe/format')).toBe('f/billing/stripe/format')
|
||||
// The same for a top-level folder whose name is not its slug.
|
||||
expect(buildPathMap(['f/my_tools/a/x'], 'my-tools', 'my_tools').get('f/my_tools/a/x')).toBe(
|
||||
'f/my-tools/a/x'
|
||||
)
|
||||
})
|
||||
it('relocates an external onto a suffix when its leaf collides with an internal path', () => {
|
||||
const m = buildPathMap(['f/proj/db', 'u/admin/db'], 'proj')
|
||||
expect(m.get('f/proj/db')).toBe('f/proj/db')
|
||||
|
||||
@@ -174,18 +174,25 @@ export function extractAppRefs(value: any): Ref[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the relocation map. Internal paths (`f/<slug>/...`) map to themselves
|
||||
* and are reserved first; external paths relocate to `f/<slug>/<name>` (`_2`/`_3`…
|
||||
* on collision). Input is sorted so suffix assignment is deterministic.
|
||||
* Build the relocation map. Paths under the source folder (`f/<sourceFolder>/...`,
|
||||
* possibly nested like `hub/billing`) keep their sub-path under `f/<slug>/` and are
|
||||
* reserved first; other paths relocate to `f/<slug>/<name>` (`_2`/`_3`… on
|
||||
* collision). Input is sorted so suffix assignment is deterministic.
|
||||
*/
|
||||
export function buildPathMap(paths: Iterable<string>, slug: string): Map<string, string> {
|
||||
export function buildPathMap(
|
||||
paths: Iterable<string>,
|
||||
slug: string,
|
||||
sourceFolder: string = slug
|
||||
): Map<string, string> {
|
||||
const map = new Map<string, string>()
|
||||
const used = new Set<string>()
|
||||
const sorted = [...new Set(paths)].sort()
|
||||
const sourcePrefix = `f/${sourceFolder}/`
|
||||
for (const p of sorted) {
|
||||
if (classifyPath(p, slug) === 'internal') {
|
||||
map.set(p, p)
|
||||
used.add(p)
|
||||
if (p.startsWith(sourcePrefix)) {
|
||||
const kept = `f/${slug}/${p.slice(sourcePrefix.length)}`
|
||||
map.set(p, kept)
|
||||
used.add(kept)
|
||||
}
|
||||
}
|
||||
for (const old of sorted) {
|
||||
@@ -640,7 +647,8 @@ export async function buildProjectBundle(
|
||||
slug: string,
|
||||
deps: BundleDeps,
|
||||
extraResourcePaths: string[] = [],
|
||||
extraVarPaths: string[] = []
|
||||
extraVarPaths: string[] = [],
|
||||
sourceFolder: string = slug
|
||||
): Promise<ProjectBundle> {
|
||||
const fetched = new Map<string, FetchedItem>()
|
||||
const queued = new Set<string>()
|
||||
@@ -701,7 +709,7 @@ export async function buildProjectBundle(
|
||||
|
||||
const fetchedItems = [...fetched.values()]
|
||||
const itemPaths = fetchedItems.map((it) => it.path)
|
||||
const map = buildPathMap([...itemPaths, ...resourcePaths, ...varPaths], slug)
|
||||
const map = buildPathMap([...itemPaths, ...resourcePaths, ...varPaths], slug, sourceFolder)
|
||||
|
||||
const items: BundledItem[] = fetchedItems.map((it) => {
|
||||
const rewritten: BundledItem = { ...it, newPath: map.get(it.path) ?? it.path }
|
||||
|
||||
Reference in New Issue
Block a user