From cf5906dc892a25db6b70b1ec3d4cc052b32fea9a Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Mon, 6 Jan 2020 16:36:19 +0000 Subject: [PATCH] Reorganise multi data entry --- .../data-components/multi-data-entry.tsx | 92 +++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/app/src/frontend/building/data-components/multi-data-entry.tsx b/app/src/frontend/building/data-components/multi-data-entry.tsx index ce4e0644..3e3b25b1 100644 --- a/app/src/frontend/building/data-components/multi-data-entry.tsx +++ b/app/src/frontend/building/data-components/multi-data-entry.tsx @@ -50,16 +50,16 @@ class MultiDataEntry extends Component this.props.onChange(this.props.slug, values); } - remove(event){ - const removeIndex = +event.target.dataset.index; + remove(index: number){ const values = this.getValues(); - values.splice(removeIndex, 1); + values.splice(index, 1); this.props.onChange(this.props.slug, values); } render() { const values = this.getValues(); const props = this.props; + const isDisabled = props.mode === 'view' || props.disabled; return tooltip={props.tooltip} disabled={props.disabled || props.value == undefined || props.value.length === 0} /> +
    { - (props.mode === 'view')? - (props.value && props.value.length)? -
      - { - props.value.map((item, index) => { - return
    • - {item} -
    • ; - }) - } -
    - :'\u00A0' - : <> - {values.map((val, i) => ( -
    - this.edit(i, val)} - - maxLength={props.maxLength} - placeholder={props.placeholder} - valueTransform={props.valueTransform} - /> -
    - -
    -
    - ))} -
    + values.length === 0 && +
    No elements
    + } + { + values.map((val, i) => ( +
  • this.setNewValue(val)} + slug={`${props.slug}-${i}`} + value={val} + disabled={isDisabled} + onChange={(key, val) => this.edit(i, val)} maxLength={props.maxLength} placeholder={props.placeholder} valueTransform={props.valueTransform} /> -
    - -
    + { + !isDisabled && +
    + +
    + } +
  • + )) + } +
+ { + !isDisabled && +
+ this.setNewValue(val)} + + maxLength={props.maxLength} + placeholder={props.placeholder} + valueTransform={props.valueTransform} + /> +
+
- +
}
; }