|
| 1 | +// Libraries |
1 | 2 | import React, {FC} from 'react' |
| 3 | +import {Columns, Form, Grid, Input} from '@influxdata/clockface' |
2 | 4 |
|
3 | | -import { |
4 | | - Grid, |
5 | | - Columns, |
6 | | - Form, |
7 | | - AutoInput, |
8 | | - AutoInputMode, |
9 | | - Input, |
10 | | - InputType, |
11 | | -} from '@influxdata/clockface' |
12 | | - |
| 5 | +// Components |
13 | 6 | import ThresholdsSettings from 'src/visualization/components/internal/ThresholdsSettings' |
14 | | -import { |
15 | | - MIN_DECIMAL_PLACES, |
16 | | - MAX_DECIMAL_PLACES, |
17 | | -} from 'src/visualization/constants' |
18 | | -import {convertUserInputToNumOrNaN} from 'src/shared/utils/convertUserInput' |
| 7 | +import {DecimalPlaces} from 'src/visualization/components/internal/DecimalPlaces' |
19 | 8 |
|
| 9 | +// Types |
20 | 10 | import {GaugeViewProperties} from 'src/types' |
21 | 11 | import {VisualizationOptionProps} from 'src/visualization' |
22 | 12 |
|
23 | 13 | interface Props extends VisualizationOptionProps { |
24 | 14 | properties: GaugeViewProperties |
25 | 15 | } |
26 | 16 |
|
27 | | -const GaugeOptions: FC<Props> = ({properties, update}) => { |
28 | | - const setDigits = (digits: number | null) => { |
29 | | - update({ |
30 | | - decimalPlaces: { |
31 | | - ...properties.decimalPlaces, |
32 | | - digits, |
33 | | - }, |
34 | | - }) |
35 | | - } |
36 | | - const handleChangeMode = (mode: AutoInputMode): void => { |
37 | | - if (mode === AutoInputMode.Auto) { |
38 | | - setDigits(null) |
39 | | - } else { |
40 | | - setDigits(2) |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - return ( |
45 | | - <Grid> |
46 | | - <Grid.Row> |
47 | | - <Grid.Column> |
48 | | - <Grid.Row> |
49 | | - <Grid.Column widthXS={Columns.Six}> |
50 | | - <Form.Element label="Value Prefix"> |
51 | | - <Input |
52 | | - testID="prefix-input" |
53 | | - value={properties.prefix} |
54 | | - onChange={evt => { |
55 | | - update({prefix: evt.target.value}) |
56 | | - }} |
57 | | - placeholder="%, MPH, etc." |
58 | | - /> |
59 | | - </Form.Element> |
60 | | - </Grid.Column> |
61 | | - <Grid.Column widthXS={Columns.Six}> |
62 | | - <Form.Element label="Value Suffix"> |
63 | | - <Input |
64 | | - testID="suffix-input" |
65 | | - value={properties.suffix} |
66 | | - onChange={evt => { |
67 | | - update({suffix: evt.target.value}) |
68 | | - }} |
69 | | - placeholder="%, MPH, etc." |
70 | | - /> |
71 | | - </Form.Element> |
72 | | - </Grid.Column> |
73 | | - </Grid.Row> |
74 | | - <Grid.Row> |
75 | | - <Grid.Column widthXS={Columns.Six}> |
76 | | - <Form.Element label="Axis Prefix"> |
77 | | - <Input |
78 | | - testID="tick-prefix-input" |
79 | | - value={properties.tickPrefix} |
80 | | - onChange={evt => { |
81 | | - update({tickPrefix: evt.target.value}) |
82 | | - }} |
83 | | - placeholder="%, MPH, etc." |
84 | | - /> |
85 | | - </Form.Element> |
86 | | - </Grid.Column> |
87 | | - <Grid.Column widthXS={Columns.Six}> |
88 | | - <Form.Element label="Axis Suffix"> |
89 | | - <Input |
90 | | - testID="tick-suffix-input" |
91 | | - value={properties.tickSuffix} |
92 | | - onChange={evt => { |
93 | | - update({tickSuffix: evt.target.value}) |
94 | | - }} |
95 | | - placeholder="%, MPH, etc." |
96 | | - /> |
97 | | - </Form.Element> |
98 | | - </Grid.Column> |
99 | | - </Grid.Row> |
100 | | - {properties.decimalPlaces && ( |
101 | | - <Form.Element label="Decimal Places"> |
102 | | - <AutoInput |
103 | | - mode={ |
104 | | - properties.decimalPlaces.digits |
105 | | - ? AutoInputMode.Custom |
106 | | - : AutoInputMode.Auto |
107 | | - } |
108 | | - onChangeMode={handleChangeMode} |
109 | | - inputComponent={ |
110 | | - <Input |
111 | | - name="decimal-places" |
112 | | - placeholder="Enter a number" |
113 | | - onChange={evt => { |
114 | | - setDigits(convertUserInputToNumOrNaN(evt)) |
115 | | - }} |
116 | | - value={properties.decimalPlaces.digits} |
117 | | - min={MIN_DECIMAL_PLACES} |
118 | | - max={MAX_DECIMAL_PLACES} |
119 | | - type={InputType.Number} |
120 | | - /> |
121 | | - } |
| 17 | +export const GaugeOptions: FC<Props> = ({properties, update}) => ( |
| 18 | + <Grid> |
| 19 | + <Grid.Row> |
| 20 | + <Grid.Column> |
| 21 | + <Grid.Row> |
| 22 | + <Grid.Column widthXS={Columns.Six}> |
| 23 | + <Form.Element label="Value Prefix"> |
| 24 | + <Input |
| 25 | + testID="prefix-input" |
| 26 | + value={properties.prefix} |
| 27 | + onChange={evt => { |
| 28 | + update({prefix: evt.target.value}) |
| 29 | + }} |
| 30 | + placeholder="%, MPH, etc." |
122 | 31 | /> |
123 | 32 | </Form.Element> |
124 | | - )} |
125 | | - </Grid.Column> |
126 | | - <Grid.Column widthXS={Columns.Twelve} widthMD={Columns.Six}> |
127 | | - <Form.Element label="Colorized Thresholds"> |
128 | | - <ThresholdsSettings |
129 | | - thresholds={properties.colors} |
130 | | - onSetThresholds={colors => { |
131 | | - update({colors}) |
132 | | - }} |
133 | | - /> |
134 | | - </Form.Element> |
135 | | - </Grid.Column> |
136 | | - </Grid.Row> |
137 | | - </Grid> |
138 | | - ) |
139 | | -} |
140 | | - |
141 | | -export default GaugeOptions |
| 33 | + </Grid.Column> |
| 34 | + <Grid.Column widthXS={Columns.Six}> |
| 35 | + <Form.Element label="Value Suffix"> |
| 36 | + <Input |
| 37 | + testID="suffix-input" |
| 38 | + value={properties.suffix} |
| 39 | + onChange={evt => { |
| 40 | + update({suffix: evt.target.value}) |
| 41 | + }} |
| 42 | + placeholder="%, MPH, etc." |
| 43 | + /> |
| 44 | + </Form.Element> |
| 45 | + </Grid.Column> |
| 46 | + </Grid.Row> |
| 47 | + <Grid.Row> |
| 48 | + <Grid.Column widthXS={Columns.Six}> |
| 49 | + <Form.Element label="Axis Prefix"> |
| 50 | + <Input |
| 51 | + testID="tick-prefix-input" |
| 52 | + value={properties.tickPrefix} |
| 53 | + onChange={evt => { |
| 54 | + update({tickPrefix: evt.target.value}) |
| 55 | + }} |
| 56 | + placeholder="%, MPH, etc." |
| 57 | + /> |
| 58 | + </Form.Element> |
| 59 | + </Grid.Column> |
| 60 | + <Grid.Column widthXS={Columns.Six}> |
| 61 | + <Form.Element label="Axis Suffix"> |
| 62 | + <Input |
| 63 | + testID="tick-suffix-input" |
| 64 | + value={properties.tickSuffix} |
| 65 | + onChange={evt => { |
| 66 | + update({tickSuffix: evt.target.value}) |
| 67 | + }} |
| 68 | + placeholder="%, MPH, etc." |
| 69 | + /> |
| 70 | + </Form.Element> |
| 71 | + </Grid.Column> |
| 72 | + </Grid.Row> |
| 73 | + {properties.decimalPlaces && ( |
| 74 | + <DecimalPlaces |
| 75 | + isEnforced={properties?.decimalPlaces?.isEnforced === true} |
| 76 | + digits={ |
| 77 | + typeof properties?.decimalPlaces?.digits === 'number' || |
| 78 | + properties?.decimalPlaces?.digits === null |
| 79 | + ? properties.decimalPlaces.digits |
| 80 | + : NaN |
| 81 | + } |
| 82 | + update={update} |
| 83 | + /> |
| 84 | + )} |
| 85 | + </Grid.Column> |
| 86 | + <Grid.Column widthXS={Columns.Twelve} widthMD={Columns.Six}> |
| 87 | + <Form.Element label="Colorized Thresholds"> |
| 88 | + <ThresholdsSettings |
| 89 | + thresholds={properties.colors} |
| 90 | + onSetThresholds={colors => { |
| 91 | + update({colors}) |
| 92 | + }} |
| 93 | + /> |
| 94 | + </Form.Element> |
| 95 | + </Grid.Column> |
| 96 | + </Grid.Row> |
| 97 | + </Grid> |
| 98 | +) |
0 commit comments