@mwater/visualization 5.4.1 → 5.4.3

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 (273) hide show
  1. package/lib/ColorComponent.js +2 -1
  2. package/lib/IdSelection.d.ts +16 -0
  3. package/lib/IdSelection.js +59 -0
  4. package/lib/MWaterAddRelatedIndicatorComponent.js +2 -2
  5. package/lib/MWaterCompleteTableSelectComponent.d.ts +3 -8
  6. package/lib/MWaterCompleteTableSelectComponent.js +36 -42
  7. package/lib/MWaterLoaderComponent.d.ts +11 -10
  8. package/lib/MWaterLoaderComponent.js +1 -1
  9. package/lib/MWaterResponsesFilterComponent.js +1 -1
  10. package/lib/MWaterTableSelectComponent.d.ts +0 -1
  11. package/lib/MWaterTableSelectComponent.js +4 -6
  12. package/lib/autotranslate.d.ts +20 -0
  13. package/lib/autotranslate.js +122 -0
  14. package/lib/axes/AxisBuilder.js +3 -3
  15. package/lib/axes/AxisColorEditorComponent.js +4 -0
  16. package/lib/axes/AxisComponent.d.ts +8 -12
  17. package/lib/axes/AxisComponent.js +32 -80
  18. package/lib/axes/CategoryMapComponent.js +4 -4
  19. package/lib/axes/RangesComponent.js +2 -2
  20. package/lib/dashboards/DashboardComponent.d.ts +12 -20
  21. package/lib/dashboards/DashboardComponent.js +109 -69
  22. package/lib/dashboards/DashboardDesign.d.ts +11 -2
  23. package/lib/dashboards/DashboardUtils.d.ts +5 -0
  24. package/lib/dashboards/DashboardUtils.js +30 -0
  25. package/lib/dashboards/DashboardViewComponent.d.ts +2 -0
  26. package/lib/dashboards/DashboardViewComponent.js +16 -3
  27. package/lib/dashboards/ServerDashboardDataSource.js +2 -1
  28. package/lib/dashboards/SettingsModalComponent.d.ts +1 -1
  29. package/lib/dashboards/SettingsModalComponent.js +256 -19
  30. package/lib/dashboards/WidgetComponent.d.ts +6 -3
  31. package/lib/dashboards/WidgetComponent.js +3 -1
  32. package/lib/datagrids/CellEditor.d.ts +19 -0
  33. package/lib/datagrids/CellEditor.js +223 -0
  34. package/lib/datagrids/DatagridComponent.d.ts +18 -87
  35. package/lib/datagrids/DatagridComponent.js +304 -222
  36. package/lib/datagrids/DatagridViewComponent.d.ts +15 -53
  37. package/lib/datagrids/DatagridViewComponent.js +256 -257
  38. package/lib/datagrids/DirectDatagridDataSource.js +2 -3
  39. package/lib/datagrids/ExprCellComponent.d.ts +8 -15
  40. package/lib/datagrids/ExprCellComponent.js +11 -15
  41. package/lib/datagrids/FindReplaceModalComponent.d.ts +4 -6
  42. package/lib/datagrids/FindReplaceModalComponent.js +38 -75
  43. package/lib/index.css +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -1
  46. package/lib/languages.js +6 -1
  47. package/lib/layouts/blocks/HorizontalBlockComponent.js +2 -2
  48. package/lib/mWaterLoader.d.ts +1 -1
  49. package/lib/maps/BufferLayer.d.ts +7 -5
  50. package/lib/maps/BufferLayer.js +69 -48
  51. package/lib/maps/BufferLayerDesign.d.ts +21 -14
  52. package/lib/maps/BufferLayerDesignerComponent.d.ts +16 -31
  53. package/lib/maps/BufferLayerDesignerComponent.js +68 -102
  54. package/lib/maps/ChoroplethLayer.d.ts +5 -4
  55. package/lib/maps/ChoroplethLayer.js +32 -9
  56. package/lib/maps/ChoroplethLayerDesign.d.ts +6 -2
  57. package/lib/maps/ChoroplethLayerDesigner.js +4 -2
  58. package/lib/maps/ClusterLayer.d.ts +3 -4
  59. package/lib/maps/ClusterLayer.js +2 -1
  60. package/lib/maps/DetailLevelSelectComponent.js +1 -1
  61. package/lib/maps/DirectMapDataSource.js +2 -1
  62. package/lib/maps/EditPopupComponent.js +5 -3
  63. package/lib/maps/GridLayer.d.ts +3 -4
  64. package/lib/maps/GridLayer.js +2 -1
  65. package/lib/maps/GridLayerDesigner.js +5 -3
  66. package/lib/maps/HoverContent.d.ts +11 -3
  67. package/lib/maps/HoverContent.js +25 -9
  68. package/lib/maps/Layer.d.ts +24 -3
  69. package/lib/maps/Layer.js +5 -1
  70. package/lib/maps/LayerFactory.js +0 -8
  71. package/lib/maps/LayerLegendComponent.js +0 -1
  72. package/lib/maps/LayerSwitcherComponent.d.ts +1 -0
  73. package/lib/maps/LayerSwitcherComponent.js +1 -1
  74. package/lib/maps/LeafletMapComponent.js +3 -1
  75. package/lib/maps/LegendComponent.d.ts +1 -0
  76. package/lib/maps/LegendComponent.js +9 -1
  77. package/lib/maps/MWaterServerLayer.d.ts +2 -2
  78. package/lib/maps/MWaterServerLayer.js +2 -2
  79. package/lib/maps/MapComponent.js +3 -3
  80. package/lib/maps/MapDesign.d.ts +2 -0
  81. package/lib/maps/MapDesignerComponent.d.ts +4 -3
  82. package/lib/maps/MapDesignerComponent.js +68 -74
  83. package/lib/maps/MapLayerViewDesignerComponent.js +2 -2
  84. package/lib/maps/MapUtils.d.ts +4 -0
  85. package/lib/maps/MapUtils.js +19 -0
  86. package/lib/maps/MapViewComponent.d.ts +8 -3
  87. package/lib/maps/MarkersLayer.d.ts +5 -4
  88. package/lib/maps/MarkersLayer.js +33 -7
  89. package/lib/maps/MarkersLayerDesign.d.ts +19 -16
  90. package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -3
  91. package/lib/maps/PopupFilterJoinsUtils.js +0 -6
  92. package/lib/maps/RasterMapViewComponent.d.ts +3 -31
  93. package/lib/maps/RasterMapViewComponent.js +7 -2
  94. package/lib/maps/ServerMapDataSource.js +2 -1
  95. package/lib/maps/SwitchableTileUrlLayer.d.ts +3 -3
  96. package/lib/maps/SwitchableTileUrlLayer.js +2 -1
  97. package/lib/maps/TileUrlLayer.d.ts +4 -5
  98. package/lib/maps/TileUrlLayer.js +2 -1
  99. package/lib/maps/VectorMapViewComponent.d.ts +5 -37
  100. package/lib/maps/VectorMapViewComponent.js +19 -8
  101. package/lib/maps/maps.d.ts +3 -0
  102. package/lib/quickfilter/Quickfilter.d.ts +2 -0
  103. package/lib/quickfilter/QuickfiltersComponent.d.ts +2 -0
  104. package/lib/quickfilter/QuickfiltersComponent.js +9 -7
  105. package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +5 -30
  106. package/lib/quickfilter/QuickfiltersDesignComponent.js +56 -63
  107. package/lib/richtext/ExprItemsHtmlConverter.d.ts +5 -2
  108. package/lib/richtext/ExprItemsHtmlConverter.js +4 -4
  109. package/lib/richtext/ExprItemsTranslator.d.ts +5 -0
  110. package/lib/richtext/ExprItemsTranslator.js +149 -0
  111. package/lib/richtext/ItemsHtmlConverter.d.ts +1 -1
  112. package/lib/richtext/ItemsHtmlConverter.js +31 -15
  113. package/lib/wellknown.js +12 -9
  114. package/lib/widgets/IFrameWidget.d.ts +4 -4
  115. package/lib/widgets/ImageWidget.d.ts +7 -4
  116. package/lib/widgets/ImageWidget.js +9 -1
  117. package/lib/widgets/ImageWidgetComponent.d.ts +1 -0
  118. package/lib/widgets/ImageWidgetComponent.js +1 -1
  119. package/lib/widgets/MapWidget.d.ts +5 -48
  120. package/lib/widgets/MapWidget.js +26 -63
  121. package/lib/widgets/MarkdownWidget.d.ts +3 -0
  122. package/lib/widgets/MarkdownWidget.js +3 -0
  123. package/lib/widgets/TOCWidget.d.ts +15 -27
  124. package/lib/widgets/TOCWidget.js +107 -183
  125. package/lib/widgets/Widget.d.ts +18 -7
  126. package/lib/widgets/Widget.js +4 -0
  127. package/lib/widgets/WidgetScopesViewComponent.js +1 -1
  128. package/lib/widgets/charts/Chart.d.ts +10 -1
  129. package/lib/widgets/charts/Chart.js +22 -11
  130. package/lib/widgets/charts/ChartViewComponent.d.ts +4 -0
  131. package/lib/widgets/charts/ChartViewComponent.js +6 -3
  132. package/lib/widgets/charts/ChartWidget.d.ts +2 -0
  133. package/lib/widgets/charts/ChartWidget.js +9 -1
  134. package/lib/widgets/charts/ChartWidgetComponent.d.ts +4 -0
  135. package/lib/widgets/charts/ChartWidgetComponent.js +2 -2
  136. package/lib/widgets/charts/calendar/CalendarChart.d.ts +1 -0
  137. package/lib/widgets/charts/calendar/CalendarChart.js +26 -0
  138. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +3 -1
  139. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -0
  140. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +8 -0
  141. package/lib/widgets/charts/layered/LayeredChart.d.ts +2 -0
  142. package/lib/widgets/charts/layered/LayeredChart.js +63 -3
  143. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +1 -1
  144. package/lib/widgets/charts/layered/LayeredChartCompiler.js +1 -1
  145. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +2 -2
  146. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +8 -3
  147. package/lib/widgets/charts/pivot/PivotChart.d.ts +1 -0
  148. package/lib/widgets/charts/pivot/PivotChart.js +63 -0
  149. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +1 -1
  150. package/lib/widgets/charts/pivot/SegmentDesignerComponent.js +7 -4
  151. package/lib/widgets/charts/table/OrderingsComponent.js +1 -1
  152. package/lib/widgets/charts/table/TableChart.d.ts +1 -0
  153. package/lib/widgets/charts/table/TableChart.js +15 -0
  154. package/lib/widgets/text/TextComponent.d.ts +11 -4
  155. package/lib/widgets/text/TextComponent.js +11 -8
  156. package/lib/widgets/text/TextWidget.d.ts +6 -3
  157. package/lib/widgets/text/TextWidget.js +7 -1
  158. package/lib/widgets/text/TextWidgetComponent.d.ts +4 -0
  159. package/lib/widgets/text/TextWidgetComponent.js +7 -1
  160. package/lib/widgets/text/TextWidgetDesign.d.ts +2 -4
  161. package/lib/widgets/text/TextWidgetDesign.js +1 -1
  162. package/package.json +7 -8
  163. package/src/ColorComponent.tsx +1 -2
  164. package/src/IdSelection.ts +62 -0
  165. package/src/MWaterAddRelatedIndicatorComponent.ts +3 -2
  166. package/src/MWaterCompleteTableSelectComponent.tsx +36 -46
  167. package/src/MWaterLoaderComponent.ts +28 -26
  168. package/src/MWaterResponsesFilterComponent.ts +5 -2
  169. package/src/MWaterTableSelectComponent.tsx +5 -9
  170. package/src/autotranslate.ts +141 -0
  171. package/src/axes/AxisBuilder.ts +3 -3
  172. package/src/axes/AxisColorEditorComponent.tsx +5 -0
  173. package/src/axes/{AxisComponent.ts → AxisComponent.tsx} +106 -106
  174. package/src/axes/CategoryMapComponent.ts +4 -4
  175. package/src/axes/RangesComponent.ts +3 -2
  176. package/src/dashboards/DashboardComponent.tsx +189 -125
  177. package/src/dashboards/DashboardDesign.ts +9 -2
  178. package/src/dashboards/DashboardUtils.ts +39 -0
  179. package/src/dashboards/DashboardViewComponent.tsx +22 -3
  180. package/src/dashboards/ServerDashboardDataSource.ts +2 -1
  181. package/src/dashboards/SettingsModalComponent.tsx +450 -35
  182. package/src/dashboards/WidgetComponent.tsx +12 -6
  183. package/src/datagrids/CellEditor.tsx +354 -0
  184. package/src/datagrids/DatagridComponent.tsx +646 -0
  185. package/src/datagrids/DatagridViewComponent.tsx +539 -0
  186. package/src/datagrids/DirectDatagridDataSource.ts +2 -3
  187. package/src/datagrids/{ExprCellComponent.ts → ExprCellComponent.tsx} +28 -23
  188. package/src/datagrids/{FindReplaceModalComponent.ts → FindReplaceModalComponent.tsx} +109 -122
  189. package/src/index.css +1 -1
  190. package/src/index.ts +0 -1
  191. package/src/languages.ts +6 -1
  192. package/src/layouts/blocks/HorizontalBlockComponent.ts +2 -2
  193. package/src/mWaterLoader.ts +1 -1
  194. package/src/maps/BufferLayer.ts +83 -60
  195. package/src/maps/BufferLayerDesign.ts +20 -14
  196. package/src/maps/BufferLayerDesignerComponent.tsx +309 -0
  197. package/src/maps/ChoroplethLayer.ts +40 -19
  198. package/src/maps/ChoroplethLayerDesign.ts +4 -2
  199. package/src/maps/ChoroplethLayerDesigner.tsx +4 -2
  200. package/src/maps/ClusterLayer.ts +4 -10
  201. package/src/maps/DetailLevelSelectComponent.ts +1 -1
  202. package/src/maps/DirectMapDataSource.ts +2 -1
  203. package/src/maps/EditPopupComponent.ts +7 -3
  204. package/src/maps/GridLayer.ts +4 -10
  205. package/src/maps/GridLayerDesigner.tsx +5 -3
  206. package/src/maps/HoverContent.tsx +40 -16
  207. package/src/maps/Layer.ts +28 -10
  208. package/src/maps/LayerFactory.ts +0 -8
  209. package/src/maps/LayerLegendComponent.ts +2 -4
  210. package/src/maps/LayerSwitcherComponent.tsx +6 -2
  211. package/src/maps/LeafletMapComponent.tsx +3 -1
  212. package/src/maps/LegendComponent.tsx +10 -1
  213. package/src/maps/MWaterServerLayer.ts +3 -3
  214. package/src/maps/MapComponent.ts +3 -3
  215. package/src/maps/MapDesign.ts +3 -0
  216. package/src/maps/MapDesignerComponent.tsx +165 -162
  217. package/src/maps/MapLayerViewDesignerComponent.ts +2 -2
  218. package/src/maps/MapUtils.ts +24 -0
  219. package/src/maps/MapViewComponent.tsx +11 -3
  220. package/src/maps/MarkersLayer.ts +44 -18
  221. package/src/maps/MarkersLayerDesign.ts +19 -16
  222. package/src/maps/PopupFilterJoinsUtils.ts +6 -2
  223. package/src/maps/RasterMapViewComponent.ts +9 -45
  224. package/src/maps/ServerMapDataSource.ts +2 -2
  225. package/src/maps/SwitchableTileUrlLayer.tsx +4 -10
  226. package/src/maps/TileUrlLayer.tsx +4 -10
  227. package/src/maps/VectorMapViewComponent.tsx +28 -55
  228. package/src/maps/maps.ts +3 -0
  229. package/src/quickfilter/Quickfilter.ts +3 -0
  230. package/src/quickfilter/QuickfiltersComponent.ts +13 -7
  231. package/src/quickfilter/QuickfiltersDesignComponent.tsx +127 -128
  232. package/src/richtext/ExprItemsHtmlConverter.ts +9 -5
  233. package/src/richtext/ExprItemsTranslator.ts +176 -0
  234. package/src/richtext/ItemsHtmlConverter.ts +33 -18
  235. package/src/wellknown.ts +33 -30
  236. package/src/widgets/ImageWidget.ts +10 -1
  237. package/src/widgets/ImageWidgetComponent.ts +3 -2
  238. package/src/widgets/{MapWidget.ts → MapWidget.tsx} +90 -101
  239. package/src/widgets/MarkdownWidget.ts +3 -0
  240. package/src/widgets/TOCWidget.tsx +281 -0
  241. package/src/widgets/Widget.ts +25 -5
  242. package/src/widgets/WidgetScopesViewComponent.ts +2 -1
  243. package/src/widgets/charts/Chart.ts +31 -12
  244. package/src/widgets/charts/ChartViewComponent.ts +13 -3
  245. package/src/widgets/charts/ChartWidget.ts +11 -1
  246. package/src/widgets/charts/ChartWidgetComponent.tsx +9 -1
  247. package/src/widgets/charts/calendar/CalendarChart.ts +29 -0
  248. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +3 -1
  249. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +9 -0
  250. package/src/widgets/charts/layered/LayeredChart.ts +71 -3
  251. package/src/widgets/charts/layered/LayeredChartCompiler.ts +2 -2
  252. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +4 -2
  253. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +10 -4
  254. package/src/widgets/charts/pivot/PivotChart.ts +73 -0
  255. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +1 -1
  256. package/src/widgets/charts/pivot/SegmentDesignerComponent.tsx +6 -4
  257. package/src/widgets/charts/table/OrderingsComponent.tsx +2 -1
  258. package/src/widgets/charts/table/TableChart.ts +17 -0
  259. package/src/widgets/text/TextComponent.tsx +22 -12
  260. package/src/widgets/text/TextWidget.ts +9 -2
  261. package/src/widgets/text/TextWidgetComponent.tsx +16 -1
  262. package/src/widgets/text/TextWidgetDesign.ts +4 -7
  263. package/test/IdSelectionTests.ts +54 -0
  264. package/test/LayeredChartCompilerTests.ts +0 -2
  265. package/test/richtext/ExprItemsTranslatorTests.ts +144 -0
  266. package/test/wellknownTests.ts +144 -0
  267. package/src/datagrids/DatagridComponent.ts +0 -478
  268. package/src/datagrids/DatagridViewComponent.ts +0 -464
  269. package/src/datagrids/EditExprCellComponent.tsx +0 -305
  270. package/src/datagrids/README.md +0 -3
  271. package/src/maps/BufferLayerDesignerComponent.ts +0 -311
  272. package/src/widgets/TOCWidget.ts +0 -326
  273. package/test/LegoLayoutEngineTests.ts +0 -69
@@ -0,0 +1,354 @@
1
+ import _ from "lodash"
2
+ import React, { useState, ChangeEvent, useCallback } from "react"
3
+ import { EnumValue, LiteralType, ExprUtils, Schema, DataSource } from "@mwater/expressions"
4
+ import { RenderCellEditorProps } from "@mwater/react-library/lib/GridComponent"
5
+ import ReactSelect from "react-select"
6
+ import DatePicker from "react-datepicker"
7
+ import "react-datepicker/dist/react-datepicker.css"
8
+ import moment, { Moment } from "moment"
9
+ import { IdLiteralComponent } from "@mwater/expressions-ui"
10
+
11
+ /** Determine if type can be edited */
12
+ export function canEditType(type: LiteralType) {
13
+ return ["text", "number", "enum", "enumset", "boolean", "date", "datetime", "id", "id[]"].includes(type)
14
+ }
15
+
16
+ /** Cell editor for a cell of the grid */
17
+ export const CellEditor = (props: {
18
+ type: LiteralType
19
+ enumValues?: EnumValue[]
20
+ idTable?: string
21
+ initialValue: any
22
+ editorOptions: RenderCellEditorProps
23
+ /** Update the cell value. Returns true if successful, false if cancelled */
24
+ updateCellValue: (value: any) => Promise<boolean>
25
+ locale?: string
26
+ schema: Schema
27
+ dataSource: DataSource
28
+ }) => {
29
+ const editorOptions = props.editorOptions
30
+ const [value, setValue] = useState(props.initialValue)
31
+ const [valid, setValid] = useState(true)
32
+
33
+ // Hook save function
34
+ editorOptions.setSaveEdit(() => {
35
+ if (!valid) {
36
+ return Promise.resolve(false)
37
+ }
38
+ if (value == props.initialValue) {
39
+ return Promise.resolve(true)
40
+ }
41
+ return props.updateCellValue(value)
42
+ })
43
+
44
+ if (editorOptions.saving) {
45
+ return (
46
+ <div style={{ backgroundColor: "#EEE", width: editorOptions.width, height: editorOptions.height, padding: 10 }}>
47
+ <i className="fa fa-spinner fa-spin" />
48
+ </div>
49
+ )
50
+ }
51
+
52
+ if (props.type == "text") {
53
+ return (
54
+ <input
55
+ type="text"
56
+ value={value || ""}
57
+ className="form-control"
58
+ onChange={(ev) => {
59
+ setValue(ev.target.value || null)
60
+ }}
61
+ onKeyDown={(ev) => {
62
+ if (ev.keyCode == 13) {
63
+ editorOptions.onEndEdit()
64
+ }
65
+ }}
66
+ style={{ height: editorOptions.height }}
67
+ ref={(node) => {
68
+ if (node) {
69
+ setTimeout(() => {
70
+ if (node) {
71
+ node.focus()
72
+ }
73
+ }, 0)
74
+ }
75
+ }}
76
+ />
77
+ )
78
+ }
79
+
80
+ if (props.type == "number") {
81
+ return (
82
+ <NumberInput
83
+ value={value}
84
+ onChange={setValue}
85
+ onValid={setValid}
86
+ height={editorOptions.height}
87
+ onEnter={editorOptions.onEndEdit}
88
+ />
89
+ )
90
+ }
91
+
92
+ if (props.type == "enum") {
93
+ return <EnumEditor value={value} onChange={setValue} enumValues={props.enumValues!} locale={props.locale} />
94
+ }
95
+
96
+ if (props.type == "enumset") {
97
+ return <EnumsetEditor value={value} onChange={setValue} enumValues={props.enumValues!} locale={props.locale} />
98
+ }
99
+
100
+ if (props.type == "boolean") {
101
+ return <BooleanEditor value={value} onChange={setValue} />
102
+ }
103
+
104
+ if (props.type == "date") {
105
+ return <DateEditor value={value} onChange={setValue} locale={props.locale} />
106
+ }
107
+
108
+ if (props.type == "datetime") {
109
+ return <DatetimeEditor value={value} onChange={setValue} locale={props.locale} />
110
+ }
111
+
112
+ if (props.type == "id") {
113
+ return (
114
+ <IdLiteralComponent
115
+ schema={props.schema}
116
+ dataSource={props.dataSource}
117
+ idTable={props.idTable!}
118
+ value={value}
119
+ onChange={setValue}
120
+ />
121
+ )
122
+ }
123
+
124
+ if (props.type == "id[]") {
125
+ return (
126
+ <IdLiteralComponent
127
+ schema={props.schema}
128
+ dataSource={props.dataSource}
129
+ idTable={props.idTable!}
130
+ value={value}
131
+ onChange={setValue}
132
+ multi
133
+ />
134
+ )
135
+ }
136
+
137
+ // if (props.type == "geometry") {
138
+ // const str = value.type == "Point" ? `${value.coordinates[1].toFixed(6)} ${value.coordinates[0].toFixed(6)}` : value.type
139
+ // return <div className="custom-table-grid-cell-text">
140
+ // { str }
141
+ // </div>
142
+ // }
143
+
144
+ // TODO
145
+ // text[]
146
+ // image
147
+ // imagelist
148
+ // json
149
+
150
+ return <div />
151
+ }
152
+
153
+ /** Number input that calls onChange when number is valid and updates valid status */
154
+ const NumberInput = (props: {
155
+ value: number | null
156
+ height: number
157
+ onChange: (value: number | null) => void
158
+ onValid: (valid: boolean) => void
159
+ onEnter: () => void
160
+ }) => {
161
+ const [str, setStr] = useState(props.value != null ? props.value + "" : "")
162
+
163
+ const handleChange = (ev: ChangeEvent<HTMLInputElement>) => {
164
+ const text = ev.target.value
165
+ setStr(text)
166
+ if (!text) {
167
+ props.onChange(null)
168
+ props.onValid(true)
169
+ } else {
170
+ const num = parseFloat(text)
171
+ if (!isNaN(num)) {
172
+ props.onChange(num)
173
+ props.onValid(true)
174
+ } else {
175
+ props.onValid(false)
176
+ }
177
+ }
178
+ }
179
+
180
+ return (
181
+ <input
182
+ type="number"
183
+ value={str}
184
+ className="form-control"
185
+ onChange={handleChange}
186
+ style={{ height: props.height }}
187
+ onKeyDown={(ev) => {
188
+ if (ev.keyCode == 13) {
189
+ props.onEnter()
190
+ }
191
+ }}
192
+ ref={(node) => {
193
+ if (node) {
194
+ setTimeout(() => {
195
+ if (node) {
196
+ node.focus()
197
+ }
198
+ }, 0)
199
+ }
200
+ }}
201
+ />
202
+ )
203
+ }
204
+
205
+ /** Editor for an enum value */
206
+ const EnumEditor = (props: {
207
+ value: any
208
+ onChange: (value: any) => void
209
+ enumValues: EnumValue[]
210
+ locale?: string
211
+ }) => {
212
+ const options = props.enumValues.map((v) => ({ label: ExprUtils.localizeString(v.name, props.locale), value: v.id }))
213
+ return (
214
+ <ReactSelect
215
+ options={options}
216
+ isClearable={true}
217
+ onChange={(opt: any) => props.onChange(opt ? (opt as any).value : null)}
218
+ value={options.find((opt: any) => opt.value == props.value) || null}
219
+ styles={{
220
+ // Keep menu above modal
221
+ menu: (style) => ({ ...style, zIndex: 2000 })
222
+ }}
223
+ ref={(node) => {
224
+ if (node) {
225
+ setTimeout(() => {
226
+ if (node) {
227
+ node.focus()
228
+ }
229
+ }, 0)
230
+ }
231
+ }}
232
+ />
233
+ )
234
+ }
235
+
236
+ /** Editor for an enumset value */
237
+ const EnumsetEditor = (props: {
238
+ value: any
239
+ onChange: (value: any) => void
240
+ enumValues: EnumValue[]
241
+ locale?: string
242
+ }) => {
243
+ const options = props.enumValues.map((v) => ({ label: ExprUtils.localizeString(v.name, props.locale), value: v.id }))
244
+
245
+ const value = _.map(props.value || [], (v) => _.find(options, (o) => o.value == v)) || []
246
+
247
+ return (
248
+ <ReactSelect
249
+ options={options}
250
+ isClearable={true}
251
+ isMulti={true}
252
+ onChange={(opt: any) => {
253
+ props.onChange(opt && opt.length > 0 ? _.pluck(opt, "value") : null)
254
+ }}
255
+ value={value as any}
256
+ styles={{
257
+ // Keep menu above modal
258
+ menu: (style) => ({ ...style, zIndex: 2000 })
259
+ }}
260
+ ref={(node) => {
261
+ if (node) {
262
+ setTimeout(() => {
263
+ if (node) {
264
+ node.focus()
265
+ }
266
+ }, 0)
267
+ }
268
+ }}
269
+ />
270
+ )
271
+ }
272
+
273
+ /** Editor for a boolean value */
274
+ const BooleanEditor = (props: { value: any; onChange: (value: any) => void }) => {
275
+ const options = [
276
+ { label: T`True`, value: true },
277
+ { label: T`False`, value: false }
278
+ ]
279
+
280
+ return (
281
+ <ReactSelect
282
+ options={options}
283
+ isClearable={true}
284
+ onChange={(opt: any) => props.onChange(opt ? (opt as any).value : null)}
285
+ value={options.find((opt) => opt.value == props.value) || null}
286
+ styles={{
287
+ // Keep menu above modal
288
+ menu: (style) => ({ ...style, zIndex: 2000 })
289
+ }}
290
+ ref={(node) => {
291
+ if (node) {
292
+ setTimeout(() => {
293
+ if (node) {
294
+ node.focus()
295
+ }
296
+ }, 0)
297
+ }
298
+ }}
299
+ />
300
+ )
301
+ }
302
+
303
+ /** Editor for a date */
304
+ const DateEditor = (props: { value: any; onChange: (value: any) => void; locale?: string }) => {
305
+ const momentDate = props.value ? moment(props.value, "YYYY-MM-DD") : null
306
+
307
+ const handleChange = useCallback(
308
+ (value: Moment) => {
309
+ props.onChange(value ? value.format("YYYY-MM-DD") : null)
310
+ },
311
+ [props.onChange]
312
+ )
313
+
314
+ return (
315
+ <div style={{ padding: 2 }}>
316
+ <DatePicker
317
+ isClearable={true}
318
+ selected={momentDate}
319
+ onChange={handleChange}
320
+ dateFormat="YYYY-MM-DD"
321
+ className="form-control"
322
+ locale={props.locale}
323
+ />
324
+ </div>
325
+ )
326
+ }
327
+
328
+ /** Editor for a date */
329
+ const DatetimeEditor = (props: { value: any; onChange: (value: any) => void; locale?: string }) => {
330
+ const momentDate = props.value ? moment(props.value, moment.ISO_8601) : null
331
+
332
+ const handleChange = useCallback(
333
+ (value: Moment) => {
334
+ props.onChange(value ? value.toISOString() : null)
335
+ },
336
+ [props.onChange]
337
+ )
338
+
339
+ return (
340
+ <div style={{ padding: 2 }}>
341
+ <DatePicker
342
+ fixedHeight={true}
343
+ isClearable={true}
344
+ selected={momentDate}
345
+ onChange={handleChange}
346
+ dateFormat="YYYY-MM-DD HH:mm"
347
+ className="form-control"
348
+ showTimeSelect={true}
349
+ timeFormat="HH:mm"
350
+ locale={props.locale}
351
+ />
352
+ </div>
353
+ )
354
+ }