@devtron-labs/devtron-fe-common-lib 0.0.7-beta-16 → 0.0.7-beta-19
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/TagLabelValueSelector.d.ts +1 -1
- package/dist/Common/CustomTagSelector/ValidationRules.d.ts +8 -10
- package/dist/Common/CustomTagSelector/index.d.ts +1 -0
- package/dist/index.js +51 -47
- package/package.json +2 -1
- package/src/Common/CustomTagSelector/TagDetails.tsx +8 -0
- package/src/Common/CustomTagSelector/TagLabelValueSelector.tsx +9 -14
- package/src/Common/CustomTagSelector/ValidationRules.ts +29 -32
- package/src/Common/CustomTagSelector/index.ts +2 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TagLabelValueSelectorType } from './Types';
|
|
3
|
-
export declare const TagLabelValueSelector: ({ selectedTagIndex, tagData, setTagData, tagOptions, isRequired, tagInputType, placeholder, tabIndex, refVar, dependentRef, noBackDrop }: TagLabelValueSelectorType) => JSX.Element;
|
|
3
|
+
export declare const TagLabelValueSelector: ({ selectedTagIndex, tagData, setTagData, tagOptions, isRequired, tagInputType, placeholder, tabIndex, refVar, dependentRef, noBackDrop, }: TagLabelValueSelectorType) => JSX.Element;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
export declare const propagateTagKeyValidator: (key: string) => {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
messages: string[];
|
|
4
|
+
};
|
|
5
|
+
export declare const propagateTagValueValidator: (value: string) => {
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
messages: string[];
|
|
8
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -8521,50 +8521,45 @@ var validateTagValue = function (value) {
|
|
|
8521
8521
|
}
|
|
8522
8522
|
return errorList;
|
|
8523
8523
|
};
|
|
8524
|
-
var
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
if (prefix.length > 253) {
|
|
8542
|
-
errorList.push('Prefix: Can be max 253 characters');
|
|
8543
|
-
}
|
|
8544
|
-
var validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix);
|
|
8545
|
-
if (!validPrefix) {
|
|
8546
|
-
errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)');
|
|
8547
|
-
}
|
|
8548
|
-
}
|
|
8549
|
-
else {
|
|
8550
|
-
errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(key).map(function (error) { return "Name: ".concat(error); })), false));
|
|
8551
|
-
}
|
|
8552
|
-
}
|
|
8553
|
-
return { isValid: errorList.length === 0, messages: errorList };
|
|
8554
|
-
};
|
|
8555
|
-
this.propagateTagValue = function (value) {
|
|
8556
|
-
var errorList = [];
|
|
8557
|
-
if (!value) {
|
|
8558
|
-
errorList.push('Value is required');
|
|
8524
|
+
var propagateTagKeyValidator = function (key) {
|
|
8525
|
+
var _a;
|
|
8526
|
+
var errorList = [];
|
|
8527
|
+
if (!key) {
|
|
8528
|
+
errorList.push('Key is required');
|
|
8529
|
+
}
|
|
8530
|
+
else {
|
|
8531
|
+
var re = new RegExp('/', 'g');
|
|
8532
|
+
var noOfSlashInKey = (_a = key.match(re)) === null || _a === void 0 ? void 0 : _a.length;
|
|
8533
|
+
if (noOfSlashInKey > 1) {
|
|
8534
|
+
errorList.push('Key: Max 1 ( / ) allowed');
|
|
8535
|
+
}
|
|
8536
|
+
else if (noOfSlashInKey === 1) {
|
|
8537
|
+
var _b = __read(key.split('/'), 2), prefix = _b[0], name_1 = _b[1];
|
|
8538
|
+
errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(name_1).map(function (error) { return "Name: ".concat(error); })), false));
|
|
8539
|
+
if (prefix.length > 253) {
|
|
8540
|
+
errorList.push('Prefix: Can be max 253 characters');
|
|
8559
8541
|
}
|
|
8560
|
-
|
|
8561
|
-
|
|
8542
|
+
var validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix);
|
|
8543
|
+
if (!validPrefix) {
|
|
8544
|
+
errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)');
|
|
8562
8545
|
}
|
|
8563
|
-
|
|
8564
|
-
|
|
8546
|
+
}
|
|
8547
|
+
else {
|
|
8548
|
+
errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(key).map(function (error) { return "Name: ".concat(error); })), false));
|
|
8549
|
+
}
|
|
8550
|
+
}
|
|
8551
|
+
return { isValid: errorList.length === 0, messages: errorList };
|
|
8552
|
+
};
|
|
8553
|
+
var propagateTagValueValidator = function (value) {
|
|
8554
|
+
var errorList = [];
|
|
8555
|
+
if (!value) {
|
|
8556
|
+
errorList.push('Value is required');
|
|
8565
8557
|
}
|
|
8566
|
-
|
|
8567
|
-
|
|
8558
|
+
else {
|
|
8559
|
+
errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(value)), false));
|
|
8560
|
+
}
|
|
8561
|
+
return { isValid: errorList.length === 0, messages: errorList };
|
|
8562
|
+
};
|
|
8568
8563
|
|
|
8569
8564
|
var _path$2;
|
|
8570
8565
|
function _extends$5() { _extends$5 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$5.apply(this, arguments); }
|
|
@@ -8626,7 +8621,6 @@ var TagLabelValueSelector = function (_a) {
|
|
|
8626
8621
|
var selectedTagIndex = _a.selectedTagIndex, tagData = _a.tagData, setTagData = _a.setTagData, tagOptions = _a.tagOptions, isRequired = _a.isRequired, tagInputType = _a.tagInputType, placeholder = _a.placeholder, _b = _a.tabIndex, tabIndex = _b === void 0 ? null : _b, refVar = _a.refVar, dependentRef = _a.dependentRef, noBackDrop = _a.noBackDrop;
|
|
8627
8622
|
var _c = __read(React.useState(''), 2), selectedValue = _c[0], setSelectedValue = _c[1];
|
|
8628
8623
|
var _d = __read(React.useState(''), 2), activeElement = _d[0], setActiveElement = _d[1];
|
|
8629
|
-
var validationRules = new ValidationRules();
|
|
8630
8624
|
React.useEffect(function () {
|
|
8631
8625
|
setSelectedValue((tagData === null || tagData === void 0 ? void 0 : tagData[tagInputType]) || '');
|
|
8632
8626
|
}, [selectedTagIndex, tagData, tagInputType]);
|
|
@@ -8644,11 +8638,11 @@ var TagLabelValueSelector = function (_a) {
|
|
|
8644
8638
|
_tagData[tagInputType] = selectedValue;
|
|
8645
8639
|
if (tagInputType === exports.KEY_VALUE.KEY) {
|
|
8646
8640
|
_tagData.isInvalidKey = selectedValue
|
|
8647
|
-
? !
|
|
8641
|
+
? !propagateTagKeyValidator(selectedValue).isValid
|
|
8648
8642
|
: _tagData.value !== '';
|
|
8649
8643
|
}
|
|
8650
8644
|
else if (selectedValue || isRequired || _tagData.propagate) {
|
|
8651
|
-
_tagData.isInvalidValue = !
|
|
8645
|
+
_tagData.isInvalidValue = !propagateTagValueValidator(selectedValue).isValid;
|
|
8652
8646
|
_tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidKey;
|
|
8653
8647
|
}
|
|
8654
8648
|
else {
|
|
@@ -8673,11 +8667,11 @@ var TagLabelValueSelector = function (_a) {
|
|
|
8673
8667
|
var field = { isValid: true, messages: [] };
|
|
8674
8668
|
if (tagInputType === exports.KEY_VALUE.KEY) {
|
|
8675
8669
|
if (selectedValue || tagData.value) {
|
|
8676
|
-
field =
|
|
8670
|
+
field = propagateTagKeyValidator(selectedValue);
|
|
8677
8671
|
}
|
|
8678
8672
|
}
|
|
8679
|
-
else if (isRequired || selectedValue) {
|
|
8680
|
-
field =
|
|
8673
|
+
else if (isRequired || selectedValue || tagData.propagate) {
|
|
8674
|
+
field = propagateTagValueValidator(selectedValue);
|
|
8681
8675
|
}
|
|
8682
8676
|
if (!field.isValid) {
|
|
8683
8677
|
return (jsxRuntime.jsxs("div", __assign({ className: "p-4", onClick: stopPropagation }, { children: [field.messages.map(function (error) { return (jsxRuntime.jsxs("div", __assign({ className: "flexbox pr-4 pl-4" }, { children: [jsxRuntime.jsx("span", { children: jsxRuntime.jsx(SvgIcCross, { className: "icon-dim-14 scr-5 mt-3 mr-4" }) }), jsxRuntime.jsx("span", { children: error })] }), error)); }), tagInputType === exports.KEY_VALUE.KEY && (jsxRuntime.jsxs("div", __assign({ className: "flexbox pr-4 pl-4" }, { children: [jsxRuntime.jsx("span", { children: jsxRuntime.jsx(SvgIcInfoOutlined, { className: "icon-dim-14 mt-3 mr-4" }) }), jsxRuntime.jsx("span", __assign({ className: "dc__italic-font-style" }, { children: "Key format: prefix/name or name" }))] })))] })));
|
|
@@ -8720,6 +8714,14 @@ var TagDetails = function (_a) {
|
|
|
8720
8714
|
var propagateTagToResource = function () {
|
|
8721
8715
|
var _tagData = __assign({}, tagData);
|
|
8722
8716
|
_tagData.propagate = !_tagData.propagate;
|
|
8717
|
+
console.log(_tagData.propagate, _tagData.value);
|
|
8718
|
+
if (_tagData.propagate) {
|
|
8719
|
+
_tagData.isInvalidValue = _tagData.key && (!_tagData.value || _tagData.isInvalidValue);
|
|
8720
|
+
}
|
|
8721
|
+
else {
|
|
8722
|
+
_tagData.isInvalidValue =
|
|
8723
|
+
_tagData.key && _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false;
|
|
8724
|
+
}
|
|
8723
8725
|
setTagData(index, _tagData);
|
|
8724
8726
|
};
|
|
8725
8727
|
return (jsxRuntime.jsxs("div", __assign({ className: "flexbox mb-8" }, { children: [jsxRuntime.jsx("div", __assign({ className: "dc__border h-30 pl-4 pr-4 br-4 mr-8 pointer ".concat(tagData.propagate ? 'bcn-7' : ''), onClick: propagateTagToResource }, { children: jsxRuntime.jsx(SvgInjectTag, { className: "icon-dim-20 mt-4 ".concat(tagData.propagate ? 'scn-0' : '') }) })), jsxRuntime.jsx(TagLabelValueSelector, { selectedTagIndex: index, tagData: tagData, setTagData: setTagData, tagInputType: exports.KEY_VALUE.KEY, placeholder: "Enter key", tabIndex: tabIndex - 1, refVar: keyRef, dependentRef: valueRef, tagOptions: suggestedTagsOptions }), jsxRuntime.jsx(TagLabelValueSelector, { selectedTagIndex: index, tagData: tagData, setTagData: setTagData, tagInputType: exports.KEY_VALUE.VALUE, placeholder: "Enter value", tabIndex: tabIndex, refVar: valueRef, dependentRef: keyRef }), jsxRuntime.jsx("div", __assign({ className: "dc__border pl-4 pr-4 dc__right-radius-4 pointer flex top", onClick: deleteTag }, { children: jsxRuntime.jsx(SvgIcCross, { className: "icon-dim-20 mt-4" }) }))] })));
|
|
@@ -16448,6 +16450,8 @@ exports.get = get;
|
|
|
16448
16450
|
exports.getTeamListMin = getTeamListMin;
|
|
16449
16451
|
exports.multiSelectStyles = multiSelectStyles;
|
|
16450
16452
|
exports.post = post;
|
|
16453
|
+
exports.propagateTagKeyValidator = propagateTagKeyValidator;
|
|
16454
|
+
exports.propagateTagValueValidator = propagateTagValueValidator;
|
|
16451
16455
|
exports.put = put;
|
|
16452
16456
|
exports.showError = showError;
|
|
16453
16457
|
exports.sortCallback = sortCallback;
|
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-19",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"typescript": "^4.9.4",
|
|
37
37
|
"react-toastify": "^8.2.0",
|
|
38
38
|
"@tippyjs/react": "^4.2.0",
|
|
39
|
+
"@types/react-select": "^5.0.1",
|
|
39
40
|
"react-select": "^5.2.2",
|
|
40
41
|
"@sentry/browser": "^7.31.1"
|
|
41
42
|
},
|
|
@@ -5,6 +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 { propagateTagValueValidator } from './ValidationRules'
|
|
8
9
|
|
|
9
10
|
export const TagDetails = ({
|
|
10
11
|
index,
|
|
@@ -24,6 +25,13 @@ export const TagDetails = ({
|
|
|
24
25
|
const propagateTagToResource = (): void => {
|
|
25
26
|
const _tagData = { ...tagData }
|
|
26
27
|
_tagData.propagate = !_tagData.propagate
|
|
28
|
+
console.log(_tagData.propagate, _tagData.value)
|
|
29
|
+
if (_tagData.propagate) {
|
|
30
|
+
_tagData.isInvalidValue = _tagData.key && (!_tagData.value || _tagData.isInvalidValue)
|
|
31
|
+
} else {
|
|
32
|
+
_tagData.isInvalidValue =
|
|
33
|
+
_tagData.key && _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false
|
|
34
|
+
}
|
|
27
35
|
setTagData(index, _tagData)
|
|
28
36
|
}
|
|
29
37
|
return (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
2
|
import PopupMenu from '../PopupMenu'
|
|
3
|
-
import {
|
|
3
|
+
import { propagateTagKeyValidator, propagateTagValueValidator } from './ValidationRules'
|
|
4
4
|
import { ReactComponent as ErrorCross } from '../../Assets/Icon/ic-cross.svg'
|
|
5
5
|
import { ReactComponent as Info } from '../../Assets/Icon/ic-info-outlined.svg'
|
|
6
6
|
import { KEY_VALUE } from '../Constants'
|
|
@@ -20,11 +20,10 @@ export const TagLabelValueSelector = ({
|
|
|
20
20
|
tabIndex = null,
|
|
21
21
|
refVar,
|
|
22
22
|
dependentRef,
|
|
23
|
-
noBackDrop
|
|
23
|
+
noBackDrop,
|
|
24
24
|
}: TagLabelValueSelectorType) => {
|
|
25
25
|
const [selectedValue, setSelectedValue] = useState<string>('')
|
|
26
26
|
const [activeElement, setActiveElement] = useState<string>('')
|
|
27
|
-
const validationRules = new ValidationRules()
|
|
28
27
|
|
|
29
28
|
useEffect(() => {
|
|
30
29
|
setSelectedValue(tagData?.[tagInputType] || '')
|
|
@@ -46,10 +45,10 @@ export const TagLabelValueSelector = ({
|
|
|
46
45
|
_tagData[tagInputType] = selectedValue
|
|
47
46
|
if (tagInputType === KEY_VALUE.KEY) {
|
|
48
47
|
_tagData.isInvalidKey = selectedValue
|
|
49
|
-
? !
|
|
48
|
+
? !propagateTagKeyValidator(selectedValue).isValid
|
|
50
49
|
: _tagData.value !== ''
|
|
51
50
|
} else if (selectedValue || isRequired || _tagData.propagate) {
|
|
52
|
-
_tagData.isInvalidValue = !
|
|
51
|
+
_tagData.isInvalidValue = !propagateTagValueValidator(selectedValue).isValid
|
|
53
52
|
_tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidKey
|
|
54
53
|
} else {
|
|
55
54
|
_tagData.isInvalidValue = false
|
|
@@ -76,10 +75,10 @@ export const TagLabelValueSelector = ({
|
|
|
76
75
|
let field = { isValid: true, messages: [] }
|
|
77
76
|
if (tagInputType === KEY_VALUE.KEY) {
|
|
78
77
|
if (selectedValue || tagData.value) {
|
|
79
|
-
field =
|
|
78
|
+
field = propagateTagKeyValidator(selectedValue)
|
|
80
79
|
}
|
|
81
|
-
} else if (isRequired || selectedValue) {
|
|
82
|
-
field =
|
|
80
|
+
} else if (isRequired || selectedValue || tagData.propagate) {
|
|
81
|
+
field = propagateTagValueValidator(selectedValue)
|
|
83
82
|
}
|
|
84
83
|
if (!field.isValid) {
|
|
85
84
|
return (
|
|
@@ -128,12 +127,8 @@ export const TagLabelValueSelector = ({
|
|
|
128
127
|
placement="right"
|
|
129
128
|
content={
|
|
130
129
|
<div>
|
|
131
|
-
<div className="mb-10 fs-12 fw-6 cn-0 dc__break-word">
|
|
132
|
-
|
|
133
|
-
</div>
|
|
134
|
-
<div className="fs-12 fw-4 cn-0 dc__break-word">
|
|
135
|
-
{tag.description}
|
|
136
|
-
</div>
|
|
130
|
+
<div className="mb-10 fs-12 fw-6 cn-0 dc__break-word">{tag.label}</div>
|
|
131
|
+
<div className="fs-12 fw-4 cn-0 dc__break-word">{tag.description}</div>
|
|
137
132
|
</div>
|
|
138
133
|
}
|
|
139
134
|
>
|
|
@@ -15,41 +15,38 @@ const validateTagValue = (value: string): string[] => {
|
|
|
15
15
|
}
|
|
16
16
|
return errorList
|
|
17
17
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
errorList.push(
|
|
32
|
-
if (prefix.length > 253) {
|
|
33
|
-
errorList.push('Prefix: Can be max 253 characters')
|
|
34
|
-
}
|
|
35
|
-
const validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix)
|
|
36
|
-
if (!validPrefix) {
|
|
37
|
-
errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)')
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
errorList.push(...validateTagValue(key).map((error) => `Name: ${error}`))
|
|
18
|
+
export const propagateTagKeyValidator = (key: string): { isValid: boolean; messages: string[] } => {
|
|
19
|
+
const errorList = []
|
|
20
|
+
if (!key) {
|
|
21
|
+
errorList.push('Key is required')
|
|
22
|
+
} else {
|
|
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')
|
|
41
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
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
errorList.push(...validateTagValue(key).map((error) => `Name: ${error}`))
|
|
42
39
|
}
|
|
43
|
-
return { isValid: errorList.length === 0, messages: errorList }
|
|
44
40
|
}
|
|
41
|
+
return { isValid: errorList.length === 0, messages: errorList }
|
|
42
|
+
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return { isValid: errorList.length === 0, messages: errorList }
|
|
44
|
+
export const propagateTagValueValidator = (value: string): { isValid: boolean; messages: string[] } => {
|
|
45
|
+
const errorList = []
|
|
46
|
+
if (!value) {
|
|
47
|
+
errorList.push('Value is required')
|
|
48
|
+
} else {
|
|
49
|
+
errorList.push(...validateTagValue(value))
|
|
54
50
|
}
|
|
51
|
+
return { isValid: errorList.length === 0, messages: errorList }
|
|
55
52
|
}
|