Skip to content

Commit 93794ec

Browse files
authored
Merge pull request #26 from database-playground/pan93412/dbp-111-admin-一次顯示-20-筆資料
DBP-111: improve admin page
2 parents 6944f64 + 03f014d commit 93794ec

File tree

39 files changed

+1244
-90
lines changed

39 files changed

+1244
-90
lines changed

app/(admin)/(activity-management)/events/_components/data-table.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
import { CursorDataTable } from "@/components/data-table/cursor";
44
import type { Direction } from "@/components/data-table/pagination";
55
import { useSuspenseQuery } from "@apollo/client/react";
6+
import type { VariablesOf } from "@graphql-typed-document-node/core";
67
import { useState } from "react";
78
import { columns, type Event } from "./data-table-columns";
89
import { EVENTS_TABLE_QUERY } from "./query";
910

10-
export function EventsDataTable() {
11-
const PAGE_SIZE = 10;
11+
export function EventsDataTable({ query }: { query?: string }) {
12+
const PAGE_SIZE = 20;
1213
const [cursors, setCursors] = useState<(string | null)[]>([null]);
1314
const [currentIndex, setCurrentIndex] = useState(0);
1415

1516
const after = cursors[currentIndex];
16-
const variables = { first: PAGE_SIZE, after };
17+
18+
const variables = {
19+
first: PAGE_SIZE,
20+
after,
21+
where: query ? { typeContains: query } : undefined,
22+
} satisfies VariablesOf<typeof EVENTS_TABLE_QUERY>;
1723

1824
const { data } = useSuspenseQuery(EVENTS_TABLE_QUERY, {
1925
variables,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use client";
2+
3+
import { Input } from "@/components/ui/input";
4+
5+
import { DataTableSkeleton } from "@/components/data-table/skeleton";
6+
import { useDebouncedValue } from "foxact/use-debounced-value";
7+
import { Suspense, useState } from "react";
8+
import { EventsDataTable } from "./data-table";
9+
10+
export default function FilterableDataTable() {
11+
const [query, setQuery] = useState("");
12+
const debouncedQuery = useDebouncedValue(query, 200);
13+
14+
return (
15+
<div className="flex flex-col">
16+
<div className="mb-4 flex items-center gap-4">
17+
<Input
18+
placeholder="搜尋事件類型"
19+
value={query}
20+
onChange={(e) => setQuery(e.target.value)}
21+
/>
22+
</div>
23+
24+
<Suspense fallback={<DataTableSkeleton />}>
25+
<EventsDataTable query={debouncedQuery} />
26+
</Suspense>
27+
</div>
28+
);
29+
}

app/(admin)/(activity-management)/events/_components/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export const EVENTS_TABLE_QUERY = graphql(`
66
$after: Cursor
77
$last: Int
88
$before: Cursor
9+
$where: EventWhereInput
910
) {
10-
events(first: $first, after: $after, last: $last, before: $before, orderBy: { field: TRIGGERED_AT, direction: DESC }) {
11+
events(first: $first, after: $after, last: $last, before: $before, where: $where, orderBy: { field: TRIGGERED_AT, direction: DESC }) {
1112
edges {
1213
node {
1314
id

app/(admin)/(activity-management)/events/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SiteHeader } from "@/components/site-header";
22
import type { Metadata } from "next";
3-
import { EventsDataTable } from "./_components/data-table";
3+
import FilterableDataTable from "./_components/filterable-data-table";
44

55
export const metadata: Metadata = {
66
title: "事件管理",
@@ -23,7 +23,7 @@ export default function Page() {
2323
</div>
2424
</div>
2525
<div>
26-
<EventsDataTable />
26+
<FilterableDataTable />
2727
</div>
2828
</main>
2929
</>

app/(admin)/(activity-management)/points/_components/data-table.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
import { CursorDataTable } from "@/components/data-table/cursor";
44
import type { Direction } from "@/components/data-table/pagination";
55
import { useSuspenseQuery } from "@apollo/client/react";
6+
import type { VariablesOf } from "@graphql-typed-document-node/core";
67
import { useState } from "react";
78
import { columns, type Point } from "./data-table-columns";
89
import { POINTS_TABLE_QUERY } from "./query";
910

10-
export function PointsDataTable() {
11-
const PAGE_SIZE = 10;
11+
export function PointsDataTable({ query }: { query?: string }) {
12+
const PAGE_SIZE = 20;
1213
const [cursors, setCursors] = useState<(string | null)[]>([null]);
1314
const [currentIndex, setCurrentIndex] = useState(0);
1415

1516
const after = cursors[currentIndex];
16-
const variables = { first: PAGE_SIZE, after };
17+
18+
const variables = {
19+
first: PAGE_SIZE,
20+
after,
21+
where: query ? { descriptionContains: query } : undefined,
22+
} satisfies VariablesOf<typeof POINTS_TABLE_QUERY>;
1723

1824
const { data } = useSuspenseQuery(POINTS_TABLE_QUERY, {
1925
variables,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use client";
2+
3+
import { Input } from "@/components/ui/input";
4+
5+
import { DataTableSkeleton } from "@/components/data-table/skeleton";
6+
import { useDebouncedValue } from "foxact/use-debounced-value";
7+
import { Suspense, useState } from "react";
8+
import { PointsDataTable } from "./data-table";
9+
10+
export default function FilterableDataTable() {
11+
const [query, setQuery] = useState("");
12+
const debouncedQuery = useDebouncedValue(query, 200);
13+
14+
return (
15+
<div className="flex flex-col">
16+
<div className="mb-4 flex items-center gap-4">
17+
<Input
18+
placeholder="搜尋描述"
19+
value={query}
20+
onChange={(e) => setQuery(e.target.value)}
21+
/>
22+
</div>
23+
24+
<Suspense fallback={<DataTableSkeleton />}>
25+
<PointsDataTable query={debouncedQuery} />
26+
</Suspense>
27+
</div>
28+
);
29+
}

app/(admin)/(activity-management)/points/_components/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export const POINTS_TABLE_QUERY = graphql(`
66
$after: Cursor
77
$last: Int
88
$before: Cursor
9+
$where: PointWhereInput
910
) {
10-
points(first: $first, after: $after, last: $last, before: $before, orderBy: { field: GRANTED_AT, direction: DESC }) {
11+
points(first: $first, after: $after, last: $last, before: $before, where: $where, orderBy: { field: GRANTED_AT, direction: DESC }) {
1112
edges {
1213
node {
1314
id

app/(admin)/(activity-management)/points/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SiteHeader } from "@/components/site-header";
22
import type { Metadata } from "next";
3-
import { PointsDataTable } from "./_components/data-table";
3+
import FilterableDataTable from "./_components/filterable-data-table";
44

55
export const metadata: Metadata = {
66
title: "積分管理",
@@ -23,7 +23,7 @@ export default function Page() {
2323
</div>
2424
</div>
2525
<div>
26-
<PointsDataTable />
26+
<FilterableDataTable />
2727
</div>
2828
</main>
2929
</>

app/(admin)/(activity-management)/submissions/_components/data-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { columns, type Submission } from "./data-table-columns";
88
import { SUBMISSIONS_TABLE_QUERY } from "./query";
99

1010
export function SubmissionsDataTable() {
11-
const PAGE_SIZE = 10;
11+
const PAGE_SIZE = 20;
1212
const [cursors, setCursors] = useState<(string | null)[]>([null]);
1313
const [currentIndex, setCurrentIndex] = useState(0);
1414

app/(admin)/(activity-management)/submissions/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { DataTableSkeleton } from "@/components/data-table/skeleton";
12
import { SiteHeader } from "@/components/site-header";
23
import type { Metadata } from "next";
4+
import { Suspense } from "react";
35
import { SubmissionsDataTable } from "./_components/data-table";
46

57
export const metadata: Metadata = {
@@ -23,7 +25,9 @@ export default function Page() {
2325
</div>
2426
</div>
2527
<div>
26-
<SubmissionsDataTable />
28+
<Suspense fallback={<DataTableSkeleton />}>
29+
<SubmissionsDataTable />
30+
</Suspense>
2731
</div>
2832
</main>
2933
</>

0 commit comments

Comments
 (0)