@@ -145,25 +125,7 @@ const TableView = ({
))}
-
+
@@ -200,7 +162,7 @@ const TableView = ({
{toast.message}
- >
+
);
};
diff --git a/src/taxonomy/tree-table/TreeTableContext.tsx b/src/taxonomy/tree-table/TreeTableContext.tsx
new file mode 100644
index 0000000000..e004956064
--- /dev/null
+++ b/src/taxonomy/tree-table/TreeTableContext.tsx
@@ -0,0 +1,80 @@
+import { createContext } from 'react';
+import type { Dispatch, SetStateAction } from 'react';
+import type { OnChangeFn, PaginationState, Row } from '@tanstack/react-table';
+
+import type {
+ CreateRowMutationState,
+ RowId,
+ ToastState,
+ TreeColumnDef,
+ TreeTable,
+ TreeRowData,
+} from './types';
+
+export interface TreeTableContextValue {
+ treeData: TreeRowData[];
+ columns: TreeColumnDef[];
+ pageCount: number;
+ pagination: PaginationState;
+ handlePaginationChange: OnChangeFn
;
+ isLoading: boolean;
+ isCreatingTopRow: boolean;
+ draftError: string;
+ createRowMutation: CreateRowMutationState;
+ updateRowMutation: CreateRowMutationState;
+ toast: ToastState;
+ setToast: Dispatch>;
+ setIsCreatingTopRow: (isCreating: boolean) => void;
+ exitDraftWithoutSave: () => void;
+ handleCreateRow: (value: string, parentRowValue?: string) => void;
+ creatingParentId: RowId | null;
+ setCreatingParentId: (id: RowId | null) => void;
+ setDraftError: (error: string) => void;
+ deleteRowMutation: CreateRowMutationState;
+ validate: (value: string, mode?: 'soft' | 'hard') => boolean;
+ handleUpdateRow: (value: string, originalValue: string) => void;
+ editingRowId: RowId | null;
+ setEditingRowId: (id: RowId | null) => void;
+ confirmDeleteDialogOpen: boolean;
+ setConfirmDeleteDialogOpen: Dispatch>;
+ confirmDeleteDialogContext: Row | null;
+ setConfirmDeleteDialogContext: Dispatch | null>>;
+ handleDeleteRow: (row: Row) => void;
+ startEditRow: (row: Row) => void;
+ startDeleteRow: (row: Row) => void;
+ table: TreeTable | null;
+}
+
+export const TreeTableContext = createContext({
+ treeData: [],
+ columns: [],
+ pageCount: -1,
+ pagination: { pageIndex: 0, pageSize: 0 },
+ handlePaginationChange: () => {},
+ isLoading: false,
+ isCreatingTopRow: false,
+ draftError: '',
+ createRowMutation: {},
+ updateRowMutation: {},
+ deleteRowMutation: {},
+ toast: { show: false, message: '', variant: 'success' },
+ setToast: () => {},
+ setIsCreatingTopRow: () => {},
+ exitDraftWithoutSave: () => {},
+ handleCreateRow: () => {},
+ creatingParentId: null,
+ setCreatingParentId: () => {},
+ setDraftError: () => {},
+ validate: () => true,
+ handleUpdateRow: () => {},
+ editingRowId: null,
+ setEditingRowId: () => {},
+ confirmDeleteDialogOpen: false,
+ setConfirmDeleteDialogOpen: () => {},
+ confirmDeleteDialogContext: null,
+ setConfirmDeleteDialogContext: () => {},
+ handleDeleteRow: () => {},
+ startEditRow: () => {},
+ startDeleteRow: () => {},
+ table: null,
+});
diff --git a/src/taxonomy/tree-table/index.ts b/src/taxonomy/tree-table/index.ts
index eca12d684c..44b27a7709 100644
--- a/src/taxonomy/tree-table/index.ts
+++ b/src/taxonomy/tree-table/index.ts
@@ -1,2 +1,3 @@
export { EditableCell } from './EditableCell';
export { TableView } from './TableView';
+export { TreeTableContext } from './TreeTableContext';