Skip to content

Commit

Permalink
(improvement) strategy editor: remember selected strategy after page …
Browse files Browse the repository at this point in the history
…change (#340)

* strategy: fix app crash
* strategy editor: remember selected strategy after page change
* Update src/components/StrategyEditor/StrategyEditor.js
Co-authored-by: Andrii R. <margareq@protonmail.ch>
* indent
* new line
Co-authored-by: Andrii R. <margareq@protonmail.ch>
  • Loading branch information
bhoomij authored Apr 8, 2021
1 parent 2488b00 commit d29a800
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/StrategyEditor/StrategyEditor.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const mapStateToProps = (state = {}) => ({
activeMarket: getActiveMarket(state),
authToken: getAuthToken(state),
strategyId: getStrategyId(state),
strategyContent: state.ui.content,
})

const mapDispatchToProps = dispatch => ({
Expand Down
16 changes: 15 additions & 1 deletion src/components/StrategyEditor/StrategyEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ export default class StrategyEditor extends React.PureComponent {
gaCreateStrategy: PropTypes.func.isRequired,
onIndicatorsChange: PropTypes.func.isRequired,
clearBacktestOptions: PropTypes.func.isRequired,
strategyContent: PropTypes.objectOf(
PropTypes.oneOfType([
PropTypes.string.isRequired,
PropTypes.oneOf([null]).isRequired,
]),
),
}
static defaultProps = {
strategyId: '',
moveable: false,
removeable: false,
renderResults: true,
strategyContent: {},
}

state = {
Expand All @@ -69,6 +76,13 @@ export default class StrategyEditor extends React.PureComponent {
openExistingStrategyModalOpen: false,
}

componentDidMount() {
const { strategyContent } = this.props
this.setState(() => ({
strategy: strategyContent,
}))
}

onCreateNewStrategy = (label, templateLabel) => {
const strategy = { label }
const template = Templates.find(t => t.label === templateLabel)
Expand Down Expand Up @@ -395,7 +409,7 @@ export default class StrategyEditor extends React.PureComponent {
openExistingStrategyModalOpen,
} = this.state

if (!strategy) {
if (!strategy || _isEmpty(strategy)) {
return this.renderPanel(this.renderEmptyContent())
}

Expand Down
4 changes: 0 additions & 4 deletions src/pages/StrategyEditor/StrategyEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export default class StrategyEditorPage extends React.Component {
.then(t => this.setState(() => ({ docsText: t })))
}

componentWillUnmount() {
this.setContent(null)
}

onIndicatorsChange = (indicators) => {
// TODO: Better color generation; to save time we generate enough colors for
// all indicators here, but optimally we'd switch on i.constructor.ui
Expand Down

0 comments on commit d29a800

Please sign in to comment.