react-graph-grid 0.1.9 → 0.1.12
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 +18 -15
- package/index.js +20 -0
- package/package.json +4 -11
- package/src/Base.jsx +81 -0
- package/src/Card.jsx +333 -0
- package/src/Dropdown.jsx +339 -0
- package/src/FieldEdit.jsx +376 -0
- package/src/Graph.jsx +482 -0
- package/src/Grid.jsx +887 -0
- package/src/GridCD.jsx +180 -0
- package/src/GridDB.jsx +897 -0
- package/src/GridFE.jsx +753 -0
- package/src/GridFL.jsx +468 -0
- package/src/GridGR.jsx +311 -0
- package/src/GridPK.jsx +414 -0
- package/src/Modal.jsx +511 -0
- package/src/Overlay.jsx +140 -0
- package/src/Tests/DebugApp.jsx +332 -0
- package/src/Tests/TestData.jsx +243 -0
- package/src/Themes/DefaultGridTheme.jsx +36 -0
- package/src/Themes/Images.jsx +438 -0
- package/src/Themes/Translate.jsx +76 -0
- package/src/css/default.css +951 -0
- package/src/main.jsx +10 -0
package/src/GridGR.jsx
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { GridClass } from './Grid';
|
|
3
|
+
import { GraphClass } from './Graph';
|
|
4
|
+
import { NodeStatus } from './Base';
|
|
5
|
+
// ==================================================================================================================================================================
|
|
6
|
+
export function GridGR(props) {
|
|
7
|
+
let grid = null;
|
|
8
|
+
|
|
9
|
+
const [gridState, setState] = useState({ grid: grid, ind: 0 });
|
|
10
|
+
|
|
11
|
+
grid = gridState.grid;
|
|
12
|
+
let needGetRows = false;
|
|
13
|
+
if (!grid || grid.uid !== props.uid && props.uid != null) {
|
|
14
|
+
grid = null;
|
|
15
|
+
if (props.findGrid) {
|
|
16
|
+
grid = props.findGrid(props);
|
|
17
|
+
}
|
|
18
|
+
grid = grid || new GridGRClass(props);
|
|
19
|
+
needGetRows = !props.noAutoRefresh && !props.parentGrids;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (props.init) {
|
|
23
|
+
props.init(grid);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
grid.refreshState = function () {
|
|
27
|
+
setState({ grid: grid, ind: grid.stateind++ });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
grid._waitingRows = needGetRows && (grid.rows.length <= 0 || grid.columns.length <= 0);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
grid.setupEvents(grid);
|
|
34
|
+
|
|
35
|
+
if (grid._waitingRows) {
|
|
36
|
+
|
|
37
|
+
grid.getRows({ filters: grid.collectFilters(), grid: grid }).then(
|
|
38
|
+
rows => {
|
|
39
|
+
grid.rows = rows;
|
|
40
|
+
grid.afterGetRows();
|
|
41
|
+
grid.refreshState();
|
|
42
|
+
}
|
|
43
|
+
).finally(() => {
|
|
44
|
+
grid._waitingRows = false;
|
|
45
|
+
grid.refreshState();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else if (grid.columns.length <= 0 && grid.getColumns) {
|
|
49
|
+
grid.prepareColumns().then(() => grid.refreshState());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
grid.clearEvents();
|
|
54
|
+
}
|
|
55
|
+
}, [grid])
|
|
56
|
+
|
|
57
|
+
return (grid.render());
|
|
58
|
+
}
|
|
59
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
60
|
+
export class GridGRClass extends GridClass {
|
|
61
|
+
|
|
62
|
+
constructor(props) {
|
|
63
|
+
super(props);
|
|
64
|
+
|
|
65
|
+
const grid = this;
|
|
66
|
+
|
|
67
|
+
if (props.entity) {
|
|
68
|
+
grid.entity = props.entity;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (props.applyConnection) {
|
|
72
|
+
grid.applyConnection = props.applyConnection;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!props.graph && (props.parentGrids || props.uid)) {
|
|
76
|
+
grid.graphUid = props.graphUid || "defaultGraphUID";
|
|
77
|
+
|
|
78
|
+
grid.parentGrids = props.parentGrids;
|
|
79
|
+
|
|
80
|
+
window._graphDict = window._graphDict || {};
|
|
81
|
+
|
|
82
|
+
window._graphDict[grid.graphUid] = window._graphDict[grid.graphUid] || new GraphClass();
|
|
83
|
+
const graph = window._graphDict[grid.graphUid];
|
|
84
|
+
|
|
85
|
+
while (graph.nodesDict[GridClass._seq]) {
|
|
86
|
+
GridClass._seq++;
|
|
87
|
+
}
|
|
88
|
+
grid.id = GridClass._seq++;
|
|
89
|
+
|
|
90
|
+
grid.graph = graph;
|
|
91
|
+
graph.uid = grid.graphUid;
|
|
92
|
+
|
|
93
|
+
grid.parents = [];
|
|
94
|
+
grid.children = [];
|
|
95
|
+
|
|
96
|
+
if (props.parentGrids) {
|
|
97
|
+
grid.graph.needCheckIntegrity = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
grid.uid = props.uid != null ? props.uid : grid.id;
|
|
101
|
+
graph.nodeCount++;
|
|
102
|
+
graph.nodesDict[grid.uid] = grid;
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
grid.uid = props.uid != null ? props.uid : grid.id;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
110
|
+
log(message, pref) {
|
|
111
|
+
const grid = this;
|
|
112
|
+
pref = pref || `grid#${grid.uid ? grid.id + '(' + grid.uid + ')' : grid.id} ${grid.title || ''}`;
|
|
113
|
+
super.log(`${pref}: ` + message, ' ');
|
|
114
|
+
}
|
|
115
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
116
|
+
clearEvents() {
|
|
117
|
+
const grid = this;
|
|
118
|
+
|
|
119
|
+
super.clearEvents();
|
|
120
|
+
|
|
121
|
+
if (window._graphDict && grid.graphUid) {
|
|
122
|
+
grid.log(' delete graph')
|
|
123
|
+
delete window._graphDict[grid.graphUid];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
127
|
+
connectToParents(noDetectCycles) {
|
|
128
|
+
const grid = this;
|
|
129
|
+
const graph = grid.graph;
|
|
130
|
+
|
|
131
|
+
grid.connectedToParents = true;
|
|
132
|
+
graph.waveCache = {};
|
|
133
|
+
if (!grid.parentGrids) return;
|
|
134
|
+
|
|
135
|
+
const parentUids = ',' + grid.parentGrids + ',';
|
|
136
|
+
for (let uid in graph.nodesDict) {
|
|
137
|
+
if (uid === grid.uid) continue;
|
|
138
|
+
|
|
139
|
+
let parentGrid = graph.nodesDict[uid];
|
|
140
|
+
if (parentUids.indexOf(parentGrid.uid) <= 0) continue;
|
|
141
|
+
|
|
142
|
+
const link = { parent: parentGrid, child: grid };
|
|
143
|
+
|
|
144
|
+
const lkey = grid.id + '_' + parentGrid.id;
|
|
145
|
+
graph.linksDict[lkey] = link;
|
|
146
|
+
grid.parents.push(parentGrid.uid);
|
|
147
|
+
parentGrid.children.push(grid.uid);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!noDetectCycles) {
|
|
151
|
+
graph.markCycles();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
155
|
+
applyConnection(link) {
|
|
156
|
+
if (!link.parent || !link.parent.rows) return '';
|
|
157
|
+
|
|
158
|
+
return link.parent.selectedValue();
|
|
159
|
+
}
|
|
160
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
161
|
+
getEntity() {
|
|
162
|
+
const grid = this;
|
|
163
|
+
return grid.entity || 'grid_' + (grid.uid || grid.id);
|
|
164
|
+
}
|
|
165
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
166
|
+
onSelectedRowChanged(e) {
|
|
167
|
+
super.onSelectedRowChanged(e);
|
|
168
|
+
|
|
169
|
+
const grid = this;
|
|
170
|
+
const graph = grid.graph;
|
|
171
|
+
if (graph && (!graph._isMakingWave || e.source == 'rowClick')) {
|
|
172
|
+
|
|
173
|
+
if (!grid.connectedToParents) {
|
|
174
|
+
grid.connectToParents();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (graph.needCheckIntegrity) {
|
|
178
|
+
grid.checkGraphIntegrity();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (graph.checkNeedTriggerWave && !graph.checkNeedTriggerWave(grid)) return;
|
|
182
|
+
|
|
183
|
+
graph.triggerWave({ nodes: [grid], withStartNodes: false });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
187
|
+
checkGraphIntegrity() {
|
|
188
|
+
const grid = this;
|
|
189
|
+
const graph = grid.graph;
|
|
190
|
+
graph.needCheckIntegrity = false;
|
|
191
|
+
|
|
192
|
+
for (let uid in graph.nodesDict) {
|
|
193
|
+
if (uid === grid.id) continue;
|
|
194
|
+
|
|
195
|
+
let node = graph.nodesDict[uid];
|
|
196
|
+
if (!node.connectedToParents) {
|
|
197
|
+
node.connectToParents();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let link;
|
|
202
|
+
for (let lkey in graph.linksDict) {
|
|
203
|
+
link = graph.linksDict[lkey];
|
|
204
|
+
if (!link || !graph.nodesDict[link.parent.uid] || !graph.nodesDict[link.child.uid]) {
|
|
205
|
+
delete graph.linksDict[lkey];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
210
|
+
collectFilters() {
|
|
211
|
+
const grid = this;
|
|
212
|
+
const filters = [];
|
|
213
|
+
|
|
214
|
+
if (grid.parentGrids && !grid.connectedToParents) {
|
|
215
|
+
return ["1=2"];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!grid.parents || grid.parents.length <= 0) return filters;
|
|
219
|
+
|
|
220
|
+
for (let uid of grid.parents) {
|
|
221
|
+
let link = grid.graph.linksDict[grid.id + '_' + grid.graph.nodesDict[uid].id];
|
|
222
|
+
|
|
223
|
+
let filter = grid.applyConnection(link);
|
|
224
|
+
if (filter == null || filter === '') continue;
|
|
225
|
+
|
|
226
|
+
let fo = { type: 'graphLink', filter: filter };
|
|
227
|
+
filters.push(fo);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return filters;
|
|
231
|
+
}
|
|
232
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
233
|
+
skipOnWaveVisit() {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
237
|
+
visitByWave(e) {
|
|
238
|
+
const grid = this;
|
|
239
|
+
|
|
240
|
+
return new Promise(function (resolve) {
|
|
241
|
+
if (grid.skipOnWaveVisit(e)) {
|
|
242
|
+
resolve(e);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
grid._waitingRows = true;
|
|
247
|
+
grid.getRows({ filters: grid.collectFilters(), grid: grid }).then(
|
|
248
|
+
rows => {
|
|
249
|
+
grid.rows = rows;
|
|
250
|
+
grid.afterGetRows(e);
|
|
251
|
+
resolve(e);
|
|
252
|
+
grid.refreshState();
|
|
253
|
+
}
|
|
254
|
+
).finally(() => {
|
|
255
|
+
grid._waitingRows = false;
|
|
256
|
+
grid.refreshState();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
261
|
+
//afterGetRows(e) {
|
|
262
|
+
// super.afterGetRows(e);
|
|
263
|
+
|
|
264
|
+
// const grid = this;
|
|
265
|
+
|
|
266
|
+
// if (grid.graph) {
|
|
267
|
+
// grid.graph.visitNodesByWave(e);
|
|
268
|
+
// }
|
|
269
|
+
//}
|
|
270
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
271
|
+
visitByWaveAlt(e) {
|
|
272
|
+
const grid = this;
|
|
273
|
+
|
|
274
|
+
return new Promise(function (resolve) {
|
|
275
|
+
if (grid.skipOnWaveVisit(e)) {
|
|
276
|
+
resolve(e);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
grid.selectedRowIndex = 0;
|
|
281
|
+
|
|
282
|
+
grid._waitingRows = true;
|
|
283
|
+
grid.refreshState();
|
|
284
|
+
|
|
285
|
+
grid.getRows({ filters: grid.collectFilters(), grid: grid }).then(
|
|
286
|
+
rows => {
|
|
287
|
+
grid.rows = rows;
|
|
288
|
+
grid.afterGetRows(e);
|
|
289
|
+
resolve(e);
|
|
290
|
+
grid.refreshState();
|
|
291
|
+
}
|
|
292
|
+
).finally(() => {
|
|
293
|
+
grid._waitingRows = false;
|
|
294
|
+
grid.refreshState();
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
299
|
+
hasVisibleParentGrids() {
|
|
300
|
+
const grid = this;
|
|
301
|
+
if (!grid.graph) return false;
|
|
302
|
+
|
|
303
|
+
for (let puid of grid.parents) {
|
|
304
|
+
let pnode = grid.graph.nodesDict[puid];
|
|
305
|
+
if (pnode.visible !== false && pnode.status === NodeStatus.grid) return true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
311
|
+
}
|