@mwater/visualization 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/lib/MWaterAddRelatedFormComponent.d.ts +1 -1
  2. package/lib/MWaterAddRelatedFormComponent.js +10 -17
  3. package/lib/MWaterContextComponent.d.ts +17 -7
  4. package/lib/MWaterContextComponent.js +51 -70
  5. package/lib/MWaterLoaderComponent.d.ts +2 -2
  6. package/lib/MWaterLoaderComponent.js +1 -1
  7. package/lib/MWaterTableSelectComponent.d.ts +0 -1
  8. package/lib/MWaterTableSelectComponent.js +20 -41
  9. package/lib/axes/RangesComponent.d.ts +12 -6
  10. package/lib/axes/RangesComponent.js +21 -10
  11. package/lib/dashboards/DashboardComponent.d.ts +1 -9
  12. package/lib/dashboards/DashboardComponent.js +16 -27
  13. package/lib/dashboards/ServerDashboardDataSource.d.ts +1 -0
  14. package/lib/dashboards/ServerDashboardDataSource.js +3 -0
  15. package/lib/datagrids/DatagridComponent.d.ts +10 -4
  16. package/lib/datagrids/DatagridComponent.js +34 -6
  17. package/lib/datagrids/DatagridDataSource.d.ts +1 -0
  18. package/lib/datagrids/DatagridDataSource.js +3 -0
  19. package/lib/datagrids/DatagridDesign.d.ts +2 -0
  20. package/lib/datagrids/DatagridDesignerComponent.js +3 -2
  21. package/lib/datagrids/DatagridViewComponent.d.ts +2 -0
  22. package/lib/datagrids/DatagridViewComponent.js +4 -3
  23. package/lib/datagrids/DirectDatagridDataSource.d.ts +1 -0
  24. package/lib/datagrids/DirectDatagridDataSource.js +26 -0
  25. package/lib/datagrids/LabeledExprGenerator.js +15 -0
  26. package/lib/datagrids/ServerDatagridDataSource.d.ts +1 -0
  27. package/lib/datagrids/ServerDatagridDataSource.js +15 -0
  28. package/lib/dayjs.d.ts +2 -0
  29. package/lib/dayjs.js +9 -0
  30. package/lib/index.d.ts +0 -1
  31. package/lib/index.js +2 -4
  32. package/lib/languages.js +5 -0
  33. package/lib/layouts/blocks/BlocksDisplayComponent.js +2 -2
  34. package/lib/layouts/grid/LegoLayoutEngine.d.ts +1 -1
  35. package/lib/maps/BufferLayerDesignerComponent.js +2 -2
  36. package/lib/maps/ChoroplethLayerDesigner.js +2 -2
  37. package/lib/maps/ClusterLayerDesignerComponent.js +2 -2
  38. package/lib/maps/DetailLevelSelectComponent.d.ts +1 -93
  39. package/lib/maps/DirectMapDataSource.js +1 -2
  40. package/lib/maps/GridLayerDesigner.js +2 -2
  41. package/lib/maps/Layer.js +7 -18
  42. package/lib/maps/MapComponent.js +1 -1
  43. package/lib/maps/MapDesignerComponent.d.ts +1 -12
  44. package/lib/maps/MapDesignerComponent.js +5 -12
  45. package/lib/maps/MarkersLayerDesignerComponent.js +2 -2
  46. package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -1
  47. package/lib/maps/PopupFilterJoinsUtils.js +4 -3
  48. package/lib/maps/RegionSelectComponent.d.ts +1 -33
  49. package/lib/maps/UtfGridLayer.js +1 -1
  50. package/lib/maps/VectorMapViewComponent.js +21 -29
  51. package/lib/quickfilter/QuickfiltersComponent.d.ts +2 -186
  52. package/lib/quickfilter/QuickfiltersDesignComponent.js +1 -1
  53. package/lib/quickfilter/TextLiteralComponent.d.ts +2 -186
  54. package/lib/quickfilter/TextLiteralComponent.js +3 -0
  55. package/lib/valueFormatter.js +52 -1
  56. package/lib/widgets/ImageWidgetComponent.js +2 -2
  57. package/lib/widgets/charts/calendar/CalendarChartDesignerComponent.js +2 -2
  58. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -1
  59. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +1 -1
  60. package/lib/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.js +2 -2
  61. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +1 -1
  62. package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.js +2 -2
  63. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.js +2 -2
  64. package/lib/widgets/charts/pivot/PivotChartLayout.d.ts +3 -2
  65. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +4 -1
  66. package/lib/widgets/charts/pivot/PivotChartQueryBuilder.js +1 -1
  67. package/lib/widgets/charts/table/TableChart.js +15 -4
  68. package/lib/widgets/charts/table/TableChartDesignerComponent.js +2 -2
  69. package/lib/widgets/charts/table/TableChartViewComponent.d.ts +2 -1
  70. package/lib/widgets/charts/table/TableChartViewComponent.js +9 -4
  71. package/lib/widgets/text/ExprItemEditorComponent.js +2 -2
  72. package/package.json +8 -8
  73. package/src/MWaterAddRelatedFormComponent.ts +15 -20
  74. package/src/MWaterAddRelatedIndicatorComponent.ts +1 -1
  75. package/src/MWaterContextComponent.tsx +140 -0
  76. package/src/MWaterLoaderComponent.ts +2 -2
  77. package/src/{MWaterTableSelectComponent.ts → MWaterTableSelectComponent.tsx} +61 -66
  78. package/src/axes/AxisBuilder.ts +1 -1
  79. package/src/axes/RangesComponent.ts +27 -16
  80. package/src/dashboards/{DashboardComponent.ts → DashboardComponent.tsx} +37 -40
  81. package/src/dashboards/ServerDashboardDataSource.ts +16 -12
  82. package/src/datagrids/DatagridComponent.ts +59 -14
  83. package/src/datagrids/DatagridDataSource.ts +8 -0
  84. package/src/datagrids/DatagridDesign.ts +3 -0
  85. package/src/datagrids/DatagridDesignerComponent.tsx +9 -1
  86. package/src/datagrids/DatagridViewComponent.ts +7 -3
  87. package/src/datagrids/DirectDatagridDataSource.ts +35 -0
  88. package/src/datagrids/LabeledExprGenerator.ts +15 -0
  89. package/src/datagrids/ServerDatagridDataSource.ts +22 -4
  90. package/src/dayjs.ts +5 -0
  91. package/src/index.ts +0 -2
  92. package/src/languages.ts +5 -0
  93. package/src/layouts/blocks/BlocksDisplayComponent.ts +2 -2
  94. package/src/layouts/grid/LegoLayoutEngine.ts +2 -2
  95. package/src/layouts/grid/WidgetContainerComponent.ts +2 -2
  96. package/src/maps/BingLayer.ts +2 -2
  97. package/src/maps/BufferLayerDesignerComponent.ts +1 -1
  98. package/src/maps/ChoroplethLayerDesigner.tsx +1 -1
  99. package/src/maps/ClusterLayerDesignerComponent.ts +1 -1
  100. package/src/maps/DirectMapDataSource.ts +1 -2
  101. package/src/maps/GridLayerDesigner.tsx +1 -1
  102. package/src/maps/Layer.ts +6 -16
  103. package/src/maps/LegendGroup.ts +1 -1
  104. package/src/maps/MWaterServerLayer.ts +2 -2
  105. package/src/maps/MapComponent.ts +1 -1
  106. package/src/maps/{MapDesignerComponent.ts → MapDesignerComponent.tsx} +8 -16
  107. package/src/maps/MarkersLayerDesignerComponent.ts +1 -1
  108. package/src/maps/PopupFilterJoinsUtils.ts +4 -4
  109. package/src/maps/RasterMapViewComponent.ts +0 -1
  110. package/src/maps/ServerMapDataSource.ts +6 -6
  111. package/src/maps/SwitchableTileUrlLayerDesigner.tsx +1 -13
  112. package/src/maps/UtfGridLayer.ts +4 -4
  113. package/src/maps/VectorMapViewComponent.tsx +23 -36
  114. package/src/maps/mapboxUtils.ts +2 -2
  115. package/src/quickfilter/QuickfiltersDesignComponent.tsx +1 -1
  116. package/src/quickfilter/TextLiteralComponent.ts +4 -0
  117. package/src/richtext/ExprItemsHtmlConverter.ts +1 -1
  118. package/src/richtext/FontColorPaletteItem.ts +1 -1
  119. package/src/richtext/FontSizePaletteItem.ts +1 -1
  120. package/src/richtext/ItemsHtmlConverter.ts +2 -2
  121. package/src/valueFormatter.ts +54 -1
  122. package/src/widgets/ImageWidgetComponent.ts +1 -1
  123. package/src/widgets/charts/calendar/CalendarChartDesignerComponent.ts +1 -1
  124. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +1 -1
  125. package/src/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.ts +1 -1
  126. package/src/widgets/charts/layered/LayeredChartLayerDesignerComponent.tsx +1 -1
  127. package/src/widgets/charts/pivot/PivotChartDesignerComponent.tsx +1 -1
  128. package/src/widgets/charts/pivot/PivotChartLayout.ts +3 -2
  129. package/src/widgets/charts/pivot/PivotChartLayoutBuilder.ts +2 -2
  130. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +7 -3
  131. package/src/widgets/charts/pivot/PivotChartQueryBuilder.ts +1 -1
  132. package/src/widgets/charts/table/TableChart.ts +24 -14
  133. package/src/widgets/charts/table/TableChartDesignerComponent.ts +1 -1
  134. package/src/widgets/charts/table/TableChartViewComponent.ts +10 -5
  135. package/src/widgets/text/ExprItemEditorComponent.tsx +1 -1
  136. package/stories/dashboards.js +3 -3
  137. package/src/MWaterContextComponent.ts +0 -144
  138. package/src/TableSelectComponent.ts +0 -60
@@ -5,7 +5,7 @@ const R = React.createElement
5
5
  import Color from "color"
6
6
  import * as ui from "@mwater/react-library/lib/bootstrap"
7
7
  import classNames from "classnames"
8
- import { PivotChartLayout, PivotChartLayoutRow } from "./PivotChartLayout"
8
+ import { PivotChartLayout, PivotChartLayoutCell, PivotChartLayoutRow } from "./PivotChartLayout"
9
9
 
10
10
  export interface PivotChartLayoutComponentProps {
11
11
  layout: PivotChartLayout
@@ -71,7 +71,7 @@ export default class PivotChartLayoutComponent extends React.Component<PivotChar
71
71
  layout: this.props.layout,
72
72
  rowIndex,
73
73
  columnIndex,
74
- onHover: this.props.editable ? () => this.setState({ hoverSection: cell.section }) : undefined,
74
+ onHover: this.props.editable ? () => this.setState({ hoverSection: cell.section ?? null }) : undefined,
75
75
  hoverSection: this.props.editable ? this.state.hoverSection : undefined,
76
76
  onEditSection: this.props.onEditSection ? this.props.onEditSection.bind(null, cell.section) : undefined,
77
77
  onSummarizeSegment: this.props.onSummarizeSegment
@@ -383,7 +383,11 @@ class LayoutCellComponent extends React.Component<LayoutCellComponentProps> {
383
383
  }
384
384
 
385
385
  // Render an unconfigured cell
386
- renderUnconfigured(cell: any) {
386
+ renderUnconfigured(cell: PivotChartLayoutCell) {
387
+ if (!cell.section) {
388
+ return null
389
+ }
390
+
387
391
  return R(
388
392
  "span",
389
393
  { style: { fontSize: "90%" } },
@@ -108,7 +108,7 @@ export default class PivotChartQueryBuilder {
108
108
  const columnSegment = columnPath[i]
109
109
  query.selects.push({
110
110
  type: "select",
111
- expr: this.axisBuilder.compileAxis({ axis: columnSegment.valueAxis, tableAlias: "main" }),
111
+ expr: compileSegmentAxis(columnSegment.valueAxis),
112
112
  alias: `c${i}`
113
113
  })
114
114
  query.groupBy!.push(i + 1 + rowPath.length)
@@ -217,7 +217,7 @@ export default class TableChart extends Chart {
217
217
  const totalColumns: string[] = []
218
218
 
219
219
  // For each column
220
- for (let colNum = 0 ; colNum < design.columns.length ; colNum++) {
220
+ for (let colNum = 0; colNum < design.columns.length; colNum++) {
221
221
  column = design.columns[colNum]
222
222
 
223
223
  const exprType = exprUtils.getExprType(column.textAxis?.expr ?? null)
@@ -242,7 +242,7 @@ export default class TableChart extends Chart {
242
242
  alias: `c${colNum}`
243
243
  })
244
244
 
245
- if(exprType === 'number' && column.summarize) {
245
+ if (exprType === 'number' && column.summarize) {
246
246
  totalColumns.push(`c${colNum}`)
247
247
  }
248
248
 
@@ -275,9 +275,9 @@ export default class TableChart extends Chart {
275
275
  }
276
276
  }
277
277
 
278
- for (let colNum = 0 ; colNum < design.columns.length ; colNum++) {
278
+ for (let colNum = 0; colNum < design.columns.length; colNum++) {
279
279
  column = design.columns[colNum]
280
- if(!column.backgroundColorAxis) continue
280
+ if (!column.backgroundColorAxis) continue
281
281
 
282
282
  query.selects.push({
283
283
  type: "select",
@@ -320,27 +320,37 @@ export default class TableChart extends Chart {
320
320
  const summaryQuery: JsonQLSelectQuery = {
321
321
  type: "query",
322
322
  selects: design.columns.map((c: any, i) => {
323
- if(totalColumns.includes(`c${i}`))
323
+ if (totalColumns.includes(`c${i}`))
324
324
  return { type: "select", expr: { type: "op", op: c.summaryType ?? 'sum', exprs: [{ type: "field", tableAlias: "t", column: `c${i}` }] }, alias: `c${i}` }
325
- else
326
- return { type: 'select', expr: {type: 'literal', value: null} , alias: `c${i}` }
325
+ else
326
+ return { type: 'select', expr: { type: 'literal', value: null }, alias: `c${i}` }
327
327
  }),
328
328
  from: { type: "subquery", query, alias: "t" },
329
329
  }
330
-
331
- return dataSource.performQuery(query, (error: any, data: any) => {
332
- if(totalColumns.length > 0)
330
+ // Query for the data in question.
331
+ dataSource.performQuery(query, (error: any, data: any) => {
332
+ if (error) {
333
+ callback(error)
334
+ }
335
+ else if (totalColumns.length > 0) {
336
+ // Query for the summaries
333
337
  dataSource.performQuery(summaryQuery, (error: any, summary: any) => {
334
- callback(error, { main: data, summary: summary[0] })
338
+ if (error) {
339
+ callback(error)
340
+ }
341
+ else {
342
+ callback(error, { main: data, summary: summary[0] })
343
+ }
335
344
  })
336
- else
337
- callback(error, { main: data})
345
+ }
346
+ else
347
+ callback(error, { main: data })
338
348
  })
339
349
  }
340
350
 
341
351
  // Create a view element for the chart
342
352
  // Options include:
343
- // schema: schema to use
353
+ // p schema: schema to use
344
354
  // dataSource: dataSource to use
345
355
  // design: design of the chart
346
356
  // data: results from queries
@@ -9,7 +9,7 @@ import { LinkComponent } from "@mwater/expressions-ui"
9
9
  import { ExprComponent } from "@mwater/expressions-ui"
10
10
  import { FilterExprComponent } from "@mwater/expressions-ui"
11
11
  import OrderingsComponent from "./OrderingsComponent"
12
- import TableSelectComponent from "../../../TableSelectComponent"
12
+ import { TableSelectComponent } from "@mwater/expressions-ui"
13
13
  import ReorderableListComponent from "@mwater/react-library/lib/reorderable/ReorderableListComponent"
14
14
  import * as ui from "@mwater/react-library/lib/bootstrap"
15
15
  import { getFormatOptions } from "../../../valueFormatter"
@@ -8,12 +8,12 @@ import AxisBuilder from "../../../axes/AxisBuilder"
8
8
  import { DataSource, ExprUtils, Schema } from "@mwater/expressions"
9
9
  import { formatValue } from "../../../valueFormatter"
10
10
  import { Image } from "@mwater/forms/lib/RotationAwareImageComponent"
11
- import { TableChartColumn } from "./TableChart"
11
+ import { TableChartColumn, TableChartDesign } from "./TableChart"
12
12
  import Color from "color"
13
13
 
14
14
  export interface TableChartViewComponentProps {
15
15
  /** Design of chart */
16
- design: any
16
+ design: TableChartDesign
17
17
  /** Data that the table has requested */
18
18
  data: any
19
19
  /** Schema to use */
@@ -249,7 +249,12 @@ class TableContentsComponent extends React.Component<TableContentsComponentProps
249
249
  } else {
250
250
  // Parse if should be JSON
251
251
  if (["image", "imagelist", "geometry", "text[]"].includes(exprType || "") && _.isString(value)) {
252
- value = JSON.parse(value)
252
+ try {
253
+ value = JSON.parse(value)
254
+ } catch (e) {
255
+ // Ignore as can happen when re-arranging columns
256
+ value = null
257
+ }
253
258
  }
254
259
 
255
260
  if (column.backgroundColorAxis && row[`bc${columnIndex}`] != null) {
@@ -272,10 +277,10 @@ class TableContentsComponent extends React.Component<TableContentsComponentProps
272
277
  node = exprUtils.stringifyExprLiteral(column.textAxis?.expr, value, this.context.locale)
273
278
  break
274
279
  case "date":
275
- node = moment(value, "YYYY-MM-DD").format("ll")
280
+ node = formatValue(exprType, value, column.format)
276
281
  break
277
282
  case "datetime":
278
- node = moment(value, moment.ISO_8601).format("lll")
283
+ node = formatValue(exprType, value, column.format)
279
284
  break
280
285
  case "image":
281
286
  node = this.renderImage(value.id)
@@ -5,7 +5,7 @@ const R = React.createElement
5
5
 
6
6
  import { DataSource, ExprUtils, Schema } from "@mwater/expressions"
7
7
  import { ExprComponent } from "@mwater/expressions-ui"
8
- import TableSelectComponent from "../../TableSelectComponent"
8
+ import { TableSelectComponent } from "@mwater/expressions-ui"
9
9
  import { getFormatOptions } from "../../valueFormatter"
10
10
  import { getDefaultFormat } from "../../valueFormatter"
11
11
  import { Checkbox } from "@mwater/react-library/lib/bootstrap"
@@ -155,9 +155,9 @@ class DashboardPopupTest extends React.Component {
155
155
  }
156
156
 
157
157
 
158
- const ModalWindowComponent = require('react-library/lib/ModalWindowComponent');
159
- const ui = require('react-library/lib/bootstrap');
160
- const update = require('react-library/lib/update');
158
+ const ModalWindowComponent = require("@mwater/react-library/lib/ModalWindowComponent");
159
+ const ui = require("@mwater/react-library/lib/bootstrap");
160
+ const update = require("@mwater/react-library/lib/update");
161
161
 
162
162
  class DashboardPopupComponent extends React.Component {
163
163
  static initClass() {
@@ -1,144 +0,0 @@
1
- import PropTypes from "prop-types"
2
- import _ from "lodash"
3
- import React from "react"
4
- const R = React.createElement
5
-
6
- import MWaterTableSelectComponent from "./MWaterTableSelectComponent"
7
- import MWaterAddRelatedFormComponent from "./MWaterAddRelatedFormComponent"
8
- import MWaterAddRelatedIndicatorComponent from "./MWaterAddRelatedIndicatorComponent"
9
- import MWaterGlobalFiltersComponent from "./MWaterGlobalFiltersComponent"
10
- import { Schema } from "@mwater/expressions"
11
-
12
- /** Creates a tableSelectElementFactory context to allow selecting of a table in an mWater-friendly way
13
- * and several other context items
14
- */
15
- export default class MWaterContextComponent extends React.Component<{
16
- apiUrl: string
17
- client?: string
18
- /** user id of logged in user */
19
- user?: string
20
- schema: Schema
21
- /** Extra tables to load in schema. Forms are not loaded by default as they are too many */
22
- extraTables?: string[]
23
- /** Called when extra tables are changed and schema will be reloaded */
24
- onExtraTablesChange?: (extraTables: string[]) => void
25
- /** Override default add layer component. See AddLayerComponent for details */
26
- addLayerElementFactory?: any
27
- }> {
28
- static childContextTypes = {
29
- tableSelectElementFactory: PropTypes.func, // Call with props of TableSelectComponent
30
- addLayerElementFactory: PropTypes.func, // Call with props of AddLayerComponent
31
- globalFiltersElementFactory: PropTypes.func, // Call with props { schema, dataSource, filterableTables, globalFilters, onChange, nullIfIrrelevant }.
32
- // Displays a component to edit global filters. nullIfIrrelevant causes null element if not applicable to filterableTables
33
-
34
- // Decorates sections (the children element, specifically) in the expression picker
35
- decorateScalarExprTreeSectionChildren: PropTypes.func,
36
-
37
- // Function to override initial open state of a section. Passed { tableId: id of table, section: section object from schema, filter: optional string filter }
38
- // Should return true to set initially open
39
- isScalarExprTreeSectionInitiallyOpen: PropTypes.func,
40
-
41
- // Function to override filtering of a section. Passed { tableId: id of table, section: section object from schema, filter: optional string filter }
42
- // Should return null for default, true to include, false to exclude
43
- isScalarExprTreeSectionMatch: PropTypes.func
44
- }
45
-
46
- getChildContext() {
47
- const context: any = {}
48
-
49
- context.tableSelectElementFactory = (props: any) => {
50
- return React.createElement(MWaterTableSelectComponent, {
51
- apiUrl: this.props.apiUrl,
52
- client: this.props.client,
53
- schema: props.schema,
54
- user: this.props.user,
55
- table: props.value,
56
- onChange: props.onChange,
57
- extraTables: this.props.extraTables,
58
- onExtraTablesChange: this.props.onExtraTablesChange,
59
- filter: props.filter,
60
- onFilterChange: props.onFilterChange
61
- })
62
- }
63
-
64
- if (this.props.addLayerElementFactory) {
65
- context.addLayerElementFactory = this.props.addLayerElementFactory
66
- }
67
-
68
- context.globalFiltersElementFactory = (props: any) => {
69
- if (props.nullIfIrrelevant && !_.any(props.filterableTables, (t: string) => t.match(/^entities./))) {
70
- return null
71
- }
72
-
73
- return React.createElement(MWaterGlobalFiltersComponent, props)
74
- }
75
-
76
- context.decorateScalarExprTreeSectionChildren = (options: any) => {
77
- // If related forms section of entities table or assets table
78
- if ((options.tableId.match(/^entities\./) || options.tableId.match(/^assets:/)) && options.section.id === "!related_forms") {
79
- return R(
80
- "div",
81
- { key: "_add_related_form_parent" },
82
- options.children,
83
- R(MWaterAddRelatedFormComponent, {
84
- key: "_add_related_form",
85
- table: options.tableId,
86
- apiUrl: this.props.apiUrl,
87
- client: this.props.client,
88
- user: this.props.user,
89
- schema: this.props.schema,
90
- onSelect: this.handleAddTable
91
- })
92
- )
93
- }
94
-
95
- // If indicators section of entities table
96
- if (options.tableId.match(/^entities\./) && options.section.id === "!indicators") {
97
- return R(
98
- "div",
99
- { key: "_add_related_indicator_parent" },
100
- options.children,
101
- R(MWaterAddRelatedIndicatorComponent, {
102
- key: "_add_related_indicator",
103
- table: options.tableId,
104
- apiUrl: this.props.apiUrl,
105
- client: this.props.client,
106
- user: this.props.user,
107
- schema: this.props.schema,
108
- onSelect: this.handleAddTable,
109
- filter: options.filter
110
- })
111
- )
112
- } else {
113
- return options.children
114
- }
115
- }
116
-
117
- // Always match indicator section
118
- context.isScalarExprTreeSectionMatch = (options: any) => {
119
- if (options.tableId.match(/^entities\./) && options.section.id === "!indicators") {
120
- return true
121
- }
122
- return null
123
- }
124
-
125
- // Always open indicator section
126
- context.isScalarExprTreeSectionInitiallyOpen = (options: any) => {
127
- if (options.tableId.match(/^entities\./) && options.section.id === "!indicators") {
128
- return true
129
- }
130
- return null
131
- }
132
-
133
- return context
134
- }
135
-
136
- handleAddTable = (table: any) => {
137
- const extraTables = _.union(this.props.extraTables || [], [table])
138
- return this.props.onExtraTablesChange!(extraTables)
139
- }
140
-
141
- render() {
142
- return this.props.children
143
- }
144
- }
@@ -1,60 +0,0 @@
1
- import _ from "lodash"
2
- import PropTypes from "prop-types"
3
- import React from "react"
4
- import * as ui from "./UIComponents"
5
- import { Expr, ExprUtils, Schema } from "@mwater/expressions"
6
- const R = React.createElement
7
-
8
- export interface TableSelectComponentProps {
9
- schema: Schema
10
- /** Current table id */
11
- value?: string | null
12
- /** Newly selected table id */
13
- onChange: (tableId: string) => void
14
- /** Some table select components (not the default) can also perform filtering. Include these props to enable this */
15
- filter?: Expr
16
- onFilterChange?: (filter: Expr) => void
17
- }
18
-
19
- export default class TableSelectComponent extends React.Component<TableSelectComponentProps> {
20
- static contextTypes = {
21
- tableSelectElementFactory: PropTypes.func, // Can be overridden by setting tableSelectElementFactory in context that takes ({ schema, value, onChange, filter, onFilterChange })
22
- locale: PropTypes.string, // e.g. "en"
23
-
24
- // Optional list of tables (ids) being used. Some overrides of the table select component may use this to present
25
- // an initially short list to select from
26
- activeTables: PropTypes.arrayOf(PropTypes.string.isRequired)
27
- }
28
-
29
- render() {
30
- if (this.context.tableSelectElementFactory) {
31
- return this.context.tableSelectElementFactory(this.props)
32
- }
33
-
34
- return React.createElement(ui.ToggleEditComponent, {
35
- forceOpen: !this.props.value,
36
- label: this.props.value
37
- ? ExprUtils.localizeString(
38
- this.props.schema.getTable(this.props.value)?.name || "(not found)",
39
- this.context.locale
40
- )
41
- : R("i", null, "Select..."),
42
- editor: (onClose: any) => {
43
- return React.createElement(ui.OptionListComponent, {
44
- hint: "Select source to get data from",
45
- items: _.map(
46
- _.filter(this.props.schema.getTables(), (table) => !table.deprecated),
47
- (table) => ({
48
- name: ExprUtils.localizeString(table.name, this.context.locale),
49
- desc: ExprUtils.localizeString(table.desc, this.context.locale),
50
- onClick: () => {
51
- onClose()
52
- return this.props.onChange(table.id)
53
- }
54
- })
55
- )
56
- })
57
- }
58
- })
59
- }
60
- }