Skip to content

Commit

Permalink
refactor: Update tableTest component to use tableId for pagination an…
Browse files Browse the repository at this point in the history
…d sorting
  • Loading branch information
Sivanwol committed Sep 6, 2024
1 parent 7217c43 commit e51f781
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 115 deletions.
3 changes: 3 additions & 0 deletions packages/backoffice-api/src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {
userRouter,
} from "@app/shared-api";

import { mockRouter } from "./router";

export const appRouter = createTRPCRouter({
auth: authRouter,
notifications: NotificationRouter,
settings: settingsRouter,
user: userRouter,
mock: mockRouter,
});

// export type definition of API
Expand Down
Empty file.
1 change: 1 addition & 0 deletions packages/backoffice-api/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./mock";
19 changes: 19 additions & 0 deletions packages/backoffice-api/src/router/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { TRPCRouterRecord } from "@trpc/server";
import { z } from "zod";

import type { DataTableType } from "@app/utils";
import { publicProcedure } from "@app/auth";
import { mockData } from "@app/utils";

export const mockRouter = {
mockData: publicProcedure
.input(z.object({ total: z.number() }))
.query(({ ctx, input }) => {
return {
entities: mockData(input.total).map((item) => ({
...(item as unknown as DataTableType),
})),
total: input.total * 4,
};
}),
} satisfies TRPCRouterRecord;
30 changes: 21 additions & 9 deletions packages/store-backoffice/src/stores/table/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,36 @@ import type {

export interface TableActions {
init: (params: {
requestReloadCb?: () => Promise<DataTableType[]>;
requestExportCb?: (data: DataTableType[]) => Promise<void>;
data?: DataTableType[];
onSort?: (sort: SortByOpt | null) => Promise<DataTableType[]>;
onPagination?: (pagination: Pagination | null) => Promise<DataTableType[]>;
onReload?: () => Promise<DataTableType[]>;
onExport?: (data: DataTableType[]) => Promise<void>;
}) => string;
setData: (tableId: string, data: DataTableType[]) => void;
setPagination: (tableId: string, pagination: Pagination) => void;
setData: (
tableId: string,
data: DataTableType[],
totalEntities: number,
) => void;
setPagination: (tableId: string, pagination: Pagination) => Promise<void>;
setExportMode: (tableId: string, mode: ExportTableMode) => void;
hasData: (tableId: string) => boolean;
bindRequestExport: (
onExport: (
tableId: string,
fn: (data: DataTableType[]) => Promise<void>,
) => void;
onReload: (tableId: string, fn: () => Promise<DataTableType[]>) => void;
onSort: (
tableId: string,
requestExportCb: (data: DataTableType[]) => Promise<void>,
fn: (sort: SortByOpt | null) => Promise<DataTableType[]>,
) => void;
bindRequestReload: (
onPagination: (
tableId: string,
requestReloadCb: () => Promise<DataTableType[]>,
fn: (pagination: Pagination | null) => Promise<DataTableType[]>,
) => void;
requestExport: (tableId: string) => Promise<void>;
reload: (tableId: string) => Promise<void>;
setSort: (tableId: string, sort: SortByOpt | null) => void;
setSort: (tableId: string, sort: SortByOpt | null) => Promise<void>;
setLoading: (tableId: string, loading: boolean) => void;
reset: (tableId: string) => void;
}
Loading

0 comments on commit e51f781

Please sign in to comment.