@iobroker/adapter-react-v5 7.2.4 → 7.2.6

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.
Files changed (375) hide show
  1. package/README.md +6 -6
  2. package/build/AdminConnection.d.ts +1 -0
  3. package/build/AdminConnection.js +2 -0
  4. package/build/AdminConnection.js.map +1 -0
  5. package/{src/Components/404.tsx → build/Components/404.js} +14 -39
  6. package/build/Components/404.js.map +1 -0
  7. package/{Components → build/Components}/ColorPicker.d.ts +2 -2
  8. package/{Components → build/Components}/ColorPicker.js +50 -65
  9. package/build/Components/ColorPicker.js.map +1 -0
  10. package/{Components → build/Components}/ComplexCron.d.ts +2 -2
  11. package/{Components → build/Components}/ComplexCron.js +43 -71
  12. package/build/Components/ComplexCron.js.map +1 -0
  13. package/{Components → build/Components}/CopyToClipboard.d.ts +1 -2
  14. package/{src/Components/CopyToClipboard.tsx → build/Components/CopyToClipboard.js} +20 -38
  15. package/build/Components/CopyToClipboard.js.map +1 -0
  16. package/{Components → build/Components}/CustomModal.d.ts +3 -3
  17. package/build/Components/CustomModal.js +60 -0
  18. package/build/Components/CustomModal.js.map +1 -0
  19. package/{Components → build/Components}/FileBrowser.d.ts +2 -2
  20. package/{Components → build/Components}/FileBrowser.js +229 -236
  21. package/build/Components/FileBrowser.js.map +1 -0
  22. package/build/Components/FileViewer.d.ts +48 -0
  23. package/build/Components/FileViewer.js +277 -0
  24. package/build/Components/FileViewer.js.map +1 -0
  25. package/{Components → build/Components}/Icon.d.ts +1 -1
  26. package/build/Components/Icon.js +140 -0
  27. package/build/Components/Icon.js.map +1 -0
  28. package/{Components → build/Components}/IconPicker.d.ts +2 -2
  29. package/build/Components/IconPicker.js +73 -0
  30. package/build/Components/IconPicker.js.map +1 -0
  31. package/{Components → build/Components}/IconSelector.d.ts +3 -3
  32. package/{Components → build/Components}/IconSelector.js +29 -57
  33. package/build/Components/IconSelector.js.map +1 -0
  34. package/{Components → build/Components}/Image.d.ts +2 -2
  35. package/{Components → build/Components}/Image.js +16 -22
  36. package/build/Components/Image.js.map +1 -0
  37. package/{Components → build/Components}/Loader.d.ts +2 -2
  38. package/{Components → build/Components}/Loader.js +15 -40
  39. package/build/Components/Loader.js.map +1 -0
  40. package/{Components → build/Components}/Loaders/MV.d.ts +2 -2
  41. package/build/Components/Loaders/MV.js +61 -0
  42. package/build/Components/Loaders/MV.js.map +1 -0
  43. package/{Components → build/Components}/Loaders/PT.d.ts +2 -2
  44. package/{Components → build/Components}/Loaders/PT.js +10 -35
  45. package/build/Components/Loaders/PT.js.map +1 -0
  46. package/{Components → build/Components}/Loaders/Vendor.d.ts +2 -2
  47. package/build/Components/Loaders/Vendor.js +52 -0
  48. package/build/Components/Loaders/Vendor.js.map +1 -0
  49. package/{Components → build/Components}/Logo.d.ts +2 -2
  50. package/build/Components/Logo.js +108 -0
  51. package/build/Components/Logo.js.map +1 -0
  52. package/{Components → build/Components}/MDUtils.d.ts +1 -2
  53. package/{Components → build/Components}/MDUtils.js +4 -9
  54. package/build/Components/MDUtils.js.map +1 -0
  55. package/{Components → build/Components}/ObjectBrowser.d.ts +4 -4
  56. package/{Components → build/Components}/ObjectBrowser.js +1152 -1116
  57. package/build/Components/ObjectBrowser.js.map +1 -0
  58. package/{Components → build/Components}/Router.d.ts +1 -2
  59. package/{Components → build/Components}/Router.js +6 -7
  60. package/build/Components/Router.js.map +1 -0
  61. package/{Components → build/Components}/SaveCloseButtons.d.ts +2 -2
  62. package/build/Components/SaveCloseButtons.js +65 -0
  63. package/build/Components/SaveCloseButtons.js.map +1 -0
  64. package/{Components → build/Components}/Schedule.d.ts +2 -2
  65. package/{Components → build/Components}/Schedule.js +242 -257
  66. package/build/Components/Schedule.js.map +1 -0
  67. package/{Components → build/Components}/SelectWithIcon.d.ts +2 -2
  68. package/build/Components/SelectWithIcon.js +135 -0
  69. package/build/Components/SelectWithIcon.js.map +1 -0
  70. package/build/Components/SimpleCron/cronText.js +15 -0
  71. package/build/Components/SimpleCron/cronText.js.map +1 -0
  72. package/{Components → build/Components}/SimpleCron/index.d.ts +2 -2
  73. package/{Components → build/Components}/SimpleCron/index.js +55 -58
  74. package/build/Components/SimpleCron/index.js.map +1 -0
  75. package/{Components → build/Components}/TabContainer.d.ts +2 -2
  76. package/build/Components/TabContainer.js +23 -0
  77. package/build/Components/TabContainer.js.map +1 -0
  78. package/{Components → build/Components}/TabContent.d.ts +3 -2
  79. package/build/Components/TabContent.js +20 -0
  80. package/build/Components/TabContent.js.map +1 -0
  81. package/build/Components/TabHeader.d.ts +6 -0
  82. package/build/Components/TabHeader.js +6 -0
  83. package/build/Components/TabHeader.js.map +1 -0
  84. package/{Components → build/Components}/TableResize.d.ts +2 -2
  85. package/{src/Components/TableResize.tsx → build/Components/TableResize.js} +64 -134
  86. package/build/Components/TableResize.js.map +1 -0
  87. package/{Components → build/Components}/TextWithIcon.d.ts +2 -2
  88. package/{src/Components/TextWithIcon.tsx → build/Components/TextWithIcon.js} +30 -75
  89. package/build/Components/TextWithIcon.js.map +1 -0
  90. package/{Components → build/Components}/ToggleThemeMenu.d.ts +1 -1
  91. package/build/Components/ToggleThemeMenu.js +13 -0
  92. package/build/Components/ToggleThemeMenu.js.map +1 -0
  93. package/{Components → build/Components}/TreeTable.d.ts +3 -3
  94. package/{Components → build/Components}/TreeTable.js +87 -99
  95. package/build/Components/TreeTable.js.map +1 -0
  96. package/{Components → build/Components}/UploadImage.d.ts +2 -2
  97. package/{Components → build/Components}/UploadImage.js +46 -69
  98. package/build/Components/UploadImage.js.map +1 -0
  99. package/{Components → build/Components}/Utils.d.ts +2 -2
  100. package/{Components → build/Components}/Utils.js +47 -60
  101. package/build/Components/Utils.js.map +1 -0
  102. package/build/Components/withWidth.d.ts +2 -0
  103. package/build/Components/withWidth.js +22 -0
  104. package/build/Components/withWidth.js.map +1 -0
  105. package/build/Connection.d.ts +1 -0
  106. package/build/Connection.js +2 -0
  107. package/build/Connection.js.map +1 -0
  108. package/{Dialogs → build/Dialogs}/ComplexCron.d.ts +2 -2
  109. package/build/Dialogs/ComplexCron.js +85 -0
  110. package/build/Dialogs/ComplexCron.js.map +1 -0
  111. package/{Dialogs → build/Dialogs}/Confirm.d.ts +2 -2
  112. package/build/Dialogs/Confirm.js +83 -0
  113. package/build/Dialogs/Confirm.js.map +1 -0
  114. package/{Dialogs → build/Dialogs}/Cron.d.ts +2 -2
  115. package/build/Dialogs/Cron.js +72 -0
  116. package/build/Dialogs/Cron.js.map +1 -0
  117. package/{Dialogs → build/Dialogs}/Error.d.ts +2 -2
  118. package/build/Dialogs/Error.js +27 -0
  119. package/build/Dialogs/Error.js.map +1 -0
  120. package/{Dialogs → build/Dialogs}/Message.d.ts +2 -2
  121. package/build/Dialogs/Message.js +29 -0
  122. package/build/Dialogs/Message.js.map +1 -0
  123. package/{Dialogs → build/Dialogs}/SelectFile.d.ts +2 -2
  124. package/build/Dialogs/SelectFile.js +116 -0
  125. package/build/Dialogs/SelectFile.js.map +1 -0
  126. package/{Dialogs → build/Dialogs}/SelectID.d.ts +3 -3
  127. package/{Dialogs → build/Dialogs}/SelectID.js +28 -53
  128. package/build/Dialogs/SelectID.js.map +1 -0
  129. package/{Dialogs → build/Dialogs}/SimpleCron.d.ts +2 -2
  130. package/build/Dialogs/SimpleCron.js +46 -0
  131. package/build/Dialogs/SimpleCron.js.map +1 -0
  132. package/build/Dialogs/TextInput.d.ts +2 -0
  133. package/build/Dialogs/TextInput.js +31 -0
  134. package/build/Dialogs/TextInput.js.map +1 -0
  135. package/{GenericApp.d.ts → build/GenericApp.d.ts} +2 -3
  136. package/{GenericApp.js → build/GenericApp.js} +162 -176
  137. package/build/GenericApp.js.map +1 -0
  138. package/{LegacyConnection.d.ts → build/LegacyConnection.d.ts} +69 -4
  139. package/{LegacyConnection.js → build/LegacyConnection.js} +106 -99
  140. package/build/LegacyConnection.js.map +1 -0
  141. package/{Prompt.d.ts → build/Prompt.d.ts} +1 -1
  142. package/{Prompt.js → build/Prompt.js} +3 -4
  143. package/build/Prompt.js.map +1 -0
  144. package/build/Theme.d.ts +5 -0
  145. package/{Theme.js → build/Theme.js} +37 -32
  146. package/build/Theme.js.map +1 -0
  147. package/build/assets/devices/parseNames.d.ts +0 -0
  148. package/build/assets/devices/parseNames.js +35 -0
  149. package/build/assets/devices/parseNames.js.map +1 -0
  150. package/build/assets/rooms/parseNames.d.ts +0 -0
  151. package/build/assets/rooms/parseNames.js +35 -0
  152. package/build/assets/rooms/parseNames.js.map +1 -0
  153. package/build/dictionary.d.ts +1 -0
  154. package/build/dictionary.js +25 -0
  155. package/build/dictionary.js.map +1 -0
  156. package/build/i18n/de.json +449 -0
  157. package/build/i18n/en.json +449 -0
  158. package/build/i18n/es.json +449 -0
  159. package/build/i18n/fr.json +449 -0
  160. package/build/i18n/it.json +449 -0
  161. package/build/i18n/nl.json +449 -0
  162. package/build/i18n/pl.json +449 -0
  163. package/build/i18n/pt.json +449 -0
  164. package/build/i18n/ru.json +449 -0
  165. package/build/i18n/uk.json +449 -0
  166. package/build/i18n/zh-cn.json +449 -0
  167. package/{i18n.d.ts → build/i18n.d.ts} +2 -2
  168. package/{i18n.js → build/i18n.js} +9 -11
  169. package/build/i18n.js.map +1 -0
  170. package/build/icons/IconAdapter.d.ts +3 -0
  171. package/build/icons/IconAdapter.js +6 -0
  172. package/build/icons/IconAdapter.js.map +1 -0
  173. package/build/icons/IconAlias.d.ts +3 -0
  174. package/build/icons/IconAlias.js +6 -0
  175. package/build/icons/IconAlias.js.map +1 -0
  176. package/build/icons/IconChannel.d.ts +3 -0
  177. package/build/icons/IconChannel.js +9 -0
  178. package/build/icons/IconChannel.js.map +1 -0
  179. package/build/icons/IconClearFilter.d.ts +3 -0
  180. package/build/icons/IconClearFilter.js +7 -0
  181. package/build/icons/IconClearFilter.js.map +1 -0
  182. package/build/icons/IconClosed.d.ts +3 -0
  183. package/build/icons/IconClosed.js +6 -0
  184. package/build/icons/IconClosed.js.map +1 -0
  185. package/build/icons/IconCopy.d.ts +3 -0
  186. package/build/icons/IconCopy.js +5 -0
  187. package/build/icons/IconCopy.js.map +1 -0
  188. package/build/icons/IconDevice.d.ts +3 -0
  189. package/build/icons/IconDevice.js +15 -0
  190. package/build/icons/IconDevice.js.map +1 -0
  191. package/build/icons/IconDocument.d.ts +3 -0
  192. package/build/icons/IconDocument.js +6 -0
  193. package/build/icons/IconDocument.js.map +1 -0
  194. package/build/icons/IconDocumentReadOnly.d.ts +3 -0
  195. package/build/icons/IconDocumentReadOnly.js +7 -0
  196. package/build/icons/IconDocumentReadOnly.js.map +1 -0
  197. package/build/icons/IconExpert.d.ts +3 -0
  198. package/build/icons/IconExpert.js +6 -0
  199. package/build/icons/IconExpert.js.map +1 -0
  200. package/build/icons/IconFx.d.ts +3 -0
  201. package/build/icons/IconFx.js +5 -0
  202. package/build/icons/IconFx.js.map +1 -0
  203. package/build/icons/IconInstance.d.ts +3 -0
  204. package/build/icons/IconInstance.js +6 -0
  205. package/build/icons/IconInstance.js.map +1 -0
  206. package/build/icons/IconLogout.d.ts +3 -0
  207. package/build/icons/IconLogout.js +6 -0
  208. package/build/icons/IconLogout.js.map +1 -0
  209. package/build/icons/IconNoIcon.d.ts +3 -0
  210. package/build/icons/IconNoIcon.js +5 -0
  211. package/build/icons/IconNoIcon.js.map +1 -0
  212. package/build/icons/IconOpen.d.ts +3 -0
  213. package/build/icons/IconOpen.js +6 -0
  214. package/build/icons/IconOpen.js.map +1 -0
  215. package/{icons → build/icons}/IconProps.d.ts +1 -1
  216. package/build/icons/IconProps.js +2 -0
  217. package/build/icons/IconProps.js.map +1 -0
  218. package/build/icons/IconState.d.ts +3 -0
  219. package/build/icons/IconState.js +6 -0
  220. package/build/icons/IconState.js.map +1 -0
  221. package/build/index.d.ts +67 -0
  222. package/build/index.js +67 -0
  223. package/build/index.js.map +1 -0
  224. package/{types.d.ts → build/types.d.ts} +1 -1
  225. package/package.json +84 -48
  226. package/AdminConnection.d.ts +0 -2
  227. package/AdminConnection.js +0 -4
  228. package/Components/404.js +0 -101
  229. package/Components/CopyToClipboard.js +0 -163
  230. package/Components/CustomModal.js +0 -88
  231. package/Components/FileViewer.d.ts +0 -10
  232. package/Components/FileViewer.js +0 -305
  233. package/Components/Icon.js +0 -148
  234. package/Components/IconPicker.js +0 -98
  235. package/Components/Loaders/MV.js +0 -66
  236. package/Components/Loaders/Vendor.js +0 -77
  237. package/Components/Logo.js +0 -117
  238. package/Components/SaveCloseButtons.js +0 -69
  239. package/Components/SelectWithIcon.js +0 -168
  240. package/Components/SimpleCron/cronText.js +0 -19
  241. package/Components/TabContainer.js +0 -25
  242. package/Components/TabContent.js +0 -21
  243. package/Components/TabHeader.d.ts +0 -6
  244. package/Components/TabHeader.js +0 -11
  245. package/Components/TableResize.js +0 -226
  246. package/Components/TextWithIcon.js +0 -119
  247. package/Components/ToggleThemeMenu.js +0 -18
  248. package/Components/withWidth.d.ts +0 -3
  249. package/Components/withWidth.js +0 -27
  250. package/Connection.d.ts +0 -3
  251. package/Connection.js +0 -8
  252. package/Dialogs/ComplexCron.js +0 -90
  253. package/Dialogs/Confirm.js +0 -111
  254. package/Dialogs/Cron.js +0 -100
  255. package/Dialogs/Error.js +0 -55
  256. package/Dialogs/Message.js +0 -57
  257. package/Dialogs/SelectFile.js +0 -119
  258. package/Dialogs/SimpleCron.js +0 -51
  259. package/Dialogs/TextInput.d.ts +0 -3
  260. package/Dialogs/TextInput.js +0 -35
  261. package/Theme.d.ts +0 -6
  262. package/i18n/de.json +0 -449
  263. package/i18n/en.json +0 -449
  264. package/i18n/es.json +0 -449
  265. package/i18n/fr.json +0 -449
  266. package/i18n/it.json +0 -449
  267. package/i18n/nl.json +0 -449
  268. package/i18n/pl.json +0 -449
  269. package/i18n/pt.json +0 -449
  270. package/i18n/ru.json +0 -449
  271. package/i18n/uk.json +0 -449
  272. package/i18n/zh-cn.json +0 -449
  273. package/icons/IconAdapter.d.ts +0 -4
  274. package/icons/IconAdapter.js +0 -10
  275. package/icons/IconAlias.d.ts +0 -4
  276. package/icons/IconAlias.js +0 -10
  277. package/icons/IconChannel.d.ts +0 -4
  278. package/icons/IconChannel.js +0 -13
  279. package/icons/IconClearFilter.d.ts +0 -4
  280. package/icons/IconClearFilter.js +0 -11
  281. package/icons/IconClosed.d.ts +0 -4
  282. package/icons/IconClosed.js +0 -10
  283. package/icons/IconCopy.d.ts +0 -4
  284. package/icons/IconCopy.js +0 -9
  285. package/icons/IconDevice.d.ts +0 -4
  286. package/icons/IconDevice.js +0 -19
  287. package/icons/IconDocument.d.ts +0 -4
  288. package/icons/IconDocument.js +0 -10
  289. package/icons/IconDocumentReadOnly.d.ts +0 -4
  290. package/icons/IconDocumentReadOnly.js +0 -11
  291. package/icons/IconExpert.d.ts +0 -4
  292. package/icons/IconExpert.js +0 -10
  293. package/icons/IconFx.d.ts +0 -4
  294. package/icons/IconFx.js +0 -9
  295. package/icons/IconInstance.d.ts +0 -4
  296. package/icons/IconInstance.js +0 -10
  297. package/icons/IconLogout.d.ts +0 -4
  298. package/icons/IconLogout.js +0 -10
  299. package/icons/IconNoIcon.d.ts +0 -4
  300. package/icons/IconNoIcon.js +0 -9
  301. package/icons/IconOpen.d.ts +0 -4
  302. package/icons/IconOpen.js +0 -10
  303. package/icons/IconProps.js +0 -2
  304. package/icons/IconState.d.ts +0 -4
  305. package/icons/IconState.js +0 -10
  306. package/index.d.ts +0 -128
  307. package/index.js +0 -215
  308. package/src/AdminConnection.tsx +0 -3
  309. package/src/Components/ColorPicker.tsx +0 -343
  310. package/src/Components/ComplexCron.tsx +0 -561
  311. package/src/Components/CustomModal.tsx +0 -170
  312. package/src/Components/FileBrowser.tsx +0 -2560
  313. package/src/Components/FileViewer.tsx +0 -412
  314. package/src/Components/Icon.tsx +0 -238
  315. package/src/Components/IconPicker.tsx +0 -165
  316. package/src/Components/IconSelector.tsx +0 -2220
  317. package/src/Components/Image.tsx +0 -193
  318. package/src/Components/Loader.tsx +0 -328
  319. package/src/Components/Logo.tsx +0 -176
  320. package/src/Components/MDUtils.tsx +0 -104
  321. package/src/Components/ObjectBrowser.tsx +0 -8947
  322. package/src/Components/Router.tsx +0 -90
  323. package/src/Components/SaveCloseButtons.tsx +0 -117
  324. package/src/Components/Schedule.tsx +0 -1998
  325. package/src/Components/SelectWithIcon.tsx +0 -239
  326. package/src/Components/TabContainer.tsx +0 -57
  327. package/src/Components/TabContent.tsx +0 -38
  328. package/src/Components/TabHeader.tsx +0 -20
  329. package/src/Components/ToggleThemeMenu.tsx +0 -52
  330. package/src/Components/TreeTable.tsx +0 -1002
  331. package/src/Components/UploadImage.tsx +0 -643
  332. package/src/Components/Utils.tsx +0 -1802
  333. package/src/Components/loader.css +0 -231
  334. package/src/Components/withWidth.tsx +0 -32
  335. package/src/Connection.tsx +0 -5
  336. package/src/Dialogs/ComplexCron.tsx +0 -163
  337. package/src/Dialogs/Confirm.tsx +0 -185
  338. package/src/Dialogs/Cron.tsx +0 -192
  339. package/src/Dialogs/Error.tsx +0 -67
  340. package/src/Dialogs/Message.tsx +0 -73
  341. package/src/Dialogs/SelectFile.tsx +0 -280
  342. package/src/Dialogs/SelectID.tsx +0 -310
  343. package/src/Dialogs/SimpleCron.tsx +0 -101
  344. package/src/Dialogs/TextInput.tsx +0 -99
  345. package/src/GenericApp.tsx +0 -1076
  346. package/src/LegacyConnection.tsx +0 -3720
  347. package/src/Prompt.tsx +0 -22
  348. package/src/Theme.tsx +0 -472
  349. package/src/icons/IconAdapter.tsx +0 -22
  350. package/src/icons/IconAlias.tsx +0 -22
  351. package/src/icons/IconChannel.tsx +0 -60
  352. package/src/icons/IconClearFilter.tsx +0 -24
  353. package/src/icons/IconClosed.tsx +0 -22
  354. package/src/icons/IconCopy.tsx +0 -21
  355. package/src/icons/IconDevice.tsx +0 -126
  356. package/src/icons/IconDocument.tsx +0 -22
  357. package/src/icons/IconDocumentReadOnly.tsx +0 -27
  358. package/src/icons/IconExpert.tsx +0 -26
  359. package/src/icons/IconFx.tsx +0 -38
  360. package/src/icons/IconInstance.tsx +0 -22
  361. package/src/icons/IconLogout.tsx +0 -32
  362. package/src/icons/IconNoIcon.tsx +0 -21
  363. package/src/icons/IconOpen.tsx +0 -22
  364. package/src/icons/IconProps.tsx +0 -16
  365. package/src/icons/IconState.tsx +0 -38
  366. package/src/index.css +0 -56
  367. /package/{Components → build/Components}/404.d.ts +0 -0
  368. /package/{Components → build/Components}/SimpleCron/cronText.d.ts +0 -0
  369. /package/{assets → build/assets}/devices.json +0 -0
  370. /package/{assets → build/assets}/lamp_ceiling.svg +0 -0
  371. /package/{assets → build/assets}/lamp_table.svg +0 -0
  372. /package/{assets → build/assets}/no_icon.svg +0 -0
  373. /package/{assets → build/assets}/rooms.json +0 -0
  374. /package/{index.css → build/index.css} +0 -0
  375. /package/{tasks.js → tasksExample.js} +0 -0
@@ -1,1002 +0,0 @@
1
- import React, { Component, type JSX } from 'react';
2
-
3
- import { HexColorPicker as ColorPicker } from 'react-colorful';
4
-
5
- import {
6
- Fab,
7
- Table,
8
- TableBody,
9
- TableCell,
10
- TableHead,
11
- TableRow,
12
- TableSortLabel,
13
- IconButton,
14
- Select,
15
- MenuItem,
16
- TextField,
17
- Checkbox,
18
- Dialog,
19
- } from '@mui/material';
20
-
21
- import {
22
- Edit as IconEdit,
23
- Delete as IconDelete,
24
- NavigateNext as IconExpand,
25
- ExpandMore as IconCollapse,
26
- Check as IconCheck,
27
- Close as IconClose,
28
- Add as IconAdd,
29
- ViewHeadline as IconList,
30
- Colorize as IconColor,
31
- } from '@mui/icons-material';
32
-
33
- import type Connection from '../Connection';
34
-
35
- import DialogSelectID from '../Dialogs/SelectID';
36
- import Utils from './Utils';
37
- import type { IobTheme } from '../types';
38
-
39
- function getAttr(obj: Record<string, any>, attr: string | string[], lookup?: Record<string, string>): any {
40
- if (typeof attr === 'string') {
41
- attr = attr.split('.');
42
- }
43
-
44
- if (!obj) {
45
- return null;
46
- }
47
-
48
- if (attr.length === 1) {
49
- if (lookup && lookup[obj[attr[0]]]) {
50
- return lookup[obj[attr[0]]];
51
- }
52
- return obj[attr[0]];
53
- }
54
-
55
- const name: string = attr.shift() as string;
56
- return getAttr(obj[name], attr);
57
- }
58
-
59
- function setAttr(obj: Record<string, any>, attr: string | string[], value: any): void {
60
- if (typeof attr === 'string') {
61
- attr = attr.split('.');
62
- }
63
-
64
- if (attr.length === 1) {
65
- return (obj[attr[0]] = value);
66
- }
67
- const name: string = attr.shift() as string;
68
- if (obj[name] === null || obj[name] === undefined) {
69
- obj[name] = {};
70
- }
71
- return setAttr(obj[name], attr, value);
72
- }
73
-
74
- const styles: Record<string, any> = {
75
- tableContainer: {
76
- width: '100%',
77
- height: '100%',
78
- overflow: 'auto',
79
- },
80
- table: {
81
- width: '100%',
82
- minWidth: 800,
83
- maxWidth: 1920,
84
- },
85
- cell: {
86
- paddingTop: 0,
87
- paddingBottom: 0,
88
- paddingLeft: 4,
89
- paddingRight: 4,
90
- },
91
- rowMainWithChildren: {},
92
- rowMainWithoutChildren: {},
93
- rowNoEdit: {
94
- opacity: 0.3,
95
- },
96
- cellExpand: {
97
- width: 30,
98
- },
99
- cellButton: {
100
- width: 30,
101
- },
102
- cellHeader: {
103
- fontWeight: 'bold',
104
- background: (theme: IobTheme) => (theme.palette.mode === 'dark' ? '#888' : '#888'),
105
- color: (theme: IobTheme) => (theme.palette.mode === 'dark' ? '#EEE' : '#111'),
106
- height: 48,
107
- wordBreak: 'break-word',
108
- whiteSpace: 'pre',
109
- },
110
- width_name_nicknames: {
111
- maxWidth: 150,
112
- },
113
- width_ioType: {
114
- maxWidth: 100,
115
- },
116
- width_type: {
117
- maxWidth: 100,
118
- },
119
- width_displayTraits: {
120
- maxWidth: 100,
121
- },
122
- width_roomHint: {
123
- maxWidth: 100,
124
- },
125
- rowSecondary: {
126
- fontStyle: 'italic',
127
- },
128
- cellSecondary: {
129
- fontSize: 10,
130
- },
131
- visuallyHidden: {
132
- border: 0,
133
- clip: 'rect(0 0 0 0)',
134
- height: 1,
135
- margin: -1,
136
- overflow: 'hidden',
137
- padding: 0,
138
- position: 'absolute',
139
- top: 20,
140
- width: 1,
141
- },
142
- fieldEditWithButton: {
143
- width: 'calc(100% - 33px)',
144
- display: 'inline-block',
145
- },
146
- fieldEdit: {
147
- width: '100%',
148
- display: 'inline-block',
149
- lineHeight: '50px',
150
- verticalAlign: 'middle',
151
- },
152
- fieldButton: {
153
- width: 30,
154
- display: 'inline-block',
155
- },
156
- colorDialog: {
157
- overflow: 'hidden',
158
- padding: 15,
159
- },
160
- subText: {
161
- fontSize: 10,
162
- fontStyle: 'italic',
163
- },
164
- glow: {
165
- animation: 'glow 0.2s 2 alternate',
166
- },
167
- };
168
-
169
- function descendingComparator(
170
- a: Record<string, any>,
171
- b: Record<string, any>,
172
- orderBy: string,
173
- lookup?: Record<string, string>,
174
- ): number {
175
- const _a = getAttr(a, orderBy, lookup) || '';
176
- const _b = getAttr(b, orderBy, lookup) || '';
177
-
178
- if (_b < _a) {
179
- return -1;
180
- }
181
- if (_b > _a) {
182
- return 1;
183
- }
184
- return 0;
185
- }
186
-
187
- function getComparator(
188
- order: 'desc' | 'asc',
189
- orderBy: string,
190
- lookup?: Record<string, string>,
191
- ): (a: Record<string, any>, b: Record<string, any>) => number {
192
- return order === 'desc'
193
- ? (a, b) => descendingComparator(a, b, orderBy, lookup)
194
- : (a, b) => -descendingComparator(a, b, orderBy, lookup);
195
- }
196
-
197
- function stableSort(
198
- array: Record<string, any>[],
199
- comparator: (a: Record<string, any>, b: Record<string, any>) => number,
200
- ): Record<string, any>[] {
201
- const stabilizedThis: { e: Record<string, any>; i: number }[] = array.map((el, index) => ({ e: el, i: index }));
202
-
203
- stabilizedThis.sort((a, b) => {
204
- const order = comparator(a.e, b.e);
205
- if (order) {
206
- return order;
207
- }
208
- return a.i - b.i;
209
- });
210
-
211
- return stabilizedThis.map(item => item.e);
212
- }
213
-
214
- interface Column {
215
- cellStyle?: Record<string, any>;
216
- editComponent?: React.FC<{ value: any; rowData: Record<string, any>; onChange: (newValue: any) => void }>;
217
- field: string;
218
- headerStyle?: Record<string, any>;
219
- hidden?: boolean;
220
- lookup?: Record<string, string>;
221
- editable?: boolean | 'never';
222
- title?: string;
223
- type?: 'string' | 'boolean' | 'numeric' | 'icon' | 'oid' | 'color';
224
- subField?: string;
225
- subLookup?: Record<string, string>;
226
- subStyle?: Record<string, any>;
227
- }
228
-
229
- interface TreeTableProps {
230
- data: Record<string, any>[];
231
- className?: string;
232
- /** name of table to save settings in localStorage */
233
- name?: string;
234
- columns: Column[];
235
- noSort?: boolean;
236
- onUpdate?: ((newData: Record<string, any>, oldData: Record<string, any>) => void) | ((addNew: true) => void);
237
- onDelete?: (oldData: Record<string, any>) => void;
238
- /** hide add button */
239
- noAdd?: boolean;
240
- themeType?: string;
241
- glowOnChange?: boolean;
242
- /** only if an oid type is used */
243
- socket?: Connection;
244
- /** Shift in pixels for every level */
245
- levelShift?: number;
246
- adapterName: string;
247
- theme: IobTheme;
248
- }
249
-
250
- interface TreeTableState {
251
- opened: string[];
252
- editMode: number | false;
253
- deleteMode: number | false;
254
- editData: Record<string, any> | null;
255
- order: 'desc' | 'asc';
256
- update: string[] | null;
257
- orderBy: string;
258
- showSelectColor: boolean;
259
- selectIdValue?: string | null;
260
- showSelectId?: boolean;
261
- data?: Record<string, any>[];
262
- }
263
-
264
- class TreeTable extends Component<TreeTableProps, TreeTableState> {
265
- private selectCallback: ((selected: string) => void) | null = null;
266
-
267
- private updateTimeout: ReturnType<typeof setTimeout> | null = null;
268
-
269
- constructor(props: TreeTableProps) {
270
- super(props);
271
-
272
- let opened =
273
- ((window as any)._localStorage || window.localStorage).getItem(this.props.name || 'iob-table') || '[]';
274
- try {
275
- opened = JSON.parse(opened) || [];
276
- } catch {
277
- opened = [];
278
- }
279
- if (!Array.isArray(opened)) {
280
- opened = [];
281
- }
282
-
283
- this.state = {
284
- opened,
285
- editMode: false,
286
- deleteMode: false,
287
- editData: null,
288
- order: 'asc',
289
- update: null,
290
- orderBy: this.props.columns[0].field,
291
- showSelectColor: false,
292
- };
293
- }
294
-
295
- static getDerivedStateFromProps(props: TreeTableProps, state: TreeTableState): Partial<TreeTableState> {
296
- if (props.glowOnChange) {
297
- const update: string[] = [];
298
- let count = 0;
299
- if (props.data && state.data) {
300
- props.data.forEach(line => {
301
- count++;
302
- const oldLine = state.data?.find(it => it.id === line.id);
303
- if (oldLine) {
304
- if (JSON.stringify(oldLine) !== JSON.stringify(line)) {
305
- update.push(line.id);
306
- }
307
- } else {
308
- update.push(line.id);
309
- }
310
- });
311
- }
312
-
313
- if (update.length && update.length !== count) {
314
- return { data: props.data, update };
315
- }
316
- return { data: props.data };
317
- }
318
-
319
- return { data: props.data };
320
- }
321
-
322
- renderCellEdit(item: Record<string, any>, col: Column): JSX.Element | null {
323
- let val = getAttr(item, col.field);
324
- if (Array.isArray(val)) {
325
- val = val[0];
326
- }
327
-
328
- if (col.lookup) {
329
- return this.renderCellEditSelect(col, val);
330
- }
331
- if (col.editComponent) {
332
- return this.renderCellEditCustom(col, val, item);
333
- }
334
- if (col.type === 'boolean' || (!col.type && typeof val === 'boolean')) {
335
- return this.renderCellEditBoolean(col, val);
336
- }
337
- if (col.type === 'color') {
338
- return this.renderCellEditColor(col, val);
339
- }
340
- if (col.type === 'oid') {
341
- return this.renderCellEditObjectID(col, val);
342
- }
343
- if (col.type === 'numeric') {
344
- return this.renderCellEditNumber(col, val);
345
- }
346
-
347
- return this.renderCellEditString(col, val);
348
- }
349
-
350
- onChange(col: Column, oldValue: string | number | boolean, newValue: string | number | boolean): void {
351
- const editData = this.state.editData ? { ...this.state.editData } : {};
352
- if (newValue === oldValue) {
353
- delete editData[col.field];
354
- } else {
355
- editData[col.field] = newValue;
356
- }
357
- this.setState({ editData });
358
- }
359
-
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
- );
378
- }
379
-
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
- );
394
- }
395
-
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
- );
411
- }
412
-
413
- renderCellEditCustom(col: Column, val: any, item: Record<string, any>): JSX.Element | null {
414
- const EditComponent = col.editComponent;
415
-
416
- // use new value if exists
417
- if (this.state.editData && this.state.editData[col.field] !== undefined) {
418
- val = this.state.editData[col.field];
419
- item = JSON.parse(JSON.stringify(item));
420
- item[col.field] = val;
421
- }
422
-
423
- return EditComponent ? (
424
- <EditComponent
425
- value={val}
426
- rowData={item}
427
- onChange={(newVal: any) => this.onChange(col, val, newVal as string | number)}
428
- />
429
- ) : null;
430
- }
431
-
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' }}
442
- />
443
- );
444
- }
445
-
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 });
456
- }}
457
- open={this.state.showSelectColor}
458
- >
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
- );
495
- }
496
-
497
- renderSelectIdDialog(): JSX.Element | null {
498
- if (this.state.showSelectId && this.props.socket) {
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
- );
516
- }
517
-
518
- return null;
519
- }
520
-
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
- />
535
-
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
- );
548
- }
549
-
550
- static renderCellNonEdit(item: Record<string, any>, col: Column): JSX.Element | string | number | null {
551
- let val = getAttr(item, col.field, col.lookup);
552
- if (Array.isArray(val)) {
553
- val = val[0];
554
- }
555
-
556
- if (col.type === 'boolean') {
557
- return (
558
- <Checkbox
559
- checked={!!val}
560
- disabled
561
- inputProps={{ 'aria-label': 'checkbox' }}
562
- />
563
- );
564
- }
565
-
566
- return val;
567
- }
568
-
569
- renderCell(item: Record<string, any>, col: Column, level: number, i: number): JSX.Element {
570
- if (this.state.editMode === i && col.editable !== 'never' && col.editable !== false) {
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
583
- key={col.field}
584
- style={{ ...styles.cell, ...(level ? styles.cellSecondary : undefined), ...col.cellStyle }}
585
- component="th"
586
- >
587
- {TreeTable.renderCellNonEdit(item, col)}
588
- </TableCell>
589
- );
590
- }
591
-
592
- static renderCellWithSubField(item: Record<string, any>, col: Column): JSX.Element {
593
- const main = getAttr(item, col.field, col.lookup);
594
- if (col.subField) {
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
- );
602
- }
603
- return (
604
- <div>
605
- <div style={styles.mainText}>{main}</div>
606
- </div>
607
- );
608
- }
609
-
610
- renderLine(item: Record<string, any>, level?: number): JSX.Element | JSX.Element[] | null {
611
- const levelShift = this.props.levelShift === undefined ? 24 : this.props.levelShift;
612
-
613
- level = level || 0;
614
- const i = this.props.data.indexOf(item);
615
- if (!item) {
616
- return null;
617
- }
618
- if (!level && item.parentId) {
619
- return null;
620
- }
621
- if (level && !item.parentId) {
622
- return null; // should never happen
623
- }
624
- // try to find children
625
- const opened = this.state.opened.includes(item.id);
626
- const children = this.props.data.filter(it => it.parentId === item.id);
627
-
628
- const row = (
629
- <TableRow
630
- key={item.id}
631
- className={`table-row-${(item.id || '').toString().replace(/[.$]/g, '_')}`}
632
- style={{
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),
640
- }}
641
- >
642
- <TableCell
643
- style={{ ...styles.cell, ...styles.cellExpand, ...(level ? styles.cellSecondary : undefined) }}
644
- >
645
- {children.length ? (
646
- <IconButton
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"
665
- >
666
- {opened ? <IconCollapse /> : <IconExpand />}
667
- </IconButton>
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
- );
774
-
775
- if (!level && opened) {
776
- const items: JSX.Element[] = children.map(it => this.renderLine(it, level + 1)) as JSX.Element[];
777
- items.unshift(row);
778
- return items;
779
- }
780
- return row;
781
- }
782
-
783
- handleRequestSort(property: string): void {
784
- const isAsc = this.state.orderBy === property && this.state.order === 'asc';
785
- this.setState({ order: isAsc ? 'desc' : 'asc', orderBy: property });
786
- }
787
-
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
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
- }
812
- >
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)}
864
- >
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
- );
888
- }
889
-
890
- render(): JSX.Element | null {
891
- const col = this.props.columns.find(_col => _col.field === this.state.orderBy);
892
- if (col) {
893
- const lookup = col.lookup;
894
- const table = stableSort(this.props.data, getComparator(this.state.order, this.state.orderBy, lookup));
895
-
896
- if (this.state.update && this.state.update.length) {
897
- this.updateTimeout && clearTimeout(this.updateTimeout);
898
- this.updateTimeout = setTimeout(() => {
899
- this.updateTimeout = null;
900
- this.setState({ update: null });
901
- }, 500);
902
- }
903
-
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
- );
922
- }
923
-
924
- return null;
925
- }
926
- }
927
- /*
928
- const columns = [
929
- {
930
- title: 'Name of field', // required, else it will be "field"
931
- field: 'fieldIdInData', // required
932
- editable: false, // or true [default - true]
933
- cellStyle: { // CSS style - // optional
934
- maxWidth: '12rem',
935
- overflow: 'hidden',
936
- wordBreak: 'break-word'
937
- },
938
- lookup: { // optional => edit will be automatically "SELECT"
939
- 'value1': 'text1',
940
- 'value2': 'text2',
941
- }
942
- },
943
- {
944
- title: 'Type', // required, else it will be "field"
945
- field: 'myType', // required
946
- editable: true, // or true [default - true]
947
- lookup: { // optional => edit will be automatically "SELECT"
948
- 'number': 'Number',
949
- 'string': 'String',
950
- 'boolean': 'Boolean',
951
- },
952
- type: 'number/string/color/oid/icon/boolean', // oid=ObjectID,icon=base64-icon
953
- editComponent: props =>
954
- <div>Prefix&#123; <br/>
955
- <textarea
956
- rows={4}
957
- style={{width: '100%', resize: 'vertical'}}
958
- value={props.value}
959
- onChange={e => props.onChange(e.target.value)}
960
- />
961
- Suffix
962
- </div>,
963
- },
964
- ];
965
- */
966
- /* const data = [
967
- {
968
- id: 'UniqueID1' // required
969
- fieldIdInData: 'Name1',
970
- myType: 'number',
971
- },
972
- {
973
- id: 'UniqueID2' // required
974
- fieldIdInData: 'Name12',
975
- myType: 'string',
976
- },
977
- ];
978
- */
979
-
980
- /*
981
- // STYLES
982
- const styles = theme => ({
983
- tableDiv: {
984
- width: '100%',
985
- overflow: 'hidden',
986
- height: 'calc(100% - 48px)',
987
- },
988
- });
989
- // renderTable
990
- renderTable() {
991
- return <div style={styles.tableDiv}>
992
- <TreeTable
993
- columns={this.columns}
994
- data={lines}
995
- onUpdate={(newData, oldData) => console.log('Update: ' + JSON.stringify(newData))}
996
- onDelete={oldData => console.log('Delete: ' + JSON.stringify(oldData))}
997
- />
998
- </div>;
999
- }
1000
- */
1001
-
1002
- export default TreeTable;