@mwater/visualization 5.4.3 → 5.4.5
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/quickfilter/Quickfilter.d.ts +1 -1
- package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +1 -8
- package/lib/quickfilter/QuickfiltersDesignComponent.js +43 -38
- package/package.json +1 -1
- package/src/quickfilter/Quickfilter.ts +1 -1
- package/src/quickfilter/QuickfiltersDesignComponent.tsx +55 -50
|
@@ -3,7 +3,7 @@ import { Expr } from "@mwater/expressions";
|
|
|
3
3
|
design is an array of quick filters (user-selectable filters).
|
|
4
4
|
*/
|
|
5
5
|
export interface Quickfilter {
|
|
6
|
-
/** Optional id for the quickfilter. If not present, a random id will be generated the first time the quickfilter is
|
|
6
|
+
/** Optional id for the quickfilter. If not present, a random id will be generated the first time the quickfilter is edited. */
|
|
7
7
|
id?: string;
|
|
8
8
|
/** filter expression (left hand side only. Usually enum, enumset, text, date, datetime, id[], text[]) */
|
|
9
9
|
expr: Expr;
|
|
@@ -11,11 +11,4 @@ export interface QuickfiltersDesignComponentProps {
|
|
|
11
11
|
/** List of possible table ids to use */
|
|
12
12
|
tables: string[];
|
|
13
13
|
}
|
|
14
|
-
export default
|
|
15
|
-
handleDesignChange: (design: Quickfilter[]) => void;
|
|
16
|
-
isMergeable(design: Quickfilter[], index: number): boolean;
|
|
17
|
-
renderQuickfilter: (item: Quickfilter, index: number) => React.JSX.Element;
|
|
18
|
-
handleAdd: () => void;
|
|
19
|
-
handleRemove: (index: number) => void;
|
|
20
|
-
render(): React.JSX.Element;
|
|
21
|
-
}
|
|
14
|
+
export default function QuickfiltersDesignComponent(props: QuickfiltersDesignComponentProps): React.JSX.Element;
|
|
@@ -26,8 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.default = QuickfiltersDesignComponent;
|
|
29
30
|
const lodash_1 = __importDefault(require("lodash"));
|
|
30
|
-
const react_1 =
|
|
31
|
+
const react_1 = __importStar(require("react"));
|
|
31
32
|
const uuid_1 = __importDefault(require("uuid"));
|
|
32
33
|
const immer_1 = require("immer");
|
|
33
34
|
const expressions_ui_1 = require("@mwater/expressions-ui");
|
|
@@ -35,31 +36,37 @@ const expressions_1 = require("@mwater/expressions");
|
|
|
35
36
|
const ui = __importStar(require("@mwater/react-library/lib/bootstrap"));
|
|
36
37
|
const ListEditorComponent_1 = require("@mwater/react-library/lib/ListEditorComponent");
|
|
37
38
|
// Displays quick filters and allows their value to be modified
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
function QuickfiltersDesignComponent(props) {
|
|
40
|
+
// Add ids if not present
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
if (props.design.some(qf => !qf.id)) {
|
|
43
|
+
const design = (0, immer_1.produce)(props.design, draft => {
|
|
44
|
+
for (let i = 0; i < draft.length; i++) {
|
|
45
|
+
if (!draft[i].id) {
|
|
46
|
+
draft[i].id = uuid_1.default.v4();
|
|
47
|
+
}
|
|
46
48
|
}
|
|
47
|
-
}
|
|
49
|
+
});
|
|
50
|
+
props.onDesignChange(design);
|
|
51
|
+
}
|
|
52
|
+
}, [props.design]);
|
|
53
|
+
const handleDesignChange = (design) => {
|
|
54
|
+
const newDesign = (0, immer_1.produce)(design, draft => {
|
|
48
55
|
// Update merged flag, clearing if not mergeable
|
|
49
56
|
for (let i = 0; i < draft.length; i++) {
|
|
50
|
-
if (draft[i].merged && !
|
|
57
|
+
if (draft[i].merged && !isMergeable(draft, i)) {
|
|
51
58
|
draft[i].merged = false;
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
});
|
|
55
|
-
|
|
62
|
+
props.onDesignChange(newDesign);
|
|
56
63
|
};
|
|
57
64
|
// Determine if quickfilter at index is mergeable with previous (same type, id table and enum values)
|
|
58
|
-
isMergeable(design, index) {
|
|
65
|
+
const isMergeable = (design, index) => {
|
|
59
66
|
if (index === 0) {
|
|
60
67
|
return false;
|
|
61
68
|
}
|
|
62
|
-
const exprUtils = new expressions_1.ExprUtils(
|
|
69
|
+
const exprUtils = new expressions_1.ExprUtils(props.schema);
|
|
63
70
|
const type = exprUtils.getExprType(design[index].expr);
|
|
64
71
|
const prevType = exprUtils.getExprType(design[index - 1].expr);
|
|
65
72
|
const idTable = exprUtils.getExprIdTable(design[index].expr);
|
|
@@ -81,33 +88,32 @@ class QuickfiltersDesignComponent extends react_1.default.Component {
|
|
|
81
88
|
return false;
|
|
82
89
|
}
|
|
83
90
|
return true;
|
|
84
|
-
}
|
|
85
|
-
renderQuickfilter = (item, index) => {
|
|
86
|
-
return react_1.default.createElement(QuickfilterDesignComponent, { key: index, design: item, schema:
|
|
87
|
-
const design =
|
|
91
|
+
};
|
|
92
|
+
const renderQuickfilter = (item, index) => {
|
|
93
|
+
return react_1.default.createElement(QuickfilterDesignComponent, { key: index, design: item, schema: props.schema, dataSource: props.dataSource, tables: props.tables, mergeable: isMergeable(props.design, index), onChange: (newItem) => {
|
|
94
|
+
const design = props.design.slice();
|
|
88
95
|
design[index] = newItem;
|
|
89
|
-
|
|
90
|
-
}, onRemove:
|
|
96
|
+
handleDesignChange(design);
|
|
97
|
+
}, onRemove: () => handleRemove(index) });
|
|
91
98
|
};
|
|
92
|
-
handleAdd = () => {
|
|
99
|
+
const handleAdd = () => {
|
|
93
100
|
// Add blank to end
|
|
94
|
-
const design =
|
|
95
|
-
|
|
101
|
+
const design = (0, immer_1.produce)(props.design, draft => {
|
|
102
|
+
draft.push({ expr: null, id: uuid_1.default.v4() });
|
|
103
|
+
});
|
|
104
|
+
props.onDesignChange(design);
|
|
96
105
|
};
|
|
97
|
-
handleRemove = (index) => {
|
|
98
|
-
const design =
|
|
106
|
+
const handleRemove = (index) => {
|
|
107
|
+
const design = props.design.slice();
|
|
99
108
|
design.splice(index, 1);
|
|
100
|
-
|
|
109
|
+
props.onDesignChange(design);
|
|
101
110
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
T `Add Quick Filter`)) : undefined));
|
|
108
|
-
}
|
|
111
|
+
return (react_1.default.createElement("div", null,
|
|
112
|
+
react_1.default.createElement(ListEditorComponent_1.ListEditorComponent, { items: props.design, onItemsChange: handleDesignChange, renderItem: renderQuickfilter, getReorderableKey: (item, index) => item.id ?? index }),
|
|
113
|
+
props.tables.length > 0 ? (react_1.default.createElement("button", { type: "button", className: "btn btn-sm btn-link", onClick: handleAdd },
|
|
114
|
+
react_1.default.createElement("span", { className: "fas fa-plus me-1" }),
|
|
115
|
+
T `Add Quick Filter`)) : undefined));
|
|
109
116
|
}
|
|
110
|
-
exports.default = QuickfiltersDesignComponent;
|
|
111
117
|
/** Single quickfilter design component */
|
|
112
118
|
class QuickfilterDesignComponent extends react_1.default.Component {
|
|
113
119
|
constructor(props) {
|
|
@@ -119,10 +125,9 @@ class QuickfilterDesignComponent extends react_1.default.Component {
|
|
|
119
125
|
}
|
|
120
126
|
handleTableChange = (table) => {
|
|
121
127
|
this.setState({ table });
|
|
122
|
-
|
|
123
|
-
expr
|
|
124
|
-
};
|
|
125
|
-
return this.props.onChange(design);
|
|
128
|
+
this.props.onChange((0, immer_1.produce)(this.props.design, draft => {
|
|
129
|
+
draft.expr = null;
|
|
130
|
+
}));
|
|
126
131
|
};
|
|
127
132
|
handleExprChange = (expr) => {
|
|
128
133
|
this.props.onChange((0, immer_1.produce)(this.props.design, draft => {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { Expr } from "@mwater/expressions"
|
|
|
4
4
|
design is an array of quick filters (user-selectable filters).
|
|
5
5
|
*/
|
|
6
6
|
export interface Quickfilter {
|
|
7
|
-
/** Optional id for the quickfilter. If not present, a random id will be generated the first time the quickfilter is
|
|
7
|
+
/** Optional id for the quickfilter. If not present, a random id will be generated the first time the quickfilter is edited. */
|
|
8
8
|
id?: string
|
|
9
9
|
|
|
10
10
|
// `table`: (deprecated) table of filter
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from "lodash"
|
|
2
|
-
import React from "react"
|
|
2
|
+
import React, { useEffect, useState } from "react"
|
|
3
3
|
import uuid from "uuid"
|
|
4
4
|
import { produce } from "immer"
|
|
5
5
|
import { ExprComponent } from "@mwater/expressions-ui"
|
|
@@ -20,35 +20,41 @@ export interface QuickfiltersDesignComponentProps {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Displays quick filters and allows their value to be modified
|
|
23
|
-
export default
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
export default function QuickfiltersDesignComponent(props: QuickfiltersDesignComponentProps) {
|
|
24
|
+
// Add ids if not present
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (props.design.some(qf => !qf.id)) {
|
|
27
|
+
const design = produce(props.design, draft => {
|
|
28
|
+
for (let i = 0; i < draft.length; i++) {
|
|
29
|
+
if (!draft[i].id) {
|
|
30
|
+
draft[i].id = uuid.v4()
|
|
31
|
+
}
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
})
|
|
34
|
+
props.onDesignChange(design)
|
|
35
|
+
}
|
|
36
|
+
}, [props.design])
|
|
33
37
|
|
|
38
|
+
const handleDesignChange = (design: Quickfilter[]) => {
|
|
39
|
+
const newDesign = produce(design, draft => {
|
|
34
40
|
// Update merged flag, clearing if not mergeable
|
|
35
41
|
for (let i = 0; i < draft.length; i++) {
|
|
36
|
-
if (draft[i].merged && !
|
|
42
|
+
if (draft[i].merged && !isMergeable(draft, i)) {
|
|
37
43
|
draft[i].merged = false
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
})
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
props.onDesignChange(newDesign)
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
// Determine if quickfilter at index is mergeable with previous (same type, id table and enum values)
|
|
46
|
-
isMergeable(design: Quickfilter[], index: number) {
|
|
52
|
+
const isMergeable = (design: Quickfilter[], index: number) => {
|
|
47
53
|
if (index === 0) {
|
|
48
54
|
return false
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
const exprUtils = new ExprUtils(
|
|
57
|
+
const exprUtils = new ExprUtils(props.schema)
|
|
52
58
|
|
|
53
59
|
const type = exprUtils.getExprType(design[index].expr)
|
|
54
60
|
const prevType = exprUtils.getExprType(design[index - 1].expr)
|
|
@@ -81,53 +87,53 @@ export default class QuickfiltersDesignComponent extends React.Component<Quickfi
|
|
|
81
87
|
return true
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
renderQuickfilter = (item: Quickfilter, index: number) => {
|
|
90
|
+
const renderQuickfilter = (item: Quickfilter, index: number) => {
|
|
85
91
|
return <QuickfilterDesignComponent
|
|
86
92
|
key={index}
|
|
87
93
|
design={item}
|
|
88
|
-
schema={
|
|
89
|
-
dataSource={
|
|
90
|
-
tables={
|
|
91
|
-
mergeable={
|
|
94
|
+
schema={props.schema}
|
|
95
|
+
dataSource={props.dataSource}
|
|
96
|
+
tables={props.tables}
|
|
97
|
+
mergeable={isMergeable(props.design, index)}
|
|
92
98
|
onChange={(newItem: Quickfilter) => {
|
|
93
|
-
const design =
|
|
99
|
+
const design = props.design.slice()
|
|
94
100
|
design[index] = newItem
|
|
95
|
-
|
|
101
|
+
handleDesignChange(design)
|
|
96
102
|
}}
|
|
97
|
-
onRemove={
|
|
103
|
+
onRemove={() => handleRemove(index)}
|
|
98
104
|
/>
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
handleAdd = () => {
|
|
107
|
+
const handleAdd = () => {
|
|
102
108
|
// Add blank to end
|
|
103
|
-
const design =
|
|
104
|
-
|
|
109
|
+
const design = produce(props.design, draft => {
|
|
110
|
+
draft.push({ expr: null, id: uuid.v4() })
|
|
111
|
+
})
|
|
112
|
+
props.onDesignChange(design)
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
handleRemove = (index: number) => {
|
|
108
|
-
const design =
|
|
115
|
+
const handleRemove = (index: number) => {
|
|
116
|
+
const design = props.design.slice()
|
|
109
117
|
design.splice(index, 1)
|
|
110
|
-
|
|
118
|
+
props.onDesignChange(design)
|
|
111
119
|
}
|
|
112
120
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
)
|
|
130
|
-
}
|
|
121
|
+
return (
|
|
122
|
+
<div>
|
|
123
|
+
<ListEditorComponent
|
|
124
|
+
items={props.design}
|
|
125
|
+
onItemsChange={handleDesignChange}
|
|
126
|
+
renderItem={renderQuickfilter}
|
|
127
|
+
getReorderableKey={(item, index) => item.id ?? index}
|
|
128
|
+
/>
|
|
129
|
+
{props.tables.length > 0 ? (
|
|
130
|
+
<button type="button" className="btn btn-sm btn-link" onClick={handleAdd}>
|
|
131
|
+
<span className="fas fa-plus me-1" />
|
|
132
|
+
{T`Add Quick Filter`}
|
|
133
|
+
</button>
|
|
134
|
+
) : undefined}
|
|
135
|
+
</div>
|
|
136
|
+
)
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
interface QuickfilterDesignComponentProps {
|
|
@@ -162,10 +168,9 @@ class QuickfilterDesignComponent extends React.Component<
|
|
|
162
168
|
|
|
163
169
|
handleTableChange = (table: string) => {
|
|
164
170
|
this.setState({ table })
|
|
165
|
-
|
|
166
|
-
expr
|
|
167
|
-
}
|
|
168
|
-
return this.props.onChange(design)
|
|
171
|
+
this.props.onChange(produce(this.props.design, draft => {
|
|
172
|
+
draft.expr = null
|
|
173
|
+
}))
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
handleExprChange = (expr: Expr) => {
|