@izumisy-tailor/tailor-data-viewer 0.3.2 → 0.3.3
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/README.md +25 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A low-level React component library for building data table interfaces with Tail
|
|
|
6
6
|
|
|
7
7
|
- **Separation of Concerns**: Data fetching, query parameter management, and UI are fully decoupled
|
|
8
8
|
- **`useCollectionVariables` Hook**: Manages filter, sort, and pagination state; outputs Tailor Platform-compatible GraphQL variables
|
|
9
|
-
- **`
|
|
9
|
+
- **`CollectionControlProvider`**: Shares collection control state via React Context across sibling components
|
|
10
10
|
- **`Table.*` Compound Components**: Static, unstyled table primitives (`<table>`, `<thead>`, `<tbody>`, `<tr>`, `<th>`, `<td>`)
|
|
11
11
|
- **`DataTable.*` Compound Components**: Data-bound table with sort indicators, cell renderers, and `useDataTable` integration
|
|
12
12
|
- **`useDataTable` Hook**: Integrates data, column visibility, row operations (optimistic updates), and props generators
|
|
@@ -95,7 +95,7 @@ const columns = [
|
|
|
95
95
|
|
|
96
96
|
// 2. Build a page
|
|
97
97
|
function OrdersPage() {
|
|
98
|
-
const { variables } = useCollectionVariables({ params: { pageSize: 20 } });
|
|
98
|
+
const { variables, control } = useCollectionVariables({ params: { pageSize: 20 } });
|
|
99
99
|
const [result] = useQuery({
|
|
100
100
|
query: GET_ORDERS,
|
|
101
101
|
variables: {
|
|
@@ -109,7 +109,7 @@ function OrdersPage() {
|
|
|
109
109
|
columns,
|
|
110
110
|
data: result.data?.orders,
|
|
111
111
|
loading: result.fetching,
|
|
112
|
-
|
|
112
|
+
control,
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
return (
|
|
@@ -131,7 +131,7 @@ function OrdersPage() {
|
|
|
131
131
|
Manages filter, sort, and pagination state. Returns `variables` containing `query`, `order`, and `pagination` sub-properties in Tailor Platform-compatible format.
|
|
132
132
|
|
|
133
133
|
```tsx
|
|
134
|
-
const { variables,
|
|
134
|
+
const { variables, control } = useCollectionVariables({
|
|
135
135
|
params: {
|
|
136
136
|
pageSize: 20,
|
|
137
137
|
initialSort: [{ field: "createdAt", direction: "Desc" }],
|
|
@@ -149,36 +149,36 @@ const [result] = useQuery({
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
// Filter operations
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
control.addFilter("status", "eq", "ACTIVE");
|
|
153
|
+
control.setFilters([{ field: "status", operator: "eq", value: "ACTIVE" }]);
|
|
154
|
+
control.removeFilter("status");
|
|
155
|
+
control.clearFilters();
|
|
156
156
|
|
|
157
157
|
// Sort operations
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
control.setSort("createdAt", "Desc");
|
|
159
|
+
control.setSort("name", "Asc", true); // append for multi-sort
|
|
160
|
+
control.clearSort();
|
|
161
161
|
|
|
162
162
|
// Pagination
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
control.nextPage(endCursor);
|
|
164
|
+
control.prevPage(startCursor);
|
|
165
|
+
control.resetPage();
|
|
166
166
|
|
|
167
167
|
// Page info tracking
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
control.setPageInfo(pageInfo);
|
|
169
|
+
control.hasPrevPage; // boolean
|
|
170
|
+
control.hasNextPage; // boolean
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
### `DataTable.Provider` / `useDataTableContext()` / `
|
|
173
|
+
### `DataTable.Provider` / `useDataTableContext()` / `useCollectionControl()`
|
|
174
174
|
|
|
175
|
-
`DataTable.Provider` wraps the table UI and provides both data table and collection context. All utility components (`Pagination`, `ColumnSelector`, `CsvButton`, `SearchFilterForm`) read from this context — no prop spreading needed.
|
|
175
|
+
`DataTable.Provider` wraps the table UI and provides both data table and collection control context. All utility components (`Pagination`, `ColumnSelector`, `CsvButton`, `SearchFilterForm`) read from this context — no prop spreading needed.
|
|
176
176
|
|
|
177
|
-
When `
|
|
177
|
+
When `control` is passed to `useDataTable`, `DataTable.Provider` automatically wraps a `CollectionControlProvider` so child components can use `useCollectionControl()`.
|
|
178
178
|
|
|
179
179
|
```tsx
|
|
180
180
|
<DataTable.Provider value={table}>
|
|
181
|
-
<StatusFilter /> {/*
|
|
181
|
+
<StatusFilter /> {/* useCollectionControl() inside */}
|
|
182
182
|
<DataTable.Root>
|
|
183
183
|
<DataTable.Headers />
|
|
184
184
|
<DataTable.Body />
|
|
@@ -187,13 +187,13 @@ When `collection` is passed to `useDataTable`, `DataTable.Provider` automaticall
|
|
|
187
187
|
</DataTable.Provider>
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
For cases where you need `
|
|
190
|
+
For cases where you need `CollectionControlProvider` without `DataTable.Provider` (e.g., non-table UIs), you can use it standalone:
|
|
191
191
|
|
|
192
192
|
```tsx
|
|
193
|
-
<
|
|
193
|
+
<CollectionControlProvider value={control}>
|
|
194
194
|
<StatusFilter />
|
|
195
195
|
<CustomKanbanBoard />
|
|
196
|
-
</
|
|
196
|
+
</CollectionControlProvider>
|
|
197
197
|
```
|
|
198
198
|
|
|
199
199
|
### Column Definition Helper
|
|
@@ -275,7 +275,7 @@ const table = useDataTable<Order>({
|
|
|
275
275
|
data: result.data?.orders, // CollectionResult<Order>
|
|
276
276
|
loading: result.fetching,
|
|
277
277
|
error: result.error,
|
|
278
|
-
|
|
278
|
+
control,
|
|
279
279
|
onClickRow: (row) => navigate(`/orders/${row.id}`),
|
|
280
280
|
rowActions: [
|
|
281
281
|
{ id: "delete", label: "Delete", variant: "destructive", onClick: (row) => handleDelete(row.id) },
|