|
6 | 6 | Steps, |
7 | 7 | SubscriptionNavigationModel, |
8 | 8 | BrokerAuthTypes, |
| 9 | + DataFormatTypes, |
9 | 10 | } from 'src/types/subscriptions' |
10 | 11 | import jsonpath from 'jsonpath' |
11 | 12 | import {IconFont} from '@influxdata/clockface' |
@@ -74,6 +75,41 @@ export const handleValidation = ( |
74 | 75 | return null |
75 | 76 | } |
76 | 77 |
|
| 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 | + |
77 | 113 | export const handleJsonPathValidation = (formVal: string): string | null => { |
78 | 114 | if (!validateJsonPath(formVal)) { |
79 | 115 | return `${formVal} is not a valid JSON Path expression` |
|
0 commit comments