Skip to content

Commit 00efee1

Browse files
committed
refactor: inline unnecessary extra function
1 parent a4d2eb6 commit 00efee1

2 files changed

Lines changed: 35 additions & 95 deletions

File tree

src/taxonomy/tag-list/TagListTable.tsx

Lines changed: 35 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {
22
useState,
33
useMemo,
4-
useEffect,
54
} from 'react';
65
import type { PaginationState } from '@tanstack/react-table';
76
import { useTagListData, useCreateTag, useUpdateTag } from '@src/taxonomy/data/apiHooks';
@@ -11,11 +10,11 @@ import type {
1110
TreeRowData,
1211
} from '../tree-table/types';
1312
import { TagTree } from './tagTree';
13+
import { getColumns } from './tagColumns';
1414
import {
1515
TABLE_MODES,
1616
} from './constants';
1717
import { useTableModes, useEditActions } from './hooks';
18-
import { createTreeTableContextValue } from './createTreeTableContextValue';
1918

2019
interface TagListTableProps {
2120
taxonomyId: number;
@@ -83,6 +82,7 @@ const TagListTable = ({ taxonomyId, maxDepth }: TagListTableProps) => {
8382
const createTagMutation = useCreateTag(taxonomyId);
8483
const updateTagMutation = useUpdateTag(taxonomyId);
8584
const pageCount = tagList?.numPages ?? -1;
85+
const canAddTag = tagList?.canAddTag !== false;
8686

8787
// TODO: to make this more readable, introduce a React context for the TagListTable instead of passing props.
8888

@@ -101,78 +101,39 @@ const TagListTable = ({ taxonomyId, maxDepth }: TagListTableProps) => {
101101
setEditingRowId,
102102
});
103103

104-
// RELOAD DATA IN VIEW MODE
105-
useEffect(() => {
106-
// Get row data in VIEW mode. Otherwise keep current data to avoid disrupting
107-
// users while they edit or create a tag.
108-
if (tableMode === TABLE_MODES.VIEW && tagList?.results) {
109-
const tree = new TagTree(tagList?.results);
110-
if (tree) {
111-
setTagTree(tree);
112-
}
113-
}
114-
}, [tagList?.results, tableMode]);
115-
116-
const contextValue = useMemo(
117-
() => createTreeTableContextValue({
118-
treeData,
119-
pageCount,
120-
pagination,
121-
handlePaginationChange,
122-
isLoading,
123-
isCreatingTopRow: isCreatingTopTag,
124-
draftError,
125-
createRowMutation: createTagMutation,
126-
updateRowMutation: updateTagMutation,
127-
toast,
128-
setToast,
129-
setIsCreatingTopRow: setIsCreatingTopTag,
130-
exitDraftWithoutSave,
131-
handleCreateRow: handleCreateTag,
132-
creatingParentId,
133-
setCreatingParentId,
134-
setDraftError,
135-
validate,
136-
handleUpdateRow: handleUpdateTag,
137-
editingRowId,
138-
setEditingRowId,
139-
onStartDraft: enterDraftMode,
140-
setActiveActionMenuRowId,
141-
hasOpenDraft,
142-
canAddTag: tagList?.canAddTag !== false,
143-
maxDepth,
144-
}),
145-
[
146-
treeData,
147-
pageCount,
148-
pagination,
149-
handlePaginationChange,
150-
isLoading,
151-
isCreatingTopTag,
152-
draftError,
153-
createTagMutation,
154-
updateTagMutation,
155-
toast,
156-
setToast,
157-
setIsCreatingTopTag,
158-
exitDraftWithoutSave,
159-
handleCreateTag,
160-
creatingParentId,
161-
setCreatingParentId,
162-
setDraftError,
163-
validate,
164-
handleUpdateTag,
165-
editingRowId,
166-
setEditingRowId,
167-
enterDraftMode,
168-
setActiveActionMenuRowId,
169-
hasOpenDraft,
170-
tagList?.canAddTag,
171-
maxDepth,
172-
],
173-
);
174-
175-
104+
// TreeTable context
105+
const contextValueArgs = {
106+
treeData,
107+
pageCount,
108+
pagination,
109+
handlePaginationChange,
110+
isLoading,
111+
isCreatingTopRow: isCreatingTopTag,
112+
draftError,
113+
createRowMutation: createTagMutation,
114+
updateRowMutation: updateTagMutation,
115+
toast,
116+
setToast,
117+
setIsCreatingTopRow: setIsCreatingTopTag,
118+
exitDraftWithoutSave,
119+
handleCreateRow: handleCreateTag,
120+
creatingParentId,
121+
setCreatingParentId,
122+
setDraftError,
123+
validate,
124+
handleUpdateRow: handleUpdateTag,
125+
editingRowId,
126+
setEditingRowId,
127+
onStartDraft: enterDraftMode,
128+
setActiveActionMenuRowId,
129+
hasOpenDraft,
130+
canAddTag,
131+
maxDepth,
132+
};
133+
const contextValue = {
134+
...contextValueArgs,
135+
columns: getColumns(contextValueArgs),
136+
};
176137

177138
return (
178139
<TreeTableContext.Provider value={contextValue}>

src/taxonomy/tag-list/createTreeTableContextValue.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)