From 53909f9ca0b6da1d9fd30179d87baba91d54960f Mon Sep 17 00:00:00 2001 From: sveisvei Date: Tue, 13 Dec 2016 23:22:26 +0100 Subject: [PATCH] pick up name from hash query when no input data --- .../src/component/feature/form-add-container.jsx | 11 ++++++++++- frontend/src/component/strategies/add-container.js | 14 ++++++++++---- .../src/component/strategies/list-component.jsx | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/component/feature/form-add-container.jsx b/frontend/src/component/feature/form-add-container.jsx index de88d3acb2..2fe90c51d6 100644 --- a/frontend/src/component/feature/form-add-container.jsx +++ b/frontend/src/component/feature/form-add-container.jsx @@ -5,7 +5,16 @@ import { createMapper, createActions } from '../input-helpers'; import FormComponent from './form'; const ID = 'add-feature-toggle'; -const mapStateToProps = createMapper({ id: ID }); +const mapStateToProps = createMapper({ + id: ID, + getDefault () { + let name; + try { + [, name] = document.location.hash.match(/name=([a-z0-9-_]+)/i); + } catch (e) {} + return { name }; + }, +}); const prepare = (methods, dispatch) => { methods.onSubmit = (input) => ( (e) => { diff --git a/frontend/src/component/strategies/add-container.js b/frontend/src/component/strategies/add-container.js index b7e865413b..53cf00f46b 100644 --- a/frontend/src/component/strategies/add-container.js +++ b/frontend/src/component/strategies/add-container.js @@ -11,9 +11,6 @@ const prepare = (methods, dispatch) => { methods.onSubmit = (input) => ( (e) => { e.preventDefault(); - - - // clean const parameters = input.parameters .filter((name) => !!name) @@ -56,4 +53,13 @@ const actions = createActions({ prepare, }); -export default connect(createMapper({ id: ID }), actions)(AddStrategy); +export default connect(createMapper({ + id: ID, + getDefault () { + let name; + try { + [, name] = document.location.hash.match(/name=([a-z0-9-_]+)/i); + } catch (e) {} + return { name }; + }, +}), actions)(AddStrategy); diff --git a/frontend/src/component/strategies/list-component.jsx b/frontend/src/component/strategies/list-component.jsx index 41aa438caf..e6eaa700a7 100644 --- a/frontend/src/component/strategies/list-component.jsx +++ b/frontend/src/component/strategies/list-component.jsx @@ -20,7 +20,7 @@ class StrategiesListComponent extends Component { return (
this.context.router.push('/strategies/create')} title="Add new strategy" />} /> + actions={ this.context.router.push('/strategies/create')} title="Add new strategy" />} /> {strategies.length > 0 ? strategies.map((strategy, i) => { return (