@mwater/visualization 5.4.0 → 5.4.2

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 (271) 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 +6 -0
  21. package/lib/dashboards/DashboardComponent.js +44 -12
  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/layouts/blocks/HorizontalBlockComponent.js +2 -2
  47. package/lib/mWaterLoader.d.ts +1 -1
  48. package/lib/maps/BufferLayer.d.ts +7 -5
  49. package/lib/maps/BufferLayer.js +69 -48
  50. package/lib/maps/BufferLayerDesign.d.ts +21 -14
  51. package/lib/maps/BufferLayerDesignerComponent.d.ts +16 -31
  52. package/lib/maps/BufferLayerDesignerComponent.js +68 -102
  53. package/lib/maps/ChoroplethLayer.d.ts +5 -4
  54. package/lib/maps/ChoroplethLayer.js +32 -9
  55. package/lib/maps/ChoroplethLayerDesign.d.ts +6 -2
  56. package/lib/maps/ChoroplethLayerDesigner.js +4 -2
  57. package/lib/maps/ClusterLayer.d.ts +3 -4
  58. package/lib/maps/ClusterLayer.js +2 -1
  59. package/lib/maps/DetailLevelSelectComponent.js +1 -1
  60. package/lib/maps/DirectMapDataSource.js +2 -1
  61. package/lib/maps/EditPopupComponent.js +5 -3
  62. package/lib/maps/GridLayer.d.ts +3 -4
  63. package/lib/maps/GridLayer.js +2 -1
  64. package/lib/maps/GridLayerDesigner.js +5 -3
  65. package/lib/maps/HoverContent.d.ts +11 -3
  66. package/lib/maps/HoverContent.js +25 -9
  67. package/lib/maps/Layer.d.ts +24 -3
  68. package/lib/maps/Layer.js +5 -1
  69. package/lib/maps/LayerFactory.js +0 -8
  70. package/lib/maps/LayerLegendComponent.js +0 -1
  71. package/lib/maps/LayerSwitcherComponent.d.ts +1 -0
  72. package/lib/maps/LayerSwitcherComponent.js +1 -1
  73. package/lib/maps/LeafletMapComponent.js +3 -1
  74. package/lib/maps/LegendComponent.d.ts +1 -0
  75. package/lib/maps/LegendComponent.js +9 -1
  76. package/lib/maps/MWaterServerLayer.d.ts +2 -2
  77. package/lib/maps/MWaterServerLayer.js +2 -2
  78. package/lib/maps/MapComponent.js +3 -3
  79. package/lib/maps/MapDesign.d.ts +2 -0
  80. package/lib/maps/MapDesignerComponent.d.ts +4 -3
  81. package/lib/maps/MapDesignerComponent.js +68 -74
  82. package/lib/maps/MapLayerViewDesignerComponent.js +2 -2
  83. package/lib/maps/MapUtils.d.ts +4 -0
  84. package/lib/maps/MapUtils.js +19 -0
  85. package/lib/maps/MapViewComponent.d.ts +8 -3
  86. package/lib/maps/MarkersLayer.d.ts +5 -4
  87. package/lib/maps/MarkersLayer.js +33 -7
  88. package/lib/maps/MarkersLayerDesign.d.ts +19 -16
  89. package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -3
  90. package/lib/maps/PopupFilterJoinsUtils.js +0 -6
  91. package/lib/maps/RasterMapViewComponent.d.ts +3 -31
  92. package/lib/maps/RasterMapViewComponent.js +7 -2
  93. package/lib/maps/ServerMapDataSource.js +2 -1
  94. package/lib/maps/SwitchableTileUrlLayer.d.ts +3 -3
  95. package/lib/maps/SwitchableTileUrlLayer.js +2 -1
  96. package/lib/maps/TileUrlLayer.d.ts +4 -5
  97. package/lib/maps/TileUrlLayer.js +2 -1
  98. package/lib/maps/VectorMapViewComponent.d.ts +5 -37
  99. package/lib/maps/VectorMapViewComponent.js +19 -8
  100. package/lib/maps/maps.d.ts +3 -0
  101. package/lib/quickfilter/QuickfiltersComponent.d.ts +2 -0
  102. package/lib/quickfilter/QuickfiltersComponent.js +9 -7
  103. package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +1 -1
  104. package/lib/quickfilter/QuickfiltersDesignComponent.js +19 -35
  105. package/lib/richtext/ExprItemsHtmlConverter.d.ts +5 -2
  106. package/lib/richtext/ExprItemsHtmlConverter.js +4 -4
  107. package/lib/richtext/ExprItemsTranslator.d.ts +5 -0
  108. package/lib/richtext/ExprItemsTranslator.js +149 -0
  109. package/lib/richtext/ItemsHtmlConverter.d.ts +1 -1
  110. package/lib/richtext/ItemsHtmlConverter.js +31 -15
  111. package/lib/wellknown.js +12 -9
  112. package/lib/widgets/IFrameWidget.d.ts +4 -4
  113. package/lib/widgets/ImageWidget.d.ts +7 -4
  114. package/lib/widgets/ImageWidget.js +9 -1
  115. package/lib/widgets/ImageWidgetComponent.d.ts +1 -0
  116. package/lib/widgets/ImageWidgetComponent.js +1 -1
  117. package/lib/widgets/MapWidget.d.ts +5 -48
  118. package/lib/widgets/MapWidget.js +26 -63
  119. package/lib/widgets/MarkdownWidget.d.ts +3 -0
  120. package/lib/widgets/MarkdownWidget.js +3 -0
  121. package/lib/widgets/TOCWidget.d.ts +15 -27
  122. package/lib/widgets/TOCWidget.js +107 -183
  123. package/lib/widgets/Widget.d.ts +18 -7
  124. package/lib/widgets/Widget.js +4 -0
  125. package/lib/widgets/WidgetScopesViewComponent.js +1 -1
  126. package/lib/widgets/charts/Chart.d.ts +10 -1
  127. package/lib/widgets/charts/Chart.js +22 -11
  128. package/lib/widgets/charts/ChartViewComponent.d.ts +4 -0
  129. package/lib/widgets/charts/ChartViewComponent.js +6 -3
  130. package/lib/widgets/charts/ChartWidget.d.ts +2 -0
  131. package/lib/widgets/charts/ChartWidget.js +9 -1
  132. package/lib/widgets/charts/ChartWidgetComponent.d.ts +4 -0
  133. package/lib/widgets/charts/ChartWidgetComponent.js +2 -2
  134. package/lib/widgets/charts/calendar/CalendarChart.d.ts +1 -0
  135. package/lib/widgets/charts/calendar/CalendarChart.js +26 -0
  136. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +3 -1
  137. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -0
  138. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +8 -0
  139. package/lib/widgets/charts/layered/LayeredChart.d.ts +2 -0
  140. package/lib/widgets/charts/layered/LayeredChart.js +63 -3
  141. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +1 -1
  142. package/lib/widgets/charts/layered/LayeredChartCompiler.js +3 -3
  143. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +2 -2
  144. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +8 -3
  145. package/lib/widgets/charts/pivot/PivotChart.d.ts +1 -0
  146. package/lib/widgets/charts/pivot/PivotChart.js +63 -0
  147. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.d.ts +1 -0
  148. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +1 -1
  149. package/lib/widgets/charts/pivot/SegmentDesignerComponent.d.ts +6 -0
  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 +79 -14
  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/layouts/blocks/HorizontalBlockComponent.ts +2 -2
  192. package/src/mWaterLoader.ts +1 -1
  193. package/src/maps/BufferLayer.ts +83 -60
  194. package/src/maps/BufferLayerDesign.ts +20 -14
  195. package/src/maps/BufferLayerDesignerComponent.tsx +309 -0
  196. package/src/maps/ChoroplethLayer.ts +40 -19
  197. package/src/maps/ChoroplethLayerDesign.ts +4 -2
  198. package/src/maps/ChoroplethLayerDesigner.tsx +4 -2
  199. package/src/maps/ClusterLayer.ts +4 -10
  200. package/src/maps/DetailLevelSelectComponent.ts +1 -1
  201. package/src/maps/DirectMapDataSource.ts +2 -1
  202. package/src/maps/EditPopupComponent.ts +7 -3
  203. package/src/maps/GridLayer.ts +4 -10
  204. package/src/maps/GridLayerDesigner.tsx +5 -3
  205. package/src/maps/HoverContent.tsx +40 -16
  206. package/src/maps/Layer.ts +28 -10
  207. package/src/maps/LayerFactory.ts +0 -8
  208. package/src/maps/LayerLegendComponent.ts +2 -4
  209. package/src/maps/LayerSwitcherComponent.tsx +6 -2
  210. package/src/maps/LeafletMapComponent.tsx +3 -1
  211. package/src/maps/LegendComponent.tsx +10 -1
  212. package/src/maps/MWaterServerLayer.ts +3 -3
  213. package/src/maps/MapComponent.ts +3 -3
  214. package/src/maps/MapDesign.ts +3 -0
  215. package/src/maps/MapDesignerComponent.tsx +165 -162
  216. package/src/maps/MapLayerViewDesignerComponent.ts +2 -2
  217. package/src/maps/MapUtils.ts +24 -0
  218. package/src/maps/MapViewComponent.tsx +11 -3
  219. package/src/maps/MarkersLayer.ts +44 -18
  220. package/src/maps/MarkersLayerDesign.ts +19 -16
  221. package/src/maps/PopupFilterJoinsUtils.ts +6 -2
  222. package/src/maps/RasterMapViewComponent.ts +9 -45
  223. package/src/maps/ServerMapDataSource.ts +2 -2
  224. package/src/maps/SwitchableTileUrlLayer.tsx +4 -10
  225. package/src/maps/TileUrlLayer.tsx +4 -10
  226. package/src/maps/VectorMapViewComponent.tsx +28 -55
  227. package/src/maps/maps.ts +3 -0
  228. package/src/quickfilter/QuickfiltersComponent.ts +13 -7
  229. package/src/quickfilter/QuickfiltersDesignComponent.tsx +56 -74
  230. package/src/richtext/ExprItemsHtmlConverter.ts +9 -5
  231. package/src/richtext/ExprItemsTranslator.ts +176 -0
  232. package/src/richtext/ItemsHtmlConverter.ts +33 -18
  233. package/src/wellknown.ts +33 -30
  234. package/src/widgets/ImageWidget.ts +10 -1
  235. package/src/widgets/ImageWidgetComponent.ts +3 -2
  236. package/src/widgets/{MapWidget.ts → MapWidget.tsx} +90 -101
  237. package/src/widgets/MarkdownWidget.ts +3 -0
  238. package/src/widgets/TOCWidget.tsx +281 -0
  239. package/src/widgets/Widget.ts +25 -5
  240. package/src/widgets/WidgetScopesViewComponent.ts +2 -1
  241. package/src/widgets/charts/Chart.ts +31 -12
  242. package/src/widgets/charts/ChartViewComponent.ts +13 -3
  243. package/src/widgets/charts/ChartWidget.ts +11 -1
  244. package/src/widgets/charts/ChartWidgetComponent.tsx +9 -1
  245. package/src/widgets/charts/calendar/CalendarChart.ts +29 -0
  246. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +3 -1
  247. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +9 -0
  248. package/src/widgets/charts/layered/LayeredChart.ts +71 -3
  249. package/src/widgets/charts/layered/LayeredChartCompiler.ts +4 -4
  250. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +4 -2
  251. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +10 -4
  252. package/src/widgets/charts/pivot/PivotChart.ts +73 -0
  253. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +1 -1
  254. package/src/widgets/charts/pivot/SegmentDesignerComponent.tsx +6 -4
  255. package/src/widgets/charts/table/OrderingsComponent.tsx +2 -1
  256. package/src/widgets/charts/table/TableChart.ts +17 -0
  257. package/src/widgets/text/TextComponent.tsx +22 -12
  258. package/src/widgets/text/TextWidget.ts +9 -2
  259. package/src/widgets/text/TextWidgetComponent.tsx +16 -1
  260. package/src/widgets/text/TextWidgetDesign.ts +4 -7
  261. package/test/IdSelectionTests.ts +54 -0
  262. package/test/LayeredChartCompilerTests.ts +0 -2
  263. package/test/richtext/ExprItemsTranslatorTests.ts +144 -0
  264. package/test/wellknownTests.ts +144 -0
  265. package/src/datagrids/DatagridComponent.ts +0 -478
  266. package/src/datagrids/DatagridViewComponent.ts +0 -464
  267. package/src/datagrids/EditExprCellComponent.tsx +0 -305
  268. package/src/datagrids/README.md +0 -3
  269. package/src/maps/BufferLayerDesignerComponent.ts +0 -311
  270. package/src/widgets/TOCWidget.ts +0 -326
  271. package/test/LegoLayoutEngineTests.ts +0 -69
@@ -1,478 +0,0 @@
1
- import _ from "lodash"
2
- import React, { ReactNode } from "react"
3
- const R = React.createElement
4
-
5
- import AutoSizeComponent from "@mwater/react-library/lib/AutoSizeComponent"
6
- import ActionCancelModalComponent from "@mwater/react-library/lib/ActionCancelModalComponent"
7
- import { DataSource, Expr, ExprUtils, Schema } from "@mwater/expressions"
8
- import { ExprCompiler } from "@mwater/expressions"
9
- import { ExprCleaner } from "@mwater/expressions"
10
- import DatagridViewComponent, { RowUpdate } from "./DatagridViewComponent"
11
- import DatagridDesignerComponent from "./DatagridDesignerComponent"
12
- import DatagridUtils from "./DatagridUtils"
13
-
14
- import QuickfiltersComponent from "../quickfilter/QuickfiltersComponent"
15
- import QuickfilterCompiler from "../quickfilter/QuickfilterCompiler"
16
- import FindReplaceModalComponent from "./FindReplaceModalComponent"
17
- import DatagridDataSource from "./DatagridDataSource"
18
- import { DatagridDesign, JsonQLFilter } from ".."
19
- import { format as d3Format } from "d3-format"
20
- import { LocaleContext } from "@mwater/expressions-ui"
21
-
22
- export interface DatagridComponentProps {
23
- /** schema to use */
24
- schema: Schema
25
-
26
- /** dataSource to use */
27
- dataSource: DataSource
28
-
29
- /** datagrid dataSource to use */
30
- datagridDataSource: DatagridDataSource
31
-
32
- design: DatagridDesign
33
- /** Called when design changes */
34
- onDesignChange?: (design: DatagridDesign) => void
35
-
36
- /** Extra element to include in title at left */
37
- titleElem?: ReactNode
38
- /** Extra elements to add to right */
39
- extraTitleButtonsElem?: ReactNode
40
-
41
- /** Check if a value is editable by testing if underlying expression is editable */
42
- canEditExpr?: (tableId: string, rowId: any, expr: Expr) => Promise<boolean>
43
-
44
- /** Update cell values by updating set of expressions and values */
45
- updateExprValues?: (tableId: string, rowUpdates: RowUpdate[]) => Promise<void>
46
-
47
- /** Called when row is clicked with (tableId, rowId) */
48
- onRowClick?: (tableId: string, rowId: any) => void
49
-
50
- /** Called when row is double-clicked with (tableId, rowId) */
51
- onRowDoubleClick?: (tableId: string, rowId: any) => void
52
-
53
- /** Locked quickfilter values. See README in quickfilters */
54
- quickfilterLocks?: any[]
55
-
56
- // Filters to add to the datagrid
57
- filters?: JsonQLFilter[]
58
- }
59
-
60
- interface DatagridComponentState {
61
- /** is design being edited */
62
- editingDesign: boolean
63
- /** True if cells can be edited directly */
64
- cellEditingEnabled: boolean
65
- /** Height of quickfilters */
66
- quickfiltersHeight: number | null
67
- quickfiltersValues: null | any[]
68
- refreshKey: number
69
- /** Number of rows */
70
- numRows?: number
71
- }
72
-
73
- // Datagrid with decorations
74
- // See README.md for description of datagrid format
75
- // Design should be cleaned already before being passed in (see DatagridUtils)
76
- export default class DatagridComponent extends React.Component<
77
- DatagridComponentProps,
78
- DatagridComponentState
79
- > {
80
- datagridView?: DatagridViewComponent | null
81
- quickfilters?: HTMLElement | null
82
- findReplaceModal: FindReplaceModalComponent | null
83
-
84
- constructor(props: DatagridComponentProps) {
85
- super(props)
86
-
87
- this.state = {
88
- editingDesign: false, // is design being edited
89
- cellEditingEnabled: false, // True if cells can be edited directly
90
- quickfiltersHeight: null, // Height of quickfilters
91
- quickfiltersValues: null,
92
- refreshKey: 1
93
- }
94
- }
95
-
96
- reload() {
97
- this.datagridView?.reload()
98
- }
99
-
100
- componentDidMount() {
101
- this.loadRowCount()
102
- this.updateHeight()
103
- }
104
-
105
- componentDidUpdate(prevProps: DatagridComponentProps, prevState: DatagridComponentState) {
106
- if (!_.isEqual(prevProps.design, this.props.design) || !_.isEqual(prevState.quickfiltersValues, this.state.quickfiltersValues) || prevState.refreshKey !== this.state.refreshKey) {
107
- this.loadRowCount()
108
- }
109
- this.updateHeight()
110
- }
111
-
112
- loadRowCount() {
113
- if (!this.props.design.showNumRows) {
114
- return
115
- }
116
- let filters = this.props.filters || []
117
-
118
- // Compile quickfilters
119
- filters = filters.concat(this.getQuickfilterFilters())
120
- this.props.datagridDataSource.countRows(this.props.design,
121
- filters,
122
- (error: any, numRows: any) => {
123
- if (error) {
124
- console.error(error)
125
- alert(T`Error loading data`)
126
- return
127
- }
128
- console.log(numRows)
129
- this.setState({ numRows })
130
- })
131
- }
132
-
133
- handleRefreshData = () => {
134
- this.props.dataSource.clearCache?.()
135
- this.setState({ refreshKey: this.state.refreshKey + 1 })
136
- }
137
-
138
- updateHeight() {
139
- // Calculate quickfilters height
140
- if (this.quickfilters) {
141
- if (this.state.quickfiltersHeight !== this.quickfilters.offsetHeight) {
142
- return this.setState({ quickfiltersHeight: this.quickfilters.offsetHeight })
143
- }
144
- } else {
145
- return this.setState({ quickfiltersHeight: 0 })
146
- }
147
- }
148
-
149
- // Get the values of the quick filters
150
- getQuickfilterValues = () => {
151
- return this.state.quickfiltersValues || []
152
- }
153
-
154
- // Get filters that are applied by the quickfilters
155
- getQuickfilterFilters = () => {
156
- return new QuickfilterCompiler(this.props.schema).compile(
157
- this.props.design.quickfilters,
158
- this.state.quickfiltersValues,
159
- this.props.quickfilterLocks
160
- )
161
- }
162
-
163
- handleCellEditingToggle = () => {
164
- if (this.state.cellEditingEnabled) {
165
- return this.setState({ cellEditingEnabled: false })
166
- } else {
167
- if (confirm(T`Turn on cell editing? This will allow you to edit the live data and is an advanced feature.`)) {
168
- return this.setState({ cellEditingEnabled: true })
169
- }
170
- }
171
- }
172
-
173
- handleEdit = () => {
174
- return this.setState({ editingDesign: true })
175
- }
176
-
177
- // Get datagrid filter compiled for quickfilter filtering
178
- getCompiledFilters(): JsonQLFilter[] {
179
- let jsonql
180
- const exprCompiler = new ExprCompiler(this.props.schema)
181
- const exprUtils = new ExprUtils(this.props.schema)
182
- const exprCleaner = new ExprCleaner(this.props.schema)
183
-
184
- const compiledFilters: JsonQLFilter[] = []
185
-
186
- if (this.props.design.filter) {
187
- // First clean the filter
188
- const cleanExpr = exprCleaner.cleanExpr(this.props.design.filter, { table: this.props.design.table! })
189
-
190
- jsonql = exprCompiler.compileExpr({ expr: cleanExpr, tableAlias: "{alias}" })
191
- if (jsonql) {
192
- compiledFilters.push({
193
- table: this.props.design.table!,
194
- jsonql
195
- })
196
- }
197
- }
198
-
199
- // Add global filters
200
- for (let filter of this.props.design.globalFilters || []) {
201
- // Check if exists and is correct type
202
- const column = this.props.schema.getColumn(this.props.design.table!, filter.columnId)
203
- if (!column) {
204
- continue
205
- }
206
-
207
- const columnExpr: Expr = { type: "field", table: this.props.design.table!, column: column.id }
208
- if (exprUtils.getExprType(columnExpr) !== filter.columnType) {
209
- continue
210
- }
211
-
212
- // Create expr
213
- let expr: Expr = {
214
- type: "op",
215
- op: filter.op,
216
- table: this.props.design.table!,
217
- exprs: [columnExpr as Expr].concat(filter.exprs)
218
- }
219
-
220
- // Clean expr
221
- expr = exprCleaner.cleanExpr(expr, { table: this.props.design.table! })
222
-
223
- jsonql = exprCompiler.compileExpr({ expr, tableAlias: "{alias}" })
224
- if (jsonql) {
225
- compiledFilters.push({
226
- table: this.props.design.table!,
227
- jsonql
228
- })
229
- }
230
- }
231
-
232
- return compiledFilters
233
- }
234
-
235
- // Toggle to allow cell editing
236
- renderCellEdit() {
237
- if (!this.props.canEditExpr) {
238
- return null
239
- }
240
-
241
- const label = [
242
- R("i", { className: this.state.cellEditingEnabled ? "fa fa-fw fa-check-square" : "fa fa-fw fa-square-o" }),
243
- " ",
244
- T`Cell Editing`
245
- ]
246
-
247
- return R(
248
- "a",
249
- {
250
- key: "cell-edit",
251
- className: "btn btn-link btn-sm",
252
- onClick: this.handleCellEditingToggle
253
- },
254
- label
255
- )
256
- }
257
-
258
- renderEditButton() {
259
- if (!this.props.onDesignChange) {
260
- return null
261
- }
262
-
263
- return R(
264
- "button",
265
- {
266
- type: "button",
267
- className: "btn btn-primary",
268
- onClick: this.handleEdit
269
- },
270
- R("span", { className: "fas fa-cog" }),
271
- " ",
272
- T`Settings`
273
- )
274
- }
275
-
276
- renderFindReplace() {
277
- if (!this.state.cellEditingEnabled) {
278
- return null
279
- }
280
-
281
- return R(
282
- "a",
283
- {
284
- key: "findreplace",
285
- className: "btn btn-link btn-sm",
286
- onClick: () => this.findReplaceModal!.show()
287
- },
288
- T`Find/Replace`
289
- )
290
- }
291
-
292
- renderTitleBar() {
293
- return R(
294
- "div",
295
- { style: { position: "absolute", top: 0, left: 0, right: 0, height: 40, padding: 4 } },
296
- R(
297
- "div",
298
- { style: { float: "right" } },
299
- this.props.design.showNumRows && this.state.numRows ? R("small", { className: 'text-muted text-sm' }, `${d3Format(',')(this.state.numRows)} rows`) : undefined,
300
- this.renderFindReplace(),
301
- this.renderCellEdit(),
302
- this.renderEditButton(),
303
- R(
304
- "a",
305
- { key: "refresh", className: "btn btn-link btn-sm", onClick: this.handleRefreshData },
306
- R("span", { className: "fas fa-sync" }),
307
- R("span", { className: "hide-600px" }, T`Refresh`)
308
- ),
309
- this.props.extraTitleButtonsElem
310
- ),
311
- this.props.titleElem
312
- )
313
- }
314
-
315
- renderQuickfilter() {
316
- return R(
317
- "div",
318
- {
319
- style: { position: "absolute", top: 40, left: 0, right: 0 },
320
- ref: (c) => {
321
- this.quickfilters = c
322
- }
323
- },
324
- R(QuickfiltersComponent, {
325
- design: this.props.design.quickfilters!,
326
- schema: this.props.schema,
327
- dataSource: this.props.dataSource,
328
- quickfiltersDataSource: this.props.datagridDataSource.getQuickfiltersDataSource(),
329
- values: this.state.quickfiltersValues || [],
330
- onValuesChange: (values: any) => this.setState({ quickfiltersValues: values }),
331
- locks: this.props.quickfilterLocks,
332
- filters: this.getCompiledFilters()
333
- })
334
- )
335
- }
336
-
337
- // Renders the editor modal
338
- renderEditor() {
339
- if (!this.state.editingDesign) {
340
- return
341
- }
342
-
343
- return R(DatagridEditorComponent, {
344
- schema: this.props.schema,
345
- dataSource: this.props.dataSource,
346
- design: this.props.design,
347
- onDesignChange: (design: any) => {
348
- // If quickfilters have changed, reset values
349
- if (!_.isEqual(this.props.design.quickfilters, design.quickfilters)) {
350
- this.setState({ quickfiltersValues: null })
351
- }
352
-
353
- this.props.onDesignChange!(design)
354
-
355
- return this.setState({ editingDesign: false })
356
- },
357
- onCancel: () => this.setState({ editingDesign: false })
358
- })
359
- }
360
-
361
- renderFindReplaceModal(filters: any) {
362
- return R(FindReplaceModalComponent, {
363
- ref: (c: FindReplaceModalComponent | null) => {
364
- this.findReplaceModal = c
365
- },
366
- schema: this.props.schema,
367
- dataSource: this.props.dataSource,
368
- datagridDataSource: this.props.datagridDataSource,
369
- design: this.props.design,
370
- filters,
371
- updateExprValues: this.props.updateExprValues!,
372
- onUpdate: () => {
373
- // Reload
374
- return this.datagridView?.reload()
375
- }
376
- })
377
- }
378
-
379
- render() {
380
- let filters = this.props.filters || []
381
-
382
- // Compile quickfilters
383
- filters = filters.concat(this.getQuickfilterFilters())
384
-
385
- return R(LocaleContext.Provider, { value: this.props.design.locale || "en" },
386
- R(
387
- "div",
388
- {
389
- style: {
390
- width: "100%",
391
- height: "100%",
392
- position: "relative",
393
- paddingTop: 40 + (this.state.quickfiltersHeight || 0)
394
- }
395
- },
396
- this.renderTitleBar(),
397
- this.renderQuickfilter(),
398
-
399
- this.renderEditor(),
400
- this.renderFindReplaceModal(filters),
401
-
402
- R(AutoSizeComponent, { injectWidth: true, injectHeight: true } as any, (size: any) => {
403
- // Clean before displaying
404
- const design = new DatagridUtils(this.props.schema).cleanDesign(this.props.design)
405
-
406
- if (!new DatagridUtils(this.props.schema).validateDesign(design)) {
407
- return R(DatagridViewComponent, {
408
- ref: (view: DatagridViewComponent | null) => {
409
- this.datagridView = view
410
- },
411
- width: size.width - 1, // minus 1 px to test if it solves the jitter with scroll
412
- height: size.height - 1,
413
- pageSize: 100,
414
- schema: this.props.schema,
415
- dataSource: this.props.dataSource,
416
- datagridDataSource: this.props.datagridDataSource,
417
- design,
418
- filters,
419
- onDesignChange: this.props.onDesignChange,
420
- onRowClick: this.props.onRowClick,
421
- onRowDoubleClick: this.props.onRowDoubleClick,
422
- canEditExpr: this.state.cellEditingEnabled ? this.props.canEditExpr : undefined,
423
- updateExprValues: this.state.cellEditingEnabled ? this.props.updateExprValues : undefined,
424
- refreshKey: this.state.refreshKey
425
- })
426
- } else if (this.props.onDesignChange) {
427
- return R(
428
- "div",
429
- { style: { textAlign: "center", marginTop: size.height / 2 } },
430
- R("a", { className: "btn btn-link", onClick: this.handleEdit }, T`Click Here to Configure`)
431
- )
432
- } else {
433
- return null
434
- }
435
- })
436
- )
437
- )
438
- }
439
- }
440
-
441
- interface DatagridEditorComponentProps {
442
- schema: Schema
443
- dataSource: DataSource
444
- design: DatagridDesign
445
- onDesignChange: (design: DatagridDesign) => void
446
- onCancel: () => void
447
- }
448
-
449
- /** Popup editor */
450
- class DatagridEditorComponent extends React.Component<DatagridEditorComponentProps, { design: DatagridDesign }> {
451
- constructor(props: DatagridEditorComponentProps) {
452
- super(props)
453
-
454
- this.state = {
455
- design: props.design
456
- }
457
- }
458
-
459
- render() {
460
- return R(
461
- ActionCancelModalComponent,
462
- {
463
- onAction: () => {
464
- this.props.onDesignChange(this.state.design)
465
- return this.setState({ design: this.props.design })
466
- },
467
- onCancel: this.props.onCancel,
468
- size: "large"
469
- },
470
- R(DatagridDesignerComponent, {
471
- schema: this.props.schema,
472
- dataSource: this.props.dataSource,
473
- design: this.state.design,
474
- onDesignChange: (design: any) => this.setState({ design })
475
- })
476
- )
477
- }
478
- }