@mwater/visualization 5.0.1 → 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.
- package/lib/MWaterAddRelatedFormComponent.d.ts +1 -1
- package/lib/MWaterAddRelatedFormComponent.js +10 -17
- package/lib/MWaterContextComponent.d.ts +17 -7
- package/lib/MWaterContextComponent.js +51 -67
- package/lib/MWaterLoaderComponent.d.ts +2 -2
- package/lib/MWaterLoaderComponent.js +1 -1
- package/lib/MWaterTableSelectComponent.d.ts +0 -1
- package/lib/MWaterTableSelectComponent.js +20 -41
- package/lib/axes/RangesComponent.d.ts +12 -6
- package/lib/axes/RangesComponent.js +21 -10
- package/lib/dashboards/DashboardComponent.d.ts +1 -9
- package/lib/dashboards/DashboardComponent.js +16 -27
- package/lib/dashboards/ServerDashboardDataSource.d.ts +1 -0
- package/lib/dashboards/ServerDashboardDataSource.js +3 -0
- package/lib/datagrids/DatagridComponent.d.ts +8 -4
- package/lib/datagrids/DatagridComponent.js +27 -5
- package/lib/datagrids/DatagridDataSource.d.ts +1 -0
- package/lib/datagrids/DatagridDataSource.js +3 -0
- package/lib/datagrids/DatagridDesign.d.ts +2 -0
- package/lib/datagrids/DatagridDesignerComponent.js +3 -2
- package/lib/datagrids/DatagridViewComponent.js +1 -1
- package/lib/datagrids/DirectDatagridDataSource.d.ts +1 -0
- package/lib/datagrids/DirectDatagridDataSource.js +26 -0
- package/lib/datagrids/ServerDatagridDataSource.d.ts +1 -0
- package/lib/datagrids/ServerDatagridDataSource.js +15 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +2 -4
- package/lib/layouts/blocks/BlocksDisplayComponent.js +2 -2
- package/lib/layouts/grid/LegoLayoutEngine.d.ts +1 -1
- package/lib/maps/BufferLayerDesignerComponent.js +2 -2
- package/lib/maps/ChoroplethLayerDesigner.js +2 -2
- package/lib/maps/ClusterLayerDesignerComponent.js +2 -2
- package/lib/maps/DirectMapDataSource.js +1 -2
- package/lib/maps/GridLayerDesigner.js +2 -2
- package/lib/maps/MapDesignerComponent.d.ts +1 -12
- package/lib/maps/MapDesignerComponent.js +5 -12
- package/lib/maps/MarkersLayerDesignerComponent.js +2 -2
- package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -1
- package/lib/maps/PopupFilterJoinsUtils.js +4 -3
- package/lib/maps/UtfGridLayer.js +1 -1
- package/lib/widgets/ImageWidgetComponent.js +2 -2
- package/lib/widgets/charts/calendar/CalendarChartDesignerComponent.js +2 -2
- package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -1
- package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +1 -1
- package/lib/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.js +2 -2
- package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.js +2 -2
- package/lib/widgets/charts/pivot/PivotChartDesignerComponent.js +2 -2
- package/lib/widgets/charts/table/TableChartDesignerComponent.js +2 -2
- package/lib/widgets/text/ExprItemEditorComponent.js +2 -2
- package/package.json +1 -1
- package/src/MWaterAddRelatedFormComponent.ts +15 -20
- package/src/MWaterContextComponent.tsx +140 -0
- package/src/MWaterLoaderComponent.ts +2 -2
- package/src/{MWaterTableSelectComponent.ts → MWaterTableSelectComponent.tsx} +61 -66
- package/src/axes/AxisBuilder.ts +1 -1
- package/src/axes/RangesComponent.ts +27 -16
- package/src/dashboards/{DashboardComponent.ts → DashboardComponent.tsx} +37 -40
- package/src/dashboards/ServerDashboardDataSource.ts +16 -12
- package/src/datagrids/DatagridComponent.ts +45 -14
- package/src/datagrids/DatagridDataSource.ts +8 -0
- package/src/datagrids/DatagridDesign.ts +3 -0
- package/src/datagrids/DatagridDesignerComponent.tsx +9 -1
- package/src/datagrids/DatagridViewComponent.ts +1 -1
- package/src/datagrids/DirectDatagridDataSource.ts +35 -0
- package/src/datagrids/ServerDatagridDataSource.ts +22 -4
- package/src/index.ts +0 -2
- package/src/layouts/blocks/BlocksDisplayComponent.ts +2 -2
- package/src/layouts/grid/LegoLayoutEngine.ts +2 -2
- package/src/layouts/grid/WidgetContainerComponent.ts +2 -2
- package/src/maps/BingLayer.ts +2 -2
- package/src/maps/BufferLayerDesignerComponent.ts +1 -1
- package/src/maps/ChoroplethLayerDesigner.tsx +1 -1
- package/src/maps/ClusterLayerDesignerComponent.ts +1 -1
- package/src/maps/DirectMapDataSource.ts +1 -2
- package/src/maps/GridLayerDesigner.tsx +1 -1
- package/src/maps/LegendGroup.ts +1 -1
- package/src/maps/MWaterServerLayer.ts +2 -2
- package/src/maps/{MapDesignerComponent.ts → MapDesignerComponent.tsx} +8 -16
- package/src/maps/MarkersLayerDesignerComponent.ts +1 -1
- package/src/maps/PopupFilterJoinsUtils.ts +4 -4
- package/src/maps/ServerMapDataSource.ts +6 -6
- package/src/maps/SwitchableTileUrlLayerDesigner.tsx +1 -13
- package/src/maps/UtfGridLayer.ts +4 -4
- package/src/maps/mapboxUtils.ts +2 -2
- package/src/richtext/ExprItemsHtmlConverter.ts +1 -1
- package/src/richtext/FontColorPaletteItem.ts +1 -1
- package/src/richtext/FontSizePaletteItem.ts +1 -1
- package/src/richtext/ItemsHtmlConverter.ts +2 -2
- package/src/widgets/ImageWidgetComponent.ts +1 -1
- package/src/widgets/charts/calendar/CalendarChartDesignerComponent.ts +1 -1
- package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +1 -1
- package/src/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.ts +1 -1
- package/src/widgets/charts/layered/LayeredChartLayerDesignerComponent.tsx +1 -1
- package/src/widgets/charts/pivot/PivotChartDesignerComponent.tsx +1 -1
- package/src/widgets/charts/table/TableChartDesignerComponent.ts +1 -1
- package/src/widgets/text/ExprItemEditorComponent.tsx +1 -1
- package/src/MWaterContextComponent.ts +0 -141
- package/src/TableSelectComponent.ts +0 -60
package/src/maps/UtfGridLayer.ts
CHANGED
|
@@ -65,8 +65,8 @@ module.exports = L.Layer.extend({
|
|
|
65
65
|
|
|
66
66
|
//Find a unique id in window we can use for our callbacks
|
|
67
67
|
//Required for jsonP
|
|
68
|
-
|
|
69
|
-
while (window["lu" + i]) {
|
|
68
|
+
let i = 0
|
|
69
|
+
while ((window as any)["lu" + i]) {
|
|
70
70
|
i++
|
|
71
71
|
}
|
|
72
72
|
this._windowKey = "lu" + i
|
|
@@ -244,9 +244,9 @@ module.exports = L.Layer.extend({
|
|
|
244
244
|
script.setAttribute("type", "text/javascript")
|
|
245
245
|
script.setAttribute("src", url)
|
|
246
246
|
|
|
247
|
-
window[wk][functionName] = function (data: any) {
|
|
247
|
+
;(window as any)[wk][functionName] = function (data: any) {
|
|
248
248
|
self._cache[key] = data
|
|
249
|
-
delete window[wk][functionName]
|
|
249
|
+
delete (window as any)[wk][functionName]
|
|
250
250
|
head.removeChild(script)
|
|
251
251
|
}
|
|
252
252
|
|
package/src/maps/mapboxUtils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Axis } from "../axes/Axis"
|
|
|
3
3
|
|
|
4
4
|
/** Compile a color mapped axis to mapbox format case statement */
|
|
5
5
|
export function compileColorMapToMapbox(axis: Axis | null | undefined, defaultColor: string): DataDrivenPropertyValueSpecification<string> | string {
|
|
6
|
-
let compiled:
|
|
6
|
+
let compiled: any
|
|
7
7
|
|
|
8
8
|
if (axis && axis.colorMap && axis.colorMap.length > 0) {
|
|
9
9
|
const excludedValues = axis.excludedValues || []
|
|
@@ -31,7 +31,7 @@ export function compileColorMapToMapbox(axis: Axis | null | undefined, defaultCo
|
|
|
31
31
|
|
|
32
32
|
/** Compile a color that is transparent if excluded to mapbox format case statement */
|
|
33
33
|
export function compileColorToMapbox(color: string, excludedValues?: any[]): DataDrivenPropertyValueSpecification<string> | string {
|
|
34
|
-
let compiled:
|
|
34
|
+
let compiled: any
|
|
35
35
|
|
|
36
36
|
if (excludedValues) {
|
|
37
37
|
// Create match operator
|
|
@@ -121,7 +121,7 @@ export default class ExprItemsHtmlConverter extends ItemsHtmlConverter {
|
|
|
121
121
|
const items = super.convertElemToItems(elem)
|
|
122
122
|
|
|
123
123
|
// Ensure exprs have unique ids
|
|
124
|
-
const takenIds = {}
|
|
124
|
+
const takenIds: { [id: string]: boolean } = {}
|
|
125
125
|
var uniqueify = (items: any) => {
|
|
126
126
|
for (let item of items) {
|
|
127
127
|
if (item.type === "expr") {
|
|
@@ -215,7 +215,7 @@ export default class ItemsHtmlConverter {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// Whitelist allowed tags and styles
|
|
218
|
-
var allowedTags = {
|
|
218
|
+
var allowedTags: { [tag: string]: number } = {
|
|
219
219
|
div: 1,
|
|
220
220
|
p: 1,
|
|
221
221
|
ul: 1,
|
|
@@ -236,7 +236,7 @@ var allowedTags = {
|
|
|
236
236
|
strong: 1,
|
|
237
237
|
font: 1
|
|
238
238
|
}
|
|
239
|
-
var allowedStyles = {
|
|
239
|
+
var allowedStyles: { [style: string]: number } = {
|
|
240
240
|
"text-align": 1,
|
|
241
241
|
"font-weight": 1,
|
|
242
242
|
"font-style": 1,
|
|
@@ -10,7 +10,7 @@ import DropdownWidgetComponent from "./DropdownWidgetComponent"
|
|
|
10
10
|
import ModalPopupComponent from "@mwater/react-library/lib/ModalPopupComponent"
|
|
11
11
|
import TabbedComponent from "@mwater/react-library/lib/TabbedComponent"
|
|
12
12
|
import { ExprComponent } from "@mwater/expressions-ui"
|
|
13
|
-
import TableSelectComponent from "
|
|
13
|
+
import { TableSelectComponent } from "@mwater/expressions-ui"
|
|
14
14
|
import ImageUploaderComponent from "./ImageUploaderComponent"
|
|
15
15
|
import ImagelistCarouselComponent from "./ImagelistCarouselComponent"
|
|
16
16
|
import { DataSource, Schema } from "@mwater/expressions"
|
|
@@ -7,7 +7,7 @@ import { DataSource, ExprUtils, Schema } from "@mwater/expressions"
|
|
|
7
7
|
import AxisBuilder from "../../../axes/AxisBuilder"
|
|
8
8
|
import AxisComponent from "../../../axes/AxisComponent"
|
|
9
9
|
import { FilterExprComponent } from "@mwater/expressions-ui"
|
|
10
|
-
import TableSelectComponent from "
|
|
10
|
+
import { TableSelectComponent } from "@mwater/expressions-ui"
|
|
11
11
|
import ColorComponent from "../../../ColorComponent"
|
|
12
12
|
import { CalendarChartDesign } from "./CalendarChart"
|
|
13
13
|
|
|
@@ -183,7 +183,7 @@ export default class ImageMosaicChart extends Chart {
|
|
|
183
183
|
|
|
184
184
|
createDataTable(design: any, schema: Schema, dataSource: DataSource, data: any) {
|
|
185
185
|
alert("Not available for Image Mosaics")
|
|
186
|
-
return
|
|
186
|
+
return []
|
|
187
187
|
}
|
|
188
188
|
// TODO
|
|
189
189
|
// renderHeaderCell = (column) =>
|
|
@@ -8,7 +8,7 @@ import { DataSource, ExprUtils, Schema } from "@mwater/expressions"
|
|
|
8
8
|
import AxisBuilder from "../../../axes/AxisBuilder"
|
|
9
9
|
import AxisComponent from "../../../axes/AxisComponent"
|
|
10
10
|
import { FilterExprComponent } from "@mwater/expressions-ui"
|
|
11
|
-
import TableSelectComponent from "
|
|
11
|
+
import { TableSelectComponent } from "@mwater/expressions-ui"
|
|
12
12
|
|
|
13
13
|
export interface ImageMosaicChartDesignerComponentProps {
|
|
14
14
|
design: any
|
|
@@ -11,7 +11,7 @@ import ColorComponent from "../../../ColorComponent"
|
|
|
11
11
|
import * as LayeredChartUtils from "./LayeredChartUtils"
|
|
12
12
|
import LayeredChartCompiler from "./LayeredChartCompiler"
|
|
13
13
|
import * as uiComponents from "../../../UIComponents"
|
|
14
|
-
import TableSelectComponent from "
|
|
14
|
+
import { TableSelectComponent } from "@mwater/expressions-ui"
|
|
15
15
|
import * as ui from "@mwater/react-library/lib/bootstrap"
|
|
16
16
|
import { Checkbox } from "@mwater/react-library/lib/bootstrap"
|
|
17
17
|
import PopoverHelpComponent from "@mwater/react-library/lib/PopoverHelpComponent"
|
|
@@ -5,7 +5,7 @@ const R = React.createElement
|
|
|
5
5
|
import uuid from "uuid"
|
|
6
6
|
import * as ui from "@mwater/react-library/lib/bootstrap"
|
|
7
7
|
import { FilterExprComponent } from "@mwater/expressions-ui"
|
|
8
|
-
import TableSelectComponent from "
|
|
8
|
+
import { TableSelectComponent } from "@mwater/expressions-ui"
|
|
9
9
|
import AxisComponent from "../../../axes/AxisComponent"
|
|
10
10
|
import { DataSource, Schema } from "@mwater/expressions"
|
|
11
11
|
|
|
@@ -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 "
|
|
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"
|
|
@@ -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 "
|
|
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"
|
|
@@ -1,141 +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
|
-
// Nothing initially open
|
|
126
|
-
context.isScalarExprTreeSectionInitiallyOpen = (options: any) => {
|
|
127
|
-
return null
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return context
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
handleAddTable = (table: any) => {
|
|
134
|
-
const extraTables = _.union(this.props.extraTables || [], [table])
|
|
135
|
-
return this.props.onExtraTablesChange!(extraTables)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
render() {
|
|
139
|
-
return this.props.children
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -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
|
-
}
|