@devtron-labs/devtron-fe-common-lib 0.0.7-beta-20 → 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.
@@ -1,8 +1,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
- };
1
+ export declare class ValidationRules {
2
+ propagateTagKey: (key: string) => {
3
+ isValid: boolean;
4
+ messages: string[];
5
+ };
6
+ propagateTagValue: (value: string) => {
7
+ isValid: boolean;
8
+ messages: string[];
9
+ };
10
+ }
@@ -4,4 +4,3 @@ export * from './TagLabelSelect';
4
4
  export * from './TagLabelValueSelector';
5
5
  export * from './ResizableTagTextArea';
6
6
  export * from './Types';
7
- export * from './ValidationRules';
package/dist/index.js CHANGED
@@ -8506,61 +8506,6 @@ function PropagateTagInfo(_a) {
8506
8506
  return (jsxRuntime.jsx(TippyCustomized, __assign({ theme: exports.TippyTheme.white, className: "w-300", placement: "top", Icon: SvgInjectTag, heading: 'Propagate tags to K8s resources', infoText: "", additionalContent: additionalInfo(), showCloseButton: true, trigger: "click", interactive: true, documentationLink: isCreateApp ? DOCUMENTATION.APP_TAGS : DOCUMENTATION.APP_OVERVIEW_TAGS, documentationLinkText: "View Documentation" }, { children: jsxRuntime.jsxs("div", __assign({ className: "flexbox cursor" }, { children: [jsxRuntime.jsx(SvgInjectTag, { className: "icon-dim-16 mt-2 mr-4" }), jsxRuntime.jsx("span", { children: "Propagate tags" }), jsxRuntime.jsx(SvgIcHelpOutline, { className: "icon-dim-16 mt-2 ml-4" })] })) })));
8507
8507
  }
8508
8508
 
8509
- var validateTagValue = function (value) {
8510
- var errorList = [];
8511
- if (value.length > 63) {
8512
- errorList.push('Can be max 63 characters');
8513
- }
8514
- var firstLastAlphanumeric = PATTERNS.START_END_ALPHANUMERIC.test(value);
8515
- if (!firstLastAlphanumeric) {
8516
- errorList.push('Must start and end with an alphanumeric character');
8517
- }
8518
- var validValue = PATTERNS.ALPHANUMERIC_WITH_SPECIAL_CHAR.test(value);
8519
- if (!validValue) {
8520
- errorList.push('Can only contain alphanumeric chars and (-), (_), (.)');
8521
- }
8522
- return errorList;
8523
- };
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');
8541
- }
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 (.)');
8545
- }
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');
8557
- }
8558
- else {
8559
- errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(value)), false));
8560
- }
8561
- return { isValid: errorList.length === 0, messages: errorList };
8562
- };
8563
-
8564
8509
  var _path$2;
8565
8510
  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); }
8566
8511
  var SvgIcInfoOutlined = function SvgIcInfoOutlined(props) {
@@ -8617,10 +8562,71 @@ function ResizableTagTextArea(_a) {
8617
8562
  return (jsxRuntime.jsx("textarea", { rows: 1, ref: refVar, value: text, placeholder: placeholder, className: "".concat(className || '', " lh-20"), style: { resize: 'none' }, onChange: handleChange, onBlur: handleOnBlur, onFocus: handleOnFocus, tabIndex: tabIndex }));
8618
8563
  }
8619
8564
 
8565
+ var validateTagValue = function (value) {
8566
+ var errorList = [];
8567
+ if (value.length > 63) {
8568
+ errorList.push('Can be max 63 characters');
8569
+ }
8570
+ var firstLastAlphanumeric = PATTERNS.START_END_ALPHANUMERIC.test(value);
8571
+ if (!firstLastAlphanumeric) {
8572
+ errorList.push('Must start and end with an alphanumeric character');
8573
+ }
8574
+ var validValue = PATTERNS.ALPHANUMERIC_WITH_SPECIAL_CHAR.test(value);
8575
+ if (!validValue) {
8576
+ errorList.push('Can only contain alphanumeric chars and (-), (_), (.)');
8577
+ }
8578
+ return errorList;
8579
+ };
8580
+ var ValidationRules = /** @class */ (function () {
8581
+ function ValidationRules() {
8582
+ this.propagateTagKey = function (key) {
8583
+ var _a;
8584
+ var errorList = [];
8585
+ if (!key) {
8586
+ errorList.push('Key is required');
8587
+ }
8588
+ else {
8589
+ var re = new RegExp('/', 'g');
8590
+ var noOfSlashInKey = (_a = key.match(re)) === null || _a === void 0 ? void 0 : _a.length;
8591
+ if (noOfSlashInKey > 1) {
8592
+ errorList.push('Key: Max 1 ( / ) allowed');
8593
+ }
8594
+ else if (noOfSlashInKey === 1) {
8595
+ var _b = __read(key.split('/'), 2), prefix = _b[0], name_1 = _b[1];
8596
+ errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(name_1).map(function (error) { return "Name: ".concat(error); })), false));
8597
+ if (prefix.length > 253) {
8598
+ errorList.push('Prefix: Can be max 253 characters');
8599
+ }
8600
+ var validPrefix = PATTERNS.KUBERNETES_KEY_PREFIX.test(prefix);
8601
+ if (!validPrefix) {
8602
+ errorList.push('Prefix: Must be a DNS subdomain (a series of DNS labels separated by dots (.)');
8603
+ }
8604
+ }
8605
+ else {
8606
+ errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(key).map(function (error) { return "Name: ".concat(error); })), false));
8607
+ }
8608
+ }
8609
+ return { isValid: errorList.length === 0, messages: errorList };
8610
+ };
8611
+ this.propagateTagValue = function (value) {
8612
+ var errorList = [];
8613
+ if (!value) {
8614
+ errorList.push('Value is required');
8615
+ }
8616
+ else {
8617
+ errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(value)), false));
8618
+ }
8619
+ return { isValid: errorList.length === 0, messages: errorList };
8620
+ };
8621
+ }
8622
+ return ValidationRules;
8623
+ }());
8624
+
8620
8625
  var TagLabelValueSelector = function (_a) {
8621
8626
  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;
8622
8627
  var _c = __read(React.useState(''), 2), selectedValue = _c[0], setSelectedValue = _c[1];
8623
8628
  var _d = __read(React.useState(''), 2), activeElement = _d[0], setActiveElement = _d[1];
8629
+ var validationRules = new ValidationRules();
8624
8630
  React.useEffect(function () {
8625
8631
  setSelectedValue((tagData === null || tagData === void 0 ? void 0 : tagData[tagInputType]) || '');
8626
8632
  }, [selectedTagIndex, tagData, tagInputType]);
@@ -8637,12 +8643,13 @@ var TagLabelValueSelector = function (_a) {
8637
8643
  var _tagData = __assign({}, tagData);
8638
8644
  _tagData[tagInputType] = selectedValue;
8639
8645
  if (tagInputType === exports.KEY_VALUE.KEY) {
8640
- _tagData.isInvalidKey = selectedValue
8641
- ? !propagateTagKeyValidator(selectedValue).isValid
8642
- : _tagData.value !== '';
8646
+ _tagData.isInvalidKey =
8647
+ selectedValue || _tagData.propagate
8648
+ ? !validationRules.propagateTagKey(selectedValue).isValid
8649
+ : _tagData.value !== '';
8643
8650
  }
8644
8651
  else if (selectedValue || isRequired || _tagData.propagate) {
8645
- _tagData.isInvalidValue = !propagateTagValueValidator(selectedValue).isValid;
8652
+ _tagData.isInvalidValue = !validationRules.propagateTagValue(selectedValue).isValid;
8646
8653
  _tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidKey;
8647
8654
  }
8648
8655
  else {
@@ -8667,11 +8674,11 @@ var TagLabelValueSelector = function (_a) {
8667
8674
  var field = { isValid: true, messages: [] };
8668
8675
  if (tagInputType === exports.KEY_VALUE.KEY) {
8669
8676
  if (selectedValue || tagData.value) {
8670
- field = propagateTagKeyValidator(selectedValue);
8677
+ field = validationRules.propagateTagKey(selectedValue);
8671
8678
  }
8672
8679
  }
8673
8680
  else if (isRequired || selectedValue || tagData.propagate) {
8674
- field = propagateTagValueValidator(selectedValue);
8681
+ field = validationRules.propagateTagValue(selectedValue);
8675
8682
  }
8676
8683
  if (!field.isValid) {
8677
8684
  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" }))] })))] })));
@@ -8707,6 +8714,7 @@ var TagDetails = function (_a) {
8707
8714
  var index = _a.index, tagData = _a.tagData, setTagData = _a.setTagData, removeTag = _a.removeTag, _b = _a.tabIndex, tabIndex = _b === void 0 ? 1 : _b, suggestedTagsOptions = _a.suggestedTagsOptions;
8708
8715
  var keyRef = React.useRef(null);
8709
8716
  var valueRef = React.useRef(null);
8717
+ var validationRules = new ValidationRules();
8710
8718
  var deleteTag = function (e) {
8711
8719
  stopPropagation(e);
8712
8720
  removeTag(index);
@@ -8714,13 +8722,14 @@ var TagDetails = function (_a) {
8714
8722
  var propagateTagToResource = function () {
8715
8723
  var _tagData = __assign({}, tagData);
8716
8724
  _tagData.propagate = !_tagData.propagate;
8717
- console.log(_tagData.propagate, _tagData.value);
8718
8725
  if (_tagData.propagate) {
8719
- _tagData.isInvalidValue = _tagData.key && (!_tagData.value || _tagData.isInvalidValue);
8726
+ _tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidValue;
8727
+ _tagData.isInvalidValue = !_tagData.value || _tagData.isInvalidValue;
8720
8728
  }
8721
8729
  else {
8722
- _tagData.isInvalidValue =
8723
- _tagData.key && _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false;
8730
+ _tagData.isInvalidKey =
8731
+ _tagData.key || _tagData.value ? validationRules.propagateTagKey(_tagData.key).isValid : false;
8732
+ _tagData.isInvalidValue = _tagData.value ? validationRules.propagateTagValue(_tagData.value).isValid : false;
8724
8733
  }
8725
8734
  setTagData(index, _tagData);
8726
8735
  };
@@ -16465,8 +16474,6 @@ exports.get = get;
16465
16474
  exports.getTeamListMin = getTeamListMin;
16466
16475
  exports.multiSelectStyles = multiSelectStyles;
16467
16476
  exports.post = post;
16468
- exports.propagateTagKeyValidator = propagateTagKeyValidator;
16469
- exports.propagateTagValueValidator = propagateTagValueValidator;
16470
16477
  exports.put = put;
16471
16478
  exports.showError = showError;
16472
16479
  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-20",
3
+ "version": "0.0.7-beta-21",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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 { propagateTagValueValidator } from './ValidationRules'
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.isInvalidValue = _tagData.key && (!_tagData.value || _tagData.isInvalidValue)
30
+ _tagData.isInvalidKey = !_tagData.key || _tagData.isInvalidValue
31
+ _tagData.isInvalidValue = !_tagData.value || _tagData.isInvalidValue
31
32
  } else {
32
- _tagData.isInvalidValue =
33
- _tagData.key && _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false
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 = selectedValue
48
- ? !propagateTagKeyValidator(selectedValue).isValid
49
- : _tagData.value !== ''
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 = !propagateTagValueValidator(selectedValue).isValid
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 = propagateTagKeyValidator(selectedValue)
80
+ field = validationRules.propagateTagKey(selectedValue)
79
81
  }
80
82
  } else if (isRequired || selectedValue || tagData.propagate) {
81
- field = propagateTagValueValidator(selectedValue)
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 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')
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
- errorList.push(...validateTagValue(key).map((error) => `Name: ${error}`))
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
- 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))
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
  }
@@ -3,5 +3,4 @@ export * from './TagDetails'
3
3
  export * from './TagLabelSelect'
4
4
  export * from './TagLabelValueSelector'
5
5
  export * from './ResizableTagTextArea'
6
- export * from './Types'
7
- export * from './ValidationRules'
6
+ export * from './Types'