Skip to content

Commit eeef895

Browse files
author
Gene Hynson
authored
feat(sub): validate against duplicate field and tag names (#6079)
1 parent 57588f8 commit eeef895

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

src/types/subscriptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export enum BrokerAuthTypes {
66
Certificate = 'certificate',
77
}
88

9+
export enum DataFormatTypes {
10+
LineProtocol = 'lineprotocol',
11+
JSON = 'json',
12+
String = 'string',
13+
}
14+
915
export interface Subscription {
1016
id?: string
1117
name?: string

src/writeData/subscriptions/components/BrokerForm.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@
9797
margin-bottom: 30px;
9898
}
9999
}
100+
.cf-status-indicator {
101+
top: unset;
102+
}

src/writeData/subscriptions/components/JsonPathInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
sanitizeType,
3232
dataTypeList,
3333
handleAvroValidation,
34+
handleDuplicateFieldTagName,
3435
} from 'src/writeData/subscriptions/utils/form'
3536
import {event} from 'src/cloud/utils/reporting'
3637
import ValidationInputWithTooltip from './ValidationInputWithTooltip'
@@ -110,7 +111,8 @@ const JsonPathInput: FC<Props> = ({
110111
: formContent.jsonFieldKeys[itemNum].name
111112
return (
112113
handleValidation(name, value) ??
113-
handleAvroValidation(name, value)
114+
handleAvroValidation(name, value) ??
115+
handleDuplicateFieldTagName(value, formContent)
114116
)
115117
}}
116118
placeholder={`${name}_name`.toLowerCase()}

src/writeData/subscriptions/components/ParsingForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import JsonParsingForm from 'src/writeData/subscriptions/components/JsonParsingF
1616
import LineProtocolForm from 'src/writeData/subscriptions/components/LineProtocolForm'
1717

1818
// Types
19-
import {Subscription} from 'src/types/subscriptions'
19+
import {DataFormatTypes, Subscription} from 'src/types/subscriptions'
2020

2121
// Styles
2222
import 'src/writeData/subscriptions/components/ParsingForm.scss'
@@ -63,20 +63,20 @@ const ParsingForm: FC<Props> = ({
6363
updateForm={updateForm}
6464
className="create"
6565
/>
66-
{formContent.dataFormat === 'lineprotocol' && (
66+
{formContent.dataFormat === DataFormatTypes.LineProtocol && (
6767
<LineProtocolForm
6868
edit={showUpgradeButton ? false : true}
6969
formContent={formContent}
7070
/>
7171
)}
72-
{formContent.dataFormat === 'json' && (
72+
{formContent.dataFormat === DataFormatTypes.JSON && (
7373
<JsonParsingForm
7474
formContent={formContent}
7575
updateForm={updateForm}
7676
edit={showUpgradeButton ? false : true}
7777
/>
7878
)}
79-
{formContent.dataFormat === 'string' && (
79+
{formContent.dataFormat === DataFormatTypes.String && (
8080
<StringParsingForm
8181
formContent={formContent}
8282
updateForm={updateForm}

src/writeData/subscriptions/components/StringPatternInput.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {Subscription} from 'src/types/subscriptions'
2121
import {
2222
handleRegexValidation,
2323
handleValidation,
24+
handleDuplicateFieldTagName,
2425
REGEX_TOOLTIP,
2526
} from 'src/writeData/subscriptions/utils/form'
2627
import {event} from 'src/cloud/utils/reporting'
@@ -90,14 +91,15 @@ const StringPatternInput: FC<Props> = ({
9091
tooltip={`This will become the the ${
9192
tagType ? 'tag' : 'field'
9293
}'s key`}
93-
validationFunc={() =>
94-
handleValidation(
95-
`${name}`,
96-
tagType
97-
? formContent.stringTags[itemNum].name
98-
: formContent.stringFields[itemNum].name
94+
validationFunc={() => {
95+
const value = tagType
96+
? formContent.stringTags[itemNum].name
97+
: formContent.stringFields[itemNum].name
98+
return (
99+
handleValidation(`${name}`, value) ??
100+
handleDuplicateFieldTagName(value, formContent)
99101
)
100-
}
102+
}}
101103
placeholder={`${name}_name`.toLowerCase()}
102104
onChange={e => {
103105
let newArr

src/writeData/subscriptions/utils/form.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Steps,
77
SubscriptionNavigationModel,
88
BrokerAuthTypes,
9+
DataFormatTypes,
910
} from 'src/types/subscriptions'
1011
import jsonpath from 'jsonpath'
1112
import {IconFont} from '@influxdata/clockface'
@@ -74,6 +75,41 @@ export const handleValidation = (
7475
return null
7576
}
7677

78+
export const handleDuplicateFieldTagName = (
79+
formVal: string,
80+
form: Subscription
81+
) => {
82+
switch (form.dataFormat) {
83+
case DataFormatTypes.LineProtocol: {
84+
return null
85+
}
86+
case DataFormatTypes.JSON: {
87+
const numMatchingFieldNames = form.jsonFieldKeys.filter(
88+
k => k.name === formVal
89+
).length
90+
const numMatchingTagNames = form.jsonTagKeys.filter(
91+
k => k.name === formVal
92+
).length
93+
// formVal already exists in form so expect there to be exactly one
94+
return numMatchingFieldNames + numMatchingTagNames > 1
95+
? `'${formVal}' name has already been used, unique column names are required`
96+
: null
97+
}
98+
case DataFormatTypes.String: {
99+
const numMatchingFieldNames = form.stringFields.filter(
100+
k => k.name === formVal
101+
).length
102+
const numMatchingTagNames = form.stringTags.filter(
103+
k => k.name === formVal
104+
).length
105+
// formVal already exists in form so expect there to be exactly one
106+
return numMatchingFieldNames + numMatchingTagNames > 1
107+
? `'${formVal}' name has already been used, unique column names are required`
108+
: null
109+
}
110+
}
111+
}
112+
77113
export const handleJsonPathValidation = (formVal: string): string | null => {
78114
if (!validateJsonPath(formVal)) {
79115
return `${formVal} is not a valid JSON Path expression`

0 commit comments

Comments
 (0)