Commit f7c83505 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH

[js][alg] fix lifecycle event, use old lifecycle handler that doesnt require `static`

parent 0385cde9
......@@ -156,6 +156,7 @@ export class EntityDetail extends React.Component<Props, State> {
<DataformatEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
{
......@@ -171,6 +172,7 @@ export class EntityDetail extends React.Component<Props, State> {
<DatabaseEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
{
......@@ -178,6 +180,7 @@ export class EntityDetail extends React.Component<Props, State> {
<ExperimentEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
{
......@@ -185,6 +188,7 @@ export class EntityDetail extends React.Component<Props, State> {
<ToolchainEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
{
......@@ -192,6 +196,7 @@ export class EntityDetail extends React.Component<Props, State> {
<PlotterEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
{
......@@ -199,6 +204,7 @@ export class EntityDetail extends React.Component<Props, State> {
<PlotterparameterEditorContainer
data={obj}
saveFunc={this.saveChanges}
index={index}
/>
}
</TabPane>
......
......@@ -82,13 +82,11 @@ export class AlgorithmEditor extends React.Component<Props, State> {
}
// if the data changes behind the scenes, update the editor with these changes
/*
getDerivedStateFromProps (nextProps: Props) {
return {
UNSAFE_componentWillReceiveProps (nextProps: Props) {
this.setState({
validity: this.getValidity(nextProps.data, nextProps.algorithms),
};
});
}
*/
// get the result types (analyzer result types are restricted to a subset of all available types)
getResultDfs = (): string[] => ANALYZER_RESULT_TYPES.concat(this.props.dataformats.filter(d => d.name.startsWith('plot')).map(d => d.name))
......
......@@ -23,6 +23,7 @@ import type { BeatObject } from '@helpers/beat';
import * as Selectors from '@store/selectors.js';
import * as Actions from '@store/actions.js';
import CacheInput from '../CacheInput.jsx';
import ValidSchemaBadge from '../ValidSchemaBadge.jsx';
import DeleteInputBtn from '../DeleteInputBtn.jsx';
......@@ -36,10 +37,10 @@ type Props = {
libraries: BeatObject[],
plotDfNames: string[],
saveFunc: (BeatObject) => any,
updateFunc: (BeatObject) => any,
};
type State = {
cache: any,
choiceCache: string,
};
......@@ -50,24 +51,15 @@ export class PlotterEditor extends React.Component<Props, State> {
}
state = {
cache: getValidObj(this.props.data),
choiceCache: '',
}
componentWillReceiveProps (nextProps: Props) {
this.setState({
cache: getValidObj(nextProps.data),
});
}
setContents = (newContents: any) => {
this.setState({
cache: {
...this.state.cache,
contents: {
...this.state.cache.contents,
...newContents,
}
this.props.updateFunc({
...this.props.data,
contents: {
...this.props.data.contents,
...newContents,
}
});
}
......@@ -86,7 +78,7 @@ export class PlotterEditor extends React.Component<Props, State> {
// renames a parameter (provide name & value & the old name)
// deletes a parameter (provide null as name, value is optional, the name)
updateParameter = (name: null | string, value: any, oldName: ?string) => {
const params = jsonClone(this.state.cache.contents.parameters);
const params = jsonClone(this.props.data.contents.parameters);
if(oldName)
delete params[oldName];
if(name !== null)
......@@ -102,13 +94,13 @@ export class PlotterEditor extends React.Component<Props, State> {
className='mx-auto'
outline
color='secondary'
onClick={() => this.props.saveFunc(this.state.cache)}
onClick={() => this.props.saveFunc(this.props.data)}
>
Save Changes (Changes are <ValidSchemaBadge entity='plotter' obj={this.state.cache} />)
Save Changes (Changes are <ValidSchemaBadge entity='plotter' obj={this.props.data} />)
</Button>
{/*
<TemplateButton
data={this.state.cache}
data={this.props.data}
entity={'plotter'}
/>
*/}
......@@ -121,7 +113,7 @@ export class PlotterEditor extends React.Component<Props, State> {
type='text'
id='plDesc'
placeholder='Plotter description...'
value={this.state.cache.contents.description}
value={this.props.data.contents.description}
onChange={(e) => this.updateDescription(e.target.value)}
/>
</FormGroup>
......@@ -131,7 +123,7 @@ export class PlotterEditor extends React.Component<Props, State> {
id='plDf'
type='select'
className='custom-select'
value={this.state.cache.contents.dataformat}
value={this.props.data.contents.dataformat}
onChange={e => this.updateDataformat(e.target.value)}
>
{
......@@ -144,7 +136,7 @@ export class PlotterEditor extends React.Component<Props, State> {
<FormGroup>
<h5>Parameters</h5>
{
(Object.entries(this.state.cache.contents.parameters): [string, any][]).map(([name, param], i, params) => (
(Object.entries(this.props.data.contents.parameters): [string, any][]).map(([name, param], i, params) => (
<Row key={i} className='mb-2'>
<Col sm='12'>
<ParameterCreate
......@@ -160,7 +152,7 @@ export class PlotterEditor extends React.Component<Props, State> {
<Button outline block
id='newParameterBtn'
onClick={() => {
const newKey = generateNewKey('parameter', Object.keys(this.state.cache.contents.parameters || {}));
const newKey = generateNewKey('parameter', Object.keys(this.props.data.contents.parameters || {}));
this.updateParameter(
newKey,
{
......@@ -182,11 +174,21 @@ export class PlotterEditor extends React.Component<Props, State> {
}
const mapStateToProps = (state, ownProps) => {
const plotters = Selectors.plotterGet(state);
const obj = {
libraries: Selectors.libraryGet(state),
plotDfNames: Selectors.dataformatGet(state).map(df => df.name).filter(df => df.startsWith('plot/')),
data: plotters[ownProps.index] || getValidObj(),
};
return obj;
};
export default connect(mapStateToProps)(PlotterEditor);
const mapDispatchToProps = (dispatch, ownProps) => ({
// replace the obj in the Redux store with the new object
updateFunc: (obj) => {
console.log(`dispatching for ${ obj.name }`);
dispatch(Actions[`plotterUpdate`](obj.name, obj));
},
});
export default connect(mapStateToProps, mapDispatchToProps)(PlotterEditor);
......@@ -23,6 +23,7 @@ import type { BeatObject } from '@helpers/beat';
import * as Selectors from '@store/selectors.js';
import * as Actions from '@store/actions.js';
import CacheInput from '../CacheInput.jsx';
import ValidSchemaBadge from '../ValidSchemaBadge.jsx';
import DeleteInputBtn from '../DeleteInputBtn.jsx';
......@@ -35,36 +36,21 @@ type Props = {
plotters: BeatObject[],
data: BeatObject,
saveFunc: (BeatObject) => any,
updateFunc: (BeatObject) => any,
};
type State = {
cache: any,
};
export class PlotterParameterEditor extends React.Component<Props, State> {
export class PlotterParameterEditor extends React.Component<Props> {
constructor(props: Props) {
//console.log(`Creating AlgDetail`);
super(props);
}
state = {
cache: getValidObj(this.props.data),
}
componentWillReceiveProps (nextProps: Props) {
this.setState({
cache: getValidObj(nextProps.data),
});
}
setContents = (newContents: any) => {
this.setState({
cache: {
...this.state.cache,
contents: {
...this.state.cache.contents,
...newContents,
}
this.props.updateFunc({
...this.props.data,
contents: {
...this.props.data.contents,
...newContents,
}
});
}
......@@ -74,7 +60,7 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
}
getPlotterName = (): string => {
return this.state.cache.contents.plotter;
return this.props.data.contents.plotter;
}
getPlotter = (name: ?string) => {
......@@ -100,7 +86,7 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
updateParameter = (pName: string, v: number | string | boolean) => {
this.setContents({
data: {
...this.state.cache.contents.data,
...this.props.data.contents.data,
[pName]: v
}
});
......@@ -117,13 +103,13 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
className='mx-auto'
outline
color='secondary'
onClick={() => this.props.saveFunc(this.state.cache)}
onClick={() => this.props.saveFunc(this.props.data)}
>
Save Changes (Changes are <ValidSchemaBadge entity='plotterparameter' obj={this.state.cache} />)
Save Changes (Changes are <ValidSchemaBadge entity='plotterparameter' obj={this.props.data} />)
</Button>
{/*
<TemplateButton
data={this.state.cache}
data={this.props.data}
entity={'plotter'}
/>
*/}
......@@ -136,7 +122,7 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
type='text'
id='ppDesc'
placeholder='Parameter description...'
value={this.state.cache.contents.description}
value={this.props.data.contents.description}
onChange={(e) => this.updateDescription(e.target.value)}
/>
</FormGroup>
......@@ -167,7 +153,7 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
<ParameterConsume
parameter={o}
updateFunc={(v: any) => this.updateParameter(pName, v)}
currVal={this.state.cache.contents.data[pName]}
currVal={this.props.data.contents.data[pName]}
/>
</Col>
</FormGroup>
......@@ -181,10 +167,20 @@ export class PlotterParameterEditor extends React.Component<Props, State> {
}
const mapStateToProps = (state, ownProps) => {
const params = Selectors.plotterparameterGet(state);
const obj = {
plotters: Selectors.plotterGet(state),
data: params[ownProps.index] || getValidObj(),
};
return obj;
};
export default connect(mapStateToProps)(PlotterParameterEditor);
const mapDispatchToProps = (dispatch, ownProps) => ({
// replace the obj in the Redux store with the new object
updateFunc: (obj) => {
console.log(`dispatching for ${ obj.name }`);
dispatch(Actions[`plotterparameterUpdate`](obj.name, obj));
},
});
export default connect(mapStateToProps, mapDispatchToProps)(PlotterParameterEditor);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment