This commit is contained in:
Timothy Jaeryang Baek committed 2026-12-04 08:20:45 +04:00
1 parent ff1ba7a507
commit 67ae3012bb
5 files changed
+291 -402

No files matched your search

@@ -20,8 +20,8 @@
import Eye from '$lib/components/icons/Eye.svelte';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Select from '$lib/components/common/Select.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import Check from '$lib/components/icons/Check.svelte';
export let onSubmit: Function = () => {};
@@ -291,36 +291,52 @@
defaultPermissions={custom ? inheritedPermissions : defaultPermissions}
/>
{:else if selectedTab == 'users'}
<!-- FilterMenu's circle trigger and radio items; the dot shows when it isn't Direct. -->
{#snippet membershipFilter()}
<div class="shrink-0">
<Select
bind:value={membershipTab}
items={[
{ value: 'direct', label: $i18n.t('Direct') },
{ value: 'inherited', label: $i18n.t('Inherited') }
]}
align="end"
triggerClass="flex items-center gap-1 rounded-lg px-1 py-0.5 text-xs font-normal text-base-500 transition hover:text-base-700 dark:text-base-400 dark:hover:text-base-200"
<Dropdown align="end">
<button
type="button"
class="relative flex size-6.5 shrink-0 items-center justify-center rounded-full border border-base-100 bg-base-50/60 transition-colors hover:bg-base-100 hover:text-base-900 disabled:cursor-not-allowed disabled:opacity-60 aria-expanded:bg-base-100 aria-expanded:text-base-900 dark:border-base-850 dark:bg-base-850/50 dark:hover:bg-base-850 dark:hover:text-base-0 dark:aria-expanded:bg-base-850 dark:aria-expanded:text-base-0 {membershipTab ===
'inherited'
? 'text-base-800 dark:text-base-100'
: 'text-base-500 dark:text-base-400'}"
aria-label={$i18n.t('Filter')}
title={$i18n.t('Filter')}
>
<svelte:fragment slot="trigger" let:selectedLabel>
<span>{selectedLabel}</span>
<ChevronDown className="size-2.5" strokeWidth="2.5" />
</svelte:fragment>
<svelte:fragment slot="item" let:item let:selected>
<span class="flex-1 text-left">{item.label}</span>
<Check className="size-3.5 {selected ? '' : 'invisible'}" />
</svelte:fragment>
</Select>
</div>
<svg
class="size-3.75"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
aria-hidden="true"><path d="M2.5 4h11M4.5 8h7M6.5 12h3" /></svg
>
{#if membershipTab === 'inherited'}
<span
class="absolute -top-0.5 -right-0.5 size-1.5 rounded-full bg-base-800 dark:bg-base-100"
></span>
{/if}
</button>
<DropdownMenu slot="content" className="w-40">
{#each [['direct', $i18n.t('Direct')], ['inherited', $i18n.t('Inherited')]] as [value, label] (value)}
<button
type="button"
role="menuitemradio"
aria-checked={membershipTab === value}
on:click={() => (membershipTab = value)}
>
<span class="min-w-0 flex-1 truncate text-left">{label}</span>
{#if membershipTab === value}<Check className="size-3! shrink-0" />{/if}
</button>
{/each}
</DropdownMenu>
</Dropdown>
{/snippet}
{#if membershipTab === 'direct'}
<Users bind:userCount groupId={group?.id} {onMemberChange}>
<svelte:fragment slot="filter">{@render membershipFilter()}</svelte:fragment>
</Users>
<Users bind:userCount groupId={group?.id} {onMemberChange} filter={membershipFilter} />
{:else}
<InheritedMembers groupId={group?.id} {groups}>
<svelte:fragment slot="filter">{@render membershipFilter()}</svelte:fragment>
</InheritedMembers>
<InheritedMembers groupId={group?.id} {groups} filter={membershipFilter} />
{/if}
{:else if selectedTab == 'preview'}
<GroupPreviewPanel groupId={group?.id} />
@@ -2,8 +2,9 @@
import { getContext } from 'svelte';
import { getGroupPreview } from '$lib/apis/groups';
import Spinner from '$lib/components/common/Spinner.svelte';
import TeamItemIcon from '$lib/components/teams/TeamItemIcon.svelte';
const i18n = getContext('i18n');
const i18n = getContext<import('svelte/store').Writable<import('i18next').i18n>>('i18n');
export let groupId: string = '';
@@ -26,111 +27,67 @@
loading = false;
}
};
// Literal $i18n.t calls, so i18n:parse keeps the keys.
$: sections = preview
? [
{
type: 'model' as const,
label: $i18n.t('Models'),
empty: $i18n.t('No models accessible'),
...preview.models
},
{
type: 'knowledge' as const,
label: $i18n.t('Knowledge'),
empty: $i18n.t('No knowledge bases accessible'),
...preview.knowledge
},
{
type: 'tool' as const,
label: $i18n.t('Tools'),
empty: $i18n.t('No tools accessible'),
...preview.tools
}
]
: [];
</script>
<div class="space-y-2">
{#if loading}
<div class="flex justify-center items-center py-8">
<Spinner className="size-5" />
</div>
{:else if error}
<div class="text-red-500 text-xs text-center py-4">{error}</div>
{:else if preview}
<div>
<div class=" mb-2 text-sm font-normal">{$i18n.t('Models')}</div>
<div class="flex flex-col w-full">
{#if preview.models.items.length === 0}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('No models accessible')}
</div>
</div>
{:else}
{#each preview.models.items as model}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs font-normal">{model.name}</div>
</div>
{/each}
{#if preview.models.total > preview.models.items.length}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('{{count}} of {{total}} accessible', {
count: preview.models.items.length,
total: preview.models.total
})}
</div>
</div>
<!-- The team Overview's groups: a muted label, then icon-and-name rows. -->
{#if loading}
<div class="my-10 flex justify-center"><Spinner className="size-4" /></div>
{:else if error}
<p role="alert" class="py-4 text-center text-xs text-red-500">{error}</p>
{:else if preview}
<div class="flex flex-col gap-4">
{#each sections as section (section.type)}
<section>
<div class="flex h-6 items-center justify-between gap-2">
<h3 class="text-xs text-base-400 dark:text-base-500">{section.label}</h3>
{#if section.total > section.items.length}
<span class="text-[0.6875rem] text-base-400 dark:text-base-500">
{$i18n.t('{{count}} of {{total}} accessible', {
count: section.items.length,
total: section.total
})}
</span>
{/if}
{/if}
</div>
</div>
<hr class="border-base-50 dark:border-base-850/30 my-1" />
<div>
<div class=" mb-2 text-sm font-normal">{$i18n.t('Knowledge')}</div>
<div class="flex flex-col w-full">
{#if preview.knowledge.items.length === 0}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('No knowledge bases accessible')}
</div>
</div>
</div>
{#if section.items.length}
<ul class="py-0.5">
{#each section.items as item (item.id)}
<li
class="flex min-h-8 items-center gap-2 py-[0.375rem] text-[0.8125rem] leading-5 text-base-800 dark:text-base-200"
>
<TeamItemIcon type={section.type} {item} />
<span class="min-w-0 truncate">{item.name}</span>
</li>
{/each}
</ul>
{:else}
{#each preview.knowledge.items as kb}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs font-normal">{kb.name}</div>
</div>
{/each}
{#if preview.knowledge.total > preview.knowledge.items.length}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('{{count}} of {{total}} accessible', {
count: preview.knowledge.items.length,
total: preview.knowledge.total
})}
</div>
</div>
{/if}
<p class="py-1.5 text-[0.8125rem] text-base-500 dark:text-base-400">{section.empty}</p>
{/if}
</div>
</div>
<hr class="border-base-50 dark:border-base-850/30 my-1" />
<div>
<div class=" mb-2 text-sm font-normal">{$i18n.t('Tools')}</div>
<div class="flex flex-col w-full">
{#if preview.tools.items.length === 0}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('No tools accessible')}
</div>
</div>
{:else}
{#each preview.tools.items as tool}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs font-normal">{tool.name}</div>
</div>
{/each}
{#if preview.tools.total > preview.tools.items.length}
<div class="flex w-full justify-between my-1">
<div class=" self-center text-xs text-base-500">
{$i18n.t('{{count}} of {{total}} accessible', {
count: preview.tools.items.length,
total: preview.tools.total
})}
</div>
</div>
{/if}
{/if}
</div>
</div>
{/if}
</div>
</section>
{/each}
</div>
{/if}
@@ -4,24 +4,23 @@
import { WEBUI_API_BASE_URL } from '$lib/constants';
import Pagination from '$lib/components/common/Pagination.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Search from '$lib/components/icons/Search.svelte';
const i18n = getContext<import('svelte/store').Writable<import('i18next').i18n>>('i18n');
export let groupId: string;
export let groups: import('../Groups.svelte').GroupListItem[] = [];
export let filter: import('svelte').Snippet | undefined = undefined;
let query = '';
let page = 1;
$: members = getGroupMembers(localStorage.token, groupId, 'inherited', query, page);
</script>
<div class="flex w-full min-w-0 flex-col text-sm">
<div class="mb-1.5 flex flex-wrap items-center gap-2">
<div class="flex min-w-0 flex-1 basis-full items-center sm:basis-0">
<div class="self-center mr-3">
<Search />
</div>
<div class="flex h-full min-h-0 w-full min-w-0 flex-col">
<!-- The Users tab's toolbar. -->
<div class="flex h-8 w-full shrink-0 items-center gap-2">
<div class="flex min-w-0 flex-1 items-center">
<div class="mr-3 ml-1 self-center"><Search className="size-3.5" /></div>
<input
class="w-full min-w-0 text-sm pr-4 rounded-r-xl outline-hidden bg-transparent"
class="w-full rounded-r-xl bg-transparent py-1 text-sm outline-hidden"
aria-label={$i18n.t('Search inherited members')}
placeholder={$i18n.t('Search')}
bind:value={query}
@@ -30,61 +29,67 @@
}}
/>
</div>
<slot name="filter" />
{@render filter?.()}
</div>
{#await members}
<div class="my-10" role="status" aria-label={$i18n.t('Loading...')}>
<Spinner className="size-5" />
<div class="my-10 flex justify-center" role="status" aria-label={$i18n.t('Loading...')}>
<Spinner className="size-4" />
</div>
{:then result}
<p class="my-2 text-xs text-base-500 dark:text-base-400">
<p class="shrink-0 px-2 pb-2 text-[0.6875rem] text-base-500 dark:text-base-400">
{$i18n.t('Inherited members are managed in their directly assigned groups.')}
</p>
{#if result.items.length > 0}
<table class="w-full table-fixed text-left text-sm text-base-500 dark:text-base-400">
<thead class="text-xs text-base-800 uppercase dark:text-base-200">
<tr class="border-b-[1.5px] border-base-50/50 dark:border-base-800/10">
<th scope="col" class="w-1/2 px-2.5 py-1.5">{$i18n.t('Name')}</th>
<th scope="col" class="px-2.5 py-1.5">{$i18n.t('Inherited via')}</th>
</tr>
</thead>
<tbody>
<!-- The Users tab's column labels and rows. -->
<div
class="flex w-full shrink-0 items-center gap-2 px-2 pb-2 text-xs text-base-400 dark:text-base-600"
>
<div class="min-w-0 flex-1">{$i18n.t('Name')}</div>
<div class="w-40 shrink-0">{$i18n.t('Inherited via')}</div>
</div>
<div class="min-h-0 flex-1 overflow-y-auto">
<ul class="flex flex-col gap-y-0.5" aria-label={$i18n.t('Inherited')}>
{#each result.items as member (member.id)}
<tr class="text-xs">
<td class="px-3 py-1 font-normal text-base-900 dark:text-base-0">
<Tooltip content={member.email} placement="top-start">
<div class="flex min-w-0 items-center gap-2">
<img
class="size-6 shrink-0 rounded-full object-cover"
src={`${WEBUI_API_BASE_URL}/users/${member.id}/profile/image`}
alt=""
/>
<div class="truncate">{member.name}</div>
</div>
</Tooltip>
</td>
<td class="px-3 py-1">
<li class="flex min-h-8 w-full items-center gap-2 rounded-xl px-2 py-[0.375rem]">
<div class="flex min-w-0 flex-1 items-center gap-2">
<img
class="size-5 shrink-0 rounded-full object-cover"
src={`${WEBUI_API_BASE_URL}/users/${member.id}/profile/image`}
alt=""
/>
<span
class="min-w-0 shrink truncate text-[0.8125rem] leading-5 text-base-800 dark:text-base-200"
>{member.name}</span
>
<span
class="min-w-0 flex-1 truncate text-[0.6875rem] leading-5 text-base-400 dark:text-base-500"
>{member.email}</span
>
</div>
<div class="flex w-40 shrink-0 flex-col">
{#each member.via_group_ids as id}
<a
class="block truncate rounded-sm transition hover:text-base-700 hover:underline dark:hover:text-base-200"
class="truncate text-xs text-base-600 transition hover:text-base-900 dark:text-base-300 dark:hover:text-base-0"
href={`/settings/admin/groups/${encodeURIComponent(id)}`}
title={groups.find((group) => group.id === id)?.path || id}
>
{groups.find((group) => group.id === id)?.path || id}
</a>
{/each}
</td>
</tr>
</div>
</li>
{/each}
</tbody>
</table>
</ul>
</div>
{:else}
<div class="px-10 py-2 text-center text-xs text-base-500">
<div class="py-10 text-center text-xs text-base-500">
{$i18n.t('No inherited members')}
</div>
{/if}
{#if result.total > 30}
<Pagination bind:page count={result.total} perPage={30} />
<div class="shrink-0">
<Pagination bind:page count={result.total} perPage={30} />
</div>
{/if}
{:catch error}
<p role="alert" class="py-4 text-center text-xs text-red-500">{String(error)}</p>
+139 -228
View File
@@ -15,6 +15,7 @@
import { addUserToGroup, removeUserFromGroup } from '$lib/apis/groups';
import { WEBUI_API_BASE_URL } from '$lib/constants';
import { settings } from '$lib/stores';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Checkbox from '$lib/components/common/Checkbox.svelte';
@@ -22,8 +23,9 @@
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import Search from '$lib/components/icons/Search.svelte';
import Pagination from '$lib/components/common/Pagination.svelte';
import ArrowDownTray from '$lib/components/icons/ArrowDownTray.svelte';
import ArrowUpTray from '$lib/components/icons/ArrowUpTray.svelte';
import DocumentArrowUp from '$lib/components/icons/DocumentArrowUp.svelte';
import Download from '$lib/components/icons/Download.svelte';
import EllipsisHorizontal from '$lib/components/icons/EllipsisHorizontal.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
import ChevronUp from '$lib/components/icons/ChevronUp.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
@@ -86,6 +88,7 @@
export let groupId: string;
export let userCount = 0;
export let onMemberChange: Function = () => {};
export let filter: import('svelte').Snippet | undefined = undefined;
let users: GroupUser[] | null = null;
let total: number | null = null;
@@ -95,15 +98,11 @@
let inputFiles: FileList | null = null;
let fileInputElement: HTMLInputElement;
let importing = false;
let showImportMenu = false;
let orderBy = groupId ? `group_id:${groupId}` : 'last_active_at'; // default sort key
let direction = 'desc'; // default sort order
let page = 1;
const sortState = (key, orderBy, direction) =>
orderBy === key ? (direction === 'asc' ? 'ascending' : 'descending') : 'none';
const setSortKey = (key: string) => {
if (orderBy === key) {
direction = direction === 'asc' ? 'desc' : 'asc';
@@ -114,14 +113,19 @@
page = 1;
};
const roleClass = (role: string) => {
// The user list's role badge colours.
$: roleClass = (role: string) => {
if (role === 'admin') {
return 'text-[#4f6f93] dark:text-[#8ba6c6]';
return ($settings?.highContrastMode ?? false)
? 'text-[#434eb8] bg-[#5e6ad2]/[0.18] dark:text-[#919eff]'
: 'text-[#5e6ad2] bg-[#5e6ad2]/[0.18] dark:text-[#919eff]';
}
if (role === 'user') {
return 'text-[#4f7a5a] dark:text-[#8db395]';
return ($settings?.highContrastMode ?? false)
? 'text-emerald-800 bg-emerald-500/[0.18] dark:text-emerald-400'
: 'text-emerald-600 bg-emerald-500/[0.18] dark:text-emerald-400';
}
return 'text-base-500 dark:text-base-400';
return 'text-base-400 bg-base-500/5 dark:text-base-600';
};
const getUserList = async () => {
@@ -284,68 +288,79 @@
});
</script>
<div class=" max-h-full h-full w-full flex flex-col overflow-y-hidden">
<div class="w-full h-fit mb-1.5">
<input
bind:this={fileInputElement}
hidden
bind:files={inputFiles}
type="file"
accept=".csv"
disabled={importing}
on:change={handleFileChange}
/>
<!-- A column label that sorts, in the team Members tab's muted column-label style. -->
{#snippet sortLabel(key: string, label: string, className: string)}
<button
type="button"
class="flex items-center gap-1 transition hover:text-base-600 dark:hover:text-base-400 {className}"
on:click={() => setSortKey(key)}
>
<span class="truncate">{label}</span>
{#if orderBy === key}
{#if direction === 'asc'}<ChevronUp className="size-2.5 shrink-0" strokeWidth="2.5" />
{:else}<ChevronDown className="size-2.5 shrink-0" strokeWidth="2.5" />{/if}
{/if}
</button>
{/snippet}
<div class="flex flex-1 flex-wrap h-fit items-center gap-2">
<div class="flex min-w-0 flex-1 basis-full items-center sm:basis-0">
<div class=" self-center mr-3">
<Search />
</div>
<input
class=" w-full text-sm pr-4 rounded-r-xl outline-hidden bg-transparent"
bind:value={query}
on:input={handleSearchInput}
placeholder={$i18n.t('Search')}
/>
</div>
<div class="flex h-full min-h-0 w-full flex-col">
<input
bind:this={fileInputElement}
hidden
bind:files={inputFiles}
type="file"
accept=".csv"
disabled={importing}
on:change={handleFileChange}
/>
<Dropdown bind:show={showImportMenu} align="end" sideOffset={6}>
<!-- The team Members tab's toolbar: search on the left, Import and the Direct/Inherited filter on the right. -->
<div class="flex h-8 w-full shrink-0 items-center gap-2">
<div class="flex min-w-0 flex-1 items-center">
<div class="mr-3 ml-1 self-center"><Search className="size-3.5" /></div>
<input
class="w-full rounded-r-xl bg-transparent py-1 text-sm outline-hidden"
bind:value={query}
on:input={handleSearchInput}
aria-label={$i18n.t('Search')}
placeholder={$i18n.t('Search')}
/>
</div>
<!-- Admin Models' toolbar: the filter, then the ⋯ Actions menu. -->
<div class="flex shrink-0 items-center gap-1">
{@render filter?.()}
<Dropdown closeOnSelect align="end">
<button
class="ml-1 flex shrink-0 items-center gap-0.5 rounded-lg px-1 py-0.5 text-xs font-normal text-base-500 transition hover:text-base-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-base-400 dark:hover:text-base-200"
type="button"
disabled={importing || !groupId}
aria-label={$i18n.t('Import CSV')}
title={$i18n.t('Import CSV')}
class="relative flex size-6.5 shrink-0 items-center justify-center rounded-full border border-base-100 bg-base-50/60 text-base-500 transition-colors hover:bg-base-100 hover:text-base-900 aria-expanded:bg-base-100 aria-expanded:text-base-900 dark:border-base-850 dark:bg-base-850/50 dark:text-base-400 dark:hover:bg-base-850 dark:hover:text-base-0 dark:aria-expanded:bg-base-850 dark:aria-expanded:text-base-0"
aria-label={$i18n.t('Actions')}
title={$i18n.t('Actions')}
>
{#if importing}
<Spinner className="size-3" />
<span class="truncate">{$i18n.t('Importing...')}</span>
{:else}
<span class="truncate">{$i18n.t('Import')}</span>
<ChevronDown className="size-2.5" strokeWidth="2.5" />
{/if}
{#if importing}<Spinner className="size-3" />
{:else}<EllipsisHorizontal className="size-3.5" />{/if}
</button>
<div slot="content">
<DropdownMenu className="min-w-[12rem]">
<DropdownMenu className="min-w-[10.625rem] shadow-sm">
<button
on:click={() => {
fileInputElement?.click();
showImportMenu = false;
}}
class="flex h-[1.6875rem] w-full cursor-pointer select-none items-center gap-2 rounded-xl bg-transparent px-2 text-[0.8125rem] hover:text-base-900 dark:hover:text-base-100 disabled:pointer-events-none disabled:opacity-40"
type="button"
disabled={importing || !groupId}
on:click={() => fileInputElement?.click()}
>
<ArrowUpTray className="size-3.5" />
<span class="self-center truncate">{$i18n.t('Import CSV')}</span>
<DocumentArrowUp className="size-3.5" />
<div class="flex items-center">{$i18n.t('Import CSV')}</div>
</button>
<button
on:click={() => {
downloadCsvTemplate();
showImportMenu = false;
}}
class="flex h-[1.6875rem] w-full cursor-pointer select-none items-center gap-2 rounded-xl bg-transparent px-2 text-[0.8125rem] hover:text-base-900 dark:hover:text-base-100"
type="button"
on:click={downloadCsvTemplate}
>
<ArrowDownTray className="size-3.5" />
<span class="self-center truncate">{$i18n.t('Download CSV Template')}</span>
<Download className="size-3.5" />
<div class="flex items-center">{$i18n.t('Download CSV Template')}</div>
</button>
<div class="px-2 py-0.5 text-[0.625rem] leading-3 text-base-400 dark:text-base-500">
@@ -354,185 +369,81 @@
</DropdownMenu>
</div>
</Dropdown>
<slot name="filter" />
</div>
</div>
{#if users === null || total === null}
<div class="my-10">
<Spinner className="size-5" />
<div class="my-10 flex justify-center"><Spinner className="size-4" /></div>
{:else if users.length > 0}
<!-- The team Members tab's column labels and rows. -->
<div
class="flex w-full shrink-0 items-center gap-2 px-2 pb-2 text-xs text-base-400 dark:text-base-600"
>
{@render sortLabel(`group_id:${groupId}`, $i18n.t('Member'), 'w-14 shrink-0')}
{@render sortLabel('name', $i18n.t('Name'), 'min-w-0 flex-1')}
{@render sortLabel('role', $i18n.t('Role'), 'w-14 shrink-0')}
{@render sortLabel('last_active_at', $i18n.t('Last Active'), 'w-20 shrink-0')}
</div>
{:else}
{#if users.length > 0}
<div class="scrollbar-hidden relative whitespace-nowrap overflow-x-auto max-w-full">
<table
class="w-full text-sm text-left text-base-500 dark:text-base-400 table-auto max-w-full"
>
<thead class="text-xs text-base-800 uppercase bg-transparent dark:text-base-200">
<tr class=" border-b-[1.5px] border-base-50/50 dark:border-base-800/10">
<th
scope="col"
class="text-left w-8"
aria-sort={sortState(`group_id:${groupId}`, orderBy, direction)}
<div class="min-h-0 flex-1 overflow-y-auto">
<ul class="flex flex-col gap-y-0.5" aria-label={$i18n.t('Users')}>
{#each users as user, userIdx (user?.id ?? userIdx)}
<li class="flex min-h-8 w-full items-center gap-2 rounded-xl px-2 py-[0.375rem]">
<div class="flex w-14 shrink-0">
<Checkbox
ariaLabel={user.name}
state={(user?.group_ids ?? []).includes(groupId) ? 'checked' : 'unchecked'}
on:change={(e) => {
toggleMember(user.id, e.detail);
}}
/>
</div>
<div class="flex min-w-0 flex-1 items-center gap-2">
<img
class="size-5 shrink-0 rounded-full object-cover"
src={`${WEBUI_API_BASE_URL}/users/${user.id}/profile/image`}
alt=""
/>
<span
class="min-w-0 shrink truncate text-[0.8125rem] leading-5 text-base-800 dark:text-base-200"
>{user.name}</span
>
<button
type="button"
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 uppercase"
on:click={() => setSortKey(`group_id:${groupId}`)}
>
{$i18n.t('MBR')}
{#if orderBy === `group_id:${groupId}`}
<span class="font-normal"
>{#if direction === 'asc'}
<ChevronUp className="size-2" />
{:else}
<ChevronDown className="size-2" />
{/if}
</span>
{:else}
<span class="invisible">
<ChevronUp className="size-2" />
</span>
{/if}
</button>
</th>
<th scope="col" class="select-none" aria-sort={sortState('name', orderBy, direction)}>
<button
type="button"
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 uppercase"
on:click={() => setSortKey('name')}
>
{$i18n.t('Name')}
{#if orderBy === 'name'}
<span class="font-normal"
>{#if direction === 'asc'}
<ChevronUp className="size-2" />
{:else}
<ChevronDown className="size-2" />
{/if}
</span>
{:else}
<span class="invisible">
<ChevronUp className="size-2" />
</span>
{/if}
</button>
</th>
<th scope="col" class="select-none" aria-sort={sortState('role', orderBy, direction)}>
<button
type="button"
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 uppercase"
on:click={() => setSortKey('role')}
>
{$i18n.t('Role')}
{#if orderBy === 'role'}
<span class="font-normal"
>{#if direction === 'asc'}
<ChevronUp className="size-2" />
{:else}
<ChevronDown className="size-2" />
{/if}
</span>
{:else}
<span class="invisible">
<ChevronUp className="size-2" />
</span>
{/if}
</button>
</th>
<th
scope="col"
class="select-none"
aria-sort={sortState('last_active_at', orderBy, direction)}
<span
class="min-w-0 flex-1 truncate text-[0.6875rem] leading-5 text-base-400 dark:text-base-500"
>{user.email}</span
>
<button
type="button"
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 uppercase"
on:click={() => setSortKey('last_active_at')}
>
{$i18n.t('Last Active')}
{#if orderBy === 'last_active_at'}
<span class="font-normal"
>{#if direction === 'asc'}
<ChevronUp className="size-2" />
{:else}
<ChevronDown className="size-2" />
{/if}
</span>
{:else}
<span class="invisible">
<ChevronUp className="size-2" />
</span>
{/if}
</button>
</th>
</tr>
</thead>
<tbody class="">
{#each users as user, userIdx (user?.id ?? userIdx)}
<tr class="dark:border-base-850 text-xs">
<td class=" px-3 py-1 w-8">
<div class="flex w-full justify-center">
<Checkbox
ariaLabel={user.name}
state={(user?.group_ids ?? []).includes(groupId) ? 'checked' : 'unchecked'}
on:change={(e) => {
toggleMember(user.id, e.detail);
}}
/>
</div>
</td>
<td class="px-3 py-1 font-normal text-base-900 dark:text-base-0 max-w-48">
<Tooltip content={user.email} placement="top-start">
<div class="flex items-center gap-2">
<img
class="rounded-full w-6 h-6 object-cover flex-shrink-0"
src={`${WEBUI_API_BASE_URL}/users/${user.id}/profile/image`}
alt="user"
/>
<div class="font-normal truncate">{user.name}</div>
</div>
</Tooltip>
</td>
<td class="px-3 py-1 min-w-[5rem] w-20">
<span class="text-xs font-normal leading-4 capitalize {roleClass(user.role)}">
{$i18n.t(user.role)}
</span>
</td>
<td class=" px-3 py-1">
<Tooltip
content={new Date(user.last_active_at * 1000).toLocaleString($i18n.language, {
dateStyle: 'medium',
timeStyle: 'long'
})}
>
{dayjs(user.last_active_at * 1000)
.locale($i18n.language)
.fromNow()}
</Tooltip>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
{:else}
<div class="text-base-500 text-xs text-center py-2 px-10">
{$i18n.t('No users were found.')}
</div>
{/if}
</div>
<div class="w-14 shrink-0">
<span
class="-ml-1.25 inline-flex items-center rounded-xs px-1.25 py-px text-xs leading-4 font-normal capitalize {roleClass(
user.role
)}">{$i18n.t(user.role)}</span
>
</div>
<div class="w-20 shrink-0 truncate text-[0.6875rem] text-base-400 dark:text-base-500">
<Tooltip
content={new Date(user.last_active_at * 1000).toLocaleString($i18n.language, {
dateStyle: 'medium',
timeStyle: 'long'
})}
>
{dayjs(user.last_active_at * 1000)
.locale($i18n.language)
.fromNow()}
</Tooltip>
</div>
</li>
{/each}
</ul>
</div>
{#if total > 30}
<Pagination bind:page count={total} perPage={30} />
<div class="shrink-0">
<Pagination bind:page count={total} perPage={30} />
</div>
{/if}
{:else}
<div class="py-10 text-center text-xs text-base-500">
{$i18n.t('No users were found.')}
</div>
{/if}
</div>
@@ -215,8 +215,8 @@
'files',
'chats',
'notes',
'automations',
'knowledge'
'knowledge',
'automations'
];
// A saved order wins; a tab it doesn't know yet takes its default place.
$: tabOrder = FOLDER_TABS.reduce(