Skip to content

Commit 348dbbb

Browse files
authored
feat: add types (#5158)
1 parent 6ee9585 commit 348dbbb

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/writeData/subscriptions/components/JsonParsingForm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
handleValidation,
3131
handleJsonPathValidation,
3232
JSON_TOOLTIP,
33+
dataTypeList,
3334
} from 'src/writeData/subscriptions/utils/form'
3435
import {event} from 'src/cloud/utils/reporting'
3536

@@ -44,10 +45,7 @@ interface Props {
4445
}
4546

4647
const JsonParsingForm: FC<Props> = ({formContent, updateForm, edit}) => {
47-
const stringType = 'String'
48-
const numberType = 'Number'
49-
const dataTypeList = [stringType, numberType]
50-
const [dataTypeM, setDataTypeM] = useState(stringType)
48+
const [dataTypeM, setDataTypeM] = useState(dataTypeList[0])
5149
const [useStaticMeasurement, setUseStaticMeasurement] = useState(
5250
!!formContent.jsonMeasurementKey.name
5351
)

src/writeData/subscriptions/components/JsonPathInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
handleValidation,
3030
JSON_TOOLTIP,
3131
sanitizeType,
32+
dataTypeList,
3233
} from 'src/writeData/subscriptions/utils/form'
3334
import {event} from 'src/cloud/utils/reporting'
3435
import ValidationInputWithTooltip from './ValidationInputWithTooltip'
@@ -48,7 +49,6 @@ const JsonPathInput: FC<Props> = ({
4849
itemNum,
4950
edit,
5051
}) => {
51-
const dataTypeList = ['String', 'Number']
5252
const [dataType, setDataType] = useState(dataTypeList[0])
5353
const tagType = name === 'Tag'
5454
return (

src/writeData/subscriptions/utils/form.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export const REGEX_TOOLTIP =
5151
export const JSON_TOOLTIP =
5252
'JsonPath expression that returns a singular value expected. See http://jsonpath.com for more info.'
5353

54+
const stringType = 'String'
55+
const floatType = 'Float'
56+
const intType = 'Integer'
57+
const booleanType = 'Boolean'
58+
59+
export const dataTypeList = [stringType, intType, floatType, booleanType]
60+
5461
export const handleValidation = (
5562
property: string,
5663
formVal: string
@@ -89,8 +96,8 @@ export const sanitizeForm = (form: Subscription): Subscription => {
8996
form.jsonMeasurementKey.path = newVal
9097
}
9198
}
92-
if (form.jsonMeasurementKey.type === 'number') {
93-
form.jsonMeasurementKey.type = 'double'
99+
if (form.jsonMeasurementKey.type === 'integer') {
100+
form.jsonMeasurementKey.type = 'int'
94101
}
95102

96103
if (form.jsonFieldKeys) {
@@ -100,8 +107,8 @@ export const sanitizeForm = (form: Subscription): Subscription => {
100107
if (newVal) {
101108
f.path = newVal
102109
}
103-
if (f.type === 'number') {
104-
f.type = 'double'
110+
if (f.type === 'integer') {
111+
f.type = 'int'
105112
}
106113
})
107114
}
@@ -112,8 +119,8 @@ export const sanitizeForm = (form: Subscription): Subscription => {
112119
if (newVal) {
113120
t.path = newVal
114121
}
115-
if (t.type === 'number') {
116-
t.type = 'double'
122+
if (t.type === 'integer') {
123+
t.type = 'int'
117124
}
118125
})
119126
}
@@ -139,8 +146,8 @@ export const sanitizeUpdateForm = (form: Subscription): Subscription => {
139146
form.jsonMeasurementKey.path = newVal
140147
}
141148
}
142-
if (form.jsonMeasurementKey.type === 'number') {
143-
form.jsonMeasurementKey.type = 'double'
149+
if (form.jsonMeasurementKey.type === 'integer') {
150+
form.jsonMeasurementKey.type = 'int'
144151
}
145152
if (form.jsonFieldKeys) {
146153
form.jsonFieldKeys.map(f => {
@@ -149,8 +156,8 @@ export const sanitizeUpdateForm = (form: Subscription): Subscription => {
149156
if (newVal) {
150157
f.path = newVal
151158
}
152-
if (f.type === 'number') {
153-
f.type = 'double'
159+
if (f.type === 'integer') {
160+
f.type = 'int'
154161
}
155162
})
156163
}
@@ -161,8 +168,8 @@ export const sanitizeUpdateForm = (form: Subscription): Subscription => {
161168
if (newVal) {
162169
t.path = newVal
163170
}
164-
if (t.type === 'number') {
165-
t.type = 'double'
171+
if (t.type === 'integer') {
172+
t.type = 'int'
166173
}
167174
})
168175
}
@@ -196,7 +203,10 @@ export const sanitizeUpdateForm = (form: Subscription): Subscription => {
196203

197204
export const sanitizeType = (type: string): string => {
198205
if (type === 'double') {
199-
type = 'Number'
206+
type = 'Float'
207+
}
208+
if (type === 'int') {
209+
type = 'Integer'
200210
}
201211
return type.charAt(0).toUpperCase() + type.slice(1)
202212
}

0 commit comments

Comments
 (0)