@xeplr/ui-table 1.0.0
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/LICENSE +21 -0
- package/package.json +17 -0
- package/src/XeplrTable.jsx +332 -0
- package/src/actions/ActionsCell.jsx +75 -0
- package/src/actions/ChildTable.jsx +159 -0
- package/src/actions/RecordDetail.jsx +213 -0
- package/src/actions/RecordModal.jsx +159 -0
- package/src/buildChangeSet.js +126 -0
- package/src/detectTypes.js +102 -0
- package/src/filters/BooleanFilter.jsx +66 -0
- package/src/filters/DateFilter.jsx +75 -0
- package/src/filters/FilterWrapper.jsx +66 -0
- package/src/filters/NumberFilter.jsx +105 -0
- package/src/filters/StringFilter.jsx +142 -0
- package/src/index.js +32 -0
- package/src/operators.js +113 -0
- package/src/resolveCellStyle.js +252 -0
- package/src/useActionsController.js +453 -0
- package/src/useTableController.js +131 -0
- package/src/xeplr-table.css +913 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xeplr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xeplr/ui-table",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Controlled TanStack Table wrapper with auto-detected column types and smart filters",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"files": ["src/"],
|
|
8
|
+
"keywords": ["table", "tanstack", "react", "filters", "datagrid"],
|
|
9
|
+
"author": "xeplr",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": { "type": "git", "url": "https://github.com/Xeplr/xeplr-ui-table" },
|
|
12
|
+
"publishConfig": { "access": "public" },
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
15
|
+
"@tanstack/react-table": "^8.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { flexRender } from '@tanstack/react-table';
|
|
3
|
+
import useTableController from './useTableController.js';
|
|
4
|
+
import useActionsController from './useActionsController.js';
|
|
5
|
+
import { TYPES } from './detectTypes.js';
|
|
6
|
+
import StringFilter from './filters/StringFilter.jsx';
|
|
7
|
+
import NumberFilter from './filters/NumberFilter.jsx';
|
|
8
|
+
import DateFilter from './filters/DateFilter.jsx';
|
|
9
|
+
import BooleanFilter from './filters/BooleanFilter.jsx';
|
|
10
|
+
import ActionsCell from './actions/ActionsCell.jsx';
|
|
11
|
+
import ChildTable from './actions/ChildTable.jsx';
|
|
12
|
+
import RecordModal from './actions/RecordModal.jsx';
|
|
13
|
+
import RecordDetail from './actions/RecordDetail.jsx';
|
|
14
|
+
import { resolveCellStyle } from './resolveCellStyle.js';
|
|
15
|
+
import './xeplr-table.css';
|
|
16
|
+
|
|
17
|
+
var filterComponentMap = {
|
|
18
|
+
[TYPES.STRING]: StringFilter,
|
|
19
|
+
[TYPES.NUMBER]: NumberFilter,
|
|
20
|
+
[TYPES.DATE]: DateFilter,
|
|
21
|
+
[TYPES.BOOLEAN]: BooleanFilter
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* childDisplay enum:
|
|
26
|
+
* 'popup' (default) — double-click row opens detail popup with children inside
|
|
27
|
+
* 'inner' — expand arrow shows children inline below the row
|
|
28
|
+
*/
|
|
29
|
+
var CHILD_DISPLAY = { POPUP: 'popup', INNER: 'inner' };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Main table component.
|
|
33
|
+
*
|
|
34
|
+
* @param {object} props
|
|
35
|
+
* @param {Array<object>} props.data - Row array
|
|
36
|
+
* @param {object} props.schema - { 0: { key, columns }, 1: { key, columns }, ... }
|
|
37
|
+
* @param {string} [props.childDisplay] - 'popup' (default) | 'inner'
|
|
38
|
+
* @param {number} [props.pageSize] - Default: 20
|
|
39
|
+
* @param {boolean} [props.enableSorting] - Default: true
|
|
40
|
+
* @param {boolean} [props.enableFiltering] - Default: true
|
|
41
|
+
* @param {boolean} [props.enablePagination] - Default: true
|
|
42
|
+
* @param {string} [props.className] - Additional CSS class
|
|
43
|
+
* @param {Function} [props.onCommit] - async (changeSet[]) => void
|
|
44
|
+
*/
|
|
45
|
+
export default function XeplrTable(props) {
|
|
46
|
+
var schema = props.schema || {};
|
|
47
|
+
var level0 = schema[0] || {};
|
|
48
|
+
var columns = level0.columns || [];
|
|
49
|
+
var nextLevel = schema[1];
|
|
50
|
+
var childKey = nextLevel ? nextLevel.key : null;
|
|
51
|
+
var hasChildren = !!childKey;
|
|
52
|
+
var childDisplay = props.childDisplay || CHILD_DISPLAY.POPUP;
|
|
53
|
+
var useInner = childDisplay === CHILD_DISPLAY.INNER;
|
|
54
|
+
var usePopup = hasChildren && !useInner;
|
|
55
|
+
|
|
56
|
+
var actions = useActionsController({
|
|
57
|
+
onCommit: props.onCommit,
|
|
58
|
+
schema: schema,
|
|
59
|
+
data: props.data
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
var { table, detectedTypes, resetFilters, resetSorting } = useTableController({
|
|
63
|
+
data: actions.hasActions ? actions.stagedData : props.data,
|
|
64
|
+
columns: columns,
|
|
65
|
+
minDetectionRows: props.minDetectionRows,
|
|
66
|
+
pageSize: props.pageSize,
|
|
67
|
+
enableSorting: props.enableSorting,
|
|
68
|
+
enableFiltering: props.enableFiltering,
|
|
69
|
+
enablePagination: props.enablePagination
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
var enableFiltering = props.enableFiltering !== false;
|
|
73
|
+
var enablePagination = props.enablePagination !== false;
|
|
74
|
+
|
|
75
|
+
var headerGroups = table.getHeaderGroups();
|
|
76
|
+
var rows = table.getRowModel().rows;
|
|
77
|
+
|
|
78
|
+
function getRowId(row) {
|
|
79
|
+
return row._tempId || row.id;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var visibleIds = rows.map(function(row) { return getRowId(row.original); });
|
|
83
|
+
var allSelected = visibleIds.length > 0 && visibleIds.every(function(id) { return actions.selectedIds.has(id); });
|
|
84
|
+
|
|
85
|
+
// Show expand column only in inner mode
|
|
86
|
+
var showExpandCol = hasChildren && useInner;
|
|
87
|
+
|
|
88
|
+
var totalColumns = headerGroups[0]?.headers.length || 1;
|
|
89
|
+
if (showExpandCol) totalColumns++;
|
|
90
|
+
if (actions.hasDelete) totalColumns++;
|
|
91
|
+
if (actions.hasActions) totalColumns++;
|
|
92
|
+
|
|
93
|
+
// Resolve modal schema columns for form hints
|
|
94
|
+
var modalSchemaColumns = columns;
|
|
95
|
+
if (actions.modal.context && actions.modal.context.level === 'nested' && actions.modal.context.path) {
|
|
96
|
+
var pathChildKeys = actions.modal.context.path.filter(function(_, i) { return i % 2 === 0; });
|
|
97
|
+
var modalLevel = pathChildKeys.length;
|
|
98
|
+
if (schema[modalLevel] && schema[modalLevel].columns) {
|
|
99
|
+
modalSchemaColumns = schema[modalLevel].columns;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Double-click handler for popup mode
|
|
104
|
+
function handleRowDoubleClick(original) {
|
|
105
|
+
if (usePopup) {
|
|
106
|
+
actions.openDetail(original);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div className={'xeplr-table-container' + (props.className ? ' ' + props.className : '')}>
|
|
112
|
+
<div className="xeplr-table-toolbar">
|
|
113
|
+
{actions.hasSave && (
|
|
114
|
+
<button type="button" className="xeplr-table-toolbar-btn xeplr-table-toolbar-btn-add" onClick={actions.openAdd}>
|
|
115
|
+
+ Add New
|
|
116
|
+
</button>
|
|
117
|
+
)}
|
|
118
|
+
{actions.hasDelete && actions.selectedIds.size > 0 && (
|
|
119
|
+
<button type="button" className="xeplr-table-toolbar-btn xeplr-table-toolbar-btn-delete" onClick={actions.handleDeleteSelected}>
|
|
120
|
+
Delete Selected ({actions.selectedIds.size})
|
|
121
|
+
</button>
|
|
122
|
+
)}
|
|
123
|
+
{actions.hasPending && (
|
|
124
|
+
<div className="xeplr-table-toolbar-pending">
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
className="xeplr-table-toolbar-btn xeplr-table-toolbar-btn-commit"
|
|
128
|
+
onClick={actions.handleCommit}
|
|
129
|
+
disabled={actions.committing}
|
|
130
|
+
>
|
|
131
|
+
{actions.committing ? 'Committing...' : 'Commit (' + actions.pendingCount + ')'}
|
|
132
|
+
</button>
|
|
133
|
+
<button
|
|
134
|
+
type="button"
|
|
135
|
+
className="xeplr-table-toolbar-btn xeplr-table-toolbar-btn-discard"
|
|
136
|
+
onClick={actions.handleDiscard}
|
|
137
|
+
disabled={actions.committing}
|
|
138
|
+
>
|
|
139
|
+
Discard
|
|
140
|
+
</button>
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
<div className="xeplr-table-toolbar-spacer" />
|
|
144
|
+
{enableFiltering && (
|
|
145
|
+
<button type="button" className="xeplr-table-toolbar-btn" onClick={resetFilters}>
|
|
146
|
+
Clear Filters
|
|
147
|
+
</button>
|
|
148
|
+
)}
|
|
149
|
+
<button type="button" className="xeplr-table-toolbar-btn" onClick={resetSorting}>
|
|
150
|
+
Clear Sort
|
|
151
|
+
</button>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<div className="xeplr-table-scroll">
|
|
155
|
+
<table className="xeplr-table">
|
|
156
|
+
<thead>
|
|
157
|
+
{headerGroups.map(function(headerGroup) {
|
|
158
|
+
return (
|
|
159
|
+
<tr key={headerGroup.id}>
|
|
160
|
+
{showExpandCol && <th className="xeplr-table-th xeplr-table-th-expand" />}
|
|
161
|
+
{actions.hasDelete && (
|
|
162
|
+
<th className="xeplr-table-th xeplr-table-th-checkbox">
|
|
163
|
+
<input type="checkbox" className="xeplr-table-checkbox" checked={allSelected}
|
|
164
|
+
onChange={function() { actions.toggleSelectAll(visibleIds); }} />
|
|
165
|
+
</th>
|
|
166
|
+
)}
|
|
167
|
+
{headerGroup.headers.map(function(header) {
|
|
168
|
+
var canSort = header.column.getCanSort();
|
|
169
|
+
var sorted = header.column.getIsSorted();
|
|
170
|
+
var dataType = header.column.columnDef.meta?.dataType || TYPES.STRING;
|
|
171
|
+
var FilterComponent = filterComponentMap[dataType];
|
|
172
|
+
var canFilter = header.column.getCanFilter() && enableFiltering;
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<th key={header.id} className="xeplr-table-th">
|
|
176
|
+
<div className="xeplr-table-header-cell">
|
|
177
|
+
<span
|
|
178
|
+
className={'xeplr-table-header-label' + (canSort ? ' sortable' : '')}
|
|
179
|
+
onClick={canSort ? header.column.getToggleSortingHandler() : undefined}
|
|
180
|
+
>
|
|
181
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
|
182
|
+
{sorted === 'asc' && <span className="xeplr-table-sort-icon"> ▲</span>}
|
|
183
|
+
{sorted === 'desc' && <span className="xeplr-table-sort-icon"> ▼</span>}
|
|
184
|
+
</span>
|
|
185
|
+
{canFilter && FilterComponent && <FilterComponent column={header.column} />}
|
|
186
|
+
</div>
|
|
187
|
+
</th>
|
|
188
|
+
);
|
|
189
|
+
})}
|
|
190
|
+
{actions.hasActions && (
|
|
191
|
+
<th className="xeplr-table-th xeplr-table-th-actions">
|
|
192
|
+
<div className="xeplr-table-header-cell">
|
|
193
|
+
<span className="xeplr-table-header-label">Actions</span>
|
|
194
|
+
</div>
|
|
195
|
+
</th>
|
|
196
|
+
)}
|
|
197
|
+
</tr>
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
</thead>
|
|
201
|
+
<tbody>
|
|
202
|
+
{rows.length === 0 && (
|
|
203
|
+
<tr>
|
|
204
|
+
<td className="xeplr-table-empty" colSpan={totalColumns}>No data</td>
|
|
205
|
+
</tr>
|
|
206
|
+
)}
|
|
207
|
+
{rows.map(function(row) {
|
|
208
|
+
var original = row.original;
|
|
209
|
+
var rowId = getRowId(original);
|
|
210
|
+
var isSelected = actions.selectedIds.has(rowId);
|
|
211
|
+
var isExpanded = useInner && actions.expandedIds.has(rowId);
|
|
212
|
+
var isNew = !!original._tempId;
|
|
213
|
+
|
|
214
|
+
var rowClass = 'xeplr-table-row';
|
|
215
|
+
if (isSelected) rowClass += ' xeplr-table-row-selected';
|
|
216
|
+
if (isNew) rowClass += ' xeplr-table-row-new';
|
|
217
|
+
if (usePopup) rowClass += ' xeplr-table-row-clickable';
|
|
218
|
+
|
|
219
|
+
var rowElements = [];
|
|
220
|
+
|
|
221
|
+
rowElements.push(
|
|
222
|
+
<tr key={row.id} className={rowClass}
|
|
223
|
+
onDoubleClick={function() { handleRowDoubleClick(original); }}>
|
|
224
|
+
{showExpandCol && (
|
|
225
|
+
<td className="xeplr-table-td xeplr-table-td-expand">
|
|
226
|
+
<button type="button"
|
|
227
|
+
className={'xeplr-table-expand-btn' + (isExpanded ? ' expanded' : '')}
|
|
228
|
+
onClick={function() { actions.toggleExpand(rowId); }}>
|
|
229
|
+
▸
|
|
230
|
+
</button>
|
|
231
|
+
</td>
|
|
232
|
+
)}
|
|
233
|
+
{actions.hasDelete && (
|
|
234
|
+
<td className="xeplr-table-td xeplr-table-td-checkbox">
|
|
235
|
+
<input type="checkbox" className="xeplr-table-checkbox" checked={isSelected}
|
|
236
|
+
onChange={function() { actions.toggleSelect(rowId); }} />
|
|
237
|
+
</td>
|
|
238
|
+
)}
|
|
239
|
+
{row.getVisibleCells().map(function(cell) {
|
|
240
|
+
var meta = cell.column.columnDef.meta;
|
|
241
|
+
var cellStyleDef = meta?.cellStyle;
|
|
242
|
+
var condStyle = cellStyleDef
|
|
243
|
+
? resolveCellStyle(cell.getValue(), cellStyleDef, cell.column.id, row.original) : null;
|
|
244
|
+
return (
|
|
245
|
+
<td key={cell.id} className="xeplr-table-td" style={condStyle}>
|
|
246
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
247
|
+
</td>
|
|
248
|
+
);
|
|
249
|
+
})}
|
|
250
|
+
{actions.hasActions && (
|
|
251
|
+
<td className="xeplr-table-td xeplr-table-td-actions">
|
|
252
|
+
<ActionsCell row={original} hasSave={actions.hasSave} hasDelete={actions.hasDelete}
|
|
253
|
+
onView={function() { usePopup ? actions.openDetail(original) : actions.openView(original); }}
|
|
254
|
+
onCopy={actions.openCopy} onEdit={actions.openEdit}
|
|
255
|
+
onDelete={function() { actions.handleDeleteRow(rowId); }} />
|
|
256
|
+
</td>
|
|
257
|
+
)}
|
|
258
|
+
</tr>
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
// Inner mode: expandable child rows
|
|
262
|
+
if (isExpanded && hasChildren) {
|
|
263
|
+
rowElements.push(
|
|
264
|
+
<tr key={row.id + '-children'} className="xeplr-table-row-expanded">
|
|
265
|
+
<td colSpan={totalColumns} className="xeplr-table-td-expanded">
|
|
266
|
+
<ChildTable
|
|
267
|
+
rootId={rowId}
|
|
268
|
+
path={[childKey]}
|
|
269
|
+
schemaLevel={1}
|
|
270
|
+
schema={schema}
|
|
271
|
+
rows={original[childKey] || []}
|
|
272
|
+
actions={actions}
|
|
273
|
+
/>
|
|
274
|
+
</td>
|
|
275
|
+
</tr>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return rowElements;
|
|
280
|
+
})}
|
|
281
|
+
</tbody>
|
|
282
|
+
</table>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
{enablePagination && (
|
|
286
|
+
<div className="xeplr-table-pagination">
|
|
287
|
+
<button type="button" onClick={function() { table.setPageIndex(0); }} disabled={!table.getCanPreviousPage()}>««</button>
|
|
288
|
+
<button type="button" onClick={function() { table.previousPage(); }} disabled={!table.getCanPreviousPage()}>«</button>
|
|
289
|
+
<span className="xeplr-table-page-info">Page {table.getState().pagination.pageIndex + 1} of {table.getPageCount()}</span>
|
|
290
|
+
<button type="button" onClick={function() { table.nextPage(); }} disabled={!table.getCanNextPage()}>»</button>
|
|
291
|
+
<button type="button" onClick={function() { table.setPageIndex(table.getPageCount() - 1); }} disabled={!table.getCanNextPage()}>»»</button>
|
|
292
|
+
<select className="xeplr-table-page-size" value={table.getState().pagination.pageSize}
|
|
293
|
+
onChange={function(e) { table.setPageSize(Number(e.target.value)); }}>
|
|
294
|
+
{[10, 20, 50, 100].map(function(size) { return <option key={size} value={size}>{size} rows</option>; })}
|
|
295
|
+
</select>
|
|
296
|
+
<span className="xeplr-table-row-count">({table.getFilteredRowModel().rows.length} total)</span>
|
|
297
|
+
</div>
|
|
298
|
+
)}
|
|
299
|
+
|
|
300
|
+
{/* Detail popup (childDisplay === 'popup') */}
|
|
301
|
+
{actions.detailRow && usePopup && (
|
|
302
|
+
<RecordDetail
|
|
303
|
+
record={actions.detailRow}
|
|
304
|
+
rootId={getRowId(actions.detailRow)}
|
|
305
|
+
schema={schema}
|
|
306
|
+
schemaColumns={columns}
|
|
307
|
+
hasSave={actions.hasSave}
|
|
308
|
+
actions={actions}
|
|
309
|
+
onClose={actions.closeDetail}
|
|
310
|
+
/>
|
|
311
|
+
)}
|
|
312
|
+
|
|
313
|
+
{/* Record edit/add modal (works on top of detail popup too) */}
|
|
314
|
+
{actions.modal.mode && (
|
|
315
|
+
<RecordModal
|
|
316
|
+
mode={actions.modal.mode}
|
|
317
|
+
record={actions.modal.record}
|
|
318
|
+
schemaColumns={modalSchemaColumns}
|
|
319
|
+
hasSave={actions.hasSave}
|
|
320
|
+
onFieldChange={actions.updateField}
|
|
321
|
+
onSave={actions.handleSave}
|
|
322
|
+
onEdit={actions.modal.context?.level === 'nested'
|
|
323
|
+
? function(rec) { actions.openNestedEdit(actions.modal.context.rootId, actions.modal.context.path, rec); }
|
|
324
|
+
: actions.openEdit}
|
|
325
|
+
onClose={actions.closeModal}
|
|
326
|
+
/>
|
|
327
|
+
)}
|
|
328
|
+
</div>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export { CHILD_DISPLAY };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Actions cell rendered in the last column of each row.
|
|
5
|
+
* Shows view (always), copy, edit (if onSave), delete (if onDelete).
|
|
6
|
+
*/
|
|
7
|
+
export default function ActionsCell(props) {
|
|
8
|
+
var row = props.row;
|
|
9
|
+
var hasSave = props.hasSave;
|
|
10
|
+
var hasDelete = props.hasDelete;
|
|
11
|
+
var onView = props.onView;
|
|
12
|
+
var onCopy = props.onCopy;
|
|
13
|
+
var onEdit = props.onEdit;
|
|
14
|
+
var onDelete = props.onDelete;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div className="xeplr-table-actions-cell">
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
className="xeplr-table-action-btn xeplr-table-action-view"
|
|
21
|
+
title="View"
|
|
22
|
+
onClick={function() { onView(row); }}
|
|
23
|
+
>
|
|
24
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
25
|
+
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
|
|
26
|
+
<circle cx="12" cy="12" r="3"/>
|
|
27
|
+
</svg>
|
|
28
|
+
</button>
|
|
29
|
+
|
|
30
|
+
{hasSave && (
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
className="xeplr-table-action-btn xeplr-table-action-copy"
|
|
34
|
+
title="Copy"
|
|
35
|
+
onClick={function() { onCopy(row); }}
|
|
36
|
+
>
|
|
37
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
38
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
39
|
+
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
|
|
40
|
+
</svg>
|
|
41
|
+
</button>
|
|
42
|
+
)}
|
|
43
|
+
|
|
44
|
+
{hasSave && (
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
className="xeplr-table-action-btn xeplr-table-action-edit"
|
|
48
|
+
title="Edit"
|
|
49
|
+
onClick={function() { onEdit(row); }}
|
|
50
|
+
>
|
|
51
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
52
|
+
<path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
|
|
53
|
+
<path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
54
|
+
</svg>
|
|
55
|
+
</button>
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
{hasDelete && (
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
className="xeplr-table-action-btn xeplr-table-action-delete"
|
|
62
|
+
title="Delete"
|
|
63
|
+
onClick={function() { onDelete(row.id); }}
|
|
64
|
+
>
|
|
65
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
66
|
+
<polyline points="3 6 5 6 21 6"/>
|
|
67
|
+
<path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/>
|
|
68
|
+
<line x1="10" y1="11" x2="10" y2="17"/>
|
|
69
|
+
<line x1="14" y1="11" x2="14" y2="17"/>
|
|
70
|
+
</svg>
|
|
71
|
+
</button>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ActionsCell from './ActionsCell.jsx';
|
|
3
|
+
import { resolveCellStyle } from '../resolveCellStyle.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Recursive nested child table.
|
|
7
|
+
* Renders rows for a child array, with expand support for deeper levels.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} props.rootId - Level-0 parent id
|
|
10
|
+
* @param {Array} props.path - Navigation path from root (e.g. ['employees'])
|
|
11
|
+
* @param {number} props.schemaLevel - Current schema level (1, 2, ...)
|
|
12
|
+
* @param {object} props.schema - Full schema object
|
|
13
|
+
* @param {Array} props.rows - Child records to display
|
|
14
|
+
* @param {object} props.actions - Actions controller
|
|
15
|
+
*/
|
|
16
|
+
export default function ChildTable(props) {
|
|
17
|
+
var rootId = props.rootId;
|
|
18
|
+
var path = props.path;
|
|
19
|
+
var schemaLevel = props.schemaLevel;
|
|
20
|
+
var schema = props.schema;
|
|
21
|
+
var rows = props.rows || [];
|
|
22
|
+
var actions = props.actions;
|
|
23
|
+
|
|
24
|
+
var schemaDef = schema[schemaLevel];
|
|
25
|
+
if (!schemaDef) return null;
|
|
26
|
+
|
|
27
|
+
var columns = schemaDef.columns || [];
|
|
28
|
+
var header = schemaDef.header || schemaDef.key;
|
|
29
|
+
|
|
30
|
+
// Check if there's a deeper level
|
|
31
|
+
var nextLevel = schema[schemaLevel + 1];
|
|
32
|
+
var nextChildKey = nextLevel ? nextLevel.key : null;
|
|
33
|
+
|
|
34
|
+
function getChildId(child) {
|
|
35
|
+
return child._tempId || child.id;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="xeplr-table-child-container">
|
|
40
|
+
<div className="xeplr-table-child-header">
|
|
41
|
+
<span className="xeplr-table-child-title">{header}</span>
|
|
42
|
+
{actions.hasSave && (
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
className="xeplr-table-toolbar-btn xeplr-table-toolbar-btn-add xeplr-table-child-add"
|
|
46
|
+
onClick={function() { actions.openNestedAdd(rootId, path, schemaLevel); }}
|
|
47
|
+
>
|
|
48
|
+
+ Add
|
|
49
|
+
</button>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
<table className="xeplr-table xeplr-table-child">
|
|
53
|
+
<thead>
|
|
54
|
+
<tr>
|
|
55
|
+
{nextChildKey && <th className="xeplr-table-th xeplr-table-th-expand" />}
|
|
56
|
+
{columns.map(function(col) {
|
|
57
|
+
return (
|
|
58
|
+
<th key={col.accessor} className="xeplr-table-th">
|
|
59
|
+
<div className="xeplr-table-header-cell">
|
|
60
|
+
<span className="xeplr-table-header-label">{col.header || col.accessor}</span>
|
|
61
|
+
</div>
|
|
62
|
+
</th>
|
|
63
|
+
);
|
|
64
|
+
})}
|
|
65
|
+
<th className="xeplr-table-th xeplr-table-th-actions">
|
|
66
|
+
<div className="xeplr-table-header-cell">
|
|
67
|
+
<span className="xeplr-table-header-label">Actions</span>
|
|
68
|
+
</div>
|
|
69
|
+
</th>
|
|
70
|
+
</tr>
|
|
71
|
+
</thead>
|
|
72
|
+
<tbody>
|
|
73
|
+
{rows.length === 0 && (
|
|
74
|
+
<tr>
|
|
75
|
+
<td className="xeplr-table-empty" colSpan={columns.length + (nextChildKey ? 2 : 1)}>
|
|
76
|
+
No {header.toLowerCase()}
|
|
77
|
+
</td>
|
|
78
|
+
</tr>
|
|
79
|
+
)}
|
|
80
|
+
{rows.map(function(child) {
|
|
81
|
+
var childId = getChildId(child);
|
|
82
|
+
var isNew = !!child._tempId;
|
|
83
|
+
var isExpanded = actions.expandedIds.has(childId);
|
|
84
|
+
|
|
85
|
+
var rowElements = [];
|
|
86
|
+
|
|
87
|
+
rowElements.push(
|
|
88
|
+
<tr key={childId} className={'xeplr-table-row' + (isNew ? ' xeplr-table-row-new' : '')}>
|
|
89
|
+
{nextChildKey && (
|
|
90
|
+
<td className="xeplr-table-td xeplr-table-td-expand">
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
className={'xeplr-table-expand-btn' + (isExpanded ? ' expanded' : '')}
|
|
94
|
+
onClick={function() { actions.toggleExpand(childId); }}
|
|
95
|
+
>
|
|
96
|
+
▸
|
|
97
|
+
</button>
|
|
98
|
+
</td>
|
|
99
|
+
)}
|
|
100
|
+
{columns.map(function(col) {
|
|
101
|
+
var value = child[col.accessor];
|
|
102
|
+
var cellStyleDef = col.cellStyle;
|
|
103
|
+
var condStyle = cellStyleDef
|
|
104
|
+
? resolveCellStyle(value, cellStyleDef, col.accessor, child)
|
|
105
|
+
: null;
|
|
106
|
+
|
|
107
|
+
var displayValue = value;
|
|
108
|
+
if (col.cell) {
|
|
109
|
+
displayValue = col.cell({ getValue: function() { return value; }, row: { original: child } });
|
|
110
|
+
} else {
|
|
111
|
+
displayValue = value != null ? String(value) : '';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<td key={col.accessor} className="xeplr-table-td" style={condStyle}>
|
|
116
|
+
{displayValue}
|
|
117
|
+
</td>
|
|
118
|
+
);
|
|
119
|
+
})}
|
|
120
|
+
<td className="xeplr-table-td xeplr-table-td-actions">
|
|
121
|
+
<ActionsCell
|
|
122
|
+
row={child}
|
|
123
|
+
hasSave={actions.hasSave}
|
|
124
|
+
hasDelete={actions.hasDelete}
|
|
125
|
+
onView={function() { actions.openNestedView(rootId, path, child); }}
|
|
126
|
+
onCopy={function() { actions.openNestedCopy(rootId, path, child); }}
|
|
127
|
+
onEdit={function() { actions.openNestedEdit(rootId, path, child); }}
|
|
128
|
+
onDelete={function() { actions.handleNestedDelete(rootId, path, childId); }}
|
|
129
|
+
/>
|
|
130
|
+
</td>
|
|
131
|
+
</tr>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
// Expanded sub-children (recursive)
|
|
135
|
+
if (isExpanded && nextChildKey) {
|
|
136
|
+
var subPath = path.concat([childId, nextChildKey]);
|
|
137
|
+
rowElements.push(
|
|
138
|
+
<tr key={childId + '-children'} className="xeplr-table-row-expanded">
|
|
139
|
+
<td colSpan={columns.length + 2} className="xeplr-table-td-expanded">
|
|
140
|
+
<ChildTable
|
|
141
|
+
rootId={rootId}
|
|
142
|
+
path={subPath}
|
|
143
|
+
schemaLevel={schemaLevel + 1}
|
|
144
|
+
schema={schema}
|
|
145
|
+
rows={child[nextChildKey] || []}
|
|
146
|
+
actions={actions}
|
|
147
|
+
/>
|
|
148
|
+
</td>
|
|
149
|
+
</tr>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return rowElements;
|
|
154
|
+
})}
|
|
155
|
+
</tbody>
|
|
156
|
+
</table>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|