@devtron-labs/devtron-fe-common-lib 0.0.7-beta-16 → 0.0.7-beta-17

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,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 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
- }
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
+ };
@@ -4,3 +4,4 @@ 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
@@ -8521,50 +8521,45 @@ var validateTagValue = function (value) {
8521
8521
  }
8522
8522
  return errorList;
8523
8523
  };
8524
- var ValidationRules = /** @class */ (function () {
8525
- function ValidationRules() {
8526
- this.propagateTagKey = function (key) {
8527
- var _a;
8528
- var errorList = [];
8529
- if (!key) {
8530
- errorList.push('Key is required');
8531
- }
8532
- else {
8533
- var re = new RegExp('/', 'g');
8534
- var noOfSlashInKey = (_a = key.match(re)) === null || _a === void 0 ? void 0 : _a.length;
8535
- if (noOfSlashInKey > 1) {
8536
- errorList.push('Key: Max 1 ( / ) allowed');
8537
- }
8538
- else if (noOfSlashInKey === 1) {
8539
- var _b = __read(key.split('/'), 2), prefix = _b[0], name_1 = _b[1];
8540
- errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(name_1).map(function (error) { return "Name: ".concat(error); })), false));
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
- else {
8561
- errorList.push.apply(errorList, __spreadArray([], __read(validateTagValue(value)), false));
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
- return { isValid: errorList.length === 0, messages: errorList };
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
- return ValidationRules;
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
- ? !validationRules.propagateTagKey(selectedValue).isValid
8641
+ ? !propagateTagKeyValidator(selectedValue).isValid
8648
8642
  : _tagData.value !== '';
8649
8643
  }
8650
8644
  else if (selectedValue || isRequired || _tagData.propagate) {
8651
- _tagData.isInvalidValue = !validationRules.propagateTagValue(selectedValue).isValid;
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 = validationRules.propagateTagKey(selectedValue);
8670
+ field = propagateTagKeyValidator(selectedValue);
8677
8671
  }
8678
8672
  }
8679
- else if (isRequired || selectedValue) {
8680
- field = validationRules.propagateTagValue(selectedValue);
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,12 @@ var TagDetails = function (_a) {
8720
8714
  var propagateTagToResource = function () {
8721
8715
  var _tagData = __assign({}, tagData);
8722
8716
  _tagData.propagate = !_tagData.propagate;
8717
+ if (_tagData.propagate) {
8718
+ _tagData.isInvalidValue = !_tagData.value || _tagData.isInvalidValue;
8719
+ }
8720
+ else {
8721
+ _tagData.isInvalidValue = _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false;
8722
+ }
8723
8723
  setTagData(index, _tagData);
8724
8724
  };
8725
8725
  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 +16448,8 @@ exports.get = get;
16448
16448
  exports.getTeamListMin = getTeamListMin;
16449
16449
  exports.multiSelectStyles = multiSelectStyles;
16450
16450
  exports.post = post;
16451
+ exports.propagateTagKeyValidator = propagateTagKeyValidator;
16452
+ exports.propagateTagValueValidator = propagateTagValueValidator;
16451
16453
  exports.put = put;
16452
16454
  exports.showError = showError;
16453
16455
  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-16",
3
+ "version": "0.0.7-beta-17",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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,11 @@ export const TagDetails = ({
24
25
  const propagateTagToResource = (): void => {
25
26
  const _tagData = { ...tagData }
26
27
  _tagData.propagate = !_tagData.propagate
28
+ if (_tagData.propagate) {
29
+ _tagData.isInvalidValue = !_tagData.value || _tagData.isInvalidValue
30
+ } else {
31
+ _tagData.isInvalidValue = _tagData.value ? propagateTagValueValidator(_tagData.value).isValid : false
32
+ }
27
33
  setTagData(index, _tagData)
28
34
  }
29
35
  return (
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect } from 'react'
2
2
  import PopupMenu from '../PopupMenu'
3
- import { ValidationRules } from './ValidationRules'
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
- ? !validationRules.propagateTagKey(selectedValue).isValid
48
+ ? !propagateTagKeyValidator(selectedValue).isValid
50
49
  : _tagData.value !== ''
51
50
  } else if (selectedValue || isRequired || _tagData.propagate) {
52
- _tagData.isInvalidValue = !validationRules.propagateTagValue(selectedValue).isValid
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 = validationRules.propagateTagKey(selectedValue)
78
+ field = propagateTagKeyValidator(selectedValue)
80
79
  }
81
- } else if (isRequired || selectedValue) {
82
- field = validationRules.propagateTagValue(selectedValue)
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
- {tag.label}
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 class ValidationRules {
19
-
20
- propagateTagKey = (key: string): { isValid: boolean; messages: string[] } => {
21
- const errorList = []
22
- if (!key) {
23
- errorList.push('Key is required')
24
- } else {
25
- const re = new RegExp('/', 'g')
26
- const noOfSlashInKey = key.match(re)?.length
27
- if (noOfSlashInKey > 1) {
28
- errorList.push('Key: Max 1 ( / ) allowed')
29
- } else if (noOfSlashInKey === 1) {
30
- const [prefix, name] = key.split('/')
31
- errorList.push(...validateTagValue(name).map((error) => `Name: ${error}`))
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
- propagateTagValue = (value: string): { isValid: boolean; messages: string[] } => {
47
- const errorList = []
48
- if (!value) {
49
- errorList.push('Value is required')
50
- } else {
51
- errorList.push(...validateTagValue(value))
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
  }
@@ -3,4 +3,5 @@ export * from './TagDetails'
3
3
  export * from './TagLabelSelect'
4
4
  export * from './TagLabelValueSelector'
5
5
  export * from './ResizableTagTextArea'
6
- export * from './Types'
6
+ export * from './Types'
7
+ export * from './ValidationRules'