@iobroker/adapter-react-v5 7.0.2 → 7.1.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/Components/404.d.ts +3 -2
- package/Components/404.js +3 -2
- package/Components/ColorPicker.d.ts +22 -8
- package/Components/ColorPicker.js +34 -17
- package/Components/ComplexCron.js +24 -24
- package/Components/CopyToClipboard.d.ts +10 -1
- package/Components/CopyToClipboard.js +17 -8
- package/Components/CustomModal.d.ts +1 -1
- package/Components/CustomModal.js +8 -8
- package/Components/FileBrowser.d.ts +11 -11
- package/Components/FileBrowser.js +135 -152
- package/Components/FileViewer.js +34 -23
- package/Components/Icon.d.ts +16 -2
- package/Components/Icon.js +19 -8
- package/Components/IconPicker.js +10 -14
- package/Components/IconSelector.d.ts +1 -1
- package/Components/IconSelector.js +64 -74
- package/Components/Image.d.ts +8 -4
- package/Components/Image.js +13 -32
- package/Components/Loader.d.ts +2 -2
- package/Components/Loader.js +21 -18
- package/Components/Loaders/MV.d.ts +6 -1
- package/Components/Loaders/MV.js +23 -7
- package/Components/Loaders/PT.d.ts +7 -2
- package/Components/Loaders/PT.js +20 -7
- package/Components/Loaders/Vendor.d.ts +2 -2
- package/Components/Loaders/Vendor.js +15 -7
- package/Components/Logo.js +16 -18
- package/Components/MDUtils.d.ts +1 -1
- package/Components/MDUtils.js +8 -4
- package/Components/ObjectBrowser.d.ts +40 -39
- package/Components/ObjectBrowser.js +550 -435
- package/Components/Router.d.ts +1 -3
- package/Components/Router.js +3 -1
- package/Components/SaveCloseButtons.d.ts +3 -3
- package/Components/SaveCloseButtons.js +3 -3
- package/Components/Schedule.d.ts +15 -15
- package/Components/Schedule.js +177 -154
- package/Components/SelectWithIcon.d.ts +2 -2
- package/Components/SelectWithIcon.js +45 -34
- package/Components/SimpleCron/index.js +83 -43
- package/Components/TabContainer.js +2 -2
- package/Components/TabContent.js +1 -1
- package/Components/TabHeader.js +1 -1
- package/Components/TableResize.d.ts +2 -2
- package/Components/TableResize.js +5 -5
- package/Components/TextWithIcon.d.ts +1 -1
- package/Components/TextWithIcon.js +10 -8
- package/Components/ToggleThemeMenu.d.ts +2 -2
- package/Components/ToggleThemeMenu.js +3 -3
- package/Components/TreeTable.d.ts +18 -18
- package/Components/TreeTable.js +76 -72
- package/Components/UploadImage.d.ts +2 -2
- package/Components/UploadImage.js +25 -21
- package/Components/Utils.d.ts +42 -22
- package/Components/Utils.js +66 -65
- package/Components/withWidth.d.ts +2 -2
- package/Components/withWidth.js +10 -6
- package/Dialogs/ComplexCron.d.ts +2 -2
- package/Dialogs/ComplexCron.js +3 -3
- package/Dialogs/Confirm.d.ts +4 -4
- package/Dialogs/Confirm.js +18 -8
- package/Dialogs/Cron.d.ts +3 -3
- package/Dialogs/Cron.js +21 -17
- package/Dialogs/Error.d.ts +3 -3
- package/Dialogs/Error.js +6 -4
- package/Dialogs/Message.d.ts +3 -3
- package/Dialogs/Message.js +6 -4
- package/Dialogs/SelectFile.d.ts +4 -4
- package/Dialogs/SelectFile.js +6 -4
- package/Dialogs/SelectID.d.ts +12 -10
- package/Dialogs/SelectID.js +12 -8
- package/Dialogs/SimpleCron.d.ts +2 -2
- package/Dialogs/SimpleCron.js +2 -2
- package/Dialogs/TextInput.d.ts +2 -2
- package/Dialogs/TextInput.js +3 -3
- package/GenericApp.d.ts +19 -13
- package/GenericApp.js +128 -85
- package/LegacyConnection.d.ts +240 -248
- package/LegacyConnection.js +500 -525
- package/README.md +1264 -1171
- package/Theme.d.ts +1 -1
- package/Theme.js +9 -12
- package/assets/devices.json +1 -0
- package/assets/rooms.json +1 -0
- package/craco-module-federation.js +3 -12
- package/i18n/de.json +434 -434
- package/i18n/en.json +434 -434
- package/i18n/es.json +434 -434
- package/i18n/fr.json +434 -434
- package/i18n/it.json +434 -434
- package/i18n/nl.json +434 -434
- package/i18n/pl.json +434 -434
- package/i18n/pt.json +434 -434
- package/i18n/ru.json +434 -434
- package/i18n/uk.json +434 -434
- package/i18n/zh-cn.json +434 -434
- package/i18n.d.ts +26 -19
- package/i18n.js +28 -22
- package/icons/IconAdapter.js +2 -2
- package/icons/IconAlias.js +2 -2
- package/icons/IconChannel.js +2 -2
- package/icons/IconClearFilter.js +2 -2
- package/icons/IconClosed.js +2 -2
- package/icons/IconCopy.js +2 -2
- package/icons/IconDevice.js +2 -2
- package/icons/IconDocument.js +2 -2
- package/icons/IconDocumentReadOnly.js +2 -2
- package/icons/IconExpert.js +2 -2
- package/icons/IconFx.js +2 -2
- package/icons/IconInstance.js +2 -2
- package/icons/IconLogout.js +2 -2
- package/icons/IconNoIcon.js +2 -2
- package/icons/IconOpen.d.ts +2 -2
- package/icons/IconOpen.js +2 -2
- package/icons/IconProps.d.ts +4 -3
- package/icons/IconState.d.ts +2 -2
- package/icons/IconState.js +2 -2
- package/index.css +3 -2
- package/package.json +4 -4
- package/src/Components/404.tsx +32 -31
- package/src/Components/ColorPicker.tsx +142 -114
- package/src/Components/ComplexCron.tsx +174 -137
- package/src/Components/CopyToClipboard.tsx +22 -9
- package/src/Components/CustomModal.tsx +76 -69
- package/src/Components/FileBrowser.tsx +959 -852
- package/src/Components/FileViewer.tsx +146 -127
- package/src/Components/Icon.tsx +80 -52
- package/src/Components/IconPicker.tsx +83 -67
- package/src/Components/IconSelector.tsx +159 -141
- package/src/Components/Image.tsx +43 -26
- package/src/Components/Loader.tsx +56 -32
- package/src/Components/Logo.tsx +62 -52
- package/src/Components/MDUtils.tsx +10 -6
- package/src/Components/ObjectBrowser.tsx +3198 -2478
- package/src/Components/Router.tsx +11 -11
- package/src/Components/SaveCloseButtons.tsx +43 -39
- package/src/Components/Schedule.tsx +1091 -853
- package/src/Components/SelectWithIcon.tsx +135 -93
- package/src/Components/TabContainer.tsx +22 -20
- package/src/Components/TabContent.tsx +13 -12
- package/src/Components/TabHeader.tsx +10 -9
- package/src/Components/TableResize.tsx +52 -37
- package/src/Components/TextWithIcon.tsx +30 -19
- package/src/Components/ToggleThemeMenu.tsx +31 -13
- package/src/Components/TreeTable.tsx +468 -385
- package/src/Components/UploadImage.tsx +153 -121
- package/src/Components/Utils.tsx +135 -127
- package/src/Components/loader.css +40 -31
- package/src/Components/withWidth.tsx +23 -12
- package/src/Connection.tsx +1 -3
- package/src/Dialogs/ComplexCron.tsx +55 -61
- package/src/Dialogs/Confirm.tsx +88 -65
- package/src/Dialogs/Cron.tsx +122 -112
- package/src/Dialogs/Error.tsx +37 -42
- package/src/Dialogs/Message.tsx +39 -37
- package/src/Dialogs/SelectFile.tsx +95 -85
- package/src/Dialogs/SelectID.tsx +141 -129
- package/src/Dialogs/SimpleCron.tsx +44 -44
- package/src/Dialogs/TextInput.tsx +60 -68
- package/src/GenericApp.tsx +342 -242
- package/src/LegacyConnection.tsx +972 -842
- package/src/Prompt.tsx +3 -1
- package/src/Theme.tsx +19 -26
- package/src/icons/IconAdapter.tsx +16 -14
- package/src/icons/IconAlias.tsx +16 -14
- package/src/icons/IconChannel.tsx +55 -16
- package/src/icons/IconClearFilter.tsx +17 -15
- package/src/icons/IconClosed.tsx +16 -11
- package/src/icons/IconCopy.tsx +16 -11
- package/src/icons/IconDevice.tsx +121 -22
- package/src/icons/IconDocument.tsx +16 -11
- package/src/icons/IconDocumentReadOnly.tsx +21 -12
- package/src/icons/IconExpert.tsx +20 -12
- package/src/icons/IconFx.tsx +16 -14
- package/src/icons/IconInstance.tsx +16 -14
- package/src/icons/IconLogout.tsx +20 -18
- package/src/icons/IconNoIcon.tsx +16 -14
- package/src/icons/IconOpen.tsx +17 -12
- package/src/icons/IconProps.tsx +4 -3
- package/src/icons/IconState.tsx +34 -13
- package/src/index.css +3 -2
- package/tasks.js +91 -0
- package/types.d.ts +141 -0
- package/Components/Loaders/PT.css +0 -109
- package/Components/Loaders/Vendor.css +0 -13
- package/Components/loader.css +0 -222
- package/Components/types.d.ts +0 -82
- package/assets/devices/Alarm Systems.svg +0 -19
- package/assets/devices/Amplifier.svg +0 -22
- package/assets/devices/Awnings.svg +0 -5
- package/assets/devices/Battery Status.svg +0 -5
- package/assets/devices/Ceiling Spotlights.svg +0 -16
- package/assets/devices/Chandelier.svg +0 -7
- package/assets/devices/Climate.svg +0 -12
- package/assets/devices/Coffee Makers.svg +0 -6
- package/assets/devices/Cold Water.svg +0 -31
- package/assets/devices/Computer.svg +0 -21
- package/assets/devices/Consumption.svg +0 -8
- package/assets/devices/Curtains.svg +0 -43
- package/assets/devices/Dishwashers.svg +0 -12
- package/assets/devices/Doors.svg +0 -6
- package/assets/devices/Doorstep.svg +0 -35
- package/assets/devices/Dryer.svg +0 -14
- package/assets/devices/Fan.svg +0 -20
- package/assets/devices/Floor Lamps.svg +0 -5
- package/assets/devices/Garage Doors.svg +0 -9
- package/assets/devices/Gates.svg +0 -32
- package/assets/devices/Hairdryer.svg +0 -23
- package/assets/devices/Handle.svg +0 -6
- package/assets/devices/Hanging Lamps.svg +0 -9
- package/assets/devices/Heater.svg +0 -44
- package/assets/devices/Hoods.svg +0 -12
- package/assets/devices/Hot Water.svg +0 -10
- package/assets/devices/Humidity.svg +0 -41
- package/assets/devices/Iron.svg +0 -5
- package/assets/devices/Irrigation.svg +0 -23
- package/assets/devices/Led Strip.svg +0 -31
- package/assets/devices/Light.svg +0 -30
- package/assets/devices/Lightings.svg +0 -46
- package/assets/devices/Lock.svg +0 -19
- package/assets/devices/Louvre.svg +0 -7
- package/assets/devices/Mowing Machine.svg +0 -9
- package/assets/devices/Music.svg +0 -13
- package/assets/devices/Outdoor Blinds.svg +0 -7
- package/assets/devices/People.svg +0 -19
- package/assets/devices/Pool.svg +0 -8
- package/assets/devices/Power Consumption.svg +0 -13
- package/assets/devices/Printer.svg +0 -10
- package/assets/devices/Pump.svg +0 -10
- package/assets/devices/Receiver.svg +0 -19
- package/assets/devices/Sconces.svg +0 -10
- package/assets/devices/Security.svg +0 -34
- package/assets/devices/Shading.svg +0 -5
- package/assets/devices/Shutters.svg +0 -11
- package/assets/devices/SmokeDetector.svg +0 -13
- package/assets/devices/Sockets.svg +0 -13
- package/assets/devices/Speaker.svg +0 -35
- package/assets/devices/Stove.svg +0 -12
- package/assets/devices/Table Lamps.svg +0 -12
- package/assets/devices/Temperature Sensors.svg +0 -28
- package/assets/devices/Tv.svg +0 -8
- package/assets/devices/Vacuum Cleaner.svg +0 -16
- package/assets/devices/Ventilation.svg +0 -12
- package/assets/devices/Washing Machines.svg +0 -16
- package/assets/devices/Water Consumption.svg +0 -6
- package/assets/devices/Water Heater.svg +0 -8
- package/assets/devices/Water.svg +0 -40
- package/assets/devices/Weather.svg +0 -28
- package/assets/devices/Window.svg +0 -8
- package/assets/rooms/Anteroom.svg +0 -53
- package/assets/rooms/Attic.svg +0 -21
- package/assets/rooms/Balcony.svg +0 -13
- package/assets/rooms/Barn.svg +0 -6
- package/assets/rooms/Basement.svg +0 -5
- package/assets/rooms/Bathroom.svg +0 -38
- package/assets/rooms/Bedroom.svg +0 -5
- package/assets/rooms/Boiler Room.svg +0 -13
- package/assets/rooms/Carport.svg +0 -17
- package/assets/rooms/Cellar.svg +0 -89
- package/assets/rooms/Chamber.svg +0 -9
- package/assets/rooms/Corridor.svg +0 -53
- package/assets/rooms/Dining Area.svg +0 -37
- package/assets/rooms/Dining Room.svg +0 -37
- package/assets/rooms/Dining.svg +0 -37
- package/assets/rooms/Dressing Room.svg +0 -5
- package/assets/rooms/Driveway.svg +0 -15
- package/assets/rooms/Entrance.svg +0 -44
- package/assets/rooms/Equipment Room.svg +0 -15
- package/assets/rooms/Front Yard.svg +0 -64
- package/assets/rooms/Gallery.svg +0 -14
- package/assets/rooms/Garage.svg +0 -20
- package/assets/rooms/Garden.svg +0 -13
- package/assets/rooms/Ground Floor.svg +0 -95
- package/assets/rooms/Guest Bathroom.svg +0 -33
- package/assets/rooms/Guest Room.svg +0 -5
- package/assets/rooms/Gym.svg +0 -5
- package/assets/rooms/Hall.svg +0 -19
- package/assets/rooms/Home Theater.svg +0 -8
- package/assets/rooms/Kitchen.svg +0 -18
- package/assets/rooms/Laundry Room.svg +0 -12
- package/assets/rooms/Living Area.svg +0 -11
- package/assets/rooms/Living Room.svg +0 -10
- package/assets/rooms/Locker Room.svg +0 -17
- package/assets/rooms/Nursery.svg +0 -5
- package/assets/rooms/Office.svg +0 -8
- package/assets/rooms/Outdoors.svg +0 -7
- package/assets/rooms/Playroom.svg +0 -6
- package/assets/rooms/Pool.svg +0 -8
- package/assets/rooms/Rear Wall.svg +0 -30
- package/assets/rooms/Second Floor.svg +0 -95
- package/assets/rooms/Shed.svg +0 -16
- package/assets/rooms/Sleeping Area.svg +0 -22
- package/assets/rooms/Stairway.svg +0 -5
- package/assets/rooms/Stairwell.svg +0 -15
- package/assets/rooms/Storeroom.svg +0 -5
- package/assets/rooms/Summer House.svg +0 -27
- package/assets/rooms/Swimming Pool.svg +0 -21
- package/assets/rooms/Terrace.svg +0 -7
- package/assets/rooms/Toilet.svg +0 -10
- package/assets/rooms/Upstairs.svg +0 -6
- package/assets/rooms/Wardrobe.svg +0 -60
- package/assets/rooms/Washroom.svg +0 -20
- package/assets/rooms/Wc.svg +0 -10
- package/assets/rooms/Windscreen.svg +0 -60
- package/assets/rooms/Workshop.svg +0 -23
- package/assets/rooms/Workspace.svg +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { Component, type JSX } from 'react';
|
|
2
2
|
|
|
3
3
|
import { HexColorPicker as ColorPicker } from 'react-colorful';
|
|
4
4
|
|
|
@@ -34,13 +34,9 @@ import type Connection from '../Connection';
|
|
|
34
34
|
|
|
35
35
|
import DialogSelectID from '../Dialogs/SelectID';
|
|
36
36
|
import Utils from './Utils';
|
|
37
|
-
import { IobTheme } from '../types';
|
|
37
|
+
import type { IobTheme } from '../types';
|
|
38
38
|
|
|
39
|
-
function getAttr(
|
|
40
|
-
obj: Record<string, any>,
|
|
41
|
-
attr: string | string[],
|
|
42
|
-
lookup?: Record<string, string>,
|
|
43
|
-
): any {
|
|
39
|
+
function getAttr(obj: Record<string, any>, attr: string | string[], lookup?: Record<string, string>): any {
|
|
44
40
|
if (typeof attr === 'string') {
|
|
45
41
|
attr = attr.split('.');
|
|
46
42
|
}
|
|
@@ -60,17 +56,13 @@ function getAttr(
|
|
|
60
56
|
return getAttr(obj[name], attr);
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
function setAttr(
|
|
64
|
-
obj: Record<string, any>,
|
|
65
|
-
attr: string | string[],
|
|
66
|
-
value: any,
|
|
67
|
-
): void {
|
|
59
|
+
function setAttr(obj: Record<string, any>, attr: string | string[], value: any): void {
|
|
68
60
|
if (typeof attr === 'string') {
|
|
69
61
|
attr = attr.split('.');
|
|
70
62
|
}
|
|
71
63
|
|
|
72
64
|
if (attr.length === 1) {
|
|
73
|
-
return obj[attr[0]] = value;
|
|
65
|
+
return (obj[attr[0]] = value);
|
|
74
66
|
}
|
|
75
67
|
const name: string = attr.shift() as string;
|
|
76
68
|
if (obj[name] === null || obj[name] === undefined) {
|
|
@@ -96,12 +88,8 @@ const styles: Record<string, any> = {
|
|
|
96
88
|
paddingLeft: 4,
|
|
97
89
|
paddingRight: 4,
|
|
98
90
|
},
|
|
99
|
-
rowMainWithChildren: {
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
rowMainWithoutChildren: {
|
|
103
|
-
|
|
104
|
-
},
|
|
91
|
+
rowMainWithChildren: {},
|
|
92
|
+
rowMainWithoutChildren: {},
|
|
105
93
|
rowNoEdit: {
|
|
106
94
|
opacity: 0.3,
|
|
107
95
|
},
|
|
@@ -210,8 +198,7 @@ function stableSort(
|
|
|
210
198
|
array: Record<string, any>[],
|
|
211
199
|
comparator: (a: Record<string, any>, b: Record<string, any>) => number,
|
|
212
200
|
): Record<string, any>[] {
|
|
213
|
-
const stabilizedThis: { e: Record<string, any>; i: number }[] =
|
|
214
|
-
array.map((el, index) => ({ e: el, i: index }));
|
|
201
|
+
const stabilizedThis: { e: Record<string, any>; i: number }[] = array.map((el, index) => ({ e: el, i: index }));
|
|
215
202
|
|
|
216
203
|
stabilizedThis.sort((a, b) => {
|
|
217
204
|
const order = comparator(a.e, b.e);
|
|
@@ -282,10 +269,11 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
282
269
|
constructor(props: TreeTableProps) {
|
|
283
270
|
super(props);
|
|
284
271
|
|
|
285
|
-
let opened =
|
|
272
|
+
let opened =
|
|
273
|
+
((window as any)._localStorage || window.localStorage).getItem(this.props.name || 'iob-table') || '[]';
|
|
286
274
|
try {
|
|
287
275
|
opened = JSON.parse(opened) || [];
|
|
288
|
-
} catch
|
|
276
|
+
} catch {
|
|
289
277
|
opened = [];
|
|
290
278
|
}
|
|
291
279
|
if (!Array.isArray(opened)) {
|
|
@@ -331,10 +319,7 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
331
319
|
return { data: props.data };
|
|
332
320
|
}
|
|
333
321
|
|
|
334
|
-
renderCellEdit(
|
|
335
|
-
item: Record<string, any>,
|
|
336
|
-
col: Column,
|
|
337
|
-
) {
|
|
322
|
+
renderCellEdit(item: Record<string, any>, col: Column): JSX.Element | null {
|
|
338
323
|
let val = getAttr(item, col.field);
|
|
339
324
|
if (Array.isArray(val)) {
|
|
340
325
|
val = val[0];
|
|
@@ -342,7 +327,8 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
342
327
|
|
|
343
328
|
if (col.lookup) {
|
|
344
329
|
return this.renderCellEditSelect(col, val);
|
|
345
|
-
}
|
|
330
|
+
}
|
|
331
|
+
if (col.editComponent) {
|
|
346
332
|
return this.renderCellEditCustom(col, val, item);
|
|
347
333
|
}
|
|
348
334
|
if (col.type === 'boolean' || (!col.type && typeof val === 'boolean')) {
|
|
@@ -361,7 +347,7 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
361
347
|
return this.renderCellEditString(col, val);
|
|
362
348
|
}
|
|
363
349
|
|
|
364
|
-
onChange(col: Column, oldValue: string | number | boolean, newValue: string | number | boolean) {
|
|
350
|
+
onChange(col: Column, oldValue: string | number | boolean, newValue: string | number | boolean): void {
|
|
365
351
|
const editData = this.state.editData ? { ...this.state.editData } : {};
|
|
366
352
|
if (newValue === oldValue) {
|
|
367
353
|
delete editData[col.field];
|
|
@@ -371,52 +357,60 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
371
357
|
this.setState({ editData });
|
|
372
358
|
}
|
|
373
359
|
|
|
374
|
-
renderCellEditSelect(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
360
|
+
renderCellEditSelect(col: Column, val: string | number): JSX.Element {
|
|
361
|
+
return (
|
|
362
|
+
<Select
|
|
363
|
+
variant="standard"
|
|
364
|
+
onChange={e => this.onChange(col, val, e.target.value)}
|
|
365
|
+
value={(this.state.editData && this.state.editData[col.field]) || val}
|
|
366
|
+
>
|
|
367
|
+
{col.lookup &&
|
|
368
|
+
Object.keys(col.lookup).map((v, i) => (
|
|
369
|
+
<MenuItem
|
|
370
|
+
key={i}
|
|
371
|
+
value={v}
|
|
372
|
+
>
|
|
373
|
+
{col.lookup?.[v]}
|
|
374
|
+
</MenuItem>
|
|
375
|
+
))}
|
|
376
|
+
</Select>
|
|
377
|
+
);
|
|
386
378
|
}
|
|
387
379
|
|
|
388
|
-
renderCellEditString(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
380
|
+
renderCellEditString(col: Column, val: string): JSX.Element {
|
|
381
|
+
return (
|
|
382
|
+
<TextField
|
|
383
|
+
variant="standard"
|
|
384
|
+
style={styles.fieldEdit}
|
|
385
|
+
fullWidth
|
|
386
|
+
value={
|
|
387
|
+
this.state.editData && this.state.editData[col.field] !== undefined
|
|
388
|
+
? this.state.editData[col.field]
|
|
389
|
+
: val
|
|
390
|
+
}
|
|
391
|
+
onChange={e => this.onChange(col, val, e.target.value)}
|
|
392
|
+
/>
|
|
393
|
+
);
|
|
399
394
|
}
|
|
400
395
|
|
|
401
|
-
renderCellEditNumber(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
396
|
+
renderCellEditNumber(col: Column, val: number): JSX.Element {
|
|
397
|
+
return (
|
|
398
|
+
<TextField
|
|
399
|
+
variant="standard"
|
|
400
|
+
style={styles.fieldEdit}
|
|
401
|
+
type="number"
|
|
402
|
+
fullWidth
|
|
403
|
+
value={
|
|
404
|
+
this.state.editData && this.state.editData[col.field] !== undefined
|
|
405
|
+
? this.state.editData[col.field]
|
|
406
|
+
: val
|
|
407
|
+
}
|
|
408
|
+
onChange={e => this.onChange(col, val, e.target.value)}
|
|
409
|
+
/>
|
|
410
|
+
);
|
|
413
411
|
}
|
|
414
412
|
|
|
415
|
-
renderCellEditCustom(
|
|
416
|
-
col: Column,
|
|
417
|
-
val: any,
|
|
418
|
-
item: Record<string, any>,
|
|
419
|
-
) {
|
|
413
|
+
renderCellEditCustom(col: Column, val: any, item: Record<string, any>): JSX.Element | null {
|
|
420
414
|
const EditComponent = col.editComponent;
|
|
421
415
|
|
|
422
416
|
// use new value if exists
|
|
@@ -426,186 +420,194 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
426
420
|
item[col.field] = val;
|
|
427
421
|
}
|
|
428
422
|
|
|
429
|
-
return EditComponent ?
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
renderCellEditBoolean(
|
|
437
|
-
col: Column,
|
|
438
|
-
val: boolean,
|
|
439
|
-
) {
|
|
440
|
-
return <Checkbox
|
|
441
|
-
checked={this.state.editData && this.state.editData[col.field] !== undefined ? !!this.state.editData[col.field] : !!val}
|
|
442
|
-
onChange={e => this.onChange(col, !!val, e.target.checked)}
|
|
443
|
-
inputProps={{ 'aria-label': 'checkbox' }}
|
|
444
|
-
/>;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
renderSelectColorDialog() {
|
|
448
|
-
return <Dialog
|
|
449
|
-
sx={{
|
|
450
|
-
'& .MuiPaper-root': styles.root,
|
|
451
|
-
'& .MuiPaper-paper': styles.paper,
|
|
452
|
-
}}
|
|
453
|
-
onClose={() => {
|
|
454
|
-
this.selectCallback = null;
|
|
455
|
-
this.setState({ showSelectColor: false });
|
|
456
|
-
}}
|
|
457
|
-
open={this.state.showSelectColor}
|
|
458
|
-
>
|
|
459
|
-
<ColorPicker
|
|
460
|
-
color={this.state.selectIdValue as string}
|
|
461
|
-
onChange={color =>
|
|
462
|
-
this.setState({ selectIdValue: color }, () =>
|
|
463
|
-
this.selectCallback && this.selectCallback(color))}
|
|
423
|
+
return EditComponent ? (
|
|
424
|
+
<EditComponent
|
|
425
|
+
value={val}
|
|
426
|
+
rowData={item}
|
|
427
|
+
onChange={(newVal: any) => this.onChange(col, val, newVal as string | number)}
|
|
464
428
|
/>
|
|
465
|
-
|
|
429
|
+
) : null;
|
|
466
430
|
}
|
|
467
431
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
value={_val}
|
|
479
|
-
inputProps={{ style: { backgroundColor: _val, color: Utils.isUseBright(_val) ? '#FFF' : '#000' } }}
|
|
480
|
-
onChange={e => this.onChange(col, !!val, e.target.value)}
|
|
432
|
+
renderCellEditBoolean(col: Column, val: boolean): JSX.Element {
|
|
433
|
+
return (
|
|
434
|
+
<Checkbox
|
|
435
|
+
checked={
|
|
436
|
+
this.state.editData && this.state.editData[col.field] !== undefined
|
|
437
|
+
? !!this.state.editData[col.field]
|
|
438
|
+
: !!val
|
|
439
|
+
}
|
|
440
|
+
onChange={e => this.onChange(col, !!val, e.target.checked)}
|
|
441
|
+
inputProps={{ 'aria-label': 'checkbox' }}
|
|
481
442
|
/>
|
|
443
|
+
);
|
|
444
|
+
}
|
|
482
445
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
446
|
+
renderSelectColorDialog(): JSX.Element {
|
|
447
|
+
return (
|
|
448
|
+
<Dialog
|
|
449
|
+
sx={{
|
|
450
|
+
'& .MuiPaper-root': styles.root,
|
|
451
|
+
'& .MuiPaper-paper': styles.paper,
|
|
452
|
+
}}
|
|
453
|
+
onClose={() => {
|
|
454
|
+
this.selectCallback = null;
|
|
455
|
+
this.setState({ showSelectColor: false });
|
|
488
456
|
}}
|
|
489
|
-
|
|
457
|
+
open={this.state.showSelectColor}
|
|
490
458
|
>
|
|
491
|
-
<
|
|
492
|
-
|
|
493
|
-
|
|
459
|
+
<ColorPicker
|
|
460
|
+
color={this.state.selectIdValue as string}
|
|
461
|
+
onChange={color =>
|
|
462
|
+
this.setState({ selectIdValue: color }, () => this.selectCallback && this.selectCallback(color))
|
|
463
|
+
}
|
|
464
|
+
/>
|
|
465
|
+
</Dialog>
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
renderCellEditColor(col: Column, val: string): JSX.Element {
|
|
470
|
+
const _val =
|
|
471
|
+
this.state.editData && this.state.editData[col.field] !== undefined ? this.state.editData[col.field] : val;
|
|
472
|
+
return (
|
|
473
|
+
<div style={styles.fieldEdit}>
|
|
474
|
+
<TextField
|
|
475
|
+
variant="standard"
|
|
476
|
+
fullWidth
|
|
477
|
+
style={styles.fieldEditWithButton}
|
|
478
|
+
value={_val}
|
|
479
|
+
inputProps={{ style: { backgroundColor: _val, color: Utils.isUseBright(_val) ? '#FFF' : '#000' } }}
|
|
480
|
+
onChange={e => this.onChange(col, !!val, e.target.value)}
|
|
481
|
+
/>
|
|
482
|
+
|
|
483
|
+
<IconButton
|
|
484
|
+
style={styles.fieldButton}
|
|
485
|
+
onClick={() => {
|
|
486
|
+
this.selectCallback = newColor => this.onChange(col, val, newColor);
|
|
487
|
+
this.setState({ showSelectColor: true, selectIdValue: val });
|
|
488
|
+
}}
|
|
489
|
+
size="large"
|
|
490
|
+
>
|
|
491
|
+
<IconColor />
|
|
492
|
+
</IconButton>
|
|
493
|
+
</div>
|
|
494
|
+
);
|
|
494
495
|
}
|
|
495
496
|
|
|
496
|
-
renderSelectIdDialog() {
|
|
497
|
+
renderSelectIdDialog(): JSX.Element | null {
|
|
497
498
|
if (this.state.showSelectId && this.props.socket) {
|
|
498
|
-
return
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
499
|
+
return (
|
|
500
|
+
<DialogSelectID
|
|
501
|
+
key="tableSelect"
|
|
502
|
+
imagePrefix="../.."
|
|
503
|
+
dialogName={this.props.adapterName}
|
|
504
|
+
themeType={this.props.themeType}
|
|
505
|
+
theme={this.props.theme}
|
|
506
|
+
socket={this.props.socket}
|
|
507
|
+
selected={this.state.selectIdValue as string}
|
|
508
|
+
onClose={() => this.setState({ showSelectId: false })}
|
|
509
|
+
onOk={(selected /* , name */) => {
|
|
510
|
+
this.setState({ showSelectId: false, selectIdValue: null });
|
|
511
|
+
this.selectCallback && this.selectCallback(selected as string);
|
|
512
|
+
this.selectCallback = null;
|
|
513
|
+
}}
|
|
514
|
+
/>
|
|
515
|
+
);
|
|
513
516
|
}
|
|
514
517
|
|
|
515
518
|
return null;
|
|
516
519
|
}
|
|
517
520
|
|
|
518
|
-
renderCellEditObjectID(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
521
|
+
renderCellEditObjectID(col: Column, val: string): JSX.Element {
|
|
522
|
+
return (
|
|
523
|
+
<div style={styles.fieldEdit}>
|
|
524
|
+
<TextField
|
|
525
|
+
variant="standard"
|
|
526
|
+
fullWidth
|
|
527
|
+
style={styles.fieldEditWithButton}
|
|
528
|
+
value={
|
|
529
|
+
this.state.editData && this.state.editData[col.field] !== undefined
|
|
530
|
+
? this.state.editData[col.field]
|
|
531
|
+
: val
|
|
532
|
+
}
|
|
533
|
+
onChange={e => this.onChange(col, val, e.target.value)}
|
|
534
|
+
/>
|
|
530
535
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
536
|
+
<IconButton
|
|
537
|
+
style={styles.fieldButton}
|
|
538
|
+
onClick={() => {
|
|
539
|
+
this.selectCallback = selected => this.onChange(col, val, selected);
|
|
540
|
+
this.setState({ showSelectId: true, selectIdValue: val });
|
|
541
|
+
}}
|
|
542
|
+
size="large"
|
|
543
|
+
>
|
|
544
|
+
<IconList />
|
|
545
|
+
</IconButton>
|
|
546
|
+
</div>
|
|
547
|
+
);
|
|
542
548
|
}
|
|
543
549
|
|
|
544
|
-
static renderCellNonEdit(
|
|
545
|
-
item: Record<string, any>,
|
|
546
|
-
col: Column,
|
|
547
|
-
) {
|
|
550
|
+
static renderCellNonEdit(item: Record<string, any>, col: Column): JSX.Element | string | number | null {
|
|
548
551
|
let val = getAttr(item, col.field, col.lookup);
|
|
549
552
|
if (Array.isArray(val)) {
|
|
550
553
|
val = val[0];
|
|
551
554
|
}
|
|
552
555
|
|
|
553
556
|
if (col.type === 'boolean') {
|
|
554
|
-
return
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
557
|
+
return (
|
|
558
|
+
<Checkbox
|
|
559
|
+
checked={!!val}
|
|
560
|
+
disabled
|
|
561
|
+
inputProps={{ 'aria-label': 'checkbox' }}
|
|
562
|
+
/>
|
|
563
|
+
);
|
|
559
564
|
}
|
|
560
565
|
|
|
561
566
|
return val;
|
|
562
567
|
}
|
|
563
568
|
|
|
564
|
-
renderCell(
|
|
565
|
-
item: Record<string, any>,
|
|
566
|
-
col: Column,
|
|
567
|
-
level: number,
|
|
568
|
-
i: number,
|
|
569
|
-
) {
|
|
569
|
+
renderCell(item: Record<string, any>, col: Column, level: number, i: number): JSX.Element {
|
|
570
570
|
if (this.state.editMode === i && col.editable !== 'never' && col.editable !== false) {
|
|
571
|
-
return
|
|
571
|
+
return (
|
|
572
|
+
<TableCell
|
|
573
|
+
key={col.field}
|
|
574
|
+
style={{ ...styles.cell, ...(level ? styles.cellSecondary : undefined), ...col.cellStyle }}
|
|
575
|
+
component="th"
|
|
576
|
+
>
|
|
577
|
+
{this.renderCellEdit(item, col)}
|
|
578
|
+
</TableCell>
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
return (
|
|
582
|
+
<TableCell
|
|
572
583
|
key={col.field}
|
|
573
584
|
style={{ ...styles.cell, ...(level ? styles.cellSecondary : undefined), ...col.cellStyle }}
|
|
574
585
|
component="th"
|
|
575
586
|
>
|
|
576
|
-
{
|
|
577
|
-
</TableCell
|
|
578
|
-
|
|
579
|
-
return <TableCell
|
|
580
|
-
key={col.field}
|
|
581
|
-
style={{ ...styles.cell, ...(level ? styles.cellSecondary : undefined), ...col.cellStyle }}
|
|
582
|
-
component="th"
|
|
583
|
-
>
|
|
584
|
-
{TreeTable.renderCellNonEdit(item, col)}
|
|
585
|
-
</TableCell>;
|
|
587
|
+
{TreeTable.renderCellNonEdit(item, col)}
|
|
588
|
+
</TableCell>
|
|
589
|
+
);
|
|
586
590
|
}
|
|
587
591
|
|
|
588
|
-
static renderCellWithSubField(
|
|
589
|
-
item: Record<string, any>,
|
|
590
|
-
col: Column,
|
|
591
|
-
) {
|
|
592
|
+
static renderCellWithSubField(item: Record<string, any>, col: Column): JSX.Element {
|
|
592
593
|
const main = getAttr(item, col.field, col.lookup);
|
|
593
594
|
if (col.subField) {
|
|
594
|
-
const sub
|
|
595
|
-
return
|
|
596
|
-
<div
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
const sub = getAttr(item, col.subField, col.subLookup);
|
|
596
|
+
return (
|
|
597
|
+
<div>
|
|
598
|
+
<div style={styles.mainText}>{main}</div>
|
|
599
|
+
<div style={{ ...styles.subText, ...(col.subStyle || undefined) }}>{sub}</div>
|
|
600
|
+
</div>
|
|
601
|
+
);
|
|
599
602
|
}
|
|
600
|
-
return
|
|
601
|
-
<div
|
|
602
|
-
|
|
603
|
+
return (
|
|
604
|
+
<div>
|
|
605
|
+
<div style={styles.mainText}>{main}</div>
|
|
606
|
+
</div>
|
|
607
|
+
);
|
|
603
608
|
}
|
|
604
609
|
|
|
605
|
-
renderLine(
|
|
606
|
-
item: Record<string, any>,
|
|
607
|
-
level?: number,
|
|
608
|
-
): React.JSX.Element | React.JSX.Element[] | null {
|
|
610
|
+
renderLine(item: Record<string, any>, level?: number): JSX.Element | JSX.Element[] | null {
|
|
609
611
|
const levelShift = this.props.levelShift === undefined ? 24 : this.props.levelShift;
|
|
610
612
|
|
|
611
613
|
level = level || 0;
|
|
@@ -623,196 +625,269 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
623
625
|
const opened = this.state.opened.includes(item.id);
|
|
624
626
|
const children = this.props.data.filter(it => it.parentId === item.id);
|
|
625
627
|
|
|
626
|
-
const row =
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
...((this.state.update && this.state.update.includes(item.id) && styles.glow) || undefined),
|
|
631
|
-
...styles.row,
|
|
632
|
-
...(level ? styles.rowSecondary : undefined),
|
|
633
|
-
...(!level && children.length ? styles.rowMainWithChildren : undefined),
|
|
634
|
-
...(!level && !children.length ? styles.rowMainWithoutChildren : undefined),
|
|
635
|
-
...(this.state.editMode !== false && this.state.editMode !== i ? styles.rowNoEdit : undefined),
|
|
636
|
-
...(this.state.deleteMode !== false && this.state.deleteMode !== i ? styles.rowNoEdit : undefined),
|
|
637
|
-
}}
|
|
638
|
-
>
|
|
639
|
-
<TableCell
|
|
640
|
-
style={{ ...styles.cell, ...styles.cellExpand, ...(level ? styles.cellSecondary : undefined) }}
|
|
641
|
-
>
|
|
642
|
-
{children.length ? <IconButton
|
|
643
|
-
onClick={() => {
|
|
644
|
-
const _opened = [...this.state.opened];
|
|
645
|
-
const pos = _opened.indexOf(item.id);
|
|
646
|
-
if (pos === -1) {
|
|
647
|
-
_opened.push(item.id);
|
|
648
|
-
_opened.sort();
|
|
649
|
-
} else {
|
|
650
|
-
_opened.splice(pos, 1);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
((window as any)._localStorage || window.localStorage).setItem(this.props.name || 'iob-table', JSON.stringify(_opened));
|
|
654
|
-
|
|
655
|
-
this.setState({ opened: _opened });
|
|
656
|
-
}}
|
|
657
|
-
size="small"
|
|
658
|
-
>
|
|
659
|
-
{opened ? <IconCollapse /> : <IconExpand />}
|
|
660
|
-
</IconButton> : null}
|
|
661
|
-
</TableCell>
|
|
662
|
-
<TableCell
|
|
663
|
-
scope="row"
|
|
628
|
+
const row = (
|
|
629
|
+
<TableRow
|
|
630
|
+
key={item.id}
|
|
631
|
+
className={`table-row-${(item.id || '').toString().replace(/[.$]/g, '_')}`}
|
|
664
632
|
style={{
|
|
665
|
-
...styles.
|
|
666
|
-
...
|
|
667
|
-
...
|
|
668
|
-
|
|
633
|
+
...((this.state.update && this.state.update.includes(item.id) && styles.glow) || undefined),
|
|
634
|
+
...styles.row,
|
|
635
|
+
...(level ? styles.rowSecondary : undefined),
|
|
636
|
+
...(!level && children.length ? styles.rowMainWithChildren : undefined),
|
|
637
|
+
...(!level && !children.length ? styles.rowMainWithoutChildren : undefined),
|
|
638
|
+
...(this.state.editMode !== false && this.state.editMode !== i ? styles.rowNoEdit : undefined),
|
|
639
|
+
...(this.state.deleteMode !== false && this.state.deleteMode !== i ? styles.rowNoEdit : undefined),
|
|
669
640
|
}}
|
|
670
641
|
>
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
</TableCell>
|
|
676
|
-
|
|
677
|
-
{this.props.columns.map((col, ii) =>
|
|
678
|
-
(!ii && !col.hidden ? null : this.renderCell(item, col, level, i)))}
|
|
679
|
-
|
|
680
|
-
{this.props.onUpdate ? <TableCell style={{ ...styles.cell, ...styles.cellButton }}>
|
|
681
|
-
{this.state.editMode === i || this.state.deleteMode === i ?
|
|
682
|
-
<IconButton
|
|
683
|
-
disabled={this.state.editMode !== false && (!this.state.editData || !Object.keys(this.state.editData).length)}
|
|
684
|
-
onClick={() => {
|
|
685
|
-
if (this.state.editMode !== false) {
|
|
686
|
-
const newData = JSON.parse(JSON.stringify(item));
|
|
687
|
-
this.state.editData && Object.keys(this.state.editData).forEach(attr =>
|
|
688
|
-
setAttr(newData, attr, this.state.editData?.[attr]));
|
|
689
|
-
this.setState({ editMode: false }, () => this.props.onUpdate && this.props.onUpdate(newData, item));
|
|
690
|
-
} else {
|
|
691
|
-
this.setState({ deleteMode: false }, () => this.props.onDelete && this.props.onDelete(item));
|
|
692
|
-
}
|
|
693
|
-
}}
|
|
694
|
-
size="large"
|
|
695
|
-
>
|
|
696
|
-
<IconCheck />
|
|
697
|
-
</IconButton>
|
|
698
|
-
:
|
|
699
|
-
<IconButton
|
|
700
|
-
disabled={this.state.editMode !== false}
|
|
701
|
-
onClick={() => this.setState({ editMode: i, editData: null })}
|
|
702
|
-
size="large"
|
|
703
|
-
>
|
|
704
|
-
<IconEdit />
|
|
705
|
-
</IconButton>}
|
|
706
|
-
</TableCell> : null}
|
|
707
|
-
|
|
708
|
-
{this.props.onDelete && !this.props.onUpdate ?
|
|
709
|
-
<TableCell style={{ ...styles.cell, ...styles.cellButton }}>
|
|
710
|
-
{this.state.deleteMode === i ?
|
|
642
|
+
<TableCell
|
|
643
|
+
style={{ ...styles.cell, ...styles.cellExpand, ...(level ? styles.cellSecondary : undefined) }}
|
|
644
|
+
>
|
|
645
|
+
{children.length ? (
|
|
711
646
|
<IconButton
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
647
|
+
onClick={() => {
|
|
648
|
+
const _opened = [...this.state.opened];
|
|
649
|
+
const pos = _opened.indexOf(item.id);
|
|
650
|
+
if (pos === -1) {
|
|
651
|
+
_opened.push(item.id);
|
|
652
|
+
_opened.sort();
|
|
653
|
+
} else {
|
|
654
|
+
_opened.splice(pos, 1);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
((window as any)._localStorage || window.localStorage).setItem(
|
|
658
|
+
this.props.name || 'iob-table',
|
|
659
|
+
JSON.stringify(_opened),
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
this.setState({ opened: _opened });
|
|
663
|
+
}}
|
|
664
|
+
size="small"
|
|
715
665
|
>
|
|
716
|
-
<
|
|
666
|
+
{opened ? <IconCollapse /> : <IconExpand />}
|
|
717
667
|
</IconButton>
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
668
|
+
) : null}
|
|
669
|
+
</TableCell>
|
|
670
|
+
<TableCell
|
|
671
|
+
scope="row"
|
|
672
|
+
style={{
|
|
673
|
+
...styles.cell,
|
|
674
|
+
...(level ? styles.cellSecondary : undefined),
|
|
675
|
+
...this.props.columns[0].cellStyle,
|
|
676
|
+
paddingLeft: levelShift * level,
|
|
677
|
+
}}
|
|
678
|
+
>
|
|
679
|
+
{this.props.columns[0].subField
|
|
680
|
+
? TreeTable.renderCellWithSubField(item, this.props.columns[0])
|
|
681
|
+
: getAttr(item, this.props.columns[0].field, this.props.columns[0].lookup)}
|
|
682
|
+
</TableCell>
|
|
683
|
+
|
|
684
|
+
{this.props.columns.map((col, ii) =>
|
|
685
|
+
!ii && !col.hidden ? null : this.renderCell(item, col, level, i),
|
|
686
|
+
)}
|
|
687
|
+
|
|
688
|
+
{this.props.onUpdate ? (
|
|
689
|
+
<TableCell style={{ ...styles.cell, ...styles.cellButton }}>
|
|
690
|
+
{this.state.editMode === i || this.state.deleteMode === i ? (
|
|
691
|
+
<IconButton
|
|
692
|
+
disabled={
|
|
693
|
+
this.state.editMode !== false &&
|
|
694
|
+
(!this.state.editData || !Object.keys(this.state.editData).length)
|
|
695
|
+
}
|
|
696
|
+
onClick={() => {
|
|
697
|
+
if (this.state.editMode !== false) {
|
|
698
|
+
const newData = JSON.parse(JSON.stringify(item));
|
|
699
|
+
this.state.editData &&
|
|
700
|
+
Object.keys(this.state.editData).forEach(attr =>
|
|
701
|
+
setAttr(newData, attr, this.state.editData?.[attr]),
|
|
702
|
+
);
|
|
703
|
+
this.setState(
|
|
704
|
+
{ editMode: false },
|
|
705
|
+
() => this.props.onUpdate && this.props.onUpdate(newData, item),
|
|
706
|
+
);
|
|
707
|
+
} else {
|
|
708
|
+
this.setState(
|
|
709
|
+
{ deleteMode: false },
|
|
710
|
+
() => this.props.onDelete && this.props.onDelete(item),
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
}}
|
|
714
|
+
size="large"
|
|
715
|
+
>
|
|
716
|
+
<IconCheck />
|
|
717
|
+
</IconButton>
|
|
718
|
+
) : (
|
|
719
|
+
<IconButton
|
|
720
|
+
disabled={this.state.editMode !== false}
|
|
721
|
+
onClick={() => this.setState({ editMode: i, editData: null })}
|
|
722
|
+
size="large"
|
|
723
|
+
>
|
|
724
|
+
<IconEdit />
|
|
725
|
+
</IconButton>
|
|
726
|
+
)}
|
|
727
|
+
</TableCell>
|
|
728
|
+
) : null}
|
|
729
|
+
|
|
730
|
+
{this.props.onDelete && !this.props.onUpdate ? (
|
|
731
|
+
<TableCell style={{ ...styles.cell, ...styles.cellButton }}>
|
|
732
|
+
{this.state.deleteMode === i ? (
|
|
733
|
+
<IconButton
|
|
734
|
+
disabled={
|
|
735
|
+
this.state.editMode !== false &&
|
|
736
|
+
(!this.state.editData || !Object.keys(this.state.editData).length)
|
|
737
|
+
}
|
|
738
|
+
onClick={() =>
|
|
739
|
+
this.setState(
|
|
740
|
+
{ deleteMode: false },
|
|
741
|
+
() => this.props.onDelete && this.props.onDelete(item),
|
|
742
|
+
)
|
|
743
|
+
}
|
|
744
|
+
size="large"
|
|
745
|
+
>
|
|
746
|
+
<IconCheck />
|
|
747
|
+
</IconButton>
|
|
748
|
+
) : null}
|
|
749
|
+
</TableCell>
|
|
750
|
+
) : null}
|
|
751
|
+
|
|
752
|
+
{this.props.onUpdate || this.props.onDelete ? (
|
|
753
|
+
<TableCell style={{ ...styles.cell, ...styles.cellButton }}>
|
|
754
|
+
{this.state.editMode === i || this.state.deleteMode === i ? (
|
|
755
|
+
<IconButton
|
|
756
|
+
onClick={() => this.setState({ editMode: false, deleteMode: false })}
|
|
757
|
+
size="large"
|
|
758
|
+
>
|
|
759
|
+
<IconClose />
|
|
760
|
+
</IconButton>
|
|
761
|
+
) : this.props.onDelete ? (
|
|
762
|
+
<IconButton
|
|
763
|
+
disabled={this.state.deleteMode !== false}
|
|
764
|
+
onClick={() => this.setState({ deleteMode: i })}
|
|
765
|
+
size="large"
|
|
766
|
+
>
|
|
767
|
+
<IconDelete />
|
|
768
|
+
</IconButton>
|
|
769
|
+
) : null}
|
|
770
|
+
</TableCell>
|
|
771
|
+
) : null}
|
|
772
|
+
</TableRow>
|
|
773
|
+
);
|
|
740
774
|
|
|
741
775
|
if (!level && opened) {
|
|
742
|
-
const items:
|
|
743
|
-
this.renderLine(it, level + 1)) as React.JSX.Element[];
|
|
776
|
+
const items: JSX.Element[] = children.map(it => this.renderLine(it, level + 1)) as JSX.Element[];
|
|
744
777
|
items.unshift(row);
|
|
745
778
|
return items;
|
|
746
779
|
}
|
|
747
780
|
return row;
|
|
748
781
|
}
|
|
749
782
|
|
|
750
|
-
handleRequestSort(property: string) {
|
|
783
|
+
handleRequestSort(property: string): void {
|
|
751
784
|
const isAsc = this.state.orderBy === property && this.state.order === 'asc';
|
|
752
785
|
this.setState({ order: isAsc ? 'desc' : 'asc', orderBy: property });
|
|
753
786
|
}
|
|
754
787
|
|
|
755
|
-
renderHead() {
|
|
756
|
-
return
|
|
757
|
-
<
|
|
758
|
-
<
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
sx={Utils.getStyle(this.props.theme, styles.cell, styles.cellHeader, styles[`width_${this.props.columns[0].field.replace(/\./g, '_')}`])}
|
|
765
|
-
style={this.props.columns[0].headerStyle || this.props.columns[0].cellStyle}
|
|
766
|
-
sortDirection={this.props.noSort ? false : (this.state.orderBy === this.props.columns[0].field ? this.state.order : false)}
|
|
767
|
-
>
|
|
768
|
-
{this.props.noSort ? null : <TableSortLabel
|
|
769
|
-
active={this.state.orderBy === this.props.columns[0].field}
|
|
770
|
-
direction={this.state.orderBy === this.props.columns[0].field ? this.state.order : 'asc'}
|
|
771
|
-
onClick={() => this.handleRequestSort(this.props.columns[0].field)}
|
|
772
|
-
>
|
|
773
|
-
{this.props.columns[0].title || this.props.columns[0].field}
|
|
774
|
-
{this.state.orderBy === this.props.columns[0].field ?
|
|
775
|
-
<span style={styles.visuallyHidden}>
|
|
776
|
-
{this.state.order === 'desc' ? 'sorted descending' : 'sorted ascending'}
|
|
777
|
-
</span> : null}
|
|
778
|
-
</TableSortLabel>}
|
|
779
|
-
</TableCell>
|
|
780
|
-
{this.props.columns.map((col, i) =>
|
|
781
|
-
(!i && !col.hidden ? null : <TableCell
|
|
782
|
-
key={col.field}
|
|
783
|
-
sx={Utils.getStyle(this.props.theme, styles.cell, styles.cellHeader, styles[`width_${col.field.replace(/\./g, '_')}`])}
|
|
784
|
-
style={col.headerStyle || col.cellStyle}
|
|
788
|
+
renderHead(): JSX.Element {
|
|
789
|
+
return (
|
|
790
|
+
<TableHead>
|
|
791
|
+
<TableRow key="headerRow">
|
|
792
|
+
<TableCell
|
|
793
|
+
component="th"
|
|
794
|
+
sx={Utils.getStyle(this.props.theme, styles.cell, styles.cellHeader, styles.cellExpand)}
|
|
795
|
+
/>
|
|
796
|
+
<TableCell
|
|
785
797
|
component="th"
|
|
798
|
+
sx={Utils.getStyle(
|
|
799
|
+
this.props.theme,
|
|
800
|
+
styles.cell,
|
|
801
|
+
styles.cellHeader,
|
|
802
|
+
styles[`width_${this.props.columns[0].field.replace(/\./g, '_')}`],
|
|
803
|
+
)}
|
|
804
|
+
style={this.props.columns[0].headerStyle || this.props.columns[0].cellStyle}
|
|
805
|
+
sortDirection={
|
|
806
|
+
this.props.noSort
|
|
807
|
+
? false
|
|
808
|
+
: this.state.orderBy === this.props.columns[0].field
|
|
809
|
+
? this.state.order
|
|
810
|
+
: false
|
|
811
|
+
}
|
|
786
812
|
>
|
|
787
|
-
{this.props.noSort ? null :
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
813
|
+
{this.props.noSort ? null : (
|
|
814
|
+
<TableSortLabel
|
|
815
|
+
active={this.state.orderBy === this.props.columns[0].field}
|
|
816
|
+
direction={
|
|
817
|
+
this.state.orderBy === this.props.columns[0].field ? this.state.order : 'asc'
|
|
818
|
+
}
|
|
819
|
+
onClick={() => this.handleRequestSort(this.props.columns[0].field)}
|
|
820
|
+
>
|
|
821
|
+
{this.props.columns[0].title || this.props.columns[0].field}
|
|
822
|
+
{this.state.orderBy === this.props.columns[0].field ? (
|
|
823
|
+
<span style={styles.visuallyHidden}>
|
|
824
|
+
{this.state.order === 'desc' ? 'sorted descending' : 'sorted ascending'}
|
|
825
|
+
</span>
|
|
826
|
+
) : null}
|
|
827
|
+
</TableSortLabel>
|
|
828
|
+
)}
|
|
829
|
+
</TableCell>
|
|
830
|
+
{this.props.columns.map((col, i) =>
|
|
831
|
+
!i && !col.hidden ? null : (
|
|
832
|
+
<TableCell
|
|
833
|
+
key={col.field}
|
|
834
|
+
sx={Utils.getStyle(
|
|
835
|
+
this.props.theme,
|
|
836
|
+
styles.cell,
|
|
837
|
+
styles.cellHeader,
|
|
838
|
+
styles[`width_${col.field.replace(/\./g, '_')}`],
|
|
839
|
+
)}
|
|
840
|
+
style={col.headerStyle || col.cellStyle}
|
|
841
|
+
component="th"
|
|
842
|
+
>
|
|
843
|
+
{this.props.noSort ? null : (
|
|
844
|
+
<TableSortLabel
|
|
845
|
+
active={this.state.orderBy === col.field}
|
|
846
|
+
direction={this.state.orderBy === col.field ? this.state.order : 'asc'}
|
|
847
|
+
onClick={() => this.handleRequestSort(col.field)}
|
|
848
|
+
>
|
|
849
|
+
{col.title || col.field}
|
|
850
|
+
{this.state.orderBy === col.field ? (
|
|
851
|
+
<span style={styles.visuallyHidden}>
|
|
852
|
+
{this.state.order === 'desc' ? 'sorted descending' : 'sorted ascending'}
|
|
853
|
+
</span>
|
|
854
|
+
) : null}
|
|
855
|
+
</TableSortLabel>
|
|
856
|
+
)}
|
|
857
|
+
</TableCell>
|
|
858
|
+
),
|
|
859
|
+
)}
|
|
860
|
+
{this.props.onUpdate ? (
|
|
861
|
+
<TableCell
|
|
862
|
+
component="th"
|
|
863
|
+
sx={Utils.getStyle(this.props.theme, styles.cell, styles.cellHeader, styles.cellButton)}
|
|
791
864
|
>
|
|
792
|
-
{
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
865
|
+
{!this.props.noAdd ? (
|
|
866
|
+
<Fab
|
|
867
|
+
color="primary"
|
|
868
|
+
size="small"
|
|
869
|
+
disabled={this.state.editMode !== false}
|
|
870
|
+
onClick={() =>
|
|
871
|
+
this.props.onUpdate && (this.props.onUpdate as (addNew: true) => void)(true)
|
|
872
|
+
}
|
|
873
|
+
>
|
|
874
|
+
<IconAdd />
|
|
875
|
+
</Fab>
|
|
876
|
+
) : null}
|
|
877
|
+
</TableCell>
|
|
878
|
+
) : null}
|
|
879
|
+
{this.props.onDelete || this.props.onUpdate ? (
|
|
880
|
+
<TableCell
|
|
881
|
+
component="th"
|
|
882
|
+
sx={Utils.getStyle(this.props.theme, styles.cell, styles.cellHeader, styles.cellButton)}
|
|
883
|
+
/>
|
|
884
|
+
) : null}
|
|
885
|
+
</TableRow>
|
|
886
|
+
</TableHead>
|
|
887
|
+
);
|
|
813
888
|
}
|
|
814
889
|
|
|
815
|
-
render() {
|
|
890
|
+
render(): JSX.Element | null {
|
|
816
891
|
const col = this.props.columns.find(_col => _col.field === this.state.orderBy);
|
|
817
892
|
if (col) {
|
|
818
893
|
const lookup = col.lookup;
|
|
@@ -826,16 +901,24 @@ class TreeTable extends Component<TreeTableProps, TreeTableState> {
|
|
|
826
901
|
}, 500);
|
|
827
902
|
}
|
|
828
903
|
|
|
829
|
-
return
|
|
830
|
-
<
|
|
831
|
-
{
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
904
|
+
return (
|
|
905
|
+
<div
|
|
906
|
+
style={styles.tableContainer}
|
|
907
|
+
className={this.props.className}
|
|
908
|
+
>
|
|
909
|
+
<Table
|
|
910
|
+
style={styles.table}
|
|
911
|
+
aria-label="simple table"
|
|
912
|
+
size="small"
|
|
913
|
+
stickyHeader
|
|
914
|
+
>
|
|
915
|
+
{this.renderHead()}
|
|
916
|
+
<TableBody>{table.map(it => this.renderLine(it))}</TableBody>
|
|
917
|
+
</Table>
|
|
918
|
+
{this.renderSelectIdDialog()}
|
|
919
|
+
{this.renderSelectColorDialog()}
|
|
920
|
+
</div>
|
|
921
|
+
);
|
|
839
922
|
}
|
|
840
923
|
|
|
841
924
|
return null;
|