mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
fix: chat model menu loading rows, hover and empty-resource text (#12839)
* fix: chat model menu loading rows, read-only hover and empty resource wording * docs: describe the loading placeholder rows on ChoiceSection.loading * fix: announce the chat model menu's loading placeholder * fix: give the loading placeholder text a screen reader can announce * style: format the loading placeholder
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
* both. Driven entirely by ChatModelSettingsConfig, so the session chat and the flow
|
||||
* chat render the same control from different data — see chatModelSettings.ts.
|
||||
*/
|
||||
import { ChevronDown, Check, Loader2 } from 'lucide-svelte'
|
||||
import { ChevronDown, Check } from 'lucide-svelte'
|
||||
import Tooltip from '$lib/components/meltComponents/Tooltip.svelte'
|
||||
import DropdownV2 from '$lib/components/DropdownV2.svelte'
|
||||
import DropdownSubmenuItem from '$lib/components/DropdownSubmenuItem.svelte'
|
||||
import MenuItem from '$lib/components/meltComponents/MenuItem.svelte'
|
||||
@@ -74,6 +75,19 @@
|
||||
}
|
||||
})
|
||||
|
||||
// Rows each section last showed, for the placeholder while it reloads. Seven fill the
|
||||
// default list height; an empty or first load assumes a full list.
|
||||
const FULL_LIST_ROWS = 7
|
||||
const settledRows = new Map<string, number>()
|
||||
$effect(() => {
|
||||
for (const sec of config.sections ?? []) {
|
||||
if (!sec.loading) settledRows.set(sec.label, sec.options.length)
|
||||
}
|
||||
})
|
||||
function placeholderRows(label: string): number {
|
||||
return Math.min(settledRows.get(label) || FULL_LIST_ROWS, FULL_LIST_ROWS)
|
||||
}
|
||||
|
||||
// Blocks are separated, not prefixed: a rule belongs between two of them, so the first
|
||||
// one rendered must not draw one above itself whichever block that turns out to be.
|
||||
const BLOCK_CLASS =
|
||||
@@ -95,7 +109,7 @@
|
||||
disabled={config.readOnly}
|
||||
endIcon={config.readOnly ? undefined : { icon: ChevronDown }}
|
||||
btnClasses="w-full max-w-[200px] text-secondary font-normal"
|
||||
title={config.readOnly ? config.readOnlyReason : config.title}
|
||||
title={config.readOnly ? undefined : config.title}
|
||||
>
|
||||
<span class="flex items-center gap-1 min-w-0">
|
||||
{#if config.shortLabel}
|
||||
@@ -167,8 +181,15 @@
|
||||
{#snippet section(sec: ChoiceSection, item: MeltItem, close: () => void)}
|
||||
<div class="px-3 pt-1.5 pb-1 text-2xs uppercase tracking-wide text-secondary">{sec.label}</div>
|
||||
{#if sec.loading}
|
||||
<div class="flex items-center gap-2 px-3 py-1.5 text-tertiary">
|
||||
<Loader2 size={14} class="animate-spin" /> Loading...
|
||||
<!-- As many lines as the list it replaces, so the menu, anchored at the composer and
|
||||
growing upward, does not jump under the pointer twice for one load. -->
|
||||
<div class={twMerge('overflow-hidden', sec.maxHeight ?? 'max-h-48')} role="status">
|
||||
<span class="sr-only">Loading models</span>
|
||||
{#each { length: placeholderRows(sec.label) }, i (i)}
|
||||
<div class="px-3 py-1.5">
|
||||
<div class="h-4 w-3/4 rounded bg-surface-secondary animate-pulse"></div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if sec.options.length === 0}
|
||||
<div class="px-3 py-1.5 text-tertiary">{sec.emptyMessage ?? 'Nothing to choose from'}</div>
|
||||
@@ -187,7 +208,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{#if sec.custom && !sec.loading}
|
||||
{#if sec.custom}
|
||||
{@const custom = sec.custom}
|
||||
<div class="px-3 pt-1 pb-1.5">
|
||||
{@render typedField(
|
||||
@@ -225,7 +246,13 @@
|
||||
{/snippet}
|
||||
|
||||
{#if config.readOnly}
|
||||
{@render trigger()}
|
||||
<!-- A disabled button gets no hover, so its native title never shows. -->
|
||||
<Tooltip disablePopup={!config.readOnlyReason}>
|
||||
{@render trigger()}
|
||||
{#snippet text()}
|
||||
{config.readOnlyReason}
|
||||
{/snippet}
|
||||
</Tooltip>
|
||||
{:else}
|
||||
<DropdownV2
|
||||
customMenu
|
||||
|
||||
@@ -23,10 +23,11 @@ export type ModelChoice = {
|
||||
}
|
||||
|
||||
export type ChoiceSection = {
|
||||
/** Section heading, e.g. 'Provider' or 'Model'. */
|
||||
/** Section heading, e.g. 'Provider' or 'Model'. Unique within the menu. */
|
||||
label: string
|
||||
options: ModelChoice[]
|
||||
/** Fetched lists render one consistent loading line instead of the options. */
|
||||
/** While a fetched list loads, placeholder rows sized like the last list it showed take the
|
||||
* options' place; the custom entry stays usable. */
|
||||
loading?: boolean
|
||||
/** Shown when the list is empty and settled. */
|
||||
emptyMessage?: string
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
type ChatModelSettingsConfig
|
||||
} from '$lib/components/copilot/chatModelSettings'
|
||||
import AppConnect from '$lib/components/AppConnectDrawer.svelte'
|
||||
import { AI_PROVIDERS, fetchAvailableModels } from '$lib/components/copilot/lib'
|
||||
import {
|
||||
AI_PROVIDERS,
|
||||
aiProviderDetails,
|
||||
fetchAvailableModels
|
||||
} from '$lib/components/copilot/lib'
|
||||
import {
|
||||
explicitOffToken,
|
||||
getReasoningCapability
|
||||
@@ -188,11 +192,19 @@
|
||||
})
|
||||
}
|
||||
|
||||
// Resources are per user: the workspace may well hold some this person cannot use. Repeated
|
||||
// as the tooltip, the only way a cut-off disabled row shows its full text.
|
||||
const noResourceLabel = $derived(
|
||||
allowedResourceTypes.length === 1
|
||||
? `No ${aiProviderDetails(allowedResourceTypes[0] as AIProvider).label} resource you can use`
|
||||
: 'No AI resource you can use'
|
||||
)
|
||||
|
||||
function providerItem(close: () => void): Item {
|
||||
const rows: Item[] = resources.loading
|
||||
? [{ displayName: 'Loading resources...', disabled: true }]
|
||||
: (resources.current ?? []).length === 0
|
||||
? [{ displayName: 'No AI resource in this workspace', disabled: true }]
|
||||
? [{ displayName: noResourceLabel, tooltip: noResourceLabel, disabled: true }]
|
||||
: (resources.current ?? []).map((r) => ({
|
||||
displayName: r.path,
|
||||
selected: r.path === resourcePath,
|
||||
|
||||
Reference in New Issue
Block a user