@neo4j-ndl/react 4.14.6 → 4.15.1
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/lib/cjs/data-grid/Components.js +25 -10
- package/lib/cjs/data-grid/Components.js.map +1 -1
- package/lib/cjs/data-grid/datagrid-types.js.map +1 -1
- package/lib/cjs/data-grid/stories/datagrid-in-dialog.story.js +1 -0
- package/lib/cjs/data-grid/stories/datagrid-in-dialog.story.js.map +1 -1
- package/lib/cjs/data-grid/stories/datagrid-using-editable-cells.story.js +145 -52
- package/lib/cjs/data-grid/stories/datagrid-using-editable-cells.story.js.map +1 -1
- package/lib/esm/data-grid/Components.js +25 -10
- package/lib/esm/data-grid/Components.js.map +1 -1
- package/lib/esm/data-grid/datagrid-types.js.map +1 -1
- package/lib/esm/data-grid/stories/datagrid-in-dialog.story.js +1 -0
- package/lib/esm/data-grid/stories/datagrid-in-dialog.story.js.map +1 -1
- package/lib/esm/data-grid/stories/datagrid-using-editable-cells.story.js +147 -54
- package/lib/esm/data-grid/stories/datagrid-using-editable-cells.story.js.map +1 -1
- package/lib/types/data-grid/Components.d.ts +16 -1
- package/lib/types/data-grid/Components.d.ts.map +1 -1
- package/lib/types/data-grid/DataGrid.d.ts +10 -1
- package/lib/types/data-grid/DataGrid.d.ts.map +1 -1
- package/lib/types/data-grid/datagrid-types.d.ts +11 -1
- package/lib/types/data-grid/datagrid-types.d.ts.map +1 -1
- package/lib/types/data-grid/stories/datagrid-in-dialog.story.d.ts.map +1 -1
- package/lib/types/data-grid/stories/datagrid-pinned-columns.stories.d.ts +10 -1
- package/lib/types/data-grid/stories/datagrid-pinned-columns.stories.d.ts.map +1 -1
- package/lib/types/data-grid/stories/datagrid-search-and-filters.stories.d.ts +10 -1
- package/lib/types/data-grid/stories/datagrid-search-and-filters.stories.d.ts.map +1 -1
- package/lib/types/data-grid/stories/datagrid-using-editable-cells.story.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -22,93 +22,186 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
22
22
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
23
|
*/
|
|
24
24
|
require("@neo4j-ndl/base/lib/neo4j-ds-styles.css");
|
|
25
|
+
const base_1 = require("@neo4j-ndl/base");
|
|
25
26
|
const react_1 = require("@neo4j-ndl/react");
|
|
27
|
+
const icons_1 = require("@neo4j-ndl/react/icons");
|
|
26
28
|
const react_table_1 = require("@tanstack/react-table");
|
|
27
29
|
const react_2 = require("react");
|
|
28
|
-
const
|
|
30
|
+
const ROLE_OPTIONS = [
|
|
31
|
+
{ label: 'Admin', value: 'admin' },
|
|
32
|
+
{ label: 'Editor', value: 'editor' },
|
|
33
|
+
{ label: 'Viewer', value: 'viewer' },
|
|
34
|
+
];
|
|
35
|
+
const PERMISSION_OPTIONS = [
|
|
36
|
+
{ label: 'Read', value: 'read' },
|
|
37
|
+
{ label: 'Write', value: 'write' },
|
|
38
|
+
{ label: 'Delete', value: 'delete' },
|
|
39
|
+
];
|
|
40
|
+
const LABEL_OPTIONS = [
|
|
41
|
+
{ label: 'Person', value: 'person' },
|
|
42
|
+
{ label: 'Movie', value: 'movie' },
|
|
43
|
+
{ label: 'Director', value: 'director' },
|
|
44
|
+
{ label: 'Actor', value: 'actor' },
|
|
45
|
+
];
|
|
46
|
+
const STATUS_OPTIONS = [
|
|
47
|
+
{ label: 'Active', value: 'active' },
|
|
48
|
+
{ label: 'Inactive', value: 'inactive' },
|
|
49
|
+
{ label: 'Pending', value: 'pending' },
|
|
50
|
+
];
|
|
51
|
+
const VALID_STATUSES = STATUS_OPTIONS.map((option) => option.value);
|
|
52
|
+
const LABEL_COLORS = {
|
|
53
|
+
actor: base_1.tokens.graph['7'],
|
|
54
|
+
director: base_1.tokens.graph['4'],
|
|
55
|
+
movie: base_1.tokens.graph['3'],
|
|
56
|
+
person: base_1.tokens.graph['1'],
|
|
57
|
+
};
|
|
58
|
+
// Render each selected value as a non-interactive GraphLabel (as a span)
|
|
59
|
+
// instead of the default Tag chip, demonstrating the components override.
|
|
60
|
+
const LabelMultiValue = (props) => ((0, jsx_runtime_1.jsx)(react_1.GraphLabel, { as: "span", type: "node", size: "small", color: LABEL_COLORS[props.data.value], children: props.data.label }));
|
|
61
|
+
// The "Dallas Kuhn" row has a status that is not part of the available
|
|
62
|
+
// options, so its dropdown cell renders in the error state.
|
|
63
|
+
const DEMO_DATA = [
|
|
64
|
+
{
|
|
65
|
+
labels: ['person', 'actor'],
|
|
66
|
+
name: 'Alicia Sanford',
|
|
67
|
+
permissions: ['read', 'write'],
|
|
68
|
+
role: 'admin',
|
|
69
|
+
status: 'active',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
labels: ['movie'],
|
|
73
|
+
name: 'Dallas Kuhn',
|
|
74
|
+
permissions: ['read'],
|
|
75
|
+
role: 'editor',
|
|
76
|
+
status: 'unknown',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
labels: ['director'],
|
|
80
|
+
name: 'Susan Daugherty MD',
|
|
81
|
+
permissions: ['read', 'write', 'delete'],
|
|
82
|
+
role: 'viewer',
|
|
83
|
+
status: 'pending',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
labels: ['person'],
|
|
87
|
+
name: 'Karen Huel',
|
|
88
|
+
permissions: ['read'],
|
|
89
|
+
role: 'editor',
|
|
90
|
+
status: 'inactive',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
labels: ['movie', 'director'],
|
|
94
|
+
name: 'Ken Kessler',
|
|
95
|
+
permissions: ['write', 'delete'],
|
|
96
|
+
role: 'admin',
|
|
97
|
+
status: 'active',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
labels: [],
|
|
101
|
+
name: 'Courtney McClure',
|
|
102
|
+
permissions: [],
|
|
103
|
+
role: 'viewer',
|
|
104
|
+
status: 'pending',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
29
107
|
const columnHelper = (0, react_table_1.createColumnHelper)();
|
|
30
108
|
const Component = () => {
|
|
31
|
-
const [data, setData] = (0, react_2.useState)(
|
|
109
|
+
const [data, setData] = (0, react_2.useState)(DEMO_DATA);
|
|
110
|
+
const updateRow = (name, update) => {
|
|
111
|
+
setData((oldData) => oldData.map((row) => (row.name === name ? Object.assign(Object.assign({}, row), update) : row)));
|
|
112
|
+
};
|
|
32
113
|
const COMMON_COLUMNS = [
|
|
114
|
+
// Editable inline text cell.
|
|
33
115
|
columnHelper.accessor('name', {
|
|
34
116
|
cell: (cell) => ((0, jsx_runtime_1.jsx)(react_1.DataGrid.InlineEditCell, { cell: cell, value: cell.getValue(), ariaLabel: "edit name" })),
|
|
35
117
|
meta: {
|
|
36
118
|
isInlineEditCell: {
|
|
37
119
|
onEditChange: (newValue, cell) => {
|
|
38
|
-
|
|
39
|
-
return oldData.map((row) => {
|
|
40
|
-
if (row.name === cell.row.original.name) {
|
|
41
|
-
return Object.assign(Object.assign({}, row), { name: newValue });
|
|
42
|
-
}
|
|
43
|
-
return row;
|
|
44
|
-
});
|
|
45
|
-
});
|
|
120
|
+
updateRow(cell.row.original.name, { name: newValue });
|
|
46
121
|
},
|
|
47
122
|
},
|
|
48
123
|
},
|
|
49
124
|
minSize: 180,
|
|
50
125
|
size: 220,
|
|
51
126
|
}),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
label: '37',
|
|
64
|
-
value: '37',
|
|
127
|
+
// Default single-select dropdown.
|
|
128
|
+
columnHelper.accessor('role', {
|
|
129
|
+
cell: (info) => ((0, jsx_runtime_1.jsx)(react_1.DataGrid.DropDownCell, { cell: info, options: ROLE_OPTIONS, ariaLabel: "select role" })),
|
|
130
|
+
meta: {
|
|
131
|
+
isDropDownCell: {
|
|
132
|
+
onChange: (newValue, cell) => {
|
|
133
|
+
if (newValue === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
updateRow(cell.row.original.name, { role: newValue });
|
|
65
137
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
minSize: 160,
|
|
141
|
+
size: 180,
|
|
142
|
+
}),
|
|
143
|
+
// Default multi-select dropdown (default Tag chips).
|
|
144
|
+
columnHelper.accessor('permissions', {
|
|
145
|
+
cell: (info) => ((0, jsx_runtime_1.jsx)(react_1.DataGrid.DropDownCell, { cell: info, options: PERMISSION_OPTIONS, ariaLabel: "select permissions" })),
|
|
146
|
+
enableSorting: false,
|
|
147
|
+
meta: {
|
|
148
|
+
isDropDownCell: {
|
|
149
|
+
isMulti: true,
|
|
150
|
+
onChange: (newValue, cell) => {
|
|
151
|
+
updateRow(cell.row.original.name, { permissions: newValue });
|
|
69
152
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
minSize: 220,
|
|
156
|
+
size: 260,
|
|
157
|
+
}),
|
|
158
|
+
// Multi-select dropdown with a custom MultiValue (GraphLabel chips).
|
|
159
|
+
columnHelper.accessor('labels', {
|
|
160
|
+
cell: (info) => ((0, jsx_runtime_1.jsx)(react_1.DataGrid.DropDownCell, { cell: info, options: LABEL_OPTIONS, ariaLabel: "select labels", components: { MultiValue: LabelMultiValue } })),
|
|
161
|
+
enableSorting: false,
|
|
162
|
+
meta: {
|
|
163
|
+
isDropDownCell: {
|
|
164
|
+
isMulti: true,
|
|
165
|
+
onChange: (newValue, cell) => {
|
|
166
|
+
updateRow(cell.row.original.name, { labels: newValue });
|
|
73
167
|
},
|
|
74
|
-
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
minSize: 240,
|
|
171
|
+
size: 280,
|
|
172
|
+
}),
|
|
173
|
+
// Single-select dropdown in an error state.
|
|
174
|
+
columnHelper.accessor('status', {
|
|
175
|
+
cell: (info) => {
|
|
176
|
+
const isInvalid = !VALID_STATUSES.includes(info.getValue());
|
|
177
|
+
const isPending = info.getValue() === 'pending';
|
|
178
|
+
const isInactive = info.getValue() === 'inactive';
|
|
179
|
+
const warningHelpText = ((0, jsx_runtime_1.jsxs)("span", { className: "n-flex n-items-center n-gap-token-2 n-text-warning-text", children: [(0, jsx_runtime_1.jsx)(icons_1.ExclamationTriangleIconSolid, { className: "n-size-token-16 n-text-warning-icon" }), "Inactive users cannot sign in"] }));
|
|
180
|
+
return ((0, jsx_runtime_1.jsx)(react_1.DataGrid.DropDownCell, { cell: info, options: STATUS_OPTIONS, ariaLabel: "select status", errorText: isInvalid ? 'Please select a valid status' : undefined, helpText: isInactive
|
|
181
|
+
? warningHelpText
|
|
182
|
+
: isPending
|
|
183
|
+
? 'Waiting for admin approval'
|
|
184
|
+
: undefined }));
|
|
185
|
+
},
|
|
75
186
|
meta: {
|
|
76
187
|
isDropDownCell: {
|
|
77
188
|
onChange: (newValue, cell) => {
|
|
78
189
|
if (newValue === undefined) {
|
|
79
|
-
// No change
|
|
80
190
|
return;
|
|
81
191
|
}
|
|
82
|
-
|
|
83
|
-
if (isNaN(parsedValue)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
setData((oldData) => {
|
|
87
|
-
return oldData.map((row) => {
|
|
88
|
-
if (row.name === cell.row.original.name) {
|
|
89
|
-
return Object.assign(Object.assign({}, row), { age: parsedValue });
|
|
90
|
-
}
|
|
91
|
-
return row;
|
|
92
|
-
});
|
|
93
|
-
});
|
|
192
|
+
updateRow(cell.row.original.name, { status: newValue });
|
|
94
193
|
},
|
|
95
194
|
},
|
|
96
195
|
},
|
|
97
|
-
minSize:
|
|
98
|
-
|
|
99
|
-
columnHelper.accessor('cypherCommand', {
|
|
100
|
-
cell: (info) => info.getValue(),
|
|
101
|
-
minSize: 400,
|
|
102
|
-
size: 400,
|
|
196
|
+
minSize: 200,
|
|
197
|
+
size: 240,
|
|
103
198
|
}),
|
|
104
199
|
];
|
|
105
200
|
const table = (0, react_table_1.useReactTable)({
|
|
201
|
+
autoResetPageIndex: false,
|
|
106
202
|
columnResizeMode: 'onChange',
|
|
107
203
|
columns: COMMON_COLUMNS,
|
|
108
204
|
data: data,
|
|
109
|
-
debugColumns: true,
|
|
110
|
-
debugHeaders: true,
|
|
111
|
-
debugTable: true,
|
|
112
205
|
defaultColumn: {
|
|
113
206
|
maxSize: 800,
|
|
114
207
|
minSize: 80,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datagrid-using-editable-cells.story.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/datagrid-using-editable-cells.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAA4C;AAC5C,uDAM+B;AAC/B,iCAAiC;AAEjC,6CAA+C;AAQ/C,MAAM,YAAY,GAAG,IAAA,gCAAkB,GAAkB,CAAC;AAE1D,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAC,4BAAe,CAAC,CAAC;IAElD,MAAM,cAAc,GAAG;QACrB,YAAY,CAAC,QAAQ,CAAC,MAAM,EAAE;YAC5B,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CACd,uBAAC,gBAAQ,CAAC,cAAc,IACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,EACtB,SAAS,EAAC,WAAW,GACrB,CACH;YACD,IAAI,EAAE;gBACJ,gBAAgB,EAAE;oBAChB,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE;wBAC/B,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;4BAClB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gCACzB,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,QA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* Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { DataGrid } from '@neo4j-ndl/react';\nimport {\n createColumnHelper,\n getCoreRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n useReactTable,\n} from '@tanstack/react-table';\nimport { useState } from 'react';\n\nimport { TABLE_DEMO_DATA } from './staticData';\n\ntype TestDataFormat = {\n name: string;\n age: number;\n cypherCommand: string;\n};\n\nconst columnHelper = createColumnHelper<TestDataFormat>();\n\nconst Component = () => {\n const [data, setData] = useState(TABLE_DEMO_DATA);\n\n const COMMON_COLUMNS = [\n columnHelper.accessor('name', {\n cell: (cell) => (\n <DataGrid.InlineEditCell\n cell={cell}\n value={cell.getValue()}\n ariaLabel=\"edit name\"\n />\n ),\n meta: {\n isInlineEditCell: {\n onEditChange: (newValue, cell) => {\n setData((oldData) => {\n return oldData.map((row) => {\n if (row.name === cell.row.original.name) {\n return {\n ...row,\n name: newValue,\n };\n }\n return row;\n });\n });\n },\n },\n },\n minSize: 180,\n size: 220,\n }),\n columnHelper.accessor('age', {\n cell: (info) => (\n <DataGrid.DropDownCell\n cell={info}\n options={[\n {\n label: '12',\n value: '12',\n },\n {\n label: '32',\n value: '32',\n },\n {\n label: '37',\n value: '37',\n },\n {\n label: '39',\n value: '39',\n },\n {\n label: '51',\n value: '51',\n },\n ]}\n ariaLabel=\"select age\"\n />\n ),\n meta: {\n isDropDownCell: {\n onChange: (newValue, cell) => {\n if (newValue === undefined) {\n // No change\n return;\n }\n\n const parsedValue = parseInt(newValue, 10);\n\n if (isNaN(parsedValue)) {\n return;\n }\n\n setData((oldData) => {\n return oldData.map((row) => {\n if (row.name === cell.row.original.name) {\n return {\n ...row,\n age: parsedValue,\n };\n }\n return row;\n });\n });\n },\n },\n },\n minSize: 80,\n }),\n columnHelper.accessor('cypherCommand', {\n cell: (info) => info.getValue(),\n minSize: 400,\n size: 400,\n }),\n ];\n const table = useReactTable({\n columnResizeMode: 'onChange',\n columns: COMMON_COLUMNS,\n data: data,\n debugColumns: true,\n debugHeaders: true,\n debugTable: true,\n defaultColumn: {\n maxSize: 800,\n minSize: 80,\n },\n enableSorting: true,\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getSortedRowModel: getSortedRowModel(),\n initialState: {\n pagination: {\n pageSize: 5,\n },\n },\n });\n\n return (\n <div className=\"n-w-full n-bg-light-neutral-text-weakest\">\n <DataGrid\n isKeyboardNavigable={true}\n isResizable={true}\n styling={{\n borderStyle: 'all-sides',\n hasZebraStriping: false,\n }}\n tableInstance={table}\n />\n </div>\n );\n};\n\nexport default Component;\n"]}
|
|
1
|
+
{"version":3,"file":"datagrid-using-editable-cells.story.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/datagrid-using-editable-cells.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,0CAAyC;AACzC,4CAAwD;AACxD,kDAAsE;AACtE,uDAM+B;AAC/B,iCAAiC;AAWjC,MAAM,YAAY,GAAG;IACnB,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAClC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACpC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;CACrC,CAAC;AAEF,MAAM,kBAAkB,GAAG;IACzB,EAAE,KAAK,EA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AAS,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;oBAC1D,CAAC;iBACF;aACF;YACD,OAAO,EAAE,GAAG;YACZ,IAAI,EAAE,GAAG;SACV,CAAC;KACH,CAAC;IACF,MAAM,KAAK,GAAG,IAAA,2BAAa,EAAC;QAC1B,kBAAkB,EAAE,KAAK;QACzB,gBAAgB,EAAE,UAAU;QAC5B,OAAO,EAAE,cAAc;QACvB,IAAI,EAAE,IAAI;QACV,aAAa,EAAE;YACb,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,EAAE;SACZ;QACD,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,IAAA,6BAAe,GAAE;QAClC,qBAAqB,EAAE,IAAA,mCAAqB,GAAE;QAC9C,iBAAiB,EAAE,IAAA,+BAAiB,GAAE;QACtC,YAAY,EAAE;YACZ,UAAU,EAAE;gBACV,QAAQ,EAAE,CAAC;aACZ;SACF;KACF,CAAC,CAAC;IAEH,OAAO,CACL,gCAAK,SAAS,EAAC,0CAA0C,YACvD,uBAAC,gBAAQ,IACP,mBAAmB,EAAE,IAAI,EACzB,WAAW,EAAE,IAAI,EACjB,OAAO,EAAE;gBACP,WAAW,EAAE,WAAW;gBACxB,gBAAgB,EAAE,KAAK;aACxB,EACD,aAAa,EAAE,KAAK,GACpB,GACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { tokens } from '@neo4j-ndl/base';\nimport { DataGrid, GraphLabel } from '@neo4j-ndl/react';\nimport { ExclamationTriangleIconSolid } from '@neo4j-ndl/react/icons';\nimport {\n createColumnHelper,\n getCoreRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n useReactTable,\n} from '@tanstack/react-table';\nimport { useState } from 'react';\nimport { type MultiValueProps } from 'react-select';\n\ntype TestDataFormat = {\n name: string;\n role: string;\n permissions: string[];\n labels: string[];\n status: string;\n};\n\nconst ROLE_OPTIONS = [\n { label: 'Admin', value: 'admin' },\n { label: 'Editor', value: 'editor' },\n { label: 'Viewer', value: 'viewer' },\n];\n\nconst PERMISSION_OPTIONS = [\n { label: 'Read', value: 'read' },\n { label: 'Write', value: 'write' },\n { label: 'Delete', value: 'delete' },\n];\n\nconst LABEL_OPTIONS = [\n { label: 'Person', value: 'person' },\n { label: 'Movie', value: 'movie' },\n { label: 'Director', value: 'director' },\n { label: 'Actor', value: 'actor' },\n];\n\nconst STATUS_OPTIONS = [\n { label: 'Active', value: 'active' },\n { label: 'Inactive', value: 'inactive' },\n { label: 'Pending', value: 'pending' },\n];\n\nconst VALID_STATUSES = STATUS_OPTIONS.map((option) => option.value);\n\ntype DropDownOption = { value: string; label: string };\n\nconst LABEL_COLORS: Record<string, string> = {\n actor: tokens.graph['7'],\n director: tokens.graph['4'],\n movie: tokens.graph['3'],\n person: tokens.graph['1'],\n};\n\n// Render each selected value as a non-interactive GraphLabel (as a span)\n// instead of the default Tag chip, demonstrating the components override.\nconst LabelMultiValue = (props: MultiValueProps<DropDownOption, boolean>) => (\n <GraphLabel\n as=\"span\"\n type=\"node\"\n size=\"small\"\n color={LABEL_COLORS[props.data.value]}\n >\n {props.data.label}\n </GraphLabel>\n);\n\n// The \"Dallas Kuhn\" row has a status that is not part of the available\n// options, so its dropdown cell renders in the error state.\nconst DEMO_DATA: TestDataFormat[] = [\n {\n labels: ['person', 'actor'],\n name: 'Alicia Sanford',\n permissions: ['read', 'write'],\n role: 'admin',\n status: 'active',\n },\n {\n labels: ['movie'],\n name: 'Dallas Kuhn',\n permissions: ['read'],\n role: 'editor',\n status: 'unknown',\n },\n {\n labels: ['director'],\n name: 'Susan Daugherty MD',\n permissions: ['read', 'write', 'delete'],\n role: 'viewer',\n status: 'pending',\n },\n {\n labels: ['person'],\n name: 'Karen Huel',\n permissions: ['read'],\n role: 'editor',\n status: 'inactive',\n },\n {\n labels: ['movie', 'director'],\n name: 'Ken Kessler',\n permissions: ['write', 'delete'],\n role: 'admin',\n status: 'active',\n },\n {\n labels: [],\n name: 'Courtney McClure',\n permissions: [],\n role: 'viewer',\n status: 'pending',\n },\n];\n\nconst columnHelper = createColumnHelper<TestDataFormat>();\n\nconst Component = () => {\n const [data, setData] = useState(DEMO_DATA);\n\n const updateRow = (name: string, update: Partial<TestDataFormat>): void => {\n setData((oldData) =>\n oldData.map((row) => (row.name === name ? { ...row, ...update } : row)),\n );\n };\n\n const COMMON_COLUMNS = [\n // Editable inline text cell.\n columnHelper.accessor('name', {\n cell: (cell) => (\n <DataGrid.InlineEditCell\n cell={cell}\n value={cell.getValue()}\n ariaLabel=\"edit name\"\n />\n ),\n meta: {\n isInlineEditCell: {\n onEditChange: (newValue, cell) => {\n updateRow(cell.row.original.name, { name: newValue });\n },\n },\n },\n minSize: 180,\n size: 220,\n }),\n // Default single-select dropdown.\n columnHelper.accessor('role', {\n cell: (info) => (\n <DataGrid.DropDownCell\n cell={info}\n options={ROLE_OPTIONS}\n ariaLabel=\"select role\"\n />\n ),\n meta: {\n isDropDownCell: {\n onChange: (newValue, cell) => {\n if (newValue === undefined) {\n return;\n }\n updateRow(cell.row.original.name, { role: newValue });\n },\n },\n },\n minSize: 160,\n size: 180,\n }),\n // Default multi-select dropdown (default Tag chips).\n columnHelper.accessor('permissions', {\n cell: (info) => (\n <DataGrid.DropDownCell\n cell={info}\n options={PERMISSION_OPTIONS}\n ariaLabel=\"select permissions\"\n />\n ),\n enableSorting: false,\n meta: {\n isDropDownCell: {\n isMulti: true,\n onChange: (newValue, cell) => {\n updateRow(cell.row.original.name, { permissions: newValue });\n },\n },\n },\n minSize: 220,\n size: 260,\n }),\n // Multi-select dropdown with a custom MultiValue (GraphLabel chips).\n columnHelper.accessor('labels', {\n cell: (info) => (\n <DataGrid.DropDownCell\n cell={info}\n options={LABEL_OPTIONS}\n ariaLabel=\"select labels\"\n components={{ MultiValue: LabelMultiValue }}\n />\n ),\n enableSorting: false,\n meta: {\n isDropDownCell: {\n isMulti: true,\n onChange: (newValue, cell) => {\n updateRow(cell.row.original.name, { labels: newValue });\n },\n },\n },\n minSize: 240,\n size: 280,\n }),\n // Single-select dropdown in an error state.\n columnHelper.accessor('status', {\n cell: (info) => {\n const isInvalid = !VALID_STATUSES.includes(info.getValue());\n\n const isPending = info.getValue() === 'pending';\n const isInactive = info.getValue() === 'inactive';\n\n const warningHelpText = (\n <span className=\"n-flex n-items-center n-gap-token-2 n-text-warning-text\">\n <ExclamationTriangleIconSolid className=\"n-size-token-16 n-text-warning-icon\" />\n Inactive users cannot sign in\n </span>\n );\n\n return (\n <DataGrid.DropDownCell\n cell={info}\n options={STATUS_OPTIONS}\n ariaLabel=\"select status\"\n errorText={isInvalid ? 'Please select a valid status' : undefined}\n helpText={\n isInactive\n ? warningHelpText\n : isPending\n ? 'Waiting for admin approval'\n : undefined\n }\n />\n );\n },\n meta: {\n isDropDownCell: {\n onChange: (newValue, cell) => {\n if (newValue === undefined) {\n return;\n }\n updateRow(cell.row.original.name, { status: newValue });\n },\n },\n },\n minSize: 200,\n size: 240,\n }),\n ];\n const table = useReactTable({\n autoResetPageIndex: false,\n columnResizeMode: 'onChange',\n columns: COMMON_COLUMNS,\n data: data,\n defaultColumn: {\n maxSize: 800,\n minSize: 80,\n },\n enableSorting: true,\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getSortedRowModel: getSortedRowModel(),\n initialState: {\n pagination: {\n pageSize: 5,\n },\n },\n });\n\n return (\n <div className=\"n-w-full n-bg-light-neutral-text-weakest\">\n <DataGrid\n isKeyboardNavigable={true}\n isResizable={true}\n styling={{\n borderStyle: 'all-sides',\n hasZebraStriping: false,\n }}\n tableInstance={table}\n />\n </div>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -424,24 +424,39 @@ const InlineEditCell = (_a) => {
|
|
|
424
424
|
}, "aria-label": ariaLabel }, restProps, htmlAttributes)));
|
|
425
425
|
};
|
|
426
426
|
const DropDownCell = (_a) => {
|
|
427
|
-
var _b;
|
|
428
|
-
var { cell, options, portalTarget: portalTargetProp, ariaLabel, className, style, htmlAttributes, ref: forwardRef, isDisabled } = _a, restProps = __rest(_a, ["cell", "options", "portalTarget", "ariaLabel", "className", "style", "htmlAttributes", "ref", "isDisabled"]);
|
|
427
|
+
var _b, _c;
|
|
428
|
+
var { cell, options, portalTarget: portalTargetProp, ariaLabel, className, style, htmlAttributes, ref: forwardRef, isDisabled, errorText, helpText, components } = _a, restProps = __rest(_a, ["cell", "options", "portalTarget", "ariaLabel", "className", "style", "htmlAttributes", "ref", "isDisabled", "errorText", "helpText", "components"]);
|
|
429
429
|
const { dataGridNav, portalTarget } = useDataGridContext();
|
|
430
430
|
const ref = useRef(null);
|
|
431
431
|
const mergedRef = useMergeRefs([ref, forwardRef]);
|
|
432
|
-
|
|
432
|
+
const dropDownMeta = (_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.isDropDownCell;
|
|
433
|
+
if (!dropDownMeta) {
|
|
433
434
|
return null;
|
|
434
435
|
}
|
|
435
|
-
const
|
|
436
|
+
const isMulti = (_c = dropDownMeta.isMulti) !== null && _c !== void 0 ? _c : false;
|
|
437
|
+
const cellValue = cell.getValue();
|
|
438
|
+
const selectedValues = (Array.isArray(cellValue) ? cellValue : [cellValue]).map((value) => value === null || value === void 0 ? void 0 : value.toString());
|
|
439
|
+
const defaultValue = isMulti
|
|
440
|
+
? options.filter((option) => selectedValues.includes(option.value))
|
|
441
|
+
: options.find((option) => option.value === (cellValue === null || cellValue === void 0 ? void 0 : cellValue.toString()));
|
|
436
442
|
const menuPortalTarget = portalTargetProp === undefined ? portalTarget : portalTargetProp;
|
|
437
|
-
return (_jsx(Select, Object.assign({ ref: mergedRef, className: className, isFluid: true, isClean: true, style: Object.assign(Object.assign({}, style), { height: '100%', width: '100%' }), type: "select", size: "medium", ariaLabel: ariaLabel, isDisabled: isDisabled, selectProps: {
|
|
438
|
-
|
|
443
|
+
return (_jsx(Select, Object.assign({ ref: mergedRef, className: className, isFluid: true, isClean: true, style: Object.assign(Object.assign({}, style), { height: '100%', width: '100%' }), type: "select", size: "medium", ariaLabel: ariaLabel, isDisabled: isDisabled, errorText: errorText, helpText: helpText, selectProps: {
|
|
444
|
+
components: components,
|
|
445
|
+
defaultValue,
|
|
446
|
+
isMulti,
|
|
439
447
|
menuPortalTarget: menuPortalTarget,
|
|
440
448
|
menuPosition: 'fixed',
|
|
441
|
-
onChange: (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
449
|
+
onChange: (selected) => {
|
|
450
|
+
const selectedOptions = Array.isArray(selected)
|
|
451
|
+
? selected
|
|
452
|
+
: selected
|
|
453
|
+
? [selected]
|
|
454
|
+
: [];
|
|
455
|
+
const values = selectedOptions.map((option) => option.value);
|
|
456
|
+
// `TValue` is not known inside the component; cast once at this boundary
|
|
457
|
+
// to invoke onChange with the resolved single/multi value.
|
|
458
|
+
const handleChange = dropDownMeta.onChange;
|
|
459
|
+
handleChange(isMulti ? values : values[0], cell);
|
|
445
460
|
dataGridNav.enable();
|
|
446
461
|
if (ref === null || ref === void 0 ? void 0 : ref.current) {
|
|
447
462
|
dataGridNav.focusParentCell(ref.current);
|