Merge pull request #1957 from appwrite/fix-select-teams-pagination

Fix: teams/users pagination
This commit is contained in:
Darshan authored and GitHub committed 2025-06-02 18:30:46 +05:30
commit 4c06e5b115
3 files changed
+53 -18

No files matched your search

+5 -3
View File
@@ -35,6 +35,8 @@
}
}
const none = undefined as never;
// function pagination(page: number, total: number) {
// const pagesShown = 5;
// const start = Math.max(
@@ -56,11 +58,11 @@
{#if !hidePages}
<Pagination
{limit}
page={currentPage}
{total}
type="button"
on:page={handleOptionClick}
createLink={undefined as never} />
createLink={none}
page={currentPage}
on:page={handleOptionClick} />
{:else}
<Layout.Stack direction="row" inline>
<Button.Button
+25 -9
View File
@@ -12,6 +12,7 @@
Layout,
Link,
Selector,
Spinner,
Table,
Typography
} from '@appwrite.io/pink-svelte';
@@ -24,9 +25,10 @@
let search = '';
let offset = 0;
let results: Models.TeamList<Record<string, unknown>>;
let selected: Set<string> = new Set();
let isLoading = false;
let hasSelection = false;
let selected: Set<string> = new Set();
let results: Models.TeamList<Record<string, unknown>>;
function reset() {
offset = 0;
@@ -41,9 +43,11 @@
async function request() {
if (!show) return;
isLoading = true;
results = await sdk
.forProject(page.params.region, page.params.project)
.teams.list([Query.limit(5), Query.offset(offset)], search || undefined);
isLoading = false;
}
function onSelection(role: string) {
@@ -71,23 +75,24 @@
</script>
<Modal title="Select teams" bind:show onSubmit={create} on:close={reset}>
<Typography.Text
<Typography.Text slot="description"
>Grant access to any member of a specific team. To grant access to team members with
specific roles, you will need to set a <Link.Button on:click={() => dispatch('custom')}
>custom permission</Link.Button
>.</Typography.Text>
<InputSearch autofocus placeholder="Search by name or ID" bind:value={search} />
{#if results?.teams?.length}
<Table.Root columns={[{ id: 'checkbox', width: 40 }, { id: 'team' }]} let:root>
<Table.Root columns={[{ id: 'checkbox', width: 20 }, { id: 'team' }]} let:root>
{#each results.teams as team (team.$id)}
{@const role = `team:${team.$id}`}
{@const exists = $groups.has(role)}
<Table.Row.Button {root} on:click={() => onSelection(role)} disabled={exists}>
<Table.Cell column="checkbox" {root}>
<Selector.Checkbox
size="s"
id={team.$id}
checked={exists || selected.has(role)}
disabled={exists} />
disabled={exists}
checked={exists || selected.has(role)} />
</Table.Cell>
<Table.Cell column="team" {root}>
<Layout.Stack direction="row" alignItems="center" gap="s">
@@ -105,10 +110,16 @@
</Table.Row.Button>
{/each}
</Table.Root>
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<Layout.Stack direction="row" justifyContent="space-between" alignItems="center">
<p class="text">Total results: {results?.total}</p>
<PaginationInline limit={5} bind:offset total={results?.total} hidePages />
</div>
<PaginationInline
limit={5}
bind:offset
total={results?.total}
hidePages
on:change={request} />
</Layout.Stack>
{:else if search}
<EmptySearch bind:search target="teams" hidePages>
<Button
@@ -119,6 +130,11 @@
size="s">Documentation</Button>
<Button secondary on:click={() => (search = '')}>Clear search</Button>
</EmptySearch>
{:else if isLoading}
<!-- 275px nearly matches the height of at-least 5 items in the table above -->
<div style:margin-inline="auto" style:min-height="275px" style:align-content="center">
<Spinner size="m" />
</div>
{:else}
<Card.Base padding="none">
<Empty title="You have no teams. Create a team to see them here." type="secondary">
+23 -6
View File
@@ -14,6 +14,7 @@
Layout,
Link,
Selector,
Spinner,
Table,
Typography
} from '@appwrite.io/pink-svelte';
@@ -27,9 +28,10 @@
let search = '';
let offset = 0;
let results: Models.UserList<Record<string, unknown>>;
let selected: Set<string> = new Set();
let isLoading = false;
let hasSelection = false;
let selected: Set<string> = new Set();
let results: Models.UserList<Record<string, unknown>>;
function reset() {
offset = 0;
@@ -44,9 +46,11 @@
async function request() {
if (!show) return;
isLoading = true;
results = await sdk
.forProject(page.params.region, page.params.project)
.users.list([Query.limit(5), Query.offset(offset)], search || undefined);
isLoading = false;
}
function onSelection(role: string) {
@@ -74,8 +78,11 @@
</script>
<Modal title="Select users" bind:show onSubmit={create} on:close={reset}>
<Typography.Text>Grant access to any authenticated or anonymous user.</Typography.Text>
<Typography.Text slot="description"
>Grant access to any authenticated or anonymous user.</Typography.Text>
<InputSearch autofocus placeholder="Search by name, email, phone or ID" bind:value={search} />
{#if results?.users?.length}
<Table.Root columns={[{ id: 'checkbox', width: 40 }, { id: 'user' }]} let:root>
{#each results.users as user (user.$id)}
@@ -86,8 +93,8 @@
<Selector.Checkbox
size="s"
id={user.$id}
checked={exists || selected.has(role)}
disabled={exists} />
disabled={exists}
checked={exists || selected.has(role)} />
</Table.Cell>
<Table.Cell column="user" {root}>
<Layout.Stack direction="row" alignItems="center" gap="s">
@@ -141,7 +148,12 @@
<Layout.Stack direction="row" justifyContent="space-between" alignItems="center">
<p class="text">Total results: {results?.total}</p>
<PaginationInline limit={5} bind:offset total={results?.total} hidePages />
<PaginationInline
limit={5}
bind:offset
total={results?.total}
hidePages
on:change={request} />
</Layout.Stack>
{:else if search}
<EmptySearch bind:search target="users" hidePages>
@@ -153,6 +165,11 @@
size="s">Documentation</Button>
<Button secondary on:click={() => (search = '')}>Clear search</Button>
</EmptySearch>
{:else if isLoading}
<!-- 275px nearly matches the height of at-least 5 items in the table above -->
<div style:margin-inline="auto" style:min-height="275px" style:align-content="center">
<Spinner size="m" />
</div>
{:else}
<Card.Base padding="none">
<Empty title="You have no users. Create a user to see them here." type="secondary">