@izumisy-tailor/tailor-data-viewer 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@izumisy-tailor/tailor-data-viewer",
3
3
  "private": false,
4
- "version": "0.1.13",
4
+ "version": "0.1.15",
5
5
  "type": "module",
6
6
  "description": "Flexible data viewer component for Tailor Platform",
7
7
  "files": [
@@ -129,9 +129,6 @@ export function DataViewTabContent({
129
129
  [tableData],
130
130
  );
131
131
 
132
- // Track cursor history for previous page navigation
133
- const [cursorHistory] = useState<string[]>([]);
134
-
135
132
  // CSV Download handler
136
133
  const handleDownloadCsv = useCallback(() => {
137
134
  if (!selectedTable || tableData.data.length === 0) return;
@@ -189,8 +186,6 @@ export function DataViewTabContent({
189
186
  [onTableConfirm],
190
187
  );
191
188
 
192
- const hasPreviousPage = cursorHistory.length > 0;
193
-
194
189
  // Show table selector centered if table is not locked yet
195
190
  if (!isTableLocked) {
196
191
  return (
@@ -317,7 +312,7 @@ export function DataViewTabContent({
317
312
  currentCount={tableData.data.length}
318
313
  onNext={tableData.nextPage}
319
314
  onPrevious={tableData.previousPage}
320
- hasPreviousPage={hasPreviousPage}
315
+ hasPreviousPage={tableData.hasPreviousPage}
321
316
  />
322
317
  </div>
323
318
  );
@@ -24,6 +24,7 @@ export interface PaginationState {
24
24
  first: number;
25
25
  after: string | null;
26
26
  hasNextPage: boolean;
27
+ endCursor: string | null;
27
28
  }
28
29
 
29
30
  export interface TableDataState {
@@ -32,6 +33,7 @@ export interface TableDataState {
32
33
  error: Error | null;
33
34
  sortState: SortState | null;
34
35
  pagination: PaginationState;
36
+ hasPreviousPage: boolean;
35
37
  refetch: () => Promise<void>;
36
38
  setSort: (field: string, direction?: "Asc" | "Desc") => void;
37
39
  nextPage: () => void;
@@ -102,6 +104,7 @@ export function useTableData(
102
104
  first: DEFAULT_PAGE_SIZE,
103
105
  after: null,
104
106
  hasNextPage: false,
107
+ endCursor: null,
105
108
  });
106
109
  const [cursorHistory, setCursorHistory] = useState<string[]>([]);
107
110
 
@@ -116,6 +119,7 @@ export function useTableData(
116
119
  first: DEFAULT_PAGE_SIZE,
117
120
  after: null,
118
121
  hasNextPage: false,
122
+ endCursor: null,
119
123
  });
120
124
  setCursorHistory([]);
121
125
  }, [table?.name]);
@@ -237,6 +241,7 @@ export function useTableData(
237
241
  setPagination((prev) => ({
238
242
  ...prev,
239
243
  hasNextPage: responseData.pageInfo.hasNextPage,
244
+ endCursor: responseData.pageInfo.endCursor,
240
245
  }));
241
246
  }
242
247
  } catch (err) {
@@ -280,19 +285,18 @@ export function useTableData(
280
285
  }, []);
281
286
 
282
287
  const nextPage = useCallback(() => {
283
- const responseData = data;
284
- if (pagination.hasNextPage && responseData.length > 0) {
288
+ if (pagination.hasNextPage && pagination.endCursor) {
285
289
  // Store current cursor for back navigation
286
290
  if (pagination.after) {
287
291
  setCursorHistory((prev) => [...prev, pagination.after!]);
288
292
  }
289
- // Get the cursor from the last item (using the GraphQL response's endCursor)
293
+ // Use endCursor from pageInfo for pagination
290
294
  setPagination((prev) => ({
291
295
  ...prev,
292
- after: (responseData[responseData.length - 1]?.id as string) ?? null,
296
+ after: prev.endCursor,
293
297
  }));
294
298
  }
295
- }, [data, pagination.hasNextPage, pagination.after]);
299
+ }, [pagination.hasNextPage, pagination.endCursor, pagination.after]);
296
300
 
297
301
  const previousPage = useCallback(() => {
298
302
  if (cursorHistory.length > 0) {
@@ -311,6 +315,7 @@ export function useTableData(
311
315
  first: DEFAULT_PAGE_SIZE,
312
316
  after: null,
313
317
  hasNextPage: false,
318
+ endCursor: null,
314
319
  });
315
320
  setCursorHistory([]);
316
321
  }, []);
@@ -321,6 +326,7 @@ export function useTableData(
321
326
  error,
322
327
  sortState,
323
328
  pagination,
329
+ hasPreviousPage: cursorHistory.length > 0 || pagination.after !== null,
324
330
  refetch: fetchData,
325
331
  setSort,
326
332
  nextPage,