Skip to content

Commit c13e952

Browse files
authored
Add Store in VectorCalculator and functional upgrades (#860)
Refactor `VectorCalculator` to use app global `Store`-concept and adjust to updates in `VectorSelector`/`SmartNodeSelector`. - Use `Context` and `useReducer` to create a app global `store` for current `state`. - Improve layout for consistent view an prevent resizing during editing/usage - Component inherit sizes from parent. - Add dialogs for improved user interaction when selecting new active expression and edited data is not saved - Updated usage according to new features in `VectorSelector`/`SmartNodeSelector` - Re-organize folder structure of components for clarity - Rename components for clarity: - ExpressionInputComponent -> `ExpressionEditComponent` - VariablesTable->`VectorSelectorTable`
1 parent 6392ddf commit c13e952

28 files changed

+2359
-2734
lines changed

react/package-lock.json

Lines changed: 805 additions & 1583 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/src/demo/VectorCalculatorDemo.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,16 @@ class VectorCalculatorDemo extends Component {
602602

603603
render() {
604604
return (
605-
<VectorCalculator
606-
id="vector_calculator"
607-
vectors={this.vectors}
608-
expressions={this.expressions}
609-
isDashControlled={false}
610-
maxExpressionDescriptionLength={35}
611-
setProps={this.setProps}
612-
/>
605+
<div style={{ height: "60vh", width: "90vw" }}>
606+
<VectorCalculator
607+
id="vector_calculator"
608+
vectors={this.vectors}
609+
expressions={this.expressions}
610+
isDashControlled={false}
611+
maxExpressionDescriptionLength={35}
612+
setProps={this.setProps}
613+
/>
614+
</div>
613615
);
614616
}
615617
}

react/src/lib/components/VectorCalculator/VectorCalculator.css

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,70 @@
11
.VectorCalculator {
22
display: block;
3-
padding: 5px;
43
flex-grow: 1;
4+
margin-top: 5px;
5+
height: 100%;
56
}
67

7-
.VectorCalculator .ExpressionInputComponent {
8-
padding: 20px;
9-
min-width: 400px;
8+
.VectorCalculator > .MuiGrid-root {
9+
height: 100%;
1010
}
1111

12-
.VectorCalculator .ExpressionTableComponent {
13-
padding: 20px;
14-
min-width: 360px;
12+
.VectorCalculator .WarningAlert {
13+
position: absolute;
14+
bottom: 8px;
15+
right: 8px;
1516
}
1617

1718
.VectorCalculator .ExpressionsTableHeader {
1819
font-weight: bold;
20+
background-color: #f7f7f7;
21+
}
22+
23+
.VectorCalculator .ExpressionsTableHeaderTable {
24+
table-layout: fixed;
1925
}
2026

21-
.VectorCalculator .ExpressionsTableHeaderNameCell {
27+
.VectorCalculator .ExpressionsTableNameCell {
2228
width: 35%;
2329
}
2430

25-
.VectorCalculator .ExpressionsTableHeaderExpressionCell {
31+
.VectorCalculator .ExpressionsTableExpressionCell {
2632
width: 65%;
2733
}
2834

35+
.VectorCalculator .TableWrapperGridItem {
36+
flex-grow: 4;
37+
height: 0;
38+
border: 1px #ccc solid;
39+
background-color: #fff;
40+
padding: 0;
41+
position: relative;
42+
}
43+
44+
.VectorCalculator .TableWrapperGridItem tbody {
45+
height: 100%;
46+
background-color: #fff;
47+
}
48+
2949
.VectorCalculator .ExpressionsTable {
3050
position: relative;
31-
max-height: 450px;
3251
max-width: 100%;
52+
max-height: 100%;
53+
height: calc(100% - 57px);
54+
background-color: #fff;
3355
}
3456

3557
.VectorCalculator .ExpressionsTable table {
3658
table-layout: fixed;
3759
}
3860

61+
.VectorCalculator .ExpressionsTable .Mui-selected {
62+
background-color: #edf4fb;
63+
}
64+
65+
.VectorCalculator .ExpressionsTable .Mui-selected:hover {
66+
background-color: #e3eefa;
67+
}
3968
.VectorCalculator .ExpressionsTableCell {
4069
display: inline-block;
4170
position: relative;
@@ -45,13 +74,43 @@
4574
text-overflow: ellipsis;
4675
}
4776

77+
.VectorCalculator .ExpressionNameTextFieldGridItem {
78+
height: 90px;
79+
}
80+
.VectorCalculator .ExpressionInputTextFieldGridItem {
81+
height: 90px;
82+
}
83+
.VectorCalculator .ExpressionDescriptionTextFieldGridItem {
84+
height: 90px;
85+
}
86+
.VectorCalculator .VectorSelectorTableGridItem {
87+
min-height: 70px;
88+
}
89+
90+
.VectorCalculator .ActionButtonsGridItem {
91+
height: 80px;
92+
}
93+
4894
.VectorCalculator .TextFieldWrapper {
4995
height: 58px;
5096
}
5197

52-
.VectorCalculator .VariablesTableContainer {
53-
overflow: visible;
98+
.VectorCalculator .VectorSelectorTableContainer {
5499
position: relative;
100+
max-height: 100%;
101+
max-width: 100%;
102+
}
103+
104+
.VectorCalculator .VectorSelectorTableContainer table {
105+
table-layout: fixed;
106+
}
107+
108+
.VectorCalculator .VectorSelectorTableVariableColumn {
109+
width: 10%;
110+
}
111+
112+
.VectorCalculator .VectorSelectorTableVectorSelectorColumn {
113+
min-width: 240px;
55114
}
56115

57116
.VectorCalculator .DisableOverlay {

react/src/lib/components/VectorCalculator/VectorCalculator.jsx

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33

4+
import {
5+
ExpressionTypePropTypes,
6+
ExternalParseDataPropTypes,
7+
} from "./utils/VectorCalculatorTypes";
48
import { VectorCalculatorComponent } from "./components/VectorCalculatorComponent";
5-
import { string } from "jsverify";
6-
import "!style-loader!css-loader!./VectorCalculator.css";
9+
import { StoreProvider } from "./components/ExpressionsStore";
710

811
/**
912
* VectorCalculator is a component that allows to calculate new vectors by creating a mathematical expression
1013
* based existing vectors.
1114
*
12-
* New calcualted vectors are created by writing a mathematical equation with single character variables,
15+
* New calculated vectors are created by writing a mathematical equation with single character variables,
1316
* where each variable is assigned a vector from the set of existing vectors.
1417
*
1518
* The component provides a list of valid expressions which can be used externally to calculate the wanted
@@ -20,9 +23,9 @@ import "!style-loader!css-loader!./VectorCalculator.css";
2023
*/
2124
export const VectorCalculator = (props) => {
2225
return (
23-
<div className={"VectorCalculator"}>
26+
<StoreProvider initialExpressions={props.expressions}>
2427
<VectorCalculatorComponent {...props} />
25-
</div>
28+
</StoreProvider>
2629
);
2730
};
2831

@@ -46,23 +49,10 @@ VectorCalculator.propTypes = {
4649
/**
4750
* Pre-defined vector calculator expressions.
4851
* Each expression consist of an expression name, mathematical expression string with variables
49-
* and a map of characther variables and the corresponding vector name.
52+
* and a map of character variables and the corresponding vector name.
5053
*/
5154
expressions: PropTypes.arrayOf(
52-
PropTypes.shape({
53-
name: PropTypes.string.isRequired,
54-
expression: PropTypes.string.isRequired,
55-
id: PropTypes.string.isRequired,
56-
variableVectorMap: PropTypes.arrayOf(
57-
PropTypes.shape({
58-
variableName: string.isRequired,
59-
vectorName: string.isRequired,
60-
})
61-
).isRequired,
62-
description: PropTypes.string,
63-
isValid: PropTypes.bool.isRequired,
64-
isDeletable: PropTypes.bool.isRequired,
65-
})
55+
PropTypes.shape(ExpressionTypePropTypes).isRequired
6656
).isRequired,
6757

6858
/**
@@ -83,12 +73,7 @@ VectorCalculator.propTypes = {
8373
/**
8474
* Data for external parsing of mathematical expression
8575
*/
86-
externalParseData: PropTypes.shape({
87-
expression: PropTypes.string.isRequired,
88-
id: PropTypes.string.isRequired,
89-
variables: PropTypes.arrayOf(string.isRequired).isRequired,
90-
isValid: PropTypes.bool.isRequired,
91-
}),
76+
externalParseData: PropTypes.shape(ExternalParseDataPropTypes),
9277

9378
/**
9479
* Dash-assigned callback that should be called to report property changes

0 commit comments

Comments
 (0)