diff --git a/src/lib/components/admin/Users/Groups/Users.svelte b/src/lib/components/admin/Users/Groups/Users.svelte index 2d3151c99f..298611a655 100644 --- a/src/lib/components/admin/Users/Groups/Users.svelte +++ b/src/lib/components/admin/Users/Groups/Users.svelte @@ -2,6 +2,12 @@ import { getContext } from 'svelte'; const i18n = getContext('i18n'); + import dayjs from 'dayjs'; + import relativeTime from 'dayjs/plugin/relativeTime'; + import localizedFormat from 'dayjs/plugin/localizedFormat'; + dayjs.extend(relativeTime); + dayjs.extend(localizedFormat); + import { getUsers } from '$lib/apis/users'; import { toast } from 'svelte-sonner'; @@ -11,6 +17,9 @@ import Search from '$lib/components/icons/Search.svelte'; import Pagination from '$lib/components/common/Pagination.svelte'; import { addUserToGroup, removeUserFromGroup } from '$lib/apis/groups'; + import ChevronDown from '$lib/components/icons/ChevronDown.svelte'; + import ChevronUp from '$lib/components/icons/ChevronUp.svelte'; + import { WEBUI_API_BASE_URL } from '$lib/constants'; export let groupId: string; export let userCount = 0; @@ -19,20 +28,28 @@ let total = 0; let query = ''; + let orderBy = `group_id:${groupId}`; // default sort key + let direction = 'desc'; // default sort order + let page = 1; + const setSortKey = (key) => { + if (orderBy === key) { + direction = direction === 'asc' ? 'desc' : 'asc'; + } else { + orderBy = key; + direction = 'asc'; + } + }; + const getUserList = async () => { try { - const res = await getUsers( - localStorage.token, - query, - `group_id:${groupId}`, - null, - page - ).catch((error) => { - toast.error(`${error}`); - return null; - }); + const res = await getUsers(localStorage.token, query, orderBy, direction, page).catch( + (error) => { + toast.error(`${error}`); + return null; + } + ); if (res) { users = res.users; @@ -60,11 +77,7 @@ getUserList(); }; - $: if (page) { - getUserList(); - } - - $: if (query !== null) { + $: if (page !== null && query !== null && orderBy !== null && direction !== null) { getUserList(); } @@ -87,40 +100,161 @@ -