summaryrefslogtreecommitdiff
path: root/lib/integration/table/integration-table.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/integration/table/integration-table.tsx')
-rw-r--r--lib/integration/table/integration-table.tsx166
1 files changed, 166 insertions, 0 deletions
diff --git a/lib/integration/table/integration-table.tsx b/lib/integration/table/integration-table.tsx
new file mode 100644
index 00000000..7a075fb4
--- /dev/null
+++ b/lib/integration/table/integration-table.tsx
@@ -0,0 +1,166 @@
+"use client";
+import * as React from "react";
+import { useDataTable } from "@/hooks/use-data-table";
+import { DataTable } from "@/components/data-table/data-table";
+import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar";
+import type {
+ DataTableAdvancedFilterField,
+ DataTableRowAction,
+} from "@/types/table"
+import { getIntegrations } from "../service";
+import { getColumns } from "./integration-table-columns";
+import { DeleteIntegrationDialog } from "./delete-integration-dialog";
+import { IntegrationEditSheet } from "./integration-edit-sheet";
+import { IntegrationTableToolbarActions } from "./integration-table-toolbar";
+import { integrations } from "@/db/schema/integration";
+import { GetIntegrationsSchema } from "../validations";
+
+interface IntegrationTableProps {
+ promises?: Promise<[{ data: typeof integrations.$inferSelect[]; pageCount: number }] >;
+}
+
+export function IntegrationTable({ promises }: IntegrationTableProps) {
+ const [rawData, setRawData] = React.useState<{ data: typeof integrations.$inferSelect[]; pageCount: number }>({ data: [], pageCount: 0 });
+ const [rowAction, setRowAction] = React.useState<DataTableRowAction<typeof integrations.$inferSelect> | null>(null);
+
+ React.useEffect(() => {
+ if (promises) {
+ promises.then(([result]) => {
+ setRawData(result);
+ });
+ } else {
+ // fallback: 클라이언트에서 직접 fetch (CSR)
+ (async () => {
+ try {
+ const result = await getIntegrations({
+ page: 1,
+ perPage: 10,
+ search: "",
+ sort: [{ id: "createdAt", desc: true }],
+ filters: [],
+ joinOperator: "and",
+ flags: ["advancedTable"],
+ code: "",
+ name: "",
+ type: "",
+ description: "",
+ sourceSystem: "",
+ targetSystem: "",
+ status: ""
+ });
+ setRawData(result);
+ } catch (error) {
+ console.error("Error refreshing data:", error);
+ }
+ })();
+ }
+ }, [promises]);
+
+ const fetchIntegrations = React.useCallback(async (params: Record<string, unknown>) => {
+ try {
+ const result = await getIntegrations(params as GetIntegrationsSchema);
+ return result;
+ } catch (error) {
+ console.error("Error fetching integrations:", error);
+ throw error;
+ }
+ }, []);
+
+ const refreshData = React.useCallback(async () => {
+ try {
+ const result = await fetchIntegrations({
+ page: 1,
+ perPage: 10,
+ search: "",
+ sort: [{ id: "createdAt", desc: true }],
+ filters: [],
+ joinOperator: "and",
+ flags: ["advancedTable"],
+ code: "",
+ name: "",
+ type: "",
+ description: "",
+ sourceSystem: "",
+ targetSystem: "",
+ status: ""
+ });
+ setRawData(result);
+ } catch (error) {
+ console.error("Error refreshing data:", error);
+ }
+ }, [fetchIntegrations]);
+
+ // 컬럼 설정 - 외부 파일에서 가져옴
+ const columns = React.useMemo(
+ () => getColumns({ setRowAction }),
+ [setRowAction]
+ )
+
+ // 고급 필터 필드 설정
+ const advancedFilterFields: DataTableAdvancedFilterField<typeof integrations.$inferSelect>[] = [
+ { id: "code", label: "코드", type: "text" },
+ { id: "name", label: "이름", type: "text" },
+ { id: "type", label: "타입", type: "select", options: [
+ { label: "REST API", value: "rest_api" },
+ { label: "SOAP", value: "soap" },
+ { label: "DB to DB", value: "db_to_db" },
+ ]},
+ { id: "description", label: "설명", type: "text" },
+ { id: "sourceSystem", label: "소스 시스템", type: "text" },
+ { id: "targetSystem", label: "타겟 시스템", type: "text" },
+ {
+ id: "status", label: "상태", type: "select", options: [
+ { label: "활성", value: "active" },
+ { label: "비활성", value: "inactive" },
+ { label: "사용중단", value: "deprecated" },
+ ]
+ },
+ { id: "createdAt", label: "생성일", type: "date" },
+ ];
+
+ const { table } = useDataTable({
+ data: rawData.data,
+ columns,
+ pageCount: rawData.pageCount,
+ enablePinning: true,
+ enableAdvancedFilter: true,
+ initialState: {
+ sorting: [{ id: "createdAt", desc: true }],
+ columnPinning: { right: ["actions"] },
+ },
+ getRowId: (originalRow) => String(originalRow.id),
+ shallow: false,
+ clearOnDefault: true,
+ })
+
+ return (
+ <>
+ <DataTable table={table}>
+ <DataTableAdvancedToolbar
+ table={table}
+ filterFields={advancedFilterFields}
+ >
+ <IntegrationTableToolbarActions table={table} onSuccess={refreshData} />
+ </DataTableAdvancedToolbar>
+ </DataTable>
+
+ <DeleteIntegrationDialog
+ open={rowAction?.type === "delete"}
+ onOpenChange={() => setRowAction(null)}
+ integrations={rowAction?.row.original ? [rowAction?.row.original] : []}
+ showTrigger={false}
+ onSuccess={() => {
+ rowAction?.row.toggleSelected(false)
+ refreshData()
+ }}
+ />
+
+ <IntegrationEditSheet
+ open={rowAction?.type === "update"}
+ onOpenChange={() => setRowAction(null)}
+ data={rowAction?.row.original ?? null}
+ onSuccess={refreshData}
+ />
+ </>
+ );
+} \ No newline at end of file