|
1 |
| -import { map } from 'lodash'; |
| 1 | +import { map, merge } from 'lodash'; |
2 | 2 | import React from 'react';
|
3 | 3 | import Select from 'antd/lib/select';
|
| 4 | +import InputNumber from 'antd/lib/input-number'; |
| 5 | +import * as Grid from 'antd/lib/grid'; |
4 | 6 | import { EditorPropTypes } from '@/visualizations';
|
5 | 7 |
|
6 |
| -const { Option } = Select; |
7 |
| - |
8 | 8 | export default function Editor({ options, data, onOptionsChange }) {
|
9 |
| - const onColumnChanged = (column) => { |
10 |
| - const newOptions = { ...options, column }; |
11 |
| - onOptionsChange(newOptions); |
| 9 | + const optionsChanged = (newOptions) => { |
| 10 | + onOptionsChange(merge({}, options, newOptions)); |
12 | 11 | };
|
13 | 12 |
|
14 | 13 | return (
|
15 |
| - <div className="form-group"> |
16 |
| - <label className="control-label" htmlFor="word-cloud-column">Word Cloud Column Name</label> |
17 |
| - <Select |
18 |
| - id="word-cloud-column" |
19 |
| - className="w-100" |
20 |
| - value={options.column} |
21 |
| - onChange={onColumnChanged} |
22 |
| - > |
23 |
| - {map(data.columns, ({ name }) => ( |
24 |
| - <Option key={name}>{name}</Option> |
25 |
| - ))} |
26 |
| - </Select> |
27 |
| - </div> |
| 14 | + <React.Fragment> |
| 15 | + <div className="form-group"> |
| 16 | + <label className="control-label" htmlFor="word-cloud-words-column">Words Column</label> |
| 17 | + <Select |
| 18 | + data-test="WordCloud.WordsColumn" |
| 19 | + id="word-cloud-words-column" |
| 20 | + className="w-100" |
| 21 | + value={options.column} |
| 22 | + onChange={column => optionsChanged({ column })} |
| 23 | + > |
| 24 | + {map(data.columns, ({ name }) => ( |
| 25 | + <Select.Option key={name} data-test={'WordCloud.WordsColumn.' + name}>{name}</Select.Option> |
| 26 | + ))} |
| 27 | + </Select> |
| 28 | + </div> |
| 29 | + <div className="form-group"> |
| 30 | + <label className="control-label" htmlFor="word-cloud-frequencies-column">Frequencies Column</label> |
| 31 | + <Select |
| 32 | + data-test="WordCloud.FrequenciesColumn" |
| 33 | + id="word-cloud-frequencies-column" |
| 34 | + className="w-100" |
| 35 | + value={options.frequenciesColumn} |
| 36 | + onChange={frequenciesColumn => optionsChanged({ frequenciesColumn })} |
| 37 | + > |
| 38 | + <Select.Option key="none" value=""><i>(count word frequencies automatically)</i></Select.Option> |
| 39 | + {map(data.columns, ({ name }) => ( |
| 40 | + <Select.Option key={'column-' + name} value={name} data-test={'WordCloud.FrequenciesColumn.' + name}>{name}</Select.Option> |
| 41 | + ))} |
| 42 | + </Select> |
| 43 | + </div> |
| 44 | + <div className="form-group"> |
| 45 | + <label className="control-label" htmlFor="word-cloud-word-length-limit"> |
| 46 | + Words Length Limit |
| 47 | + </label> |
| 48 | + <Grid.Row gutter={15} type="flex"> |
| 49 | + <Grid.Col span={12}> |
| 50 | + <InputNumber |
| 51 | + data-test="WordCloud.WordLengthLimit.Min" |
| 52 | + className="w-100" |
| 53 | + placeholder="Min" |
| 54 | + min={0} |
| 55 | + value={options.wordLengthLimit.min} |
| 56 | + onChange={value => optionsChanged({ wordLengthLimit: { min: value > 0 ? value : null } })} |
| 57 | + /> |
| 58 | + </Grid.Col> |
| 59 | + <Grid.Col span={12}> |
| 60 | + <InputNumber |
| 61 | + data-test="WordCloud.WordLengthLimit.Max" |
| 62 | + className="w-100" |
| 63 | + placeholder="Max" |
| 64 | + min={0} |
| 65 | + value={options.wordLengthLimit.max} |
| 66 | + onChange={value => optionsChanged({ wordLengthLimit: { max: value > 0 ? value : null } })} |
| 67 | + /> |
| 68 | + </Grid.Col> |
| 69 | + </Grid.Row> |
| 70 | + </div> |
| 71 | + <div className="form-group"> |
| 72 | + <label className="control-label" htmlFor="word-cloud-word-length-limit"> |
| 73 | + Frequencies Limit |
| 74 | + </label> |
| 75 | + <Grid.Row gutter={15} type="flex"> |
| 76 | + <Grid.Col span={12}> |
| 77 | + <InputNumber |
| 78 | + data-test="WordCloud.WordCountLimit.Min" |
| 79 | + className="w-100" |
| 80 | + placeholder="Min" |
| 81 | + min={0} |
| 82 | + value={options.wordCountLimit.min} |
| 83 | + onChange={value => optionsChanged({ wordCountLimit: { min: value > 0 ? value : null } })} |
| 84 | + /> |
| 85 | + </Grid.Col> |
| 86 | + <Grid.Col span={12}> |
| 87 | + <InputNumber |
| 88 | + data-test="WordCloud.WordCountLimit.Max" |
| 89 | + className="w-100" |
| 90 | + placeholder="Max" |
| 91 | + min={0} |
| 92 | + value={options.wordCountLimit.max} |
| 93 | + onChange={value => optionsChanged({ wordCountLimit: { max: value > 0 ? value : null } })} |
| 94 | + /> |
| 95 | + </Grid.Col> |
| 96 | + </Grid.Row> |
| 97 | + </div> |
| 98 | + </React.Fragment> |
28 | 99 | );
|
29 | 100 | }
|
30 | 101 |
|
|
0 commit comments