From a4961cc6d30288c514cab947758711f75e69cf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 12 Feb 2020 22:10:43 +0100 Subject: [PATCH] fix: missing feature toggle should pre-fill name --- .../feature/form/form-add-feature-container.jsx | 8 +++++--- frontend/src/component/feature/form/util.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/component/feature/form/form-add-feature-container.jsx b/frontend/src/component/feature/form/form-add-feature-container.jsx index b60bc082b4..5f894cf122 100644 --- a/frontend/src/component/feature/form/form-add-feature-container.jsx +++ b/frontend/src/component/feature/form/form-add-feature-container.jsx @@ -4,14 +4,16 @@ import { connect } from 'react-redux'; import arrayMove from 'array-move'; import { createFeatureToggles, validateName } from './../../../store/feature-actions'; import AddFeatureComponent from './form-add-feature-component'; +import { loadNameFromHash } from './util'; const defaultStrategy = { name: 'default' }; class WrapperComponent extends Component { - constructor() { - super(); + constructor(props) { + super(props); + const name = loadNameFromHash(); this.state = { - featureToggle: { name: '', description: '', strategies: [], enabled: true }, + featureToggle: { name, description: '', strategies: [], enabled: true }, errors: {}, dirty: false, }; diff --git a/frontend/src/component/feature/form/util.js b/frontend/src/component/feature/form/util.js index 8864343b74..0fcca83bda 100644 --- a/frontend/src/component/feature/form/util.js +++ b/frontend/src/component/feature/form/util.js @@ -5,3 +5,13 @@ export const trim = value => { return value; } }; + +export function loadNameFromHash() { + let field = ''; + try { + [, field] = document.location.hash.match(/name=([a-z0-9-_.]+)/i); + } catch (e) { + // nothing + } + return field; +}