mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-15 14:00:05 +00:00
fix: default sorting on tables (#299)
Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
@@ -1,9 +1,24 @@
|
|||||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||||
import OIDCService from '$lib/services/oidc-service';
|
import OIDCService from '$lib/services/oidc-service';
|
||||||
|
import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ cookies }) => {
|
export const load: PageServerLoad = async ({ cookies }) => {
|
||||||
const oidcService = new OIDCService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const oidcService = new OIDCService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||||
const clients = await oidcService.listClients();
|
|
||||||
|
// Create request options with default sorting
|
||||||
|
const requestOptions: SearchPaginationSortRequest = {
|
||||||
|
sort: {
|
||||||
|
column: 'name',
|
||||||
|
direction: 'asc'
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
page: 1,
|
||||||
|
limit: 10
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const clients = await oidcService.listClients(requestOptions);
|
||||||
|
|
||||||
return clients;
|
return clients;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,10 +11,20 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import OneTimeLinkModal from './client-secret.svelte';
|
import OneTimeLinkModal from './client-secret.svelte';
|
||||||
|
|
||||||
let { clients: initialClients }: { clients: Paginated<OidcClient> } = $props();
|
let {
|
||||||
|
clients: initialClients
|
||||||
|
}: {
|
||||||
|
clients: Paginated<OidcClient>;
|
||||||
|
} = $props();
|
||||||
let clients = $state<Paginated<OidcClient>>(initialClients);
|
let clients = $state<Paginated<OidcClient>>(initialClients);
|
||||||
let oneTimeLink = $state<string | null>(null);
|
let oneTimeLink = $state<string | null>(null);
|
||||||
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
let requestOptions: SearchPaginationSortRequest | undefined = $state({
|
||||||
|
sort: { column: 'name', direction: 'asc' },
|
||||||
|
pagination: {
|
||||||
|
page: initialClients.pagination.currentPage,
|
||||||
|
limit: initialClients.pagination.itemsPerPage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
clients = initialClients;
|
clients = initialClients;
|
||||||
@@ -46,6 +56,7 @@
|
|||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={clients}
|
items={clients}
|
||||||
{requestOptions}
|
{requestOptions}
|
||||||
|
defaultSort={{ column: 'name', direction: 'asc' }}
|
||||||
onRefresh={async (o) => (clients = await oidcService.listClients(o))}
|
onRefresh={async (o) => (clients = await oidcService.listClients(o))}
|
||||||
columns={[
|
columns={[
|
||||||
{ label: 'Logo' },
|
{ label: 'Logo' },
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||||
import UserGroupService from '$lib/services/user-group-service';
|
import UserGroupService from '$lib/services/user-group-service';
|
||||||
|
import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ cookies }) => {
|
export const load: PageServerLoad = async ({ cookies }) => {
|
||||||
const userGroupService = new UserGroupService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const userGroupService = new UserGroupService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||||
const userGroups = await userGroupService.list();
|
|
||||||
|
// Create request options with default sorting
|
||||||
|
const requestOptions: SearchPaginationSortRequest = {
|
||||||
|
sort: {
|
||||||
|
column: 'friendlyName',
|
||||||
|
direction: 'asc'
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
page: 1,
|
||||||
|
limit: 10
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const userGroups = await userGroupService.list(requestOptions);
|
||||||
return userGroups;
|
return userGroups;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,13 @@
|
|||||||
$props();
|
$props();
|
||||||
|
|
||||||
let userGroups = $state<Paginated<UserGroupWithUserCount>>(initialUserGroups);
|
let userGroups = $state<Paginated<UserGroupWithUserCount>>(initialUserGroups);
|
||||||
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
let requestOptions: SearchPaginationSortRequest | undefined = $state({
|
||||||
|
sort: { column: 'friendlyName', direction: 'asc' },
|
||||||
|
pagination: {
|
||||||
|
page: initialUserGroups.pagination.currentPage,
|
||||||
|
limit: initialUserGroups.pagination.itemsPerPage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const userGroupService = new UserGroupService();
|
const userGroupService = new UserGroupService();
|
||||||
|
|
||||||
@@ -47,6 +53,7 @@
|
|||||||
items={userGroups}
|
items={userGroups}
|
||||||
onRefresh={async (o) => (userGroups = await userGroupService.list(o))}
|
onRefresh={async (o) => (userGroups = await userGroupService.list(o))}
|
||||||
{requestOptions}
|
{requestOptions}
|
||||||
|
defaultSort={{ column: 'friendlyName', direction: 'asc' }}
|
||||||
columns={[
|
columns={[
|
||||||
{ label: 'Friendly Name', sortColumn: 'friendlyName' },
|
{ label: 'Friendly Name', sortColumn: 'friendlyName' },
|
||||||
{ label: 'Name', sortColumn: 'name' },
|
{ label: 'Name', sortColumn: 'name' },
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import AdvancedTable from '$lib/components/advanced-table.svelte';
|
import AdvancedTable from '$lib/components/advanced-table.svelte';
|
||||||
import * as Table from '$lib/components/ui/table';
|
import * as Table from '$lib/components/ui/table';
|
||||||
import UserService from '$lib/services/user-service';
|
import UserService from '$lib/services/user-service';
|
||||||
import type { Paginated } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { User } from '$lib/types/user.type';
|
import type { User } from '$lib/types/user.type';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -10,15 +10,24 @@
|
|||||||
selectionDisabled = false,
|
selectionDisabled = false,
|
||||||
selectedUserIds = $bindable()
|
selectedUserIds = $bindable()
|
||||||
}: { users: Paginated<User>; selectionDisabled?: boolean; selectedUserIds: string[] } = $props();
|
}: { users: Paginated<User>; selectionDisabled?: boolean; selectedUserIds: string[] } = $props();
|
||||||
|
let requestOptions: SearchPaginationSortRequest | undefined = $state({
|
||||||
|
sort: { column: 'friendlyName', direction: 'asc' },
|
||||||
|
pagination: {
|
||||||
|
page: initialUsers.pagination.currentPage,
|
||||||
|
limit: initialUsers.pagination.itemsPerPage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let users = $state<Paginated<User>>(initialUsers);
|
||||||
|
|
||||||
const userService = new UserService();
|
const userService = new UserService();
|
||||||
|
|
||||||
let users = $state(initialUsers);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={users}
|
items={users}
|
||||||
onRefresh={async (o) => (users = await userService.list(o))}
|
onRefresh={async (o) => (users = await userService.list(o))}
|
||||||
|
{requestOptions}
|
||||||
|
defaultSort={{ column: 'name', direction: 'asc' }}
|
||||||
columns={[
|
columns={[
|
||||||
{ label: 'Name', sortColumn: 'name' },
|
{ label: 'Name', sortColumn: 'name' },
|
||||||
{ label: 'Email', sortColumn: 'email' }
|
{ label: 'Email', sortColumn: 'email' }
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
import { ACCESS_TOKEN_COOKIE_NAME } from '$lib/constants';
|
||||||
import UserService from '$lib/services/user-service';
|
import UserService from '$lib/services/user-service';
|
||||||
|
import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ cookies }) => {
|
export const load: PageServerLoad = async ({ cookies }) => {
|
||||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
||||||
const users = await userService.list();
|
|
||||||
|
// Create request options with default sorting
|
||||||
|
const requestOptions: SearchPaginationSortRequest = {
|
||||||
|
sort: {
|
||||||
|
column: 'firstName',
|
||||||
|
direction: 'asc'
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
page: 1,
|
||||||
|
limit: 10
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const users = await userService.list(requestOptions);
|
||||||
return users;
|
return users;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,10 +17,17 @@
|
|||||||
import OneTimeLinkModal from './one-time-link-modal.svelte';
|
import OneTimeLinkModal from './one-time-link-modal.svelte';
|
||||||
|
|
||||||
let { users = $bindable() }: { users: Paginated<User> } = $props();
|
let { users = $bindable() }: { users: Paginated<User> } = $props();
|
||||||
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
|
||||||
|
|
||||||
let userIdToCreateOneTimeLink: string | null = $state(null);
|
let userIdToCreateOneTimeLink: string | null = $state(null);
|
||||||
|
|
||||||
|
let requestOptions: SearchPaginationSortRequest | undefined = $state({
|
||||||
|
sort: { column: 'firstName', direction: 'asc' },
|
||||||
|
pagination: {
|
||||||
|
page: users.pagination.currentPage,
|
||||||
|
limit: users.pagination.itemsPerPage
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const userService = new UserService();
|
const userService = new UserService();
|
||||||
|
|
||||||
async function deleteUser(user: User) {
|
async function deleteUser(user: User) {
|
||||||
@@ -47,6 +54,7 @@
|
|||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={users}
|
items={users}
|
||||||
{requestOptions}
|
{requestOptions}
|
||||||
|
defaultSort={{ column: 'firstName', direction: 'asc' }}
|
||||||
onRefresh={async (options) => (users = await userService.list(options))}
|
onRefresh={async (options) => (users = await userService.list(options))}
|
||||||
columns={[
|
columns={[
|
||||||
{ label: 'First name', sortColumn: 'firstName' },
|
{ label: 'First name', sortColumn: 'firstName' },
|
||||||
|
|||||||
Reference in New Issue
Block a user