mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 08:20:12 +00:00
refactor: drop the group data pages option and keep data as a sidebar section
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f1572c5d4d
commit
2ef4ce357c
@@ -1,5 +1,15 @@
|
||||
<script module lang="ts">
|
||||
import { isObjectStorageResourceType } from './assets/exploreAsset'
|
||||
const OBJECT_STORAGE_RESOURCE_TYPES = [
|
||||
's3',
|
||||
'azure_blob',
|
||||
's3_aws_oidc',
|
||||
'azure_workload_identity',
|
||||
'gcloud_storage'
|
||||
]
|
||||
|
||||
export function isObjectStorageResourceType(resourceType: string | undefined): boolean {
|
||||
return resourceType !== undefined && OBJECT_STORAGE_RESOURCE_TYPES.includes(resourceType)
|
||||
}
|
||||
|
||||
export function assetCanBeExplored(
|
||||
asset: Asset,
|
||||
@@ -19,10 +29,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { isDbType } from '$lib/components/dbTypes'
|
||||
import { type Asset } from '$lib/components/assets/lib'
|
||||
import { formatAsset, type Asset } from '$lib/components/assets/lib'
|
||||
import { Button, ButtonType } from '$lib/components/common'
|
||||
import S3FilePicker from '$lib/components/S3FilePicker.svelte'
|
||||
import { exploreAsset } from './assets/exploreAsset'
|
||||
import { VolumeService } from '$lib/gen'
|
||||
import { globalDbManagerDrawer, globalS3FilePickerExplorer } from '$lib/stores'
|
||||
import { isS3Uri } from '$lib/utils'
|
||||
import { Database, File, HardDriveIcon } from 'lucide-svelte'
|
||||
import DucklakeIcon from './icons/DucklakeIcon.svelte'
|
||||
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
|
||||
@@ -56,7 +68,12 @@
|
||||
workspace?: string
|
||||
} = $props()
|
||||
|
||||
let dbManagerDrawer = $derived(globalDbManagerDrawer.val)
|
||||
let ws = $derived(workspace ?? $operatingWorkspace)
|
||||
const assetUri = $derived(formatAsset(asset))
|
||||
// Contexts with a select/upload flow pass their own picker; everything else
|
||||
// (e.g. the resources list) falls back to the global read-only explorer.
|
||||
let effectiveS3FilePicker = $derived(s3FilePicker ?? globalS3FilePickerExplorer.val)
|
||||
let isStorageResource = $derived(
|
||||
asset.kind === 'resource' && isObjectStorageResourceType(_resourceMetadata?.resource_type)
|
||||
)
|
||||
@@ -70,11 +87,53 @@
|
||||
iconOnly={noText}
|
||||
{btnClasses}
|
||||
on:click={async () => {
|
||||
await exploreAsset(asset, {
|
||||
workspace: ws,
|
||||
resourceType: _resourceMetadata?.resource_type,
|
||||
s3FilePicker
|
||||
})
|
||||
if (asset.kind === 'resource' && isDbType(_resourceMetadata?.resource_type)) {
|
||||
let [resourcePath, specificTable] = asset.path.split('?table=')
|
||||
dbManagerDrawer?.openDrawer(
|
||||
{
|
||||
type: 'database',
|
||||
resourceType: _resourceMetadata.resource_type,
|
||||
resourcePath,
|
||||
specificTable
|
||||
},
|
||||
ws
|
||||
)
|
||||
} else if (isStorageResource) {
|
||||
effectiveS3FilePicker?.open(undefined, { s3ResourcePath: asset.path, workspace: ws })
|
||||
} else if (asset.kind === 's3object' && isS3Uri(assetUri)) {
|
||||
effectiveS3FilePicker?.open(assetUri, { workspace: ws })
|
||||
} else if (asset.kind === 'volume') {
|
||||
const storage = (await VolumeService.getVolumeStorage({ workspace: ws! })) ?? undefined
|
||||
effectiveS3FilePicker?.open(
|
||||
{ s3: `volumes/${ws}/${asset.path}/`, storage },
|
||||
{ workspace: ws }
|
||||
)
|
||||
} else if (asset.kind === 'ducklake') {
|
||||
let ducklake = asset.path.split('/')[0]
|
||||
let specificTableSplit = asset.path.split('/')[1]?.split('.') as string[] | undefined
|
||||
let [specificSchema, specificTable] =
|
||||
specificTableSplit?.length === 2
|
||||
? [specificTableSplit[0], specificTableSplit[1]]
|
||||
: [undefined, specificTableSplit?.[0]]
|
||||
dbManagerDrawer?.openDrawer({ type: 'ducklake', ducklake, specificSchema, specificTable }, ws)
|
||||
} else if (asset.kind === 'datatable') {
|
||||
let datatable = asset.path.split('/')[0]
|
||||
let specificTableSplit = asset.path.split('/')[1]?.split('.') as string[] | undefined
|
||||
let [specificSchema, specificTable] =
|
||||
specificTableSplit?.length === 2
|
||||
? [specificTableSplit[0], specificTableSplit[1]]
|
||||
: [undefined, specificTableSplit?.[0]]
|
||||
dbManagerDrawer?.openDrawer(
|
||||
{
|
||||
type: 'database',
|
||||
resourceType: 'postgresql',
|
||||
resourcePath: `datatable://${datatable}`,
|
||||
specificTable,
|
||||
specificSchema
|
||||
},
|
||||
ws
|
||||
)
|
||||
}
|
||||
onClick?.()
|
||||
}}
|
||||
endIcon={asset.kind === 's3object' || isStorageResource
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
import { isDbType } from '$lib/components/dbTypes'
|
||||
import { formatAsset, type Asset } from '$lib/components/assets/lib'
|
||||
import { VolumeService } from '$lib/gen'
|
||||
import { globalDbManagerDrawer, globalS3FilePickerExplorer } from '$lib/stores'
|
||||
import { isS3Uri } from '$lib/utils'
|
||||
|
||||
const OBJECT_STORAGE_RESOURCE_TYPES = [
|
||||
's3',
|
||||
'azure_blob',
|
||||
's3_aws_oidc',
|
||||
'azure_workload_identity',
|
||||
'gcloud_storage'
|
||||
]
|
||||
|
||||
export function isObjectStorageResourceType(resourceType: string | undefined): boolean {
|
||||
return resourceType !== undefined && OBJECT_STORAGE_RESOURCE_TYPES.includes(resourceType)
|
||||
}
|
||||
|
||||
// An S3FilePicker instance, typed loosely as `globalS3FilePickerExplorer` is: its instance type
|
||||
// resolves differently in .ts and .svelte contexts.
|
||||
type S3Picker = any
|
||||
|
||||
/** Opens an asset in its drawer: the database manager for a data table, a ducklake or a database
|
||||
* resource, the file browser for object storage and volumes. `s3FilePicker` is for a context with
|
||||
* its own select/upload flow; otherwise the logged layout's read-only explorer is used. */
|
||||
export async function exploreAsset(
|
||||
asset: Asset,
|
||||
opts: { workspace?: string; resourceType?: string; s3FilePicker?: S3Picker }
|
||||
): Promise<void> {
|
||||
const ws = opts.workspace
|
||||
const dbManagerDrawer = globalDbManagerDrawer.val
|
||||
const s3FilePicker = opts.s3FilePicker ?? globalS3FilePickerExplorer.val
|
||||
const assetUri = formatAsset(asset)
|
||||
if (asset.kind === 'resource' && isDbType(opts.resourceType)) {
|
||||
let [resourcePath, specificTable] = asset.path.split('?table=')
|
||||
dbManagerDrawer?.openDrawer(
|
||||
{ type: 'database', resourceType: opts.resourceType, resourcePath, specificTable },
|
||||
ws
|
||||
)
|
||||
} else if (asset.kind === 'resource' && isObjectStorageResourceType(opts.resourceType)) {
|
||||
s3FilePicker?.open(undefined, { s3ResourcePath: asset.path, workspace: ws })
|
||||
} else if (asset.kind === 's3object' && isS3Uri(assetUri)) {
|
||||
s3FilePicker?.open(assetUri, { workspace: ws })
|
||||
} else if (asset.kind === 'volume') {
|
||||
const storage = (await VolumeService.getVolumeStorage({ workspace: ws! })) ?? undefined
|
||||
s3FilePicker?.open({ s3: `volumes/${ws}/${asset.path}/`, storage }, { workspace: ws })
|
||||
} else if (asset.kind === 'ducklake' || asset.kind === 'datatable') {
|
||||
const [name, tablePart] = asset.path.split('/')
|
||||
const specificTableSplit = tablePart?.split('.')
|
||||
const [specificSchema, specificTable] =
|
||||
specificTableSplit?.length === 2
|
||||
? [specificTableSplit[0], specificTableSplit[1]]
|
||||
: [undefined, specificTableSplit?.[0]]
|
||||
dbManagerDrawer?.openDrawer(
|
||||
asset.kind === 'ducklake'
|
||||
? { type: 'ducklake', ducklake: name, specificSchema, specificTable }
|
||||
: {
|
||||
type: 'database',
|
||||
resourceType: 'postgresql',
|
||||
resourcePath: `datatable://${name}`,
|
||||
specificTable,
|
||||
specificSchema
|
||||
},
|
||||
ws
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<!--
|
||||
@component
|
||||
The Data menu's configured data tables, ducklakes and object storages, each opening its drawer
|
||||
(Manage or Explore) as the Assets page's cards do. Mounted with the open menu, so the lists are
|
||||
fetched on open.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { resource } from 'runed'
|
||||
import { Database, File } from 'lucide-svelte'
|
||||
import type { MenubarMenuElements } from '@melt-ui/svelte'
|
||||
import MenuItem from '$lib/components/meltComponents/MenuItem.svelte'
|
||||
import DucklakeIcon from '$lib/components/icons/DucklakeIcon.svelte'
|
||||
import { SettingService, WorkspaceService } from '$lib/gen'
|
||||
import type { Asset } from '$lib/components/assets/lib'
|
||||
import { exploreAsset } from '$lib/components/assets/exploreAsset'
|
||||
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
|
||||
import { useRoleCapabilities } from '$lib/operatorWriteRights'
|
||||
|
||||
let { item, itemClass }: { item: MenubarMenuElements['item']; itemClass: string } = $props()
|
||||
|
||||
const operatingWorkspace = useOperatingWorkspace()
|
||||
const roleCaps = useRoleCapabilities()
|
||||
|
||||
type Store = { asset: Asset; label: string; action: 'Manage' | 'Explore' }
|
||||
type StoreGroup = { title: string; stores: Store[] }
|
||||
|
||||
// A list that fails to load is left out rather than failing the menu.
|
||||
const groups = resource(
|
||||
() => ($roleCaps.code ? $operatingWorkspace : undefined),
|
||||
async (workspace): Promise<StoreGroup[]> => {
|
||||
if (!workspace) return []
|
||||
const [tables, ducklakes, storages] = await Promise.all([
|
||||
WorkspaceService.listDataTables({ workspace }).catch(() => []),
|
||||
WorkspaceService.listDucklakes({ workspace }).catch(() => []),
|
||||
SettingService.getSecondaryStorageNames({ workspace, includeDefault: true }).catch(() => [])
|
||||
])
|
||||
const all: StoreGroup[] = [
|
||||
{
|
||||
title: 'Data tables',
|
||||
stores: tables.map(({ name }): Store => ({
|
||||
asset: { kind: 'datatable', path: name },
|
||||
label: name === 'main' ? 'Main data table' : name,
|
||||
action: 'Manage'
|
||||
}))
|
||||
},
|
||||
{
|
||||
title: 'Ducklakes',
|
||||
stores: ducklakes.map((name): Store => ({
|
||||
asset: { kind: 'ducklake', path: name },
|
||||
label: name === 'main' ? 'Main ducklake' : name,
|
||||
action: 'Manage'
|
||||
}))
|
||||
},
|
||||
{
|
||||
title: 'Object storage',
|
||||
stores: storages.map((name): Store => ({
|
||||
asset: { kind: 's3object', path: name === '_default_' ? '/' : `${name}/` },
|
||||
label: name === '_default_' ? 'Primary storage' : name,
|
||||
action: 'Explore'
|
||||
}))
|
||||
}
|
||||
]
|
||||
return all.filter((g) => g.stores.length > 0)
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<!-- Headed as DropdownV2's `sectionTitle` rows are. -->
|
||||
{#each groups.current ?? [] as group (group.title)}
|
||||
<div class="my-1 border-t border-border-light"></div>
|
||||
<p class="px-4 pt-1.5 pb-1 text-2xs uppercase tracking-wide text-secondary">{group.title}</p>
|
||||
{#each group.stores as store (`${store.asset.kind}:${store.asset.path}`)}
|
||||
<MenuItem
|
||||
class={itemClass}
|
||||
{item}
|
||||
onClick={() => exploreAsset(store.asset, { workspace: $operatingWorkspace })}
|
||||
>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
{#if store.asset.kind === 'ducklake'}
|
||||
<DucklakeIcon size={16} />
|
||||
{:else if store.asset.kind === 'datatable'}
|
||||
<Database size={16} />
|
||||
{:else}
|
||||
<File size={16} />
|
||||
{/if}
|
||||
<span class="truncate">{store.label}</span>
|
||||
<span class="ml-auto pl-4 text-hint">{store.action}</span>
|
||||
</div>
|
||||
</MenuItem>
|
||||
{/each}
|
||||
{/each}
|
||||
@@ -22,7 +22,6 @@
|
||||
GraduationCap,
|
||||
PanelLeft,
|
||||
Star,
|
||||
Database,
|
||||
FolderOpen,
|
||||
Users
|
||||
} from 'lucide-svelte'
|
||||
@@ -248,13 +247,6 @@
|
||||
icon: Star,
|
||||
toggle: sidebarPrefs.favorites.val,
|
||||
action: () => (sidebarPrefs.favorites.val = !sidebarPrefs.favorites.val)
|
||||
},
|
||||
{
|
||||
displayName: 'Group data pages',
|
||||
description: 'Variables, Resources and Assets under one Data menu, rather than a Data section',
|
||||
icon: Database,
|
||||
toggle: !sidebarPrefs.splitData.val,
|
||||
action: () => (sidebarPrefs.splitData.val = !sidebarPrefs.splitData.val)
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -53,8 +53,6 @@
|
||||
getServiceIcon
|
||||
} from '../triggers/native/utils'
|
||||
import type { NativeServiceName } from '$lib/gen/types.gen'
|
||||
import DataStoresMenuItems from './DataStoresMenuItems.svelte'
|
||||
import { sidebarPrefs } from './sidebarPrefs.svelte'
|
||||
import {
|
||||
Menubar,
|
||||
Menu,
|
||||
@@ -62,7 +60,7 @@
|
||||
MenuItem,
|
||||
MeltButton
|
||||
} from '$lib/components/meltComponents'
|
||||
import MenuButton, { sidebarClasses } from './MenuButton.svelte'
|
||||
import MenuButton from './MenuButton.svelte'
|
||||
import SidebarSectionHeader from './SidebarSectionHeader.svelte'
|
||||
import GoogleCloudIcon from '../icons/triggers/GoogleCloudIcon.svelte'
|
||||
import AzureIcon from '../icons/triggers/AzureIcon.svelte'
|
||||
@@ -233,29 +231,14 @@
|
||||
}))
|
||||
.filter((l) => !excludeMainLabels.includes(l.label))
|
||||
)
|
||||
// Main-menu pages folded under one menu each, to keep the nav short.
|
||||
const MAIN_MENU_GROUPS = [
|
||||
{
|
||||
label: 'Data',
|
||||
icon: Database,
|
||||
members: ['Variables', 'Resources', 'Assets'],
|
||||
aiId: 'sidebar-menu-data',
|
||||
aiDescription: 'Menu with the variables, resources and assets pages'
|
||||
}
|
||||
]
|
||||
const groupedLabels = new Set(MAIN_MENU_GROUPS.flatMap((g) => g.members))
|
||||
let ungroupedMainLinks = $derived(mainMenuLinks.filter((l) => !groupedLabels.has(l.label)))
|
||||
// A disabled MenuLink renders nothing, so its page leaves the menu, and a group with no
|
||||
// Main-menu pages listed in a collapsible Data section of their own, as Triggers.
|
||||
const DATA_LABELS = ['Variables', 'Resources', 'Assets']
|
||||
let ungroupedMainLinks = $derived(mainMenuLinks.filter((l) => !DATA_LABELS.includes(l.label)))
|
||||
// A disabled MenuLink renders nothing, so its page leaves the section, and a section with no
|
||||
// page left leaves the nav.
|
||||
let menuGroups = $derived(
|
||||
MAIN_MENU_GROUPS.map((g) => ({
|
||||
...g,
|
||||
links: mainMenuLinks.filter((l) => g.members.includes(l.label) && !l.disabled)
|
||||
})).filter((g) => g.links.length > 0)
|
||||
let dataLinks = $derived(
|
||||
mainMenuLinks.filter((l) => DATA_LABELS.includes(l.label) && !l.disabled)
|
||||
)
|
||||
// "Customize sidebar" can unfold the Data menu into a collapsible section of the nav, as Triggers.
|
||||
let mainMenuGroups = $derived(sidebarPrefs.splitData.val ? [] : menuGroups)
|
||||
let dataSection = $derived(sidebarPrefs.splitData.val ? menuGroups[0] : undefined)
|
||||
const dataSectionCollapsed = useLocalStorageValue(
|
||||
'windmill_data_section_collapsed',
|
||||
false,
|
||||
@@ -540,52 +523,10 @@
|
||||
{#each ungroupedMainLinks as menuLink (menuLink.href ?? menuLink.label)}
|
||||
<MenuLink class="!text-xs" {...menuLink} {isCollapsed} />
|
||||
{/each}
|
||||
<Menubar class="flex flex-col gap-0.5">
|
||||
{#snippet children({ createMenu })}
|
||||
{#each mainMenuGroups as group (group.label)}
|
||||
{@const onGroupPage = group.links.some((l) => page.url.pathname.startsWith(l.href))}
|
||||
<Menu {createMenu} usePointerDownOutside placement="bottom-start">
|
||||
{#snippet triggr({ trigger })}
|
||||
<MenuButton
|
||||
class="!text-xs"
|
||||
icon={group.icon}
|
||||
label={group.label}
|
||||
{isCollapsed}
|
||||
showChevron
|
||||
buttonClass={onGroupPage ? sidebarClasses.selectedBg : undefined}
|
||||
labelClass={onGroupPage ? sidebarClasses.selectedText : undefined}
|
||||
aiId={group.aiId}
|
||||
aiDescription={group.aiDescription}
|
||||
{trigger}
|
||||
/>
|
||||
{/snippet}
|
||||
{#snippet children({ item })}
|
||||
{#each group.links as link (link.href)}
|
||||
<MenuItem
|
||||
class={itemClass}
|
||||
href={link.href}
|
||||
{item}
|
||||
aiId={link.aiId}
|
||||
aiDescription={link.aiDescription}
|
||||
>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<link.icon size={16} />
|
||||
{link.label}
|
||||
</div>
|
||||
</MenuItem>
|
||||
{/each}
|
||||
{#if group.label === 'Data'}
|
||||
<DataStoresMenuItems {item} {itemClass} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Menu>
|
||||
{/each}
|
||||
{/snippet}
|
||||
</Menubar>
|
||||
</div>
|
||||
{/if}
|
||||
{#if showMain}
|
||||
{#if dataSection}
|
||||
{#if dataLinks.length > 0}
|
||||
<!-- 8px: the layout's 2px gap above this nav makes it 10 under Runs. -->
|
||||
<div class={isCollapsed ? '' : 'mt-2'}>
|
||||
<!-- Collapsed, no title row: the rail's icons keep one pitch across sections. -->
|
||||
@@ -598,7 +539,7 @@
|
||||
{/if}
|
||||
{#if isCollapsed || !dataSectionCollapsed.val}
|
||||
<div transition:slide={{ duration: 180 }} class="flex flex-col gap-0.5">
|
||||
{#each dataSection.links as menuLink (menuLink.href)}
|
||||
{#each dataLinks as menuLink (menuLink.href)}
|
||||
<MenuLink class="!text-xs" {...menuLink} {isCollapsed} />
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,5 @@ import { useLocalStorageValue } from '$lib/svelte5Utils.svelte'
|
||||
* menu that flips a choice and the sidebar that reads it share one value. */
|
||||
export const sidebarPrefs = {
|
||||
/** The starred items as a section of their own. */
|
||||
favorites: useLocalStorageValue('windmill_sidebar_show_favorites', false, 'boolean'),
|
||||
/** Variables, Resources and Assets as a collapsible Data section instead of one Data menu. */
|
||||
splitData: useLocalStorageValue('windmill_sidebar_split_data', true, 'boolean')
|
||||
favorites: useLocalStorageValue('windmill_sidebar_show_favorites', false, 'boolean')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user