react-graph-grid 0.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.
@@ -0,0 +1,262 @@
1
+ import { useState } from 'react';
2
+ import TestData from '../Tests/TestData';
3
+ import { Overlay } from '../Overlay';
4
+ import { Modal } from '../Modal';
5
+ import { Dropdown } from '../Dropdown';
6
+ import { Grid } from '../Grid';
7
+ import { GridGR } from '../GridGR';
8
+ import { GridDB } from '../GridDB';
9
+ import { GridFL } from '../GridFL';
10
+ //import { GridINU } from '../GridINU';
11
+ //import { GraphComponent } from '../GraphComponent';
12
+
13
+ function DebugApp() {
14
+ const [state, setState] = useState({ menuItem: - 2 });
15
+
16
+ window._logEnabled = true;
17
+
18
+ const GetFamily = function (e) {
19
+ return new Promise(function (resolve, reject) {
20
+
21
+ const rows = new TestData().getFamily(e);
22
+
23
+ if (rows != null) {
24
+ resolve(rows);
25
+ } else {
26
+ reject(Error("Error getting rows"));
27
+ }
28
+ });
29
+ };
30
+
31
+ const GetButtons = function () {
32
+ return [
33
+ {
34
+ id: 1,
35
+ name: 'info',
36
+ title: 'Persone Info',
37
+ label: 'Persone Info',
38
+ click: function (e) {
39
+ const selRow = e.grid.selectedRowIndex >= 0 && e.grid.rows.length > 0 ? e.grid.rows[e.grid.selectedRowIndex] : null;
40
+ if (!selRow) return;
41
+
42
+ alert(`Persone Name = ${selRow.Name}, Persone Birth Day = ${selRow.Date}`);
43
+ },
44
+ getDisabled: function (e) {
45
+ return !e.grid.rows || e.grid.rows.length <= 0;
46
+ }
47
+ },
48
+ {
49
+ id: 2,
50
+ name: 'clear',
51
+ title: 'Clear console',
52
+ label: 'Clear console',
53
+ click: function () {
54
+ console.clear();
55
+ },
56
+ }
57
+ ]
58
+ }
59
+
60
+ const GetCities = function (e) {
61
+ return new Promise(function (resolve, reject) {
62
+
63
+ const rows = new TestData().getCity(e);
64
+
65
+ if (rows != null) {
66
+ resolve(rows);
67
+ } else {
68
+ reject(Error("Error getting rows"));
69
+ }
70
+ });
71
+ };
72
+
73
+ const GetCityColumns = function () {
74
+ return new TestData().GetCityColumns();
75
+ }
76
+
77
+ const GetFamilyColumns = function () {
78
+ return new TestData().GetFamilyColumns();
79
+ }
80
+
81
+ const ResetColumnsOrder = function () {
82
+ const grid = window.gridComponent;
83
+ if (!grid) return;
84
+
85
+ grid.resetColumnsOrderToDefault();
86
+ }
87
+
88
+ const ResetColumnsWidths = function () {
89
+ const grid = window.gridComponent;
90
+ if (!grid) return;
91
+
92
+ grid.resetColumnsWidthsToDefault();
93
+ }
94
+
95
+ const GetPopupItems = function () {
96
+ return new Promise(function (resolve) {
97
+
98
+ const items = [
99
+ { id: 1, text: 'test 1 item' },
100
+ { id: 2, text: 'test 2 item' },
101
+ { id: 3, text: 'test 3 item' },
102
+ { id: 4, text: 'test 4 item' },
103
+ { id: 5, text: 'test 5 item' }
104
+ ];
105
+ resolve(items);
106
+ });
107
+ };
108
+
109
+ const drawGridInModal = function () {
110
+ return (
111
+ <>
112
+ <div className="div-on-menu">
113
+ <button onClick={() => { console.clear() }} className="modal-window-footer-button">Clear console</button>
114
+ </div>
115
+ <Grid getRows={GetFamily}
116
+ init={(grid) => { window.gridComponent = grid }}
117
+ ></Grid>
118
+ </>
119
+ )
120
+ }
121
+
122
+ const drawDropdownInModal = function (wnd) {
123
+ return (
124
+ <>
125
+ <div className="div-on-menu">
126
+ <button onClick={() => { console.clear() }} className="modal-window-footer-button">Clear console</button>
127
+ <button onClick={(e) => { wnd.ddComponent.popup(e); }} className="modal-window-footer-button">Show Dropdown</button>
128
+ </div>
129
+ <div>
130
+ {
131
+ wnd.ddComponent && wnd.ddComponent.clickedItem ? <span>{'Item Clicked : ' + wnd.ddComponent.clickedItem}</span> : <></>
132
+ }
133
+ </div>
134
+ <Dropdown init={(dd) => { wnd.ddComponent = dd; }} getItems={GetPopupItems}
135
+ onItemClick={(e) => { /*console.log('Item clicked: ' + e.itemId); */e.dropdown.clickedItem = e.itemId; wnd.refreshState(); }}
136
+ >
137
+ </Dropdown>
138
+ </>
139
+ )
140
+ }
141
+
142
+ const drawClearConsole = function () {
143
+ return (
144
+ <button onClick={() => { console.clear() }} className="modal-window-footer-button">Clear console</button>
145
+ );
146
+ }
147
+
148
+ const drawTest = function () {
149
+ return (<></>);
150
+ }
151
+
152
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
153
+ const getTestApp = () => {
154
+ console.log('state == ' + state.menuItem);
155
+ switch (state.menuItem) {
156
+ case 0:
157
+ return <></>
158
+ case 1:
159
+ return (
160
+ <>
161
+ <div className="div-on-menu">
162
+ 1. Drag column to reorder
163
+ 2. Doubleclick on divider to autowidth
164
+ </div>
165
+ <div className="div-on-menu">
166
+ <button onClick={() => ResetColumnsOrder()} className="modal-window-footer-button">Reset columns order</button>
167
+ <button onClick={() => ResetColumnsWidths()} className="modal-window-footer-button">Reset columns widths</button>
168
+ {drawClearConsole()}
169
+ </div>
170
+ <Grid getRows={GetFamily} init={(grid) => { window.gridComponent = grid; }}></Grid>
171
+ </>
172
+ )
173
+ case 2:
174
+ return (
175
+ <>
176
+ <div className="div-on-menu">
177
+ {drawClearConsole()}
178
+ </div>
179
+
180
+ <Overlay init={(ovl) => { window.overlayComponent = ovl }} closeWhenEscape={true} closeWhenClick={true}></Overlay>
181
+ </>
182
+ )
183
+ case 3:
184
+ return (
185
+ <>
186
+ <Modal uid="m01" isModal={true} renderContent={() => { return drawGridInModal() }} closeWhenEscape={true}
187
+ pos={{ x: 100, y: 100, w: 600, h: 450 }} title='Modal Grid'></Modal>
188
+ </>
189
+ )
190
+ case 4:
191
+ return (
192
+ <>
193
+ <Modal uid="m02" isModal={true} renderContent={(wnd) => { return drawDropdownInModal(wnd) }} closeWhenEscape={true}
194
+ dimensionsByContent={true}
195
+ pos={{ x: 100, y: 100, w: 300, h: 250 }}></Modal>
196
+ </>
197
+ )
198
+ case 5:
199
+ return (
200
+ <>
201
+ <div className="div-on-menu">
202
+ {drawClearConsole()}
203
+ </div>
204
+ <div className="div-with-grid">
205
+ <GridGR uid="people" getRows={GetFamily}></GridGR>
206
+ </div>
207
+ <div className="div-with-grid">
208
+ <GridGR uid="cities" parentGrids="people" getRows={GetCities} getColumns={GetCityColumns}></GridGR>
209
+ </div>
210
+ </>
211
+ );
212
+ case 6:
213
+ return (
214
+ <>
215
+ <div className="div-with-grid">
216
+ <GridDB getRows={GetFamily} buttons={GetButtons()} getColumns={GetFamilyColumns} multi={true}></GridDB>
217
+ </div>
218
+ </>
219
+ );
220
+ case 7:
221
+ return (
222
+ <>
223
+ <div className="div-with-grid">
224
+ <GridFL getRows={GetFamily} buttons={GetButtons()} getColumns={GetFamilyColumns}></GridFL>
225
+ </div>
226
+ </>
227
+ );
228
+ case 11:
229
+ return (
230
+ <>
231
+ {drawTest()}
232
+ </>
233
+ );
234
+ default:
235
+ return null;
236
+ }
237
+ };
238
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
239
+ return (
240
+ <div >
241
+ <select onChange={(e) => {
242
+ //console.log('this == ' + e);
243
+ setState({ menuItem: e.target.selectedIndex });
244
+ }}>
245
+ <option>0. None</option>
246
+ <option>1. ReactGrid</option>
247
+ <option>2. Overlay</option>
248
+ <option>3. Modal</option>
249
+ <option>4. Dropdown</option>
250
+ <option>5. Two Grids</option>
251
+ <option>6. GridDB</option>
252
+ <option>7. GridFL</option>
253
+ <option>11. TEST</option>
254
+ </select>
255
+ <div className="div-on-menu">
256
+ {getTestApp()}
257
+ </div>
258
+ </div>
259
+ );
260
+ }
261
+
262
+ export default DebugApp;