Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add search to database collections #342

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import { Button } from '$lib/elements/forms';
import { Empty, Copy, GridItem1, CardContainer, Heading, Pagination } from '$lib/components';
import {
Empty,
EmptySearch,
Copy,
GridItem1,
CardContainer,
Heading,
Pagination,
SearchQuery
} from '$lib/components';
import { Pill } from '$lib/elements';
import { Container } from '$lib/layout';
import { base } from '$app/paths';
Expand All @@ -29,13 +38,15 @@
</script>

<Container>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<div class="u-flex u-flex-vertical u-gap-12 common-section u-main-space-between">
<Heading tag="h2" size="5">Collections</Heading>

<Button on:click={() => (showCreate = true)} event="create_collection">
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create collection</span>
</Button>
<SearchQuery search={data.search} placeholder="Search by name">
<Button on:click={() => (showCreate = true)} event="create_collection">
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create collection</span>
</Button>
</SearchQuery>
</div>

{#if data.collections.total}
Expand Down Expand Up @@ -71,6 +82,15 @@
offset={data.offset}
sum={data.collections.total} />
</div>
{:else if data.search}
<EmptySearch>
<div class="u-text-center">
<b>Sorry, we couldn't find '{data.search}'</b>
<p>There are no collections that match your search.</p>
</div>
<Button href={`/console/project-${project}/databases/database-${databaseId}`} secondary
>Clear Search</Button>
</EmptySearch>
{:else}
<Empty
single
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import { pageToOffset } from '$lib/helpers/load';
import { CARD_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params, parent }) => {
export const load: PageLoad = async ({ params, parent, url }) => {
await parent();
const page = Number(params.page);
const offset = pageToOffset(page, CARD_LIMIT);
const search = url.search.slice(1) ?? undefined;

return {
offset,
collections: await sdkForProject.databases.listCollections(params.database, [
Query.limit(CARD_LIMIT),
Query.offset(offset),
Query.orderDesc('$createdAt')
])
search,
collections: await sdkForProject.databases.listCollections(
params.database,
[Query.limit(CARD_LIMIT), Query.offset(offset), Query.orderDesc('$createdAt')],
search
)
};
};