From f04f3e9b29f164785f5e6c12b3839cbb55133682 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Sat, 10 Dec 2016 22:08:41 +0100 Subject: [PATCH] add simple param type field --- frontend/src/component/feature/form/index.jsx | 2 +- .../src/component/strategies/add-container.js | 4 +-- .../src/component/strategies/add-strategy.jsx | 30 +++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/frontend/src/component/feature/form/index.jsx b/frontend/src/component/feature/form/index.jsx index 1682ea1c79..37f73ab84b 100644 --- a/frontend/src/component/feature/form/index.jsx +++ b/frontend/src/component/feature/form/index.jsx @@ -74,7 +74,7 @@ class AddFeatureToggleComponent extends Component { onChange={() => { setValue('enabled', !enabled); }}>Enabled -
+
{ const parametersTemplate = {}; Object.keys(input).forEach(key => { if (key.startsWith(PARAM_PREFIX)) { - parametersTemplate[input[key]] = 'string'; + parametersTemplate[input[key]] = input[key.replace(PARAM_PREFIX, TYPE_PREFIX)] || 'string'; } }); input.parametersTemplate = parametersTemplate; diff --git a/frontend/src/component/strategies/add-strategy.jsx b/frontend/src/component/strategies/add-strategy.jsx index 576cfeb83e..c42848dbff 100644 --- a/frontend/src/component/strategies/add-strategy.jsx +++ b/frontend/src/component/strategies/add-strategy.jsx @@ -16,17 +16,29 @@ function gerArrayWithEntries (num) { return Array.from(Array(num)); } export const PARAM_PREFIX = 'param_'; +export const TYPE_PREFIX = 'type_'; const genParams = (input, num = 0, setValue) => (
{gerArrayWithEntries(num).map((v, i) => { const key = `${PARAM_PREFIX}${i + 1}`; + const typeKey = `${TYPE_PREFIX}${i + 1}`; return ( - setValue(key, target.value)} - value={input[key]} /> +
+ setValue(key, target.value)} + value={input[key]} /> + setValue(typeKey, target.value)} + value={input[typeKey]} /> + +
); })}
); @@ -63,10 +75,10 @@ const AddStrategy = ({
{genParams(input, input._params, setValue)} - { + { e.preventDefault(); incValue('_params'); - }}/> Add parameter + }}/> &nsbp;Add parameter