Skip to content

Commit 17644a4

Browse files
authored
fix: subscriptions json bugs/ clean up (#4516)
1 parent d07c1dc commit 17644a4

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

src/writeData/subscriptions/components/BrokerFormContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ const BrokerFormContent: FC<Props> = ({
5858
<Grid.Row>
5959
<Grid.Column widthSM={Columns.Twelve}>
6060
<Form.ValidationElement
61-
label="Connection Name"
61+
label="Subscription Name"
6262
value={formContent.name}
6363
required={true}
6464
validationFunc={() =>
65-
handleValidation('Connection Name', formContent.name)
65+
handleValidation('Subscription Name', formContent.name)
6666
}
6767
prevalidate={false}
6868
>

src/writeData/subscriptions/components/JsonParsingForm.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ const JsonParsingForm: FC<Props> = ({formContent, updateForm, edit}) => {
7777
placeholder="eg. $.myJSON.myObject[0].timestampKey"
7878
name="timestamp"
7979
autoFocus={true}
80-
value={
81-
formContent.jsonTimestamp && formContent.jsonTimestamp.path
82-
? formContent.jsonTimestamp.path
83-
: ''
84-
}
80+
value={formContent.jsonTimestamp.path}
8581
onChange={e => {
8682
formContent.jsonTimestamp.path = e.target.value
8783
updateForm({...formContent})

src/writeData/subscriptions/components/StringParsingForm.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ const StringParsingForm: FC<Props> = ({formContent, updateForm, edit}) => {
6969
placeholder="eg. regexExample"
7070
name="timestamp"
7171
autoFocus={true}
72-
value={
73-
formContent.stringTimestamp
74-
? formContent.stringTimestamp.pattern
75-
: ''
76-
}
72+
value={formContent.stringTimestamp.pattern}
7773
onChange={e => {
7874
formContent.stringTimestamp.pattern = e.target.value
7975
updateForm({...formContent})

src/writeData/subscriptions/components/SubscriptionDetailsPage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
color: #34bb55;
6262
margin-left: 10px;
6363
}
64-
&--INVALID {
64+
&--ERRORED {
6565
color: #e85b1c;
6666
margin-left: 10px;
6767
}

src/writeData/subscriptions/context/subscription.create.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const DEFAULT_CONTEXT: SubscriptionCreateContextType = {
3939
topic: '',
4040
dataFormat: 'lineprotocol',
4141
jsonMeasurementKey: {
42+
name: 'measurement',
4243
path: '',
4344
type: 'string',
4445
},

src/writeData/subscriptions/utils/form.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ export const sanitizeForm = (form: Subscription): Subscription => {
6060
form.jsonTimestamp.path = newVal
6161
}
6262
}
63-
64-
if (form.jsonTimestamp?.path === '') {
65-
delete form.jsonTimestamp
66-
}
6763
if (form.stringMeasurement) {
6864
form.stringMeasurement.pattern =
6965
form.stringMeasurement?.pattern.replace(/\\\\/g, '\\') ?? ''
@@ -78,9 +74,6 @@ export const sanitizeForm = (form: Subscription): Subscription => {
7874
t.pattern = t.pattern?.replace(/\\\\/g, '\\') ?? ''
7975
})
8076
}
81-
if (form.stringTimestamp?.pattern === '') {
82-
delete form.stringTimestamp
83-
}
8477
if (form.brokerPassword === '' || form.brokerUsername === '') {
8578
delete form.brokerUsername
8679
delete form.brokerPassword
@@ -89,24 +82,46 @@ export const sanitizeForm = (form: Subscription): Subscription => {
8982
}
9083

9184
export const sanitizeUpdateForm = (form: Subscription): Subscription => {
92-
if (form.jsonMeasurementKey) {
85+
if (form.jsonMeasurementKey.path) {
86+
const startChar = form.jsonMeasurementKey?.path.charAt(0) ?? ''
87+
const newVal = checkJSONPathStarts$(startChar, form.jsonMeasurementKey.path)
88+
if (newVal) {
89+
form.jsonMeasurementKey.path = newVal
90+
}
9391
if (form.jsonMeasurementKey.type === 'number') {
9492
form.jsonMeasurementKey.type = 'double'
9593
}
9694
}
95+
if (form.jsonFieldKeys) {
96+
form.jsonFieldKeys.map(f => {
97+
const startChar = f.path?.charAt(0) ?? ''
98+
const newVal = checkJSONPathStarts$(startChar, f.path)
99+
if (newVal) {
100+
f.path = newVal
101+
}
102+
if (f.type === 'number') {
103+
f.type = 'double'
104+
}
105+
})
106+
}
97107
if (form.jsonTagKeys) {
98108
form.jsonTagKeys.map(t => {
109+
const startChar = t.path?.charAt(0) ?? ''
110+
const newVal = checkJSONPathStarts$(startChar, t.path)
111+
if (newVal) {
112+
t.path = newVal
113+
}
99114
if (t.type === 'number') {
100115
t.type = 'double'
101116
}
102117
})
103118
}
104-
if (form.jsonFieldKeys) {
105-
form.jsonFieldKeys.map(f => {
106-
if (f.type === 'number') {
107-
f.type = 'double'
108-
}
109-
})
119+
if (form.jsonTimestamp?.path) {
120+
const startChar = form.jsonTimestamp.path.charAt(0)
121+
const newVal = checkJSONPathStarts$(startChar, form.jsonTimestamp.path)
122+
if (newVal) {
123+
form.jsonTimestamp.path = newVal
124+
}
110125
}
111126
delete form.id
112127
delete form.orgID

0 commit comments

Comments
 (0)