@devtron-labs/devtron-fe-common-lib 0.0.7-beta-19 → 0.0.7-beta-21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Common/CustomTagSelector/ValidationRules.d.ts +10 -8
- package/dist/Common/CustomTagSelector/index.d.ts +0 -1
- package/dist/index.js +1919 -1897
- package/package.json +2 -3
- package/src/Common/CustomTagSelector/TagDetails.tsx +7 -5
- package/src/Common/CustomTagSelector/TagLabelValueSelector.tsx +9 -7
- package/src/Common/CustomTagSelector/ValidationRules.ts +31 -29
- package/src/Common/CustomTagSelector/index.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtron-labs/devtron-fe-common-lib",
|
|
3
|
-
"version": "0.0.7-beta-
|
|
3
|
+
"version": "0.0.7-beta-21",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"typescript": "^4.9.4",
|
|
37
37
|
"react-toastify": "^8.2.0",
|
|
38
38
|
"@tippyjs/react": "^4.2.0",
|
|
39
|
-
"
|
|
40
|
-
"react-select": "^5.2.2",
|
|
39
|
+
"react-select": "5.2.2",
|
|
41
40
|
"@sentry/browser": "^7.31.1"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
@@ -5,7 +5,7 @@ import { TagLabelValueSelector } from './TagLabelValueSelector'
|
|
|
5
5
|
import { KEY_VALUE } from '../Constants'
|
|
6
6
|
import { stopPropagation } from '../Helper'
|
|
7
7
|
import { TagDetailType } from './Types'
|
|
8
|
-
import {
|
|
8
|
+
import { ValidationRules } from './ValidationRules'
|
|
9
9
|
|
|
10
10
|
export const TagDetails = ({
|
|
11
11
|
index,
|
|
@@ -17,6 +17,7 @@ export const TagDetails = ({
|
|
|
17
17
|
}: TagDetailType) => {
|
|
18
18
|
const keyRef = useRef(null)
|
|
19
19
|
const valueRef = useRef(null)
|
|
20
|
+
const validationRules = new ValidationRules()
|
|
20
21
|
|
|
21
22
|
const deleteTag = (e): void => {
|
|
22
23
|
stopPropagation(e)
|
|
@@ -25,12 +26,13 @@ export const TagDetails = ({
|
|
|
25
26
|
const propagateTagToResource = (): void => {
|
|
26
27
|
const _tagData = { ...tagData }
|
|
27
28
|
_tagData.propagate = !_tagData.propagate
|
|
28
|
-
console.log(_tagData.propagate, _tagData.value)
|
|
29
29
|
if (_tagData.propagate) {
|
|
30
|
-
_tagData.
|
|
30
|
+
_tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidValue
|
|
31
|
+
_tagData.isInvalidValue = !_tagData.value || _tagData.isInvalidValue
|
|
31
32
|
} else {
|
|
32
|
-
_tagData.
|
|
33
|
-
_tagData.key
|
|
33
|
+
_tagData.isInvalidKey =
|
|
34
|
+
_tagData.key || _tagData.value ? validationRules.propagateTagKey(_tagData.key).isValid : false
|
|
35
|
+
_tagData.isInvalidValue = _tagData.value ? validationRules.propagateTagValue(_tagData.value).isValid : false
|
|
34
36
|
}
|
|
35
37
|
setTagData(index, _tagData)
|
|
36
38
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
2
|
import PopupMenu from '../PopupMenu'
|
|
3
|
-
import { propagateTagKeyValidator, propagateTagValueValidator } from './ValidationRules'
|
|
4
3
|
import { ReactComponent as ErrorCross } from '../../Assets/Icon/ic-cross.svg'
|
|
5
4
|
import { ReactComponent as Info } from '../../Assets/Icon/ic-info-outlined.svg'
|
|
6
5
|
import { KEY_VALUE } from '../Constants'
|
|
@@ -8,6 +7,7 @@ import { stopPropagation } from '../Helper'
|
|
|
8
7
|
import { ResizableTagTextArea } from './ResizableTagTextArea'
|
|
9
8
|
import { SuggestedTagOptionType, TagLabelValueSelectorType } from './Types'
|
|
10
9
|
import Tippy from '@tippyjs/react'
|
|
10
|
+
import { ValidationRules } from './ValidationRules'
|
|
11
11
|
|
|
12
12
|
export const TagLabelValueSelector = ({
|
|
13
13
|
selectedTagIndex,
|
|
@@ -24,6 +24,7 @@ export const TagLabelValueSelector = ({
|
|
|
24
24
|
}: TagLabelValueSelectorType) => {
|
|
25
25
|
const [selectedValue, setSelectedValue] = useState<string>('')
|
|
26
26
|
const [activeElement, setActiveElement] = useState<string>('')
|
|
27
|
+
const validationRules = new ValidationRules()
|
|
27
28
|
|
|
28
29
|
useEffect(() => {
|
|
29
30
|
setSelectedValue(tagData?.[tagInputType] || '')
|
|
@@ -44,11 +45,12 @@ export const TagLabelValueSelector = ({
|
|
|
44
45
|
const _tagData = { ...tagData }
|
|
45
46
|
_tagData[tagInputType] = selectedValue
|
|
46
47
|
if (tagInputType === KEY_VALUE.KEY) {
|
|
47
|
-
_tagData.isInvalidKey =
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
_tagData.isInvalidKey =
|
|
49
|
+
selectedValue || _tagData.propagate
|
|
50
|
+
? !validationRules.propagateTagKey(selectedValue).isValid
|
|
51
|
+
: _tagData.value !== ''
|
|
50
52
|
} else if (selectedValue || isRequired || _tagData.propagate) {
|
|
51
|
-
_tagData.isInvalidValue = !
|
|
53
|
+
_tagData.isInvalidValue = !validationRules.propagateTagValue(selectedValue).isValid
|
|
52
54
|
_tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidKey
|
|
53
55
|
} else {
|
|
54
56
|
_tagData.isInvalidValue = false
|
|
@@ -75,10 +77,10 @@ export const TagLabelValueSelector = ({
|
|
|
75
77
|
let field = { isValid: true, messages: [] }
|
|
76
78
|
if (tagInputType === KEY_VALUE.KEY) {
|
|
77
79
|
if (selectedValue || tagData.value) {
|
|
78
|
-
field =
|
|
80
|
+
field = validationRules.propagateTagKey(selectedValue)
|
|
79
81
|
}
|
|
80
82
|
} else if (isRequired || selectedValue || tagData.propagate) {
|
|
81
|
-
field =
|
|
83
|
+
field = validationRules.propagateTagValue(selectedValue)
|
|
82
84
|
}
|
|
83
85
|
if (!field.isValid) {
|
|
84
86
|
return (
|
|
@@ -15,38 +15,40 @@ const validateTagValue = (value: string): string[] => {
|
|
|
15
15
|
}
|
|
16
16
|
return errorList
|
|
17
17
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const re = new RegExp('/', 'g')
|
|
24
|
-
const noOfSlashInKey = key.match(re)?.length
|
|
25
|
-
if (noOfSlashInKey > 1) {
|
|
26
|
-
errorList.push('Key: Max 1 ( / ) allowed')
|
|
27
|
-
} else if (noOfSlashInKey === 1) {
|
|
28
|
-
const [prefix, name] = key.split('/')
|
|
29
|
-
errorList.push(...validateTagValue(name).map((error) => `Name: ${error}`))
|
|
30
|
-
if (prefix.length > 253) {
|
|
31
|
-
errorList.push('Prefix: Can be max 253 characters')
|
|
32
|
-
}
|
|
33
|
-
const validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix)
|
|
34
|
-
if (!validPrefix) {
|
|
35
|
-
errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)')
|
|
36
|
-
}
|
|
18
|
+
export class ValidationRules {
|
|
19
|
+
propagateTagKey = (key: string): { isValid: boolean; messages: string[] } => {
|
|
20
|
+
const errorList = []
|
|
21
|
+
if (!key) {
|
|
22
|
+
errorList.push('Key is required')
|
|
37
23
|
} else {
|
|
38
|
-
|
|
24
|
+
const re = new RegExp('/', 'g')
|
|
25
|
+
const noOfSlashInKey = key.match(re)?.length
|
|
26
|
+
if (noOfSlashInKey > 1) {
|
|
27
|
+
errorList.push('Key: Max 1 ( / ) allowed')
|
|
28
|
+
} else if (noOfSlashInKey === 1) {
|
|
29
|
+
const [prefix, name] = key.split('/')
|
|
30
|
+
errorList.push(...validateTagValue(name).map((error) => `Name: ${error}`))
|
|
31
|
+
if (prefix.length > 253) {
|
|
32
|
+
errorList.push('Prefix: Can be max 253 characters')
|
|
33
|
+
}
|
|
34
|
+
const validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix)
|
|
35
|
+
if (!validPrefix) {
|
|
36
|
+
errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)')
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
errorList.push(...validateTagValue(key).map((error) => `Name: ${error}`))
|
|
40
|
+
}
|
|
39
41
|
}
|
|
42
|
+
return { isValid: errorList.length === 0, messages: errorList }
|
|
40
43
|
}
|
|
41
|
-
return { isValid: errorList.length === 0, messages: errorList }
|
|
42
|
-
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
propagateTagValue = (value: string): { isValid: boolean; messages: string[] } => {
|
|
46
|
+
const errorList = []
|
|
47
|
+
if (!value) {
|
|
48
|
+
errorList.push('Value is required')
|
|
49
|
+
} else {
|
|
50
|
+
errorList.push(...validateTagValue(value))
|
|
51
|
+
}
|
|
52
|
+
return { isValid: errorList.length === 0, messages: errorList }
|
|
50
53
|
}
|
|
51
|
-
return { isValid: errorList.length === 0, messages: errorList }
|
|
52
54
|
}
|