mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-27 23:59:20 -05:00
fix(a11y): Analytics and group member tables can be sorted from the keyboard (#33432)
This commit is contained in:
2 files changed
+116
-62
No files matched your search
@@ -159,6 +159,9 @@
|
||||
let userOrderBy = 'total_tokens';
|
||||
let userDirection: 'asc' | 'desc' = 'desc';
|
||||
|
||||
const sortState = (key, orderBy, direction) =>
|
||||
orderBy === key ? (direction === 'asc' ? 'ascending' : 'descending') : 'none';
|
||||
|
||||
const toggleModelSort = (key: string) => {
|
||||
if (modelOrderBy === key) {
|
||||
modelDirection = modelDirection === 'asc' ? 'desc' : 'asc';
|
||||
@@ -563,10 +566,14 @@
|
||||
<th scope="col" class="font-normal px-2.5 py-1.5 w-8">#</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none"
|
||||
on:click={() => toggleModelSort('name')}
|
||||
class="font-normal select-none"
|
||||
aria-sort={sortState('name', modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5"
|
||||
on:click={() => toggleModelSort('name')}
|
||||
>
|
||||
{$i18n.t('Model')}
|
||||
{#if modelOrderBy === 'name'}
|
||||
<span class="font-normal">
|
||||
@@ -577,14 +584,18 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleModelSort('count')}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState('count', modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleModelSort('count')}
|
||||
>
|
||||
{$i18n.t('Messages')}
|
||||
{#if modelOrderBy === 'count'}
|
||||
<span class="font-normal">
|
||||
@@ -595,14 +606,18 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleModelSort('users')}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState('users', modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleModelSort('users')}
|
||||
>
|
||||
{$i18n.t('Users')}
|
||||
{#if modelOrderBy === 'users'}
|
||||
<span class="font-normal">
|
||||
@@ -613,14 +628,18 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleModelSort('chats')}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState('chats', modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleModelSort('chats')}
|
||||
>
|
||||
{$i18n.t('Chats')}
|
||||
{#if modelOrderBy === 'chats'}
|
||||
<span class="font-normal">
|
||||
@@ -631,17 +650,21 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<!-- {$i18n.t('Tokens')} -->
|
||||
{#each tokenColumns as column}
|
||||
<th
|
||||
scope="col"
|
||||
title={`${column.label} ${$i18n.t('tokens')}`}
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleModelSort(column.key)}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState(column.key, modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleModelSort(column.key)}
|
||||
>
|
||||
{column.label}
|
||||
{#if modelOrderBy === column.key}
|
||||
<span class="font-normal">
|
||||
@@ -652,15 +675,19 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
{/each}
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right w-16"
|
||||
on:click={() => toggleModelSort('percentage')}
|
||||
class="font-normal select-none text-right w-16"
|
||||
aria-sort={sortState('percentage', modelOrderBy, modelDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleModelSort('percentage')}
|
||||
>
|
||||
{selectedMetric === 'tokens'
|
||||
? $i18n.t('Token share')
|
||||
: $i18n.t('Message share')}
|
||||
@@ -673,7 +700,7 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -772,10 +799,14 @@
|
||||
<th scope="col" class="font-normal px-2.5 py-1.5 w-8">#</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none"
|
||||
on:click={() => toggleUserSort('name')}
|
||||
class="font-normal select-none"
|
||||
aria-sort={sortState('name', userOrderBy, userDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5"
|
||||
on:click={() => toggleUserSort('name')}
|
||||
>
|
||||
{$i18n.t('User')}
|
||||
{#if userOrderBy === 'name'}
|
||||
<span class="font-normal">
|
||||
@@ -786,14 +817,18 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleUserSort('count')}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState('count', userOrderBy, userDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleUserSort('count')}
|
||||
>
|
||||
{$i18n.t('Messages')}
|
||||
{#if userOrderBy === 'count'}
|
||||
<span class="font-normal">
|
||||
@@ -804,17 +839,21 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<!-- {$i18n.t('Tokens')} -->
|
||||
{#each tokenColumns as column}
|
||||
<th
|
||||
scope="col"
|
||||
title={`${column.label} ${$i18n.t('tokens')}`}
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right"
|
||||
on:click={() => toggleUserSort(column.key)}
|
||||
class="font-normal select-none text-right"
|
||||
aria-sort={sortState(column.key, userOrderBy, userDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleUserSort(column.key)}
|
||||
>
|
||||
{column.label}
|
||||
{#if userOrderBy === column.key}
|
||||
<span class="font-normal">
|
||||
@@ -825,15 +864,19 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
{/each}
|
||||
<th
|
||||
scope="col"
|
||||
class="font-normal px-2.5 py-1.5 cursor-pointer select-none text-right w-16"
|
||||
on:click={() => toggleUserSort('percentage')}
|
||||
class="font-normal select-none text-right w-16"
|
||||
aria-sort={sortState('percentage', userOrderBy, userDirection)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center justify-end">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full gap-1.5 items-center px-2.5 py-1.5 justify-end"
|
||||
on:click={() => toggleUserSort('percentage')}
|
||||
>
|
||||
{selectedMetric === 'tokens'
|
||||
? $i18n.t('Token share')
|
||||
: $i18n.t('Message share')}
|
||||
@@ -846,7 +889,7 @@
|
||||
{:else}
|
||||
<span class="invisible"><ChevronUp className="size-2" /></span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -101,6 +101,9 @@
|
||||
|
||||
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';
|
||||
@@ -370,10 +373,14 @@
|
||||
<tr class=" border-b-[1.5px] border-gray-50/50 dark:border-gray-800/10">
|
||||
<th
|
||||
scope="col"
|
||||
class="px-2.5 py-1.5 cursor-pointer text-left w-8"
|
||||
on:click={() => setSortKey(`group_id:${groupId}`)}
|
||||
class="text-left w-8"
|
||||
aria-sort={sortState(`group_id:${groupId}`, orderBy, direction)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<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}`}
|
||||
@@ -389,15 +396,15 @@
|
||||
<ChevronUp className="size-2" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
|
||||
<th
|
||||
scope="col"
|
||||
class="px-2.5 py-1.5 cursor-pointer select-none"
|
||||
on:click={() => setSortKey('name')}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<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'}
|
||||
@@ -413,14 +420,14 @@
|
||||
<ChevronUp className="size-2" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-2.5 py-1.5 cursor-pointer select-none"
|
||||
on:click={() => setSortKey('role')}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<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'}
|
||||
@@ -436,15 +443,19 @@
|
||||
<ChevronUp className="size-2" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
|
||||
<th
|
||||
scope="col"
|
||||
class="px-2.5 py-1.5 cursor-pointer select-none"
|
||||
on:click={() => setSortKey('last_active_at')}
|
||||
class="select-none"
|
||||
aria-sort={sortState('last_active_at', orderBy, direction)}
|
||||
>
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<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'}
|
||||
@@ -460,7 +471,7 @@
|
||||
<ChevronUp className="size-2" />
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
Reference in new issue
Block a user