@antscorp/antsomi-ui 1.3.5-beta.934 → 1.3.5-beta.936

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.
@@ -19,7 +19,7 @@ import { TagTextArea, TagifyWrapper, WrapperPlaceHolder } from './styled';
19
19
  import { parseTagStringToTagify, convertInputStringToOriginal, emojiManufacturer, getEmojiTag, isPersonalizeTagType, generateTagContent, unescapeString, hasLineBreak, selectRange, isTagClickable, findURLInTextNodes, getAttributesString, isAnchorNodeChildOfElement, isShortLinkTagType, } from './utils';
20
20
  import { acceptablePatternChecking, detectURLRegex, getCachedRegex, getPersonalizeTagInfo, getShortLinkTagInfo, patternHandlers, } from './patternHandlers';
21
21
  // Constants
22
- import { DETECT_LINK, EMOJI, FORCE_SHOW_TOOLTIP, INVALID_TAG, MESSAGE_TAG, NO_VIEW_TAG, PERSONALIZE_PTN, PROMOTION_CODE, READONLY_TAG, REMOVED_TAG, SHORT_LINK, SHORT_LINK_PTN, SHORT_LINK_V2, defaultCssVariables, tagifyDefaultProps, } from './constants';
22
+ import { DETECT_LINK, EMOJI, ERROR_TAG, FORCE_SHOW_TOOLTIP, INVALID_TAG, MESSAGE_TAG, PERSONALIZE_PTN, PROMOTION_CODE, READONLY_TAG, SHORT_LINK, SHORT_LINK_PTN, SHORT_LINK_V2, WARNING_TAG, defaultCssVariables, tagifyDefaultProps, } from './constants';
23
23
  const TagifyInput = forwardRef((props, ref) => {
24
24
  // Props
25
25
  const { initialValue, escapeHTML, status, readonly, readonlyTag, realtime, disabled, maxLength, maxHeight, minWidth, placeholder, minWidthPlaceholder, isSingleLineText, acceptableTagPattern, mapAttributes, mapErrorAttributes, maxPersonalizeTags, name, children, cssTagifyVariables, onTagClick, onChange, } = props;
@@ -552,7 +552,7 @@ const TagifyInput = forwardRef((props, ref) => {
552
552
  while ((match = regex.exec(value)) !== null) {
553
553
  const [, personalizeContent] = match;
554
554
  const [tagCode] = personalizeContent.split('||');
555
- const { label: tagLabel, isValid, message, type, isRemoved, hasViewPermission, } = getPersonalizeTagInfo(tagCode, attributes, errorAttributes);
555
+ const { label: tagLabel, isValid, message, type, isRemoved, canView, isArchived, isActive, isExpired, } = getPersonalizeTagInfo(tagCode, attributes, errorAttributes);
556
556
  const isPromotionCode = type === PROMOTION_CODE;
557
557
  const tagTextNode = tagifyRef.current?.getTagTextNode(tagElement);
558
558
  /*
@@ -562,42 +562,31 @@ const TagifyInput = forwardRef((props, ref) => {
562
562
  if (tagTextNode) {
563
563
  tagTextNode.textContent = tagLabel;
564
564
  // Clear all previous attributes
565
- tagElement.removeAttribute(REMOVED_TAG);
566
- tagElement.removeAttribute(NO_VIEW_TAG);
567
565
  tagElement.removeAttribute(INVALID_TAG);
566
+ tagElement.removeAttribute(ERROR_TAG);
567
+ tagElement.removeAttribute(WARNING_TAG);
568
568
  tagElement.removeAttribute(READONLY_TAG);
569
569
  tagElement.removeAttribute(MESSAGE_TAG);
570
570
  // In case promotion pool has something wrong
571
571
  if (isPromotionCode && message) {
572
- if (isRemoved) {
573
- tagElement.setAttribute(REMOVED_TAG, 'true');
572
+ if (isRemoved || isArchived || !isActive || isExpired) {
573
+ tagElement.setAttribute(ERROR_TAG, 'true');
574
574
  tagElement.setAttribute(MESSAGE_TAG, message);
575
- tagifyRef.current?.getSetTagData(tagElement, {
576
- ...tagData,
577
- status: 'error',
578
- statusMsg: message,
579
- });
580
575
  }
581
- else if (!hasViewPermission) {
582
- tagElement.setAttribute(NO_VIEW_TAG, 'true');
576
+ else if (!canView) {
577
+ tagElement.setAttribute(WARNING_TAG, 'true');
583
578
  tagElement.setAttribute(MESSAGE_TAG, message);
584
- tagifyRef.current?.getSetTagData(tagElement, {
585
- ...tagData,
586
- status: 'warning',
587
- statusMsg: message,
588
- });
589
579
  }
590
580
  else if (!isValid) {
591
581
  tagElement.setAttribute(READONLY_TAG, 'true');
592
582
  tagElement.setAttribute(INVALID_TAG, 'true');
593
583
  tagElement.setAttribute(MESSAGE_TAG, message);
594
- tagifyRef.current?.getSetTagData(tagElement, {
595
- ...tagData,
596
- status: 'warning',
597
- statusMsg: message,
598
- });
599
584
  }
600
585
  }
586
+ else if ((isArchived || !isActive || isExpired) && message) {
587
+ tagElement.setAttribute(ERROR_TAG, 'true');
588
+ tagElement.setAttribute(MESSAGE_TAG, message);
589
+ }
601
590
  }
602
591
  }
603
592
  }
@@ -623,20 +612,15 @@ const TagifyInput = forwardRef((props, ref) => {
623
612
  if (tagTextNode) {
624
613
  tagTextNode.textContent = tagLabel;
625
614
  // Clear all previous attributes
626
- tagElement.removeAttribute(REMOVED_TAG);
627
- tagElement.removeAttribute(NO_VIEW_TAG);
628
615
  tagElement.removeAttribute(INVALID_TAG);
616
+ tagElement.removeAttribute(ERROR_TAG);
617
+ tagElement.removeAttribute(WARNING_TAG);
629
618
  tagElement.removeAttribute(READONLY_TAG);
630
619
  tagElement.removeAttribute(MESSAGE_TAG);
631
620
  // In case promotion pool has something wrong
632
621
  if (!isValid && message) {
633
- tagElement.setAttribute(REMOVED_TAG, 'true');
622
+ tagElement.setAttribute(ERROR_TAG, 'true');
634
623
  tagElement.setAttribute(MESSAGE_TAG, message);
635
- tagifyRef.current?.getSetTagData(tagElement, {
636
- ...tagData,
637
- status: 'error',
638
- statusMsg: message,
639
- });
640
624
  }
641
625
  }
642
626
  }
@@ -919,8 +903,8 @@ const TagifyInput = forwardRef((props, ref) => {
919
903
  useDeepCompareEffect(() => {
920
904
  const showTooltip = (tagElement) => {
921
905
  const tagRect = tagElement.getBoundingClientRect();
922
- const removeTag = tagElement.getAttribute(REMOVED_TAG);
923
- const noViewTag = tagElement.getAttribute(NO_VIEW_TAG);
906
+ const errorTag = tagElement.getAttribute(ERROR_TAG);
907
+ const warningTag = tagElement.getAttribute(WARNING_TAG);
924
908
  const invalidTag = tagElement.getAttribute(INVALID_TAG);
925
909
  const messageTag = tagElement.getAttribute(MESSAGE_TAG);
926
910
  const forceShowTooltipAttr = tagElement.getAttribute(FORCE_SHOW_TOOLTIP);
@@ -933,7 +917,7 @@ const TagifyInput = forwardRef((props, ref) => {
933
917
  const tooltip = document.querySelector('.tagify__tooltip');
934
918
  tooltip?.setAttribute('style', 'display: block !important;visibility: hidden !important;');
935
919
  const tooltipRect = tooltip?.getBoundingClientRect();
936
- const hasWrongAttribute = removeTag === 'true' || noViewTag === 'true' || invalidTag === 'true';
920
+ const hasWrongAttribute = errorTag === 'true' || warningTag === 'true' || invalidTag === 'true';
937
921
  const isTooltipVisible = tooltipRect && hasWrongAttribute;
938
922
  const isForceVisible = tooltipRect && forceShowTooltipAttr === 'true';
939
923
  if (isTooltipVisible || isForceVisible) {
@@ -11,8 +11,10 @@ export declare const TAG_CUSTOM_ATTRIBUTES: {
11
11
  readonly NO_VIEW_TAG: "no-view-tag";
12
12
  readonly MESSAGE_TAG: "message-tag";
13
13
  readonly FORCE_SHOW_TOOLTIP: "force-show-tooltip";
14
+ readonly ERROR_TAG: "error-tag";
15
+ readonly WARNING_TAG: "warning-tag";
14
16
  };
15
- export declare const READONLY_TAG: "readonly-tag", INVALID_TAG: "invalid-tag", REMOVED_TAG: "removed-tag", NO_VIEW_TAG: "no-view-tag", MESSAGE_TAG: "message-tag", FORCE_SHOW_TOOLTIP: "force-show-tooltip";
17
+ export declare const READONLY_TAG: "readonly-tag", INVALID_TAG: "invalid-tag", REMOVED_TAG: "removed-tag", NO_VIEW_TAG: "no-view-tag", MESSAGE_TAG: "message-tag", FORCE_SHOW_TOOLTIP: "force-show-tooltip", ERROR_TAG: "error-tag", WARNING_TAG: "warning-tag";
16
18
  export declare const defaultCssVariables: {
17
19
  '--input-color': string | undefined;
18
20
  '--input-font-size': string;
@@ -12,8 +12,10 @@ export const TAG_CUSTOM_ATTRIBUTES = {
12
12
  NO_VIEW_TAG: 'no-view-tag',
13
13
  MESSAGE_TAG: 'message-tag',
14
14
  FORCE_SHOW_TOOLTIP: 'force-show-tooltip',
15
+ ERROR_TAG: 'error-tag',
16
+ WARNING_TAG: 'warning-tag',
15
17
  };
16
- export const { READONLY_TAG, INVALID_TAG, REMOVED_TAG, NO_VIEW_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP, } = TAG_CUSTOM_ATTRIBUTES;
18
+ export const { READONLY_TAG, INVALID_TAG, REMOVED_TAG, NO_VIEW_TAG, MESSAGE_TAG, FORCE_SHOW_TOOLTIP, ERROR_TAG, WARNING_TAG, } = TAG_CUSTOM_ATTRIBUTES;
17
19
  export const defaultCssVariables = {
18
20
  '--input-color': globalToken?.colorText,
19
21
  '--input-font-size': `${globalToken?.fontSize}px`,
@@ -5,7 +5,10 @@ interface TagInfo {
5
5
  isValid: boolean;
6
6
  message?: string;
7
7
  isRemoved?: boolean;
8
- hasViewPermission?: boolean;
8
+ canView?: boolean;
9
+ isArchived?: boolean;
10
+ isActive?: boolean;
11
+ isExpired?: boolean;
9
12
  }
10
13
  /**
11
14
  * Retrieves a cached regular expression or compiles and caches it if not found.
@@ -220,7 +220,9 @@ const getLabelAttribute = (type, attributeName, subAttributeName, mapAttributes)
220
220
  mapping[attributeName]?.value ||
221
221
  type);
222
222
  }
223
- const combineAttribute = `${attributeName}.${subAttributeName}`;
223
+ const combineAttribute = subAttributeName
224
+ ? `${attributeName}.${subAttributeName}`
225
+ : attributeName;
224
226
  return (mapping[combineAttribute]?.label ||
225
227
  mapping[combineAttribute]?.display ||
226
228
  mapping[combineAttribute]?.template_name ||
@@ -230,16 +232,36 @@ export const getPersonalizeTagInfo = (originalTag, mapAttributes, mapErrorAttrib
230
232
  try {
231
233
  const [type, attributeName, subAttributeName] = originalTag.split('.');
232
234
  const isCsGroup = type === CONTENT_SOURCE_GROUP;
235
+ const combineAttribute = subAttributeName
236
+ ? `${attributeName}.${subAttributeName}`
237
+ : attributeName;
238
+ // Check additional case for each tag type
239
+ let [isValid, message, isRemoved, canView, isArchived, isActive, isExpired] = [
240
+ true,
241
+ '',
242
+ false,
243
+ true,
244
+ false,
245
+ true,
246
+ false,
247
+ ];
233
248
  if (!mapAttributes || (!mapAttributes[type] && !isCsGroup)) {
234
249
  // return fallback if no mapping
235
- return { type, label: attributeName || type, isValid: false, isRemoved: false };
250
+ return {
251
+ type,
252
+ label: attributeName || type,
253
+ isValid: false,
254
+ isRemoved,
255
+ canView,
256
+ isArchived,
257
+ isActive,
258
+ isExpired,
259
+ };
236
260
  }
237
261
  // Get label based on mapping
238
262
  const label = isCsGroup
239
263
  ? getContentSourceLabel(attributeName, subAttributeName, mapAttributes)
240
264
  : getLabelAttribute(type, attributeName, subAttributeName, mapAttributes);
241
- // Check additional case for each tag type
242
- let [isValid, message, isRemoved, hasViewPermission] = [true, '', false, true];
243
265
  switch (type) {
244
266
  case PROMOTION_CODE: {
245
267
  // Check if the code is exist in the map
@@ -251,15 +273,30 @@ export const getPersonalizeTagInfo = (originalTag, mapAttributes, mapErrorAttrib
251
273
  if (mapErrorAttributes &&
252
274
  mapErrorAttributes[type] &&
253
275
  mapErrorAttributes[type][attributeName]) {
254
- const { isEdit = false, isView = false, isExist = true, } = mapErrorAttributes[type][attributeName] || {};
255
- // Case Pool removed
276
+ const { isEdit = false, isView = false, isExist = true, isArchived: _isArchived = false, isActive: _isActive = true, isExpired: _isExpired = false, } = mapErrorAttributes[type][attributeName] || {};
256
277
  if (!isExist) {
278
+ // Case Pool Removed
257
279
  isRemoved = !isExist;
258
280
  message = translate(translations._PERSONALIZATION_TAG_ERR_REMOVED, 'This pool is removed');
259
281
  }
282
+ else if (_isArchived) {
283
+ // Case Pool is Archived
284
+ isArchived = true;
285
+ message = translate(translations._PERSONALIZATION_TAG_ERR_ATT_ARCHIVE, 'This attribute has been archived');
286
+ }
287
+ else if (!_isActive) {
288
+ // Case Pool is Inactive
289
+ isActive = false;
290
+ message = translate(translations._PERSONALIZATION_TAG_ERR_POOL_DEACTIVATE, 'This pool has been deactivated. You have to turn it on to use');
291
+ }
292
+ else if (_isExpired) {
293
+ // Case Pool is Expired
294
+ isExpired = true;
295
+ message = translate(translations._PERSONALIZATION_TAG_ERR_POOL_EXPIRE, 'This pool has expired, new codes could not be allocated');
296
+ }
260
297
  else if (!isView) {
261
- // Case No permission
262
- hasViewPermission = isView;
298
+ // Case Pool Can't View
299
+ canView = isView;
263
300
  message = translate(translations._PERMISSION_ERR_POOL, 'You do not have permission on this pool');
264
301
  }
265
302
  }
@@ -268,6 +305,22 @@ export const getPersonalizeTagInfo = (originalTag, mapAttributes, mapErrorAttrib
268
305
  break;
269
306
  }
270
307
  default: {
308
+ if (mapAttributes[type] &&
309
+ combineAttribute &&
310
+ !has(mapAttributes[type], combineAttribute)) {
311
+ isValid = false;
312
+ message = 'This attribute does not exist anymore';
313
+ }
314
+ if (mapErrorAttributes &&
315
+ mapErrorAttributes[type] &&
316
+ mapErrorAttributes[type][combineAttribute]) {
317
+ const { isArchived: _isArchived = false, isActive: _isActive = true, isExpired: _isExpired = false, } = mapErrorAttributes[type][combineAttribute] || {};
318
+ if (_isArchived) {
319
+ // Case Pool is Archived
320
+ isArchived = true;
321
+ message = translate(translations._PERSONALIZATION_TAG_ERR_ATT_ARCHIVE, 'This attribute has been archived');
322
+ }
323
+ }
271
324
  break;
272
325
  }
273
326
  }
@@ -277,7 +330,10 @@ export const getPersonalizeTagInfo = (originalTag, mapAttributes, mapErrorAttrib
277
330
  isValid,
278
331
  label: label || type,
279
332
  isRemoved,
280
- hasViewPermission,
333
+ canView,
334
+ isArchived,
335
+ isActive,
336
+ isExpired,
281
337
  };
282
338
  }
283
339
  catch (error) {
@@ -295,14 +351,14 @@ export const getShortLinkTagInfo = (params) => {
295
351
  const isExistShortLink = has(mapAttributes[type], shortener);
296
352
  if (!isExistShortLink) {
297
353
  isValid = false;
298
- message = translate('', 'This shortener is inactivated or removed');
354
+ message = translate(translations?._PER_TAG_LINK_ERR || '', 'This shortener is inactivated or removed');
299
355
  if (mapErrorAttributes &&
300
356
  mapErrorAttributes?.[type] &&
301
357
  mapErrorAttributes?.[type]?.[shortener]) {
302
358
  const { isView = true, isExist = true } = mapErrorAttributes[type][shortener] || {};
303
359
  if (!isExist || !isView) {
304
360
  isValid = false;
305
- message = translate('', 'This shortener is inactivated or removed');
361
+ message = translate(translations?._PER_TAG_LINK_ERR || '', 'This shortener is inactivated or removed');
306
362
  }
307
363
  }
308
364
  }
@@ -324,7 +380,7 @@ export const getShortLinkTagInfo = (params) => {
324
380
  label,
325
381
  type,
326
382
  isValid: false,
327
- message: translate('', 'This shortener is inactivated or removed'),
383
+ message: translate(translations._PER_TAG_LINK_ERR, 'This shortener is inactivated or removed'),
328
384
  };
329
385
  }
330
386
  };
@@ -479,6 +535,8 @@ const handlePersonalizeTagPattern = match => {
479
535
  type: type,
480
536
  value: personalizeTag,
481
537
  attributeName,
538
+ subAttributeName,
539
+ key: subAttributeName ? `${attributeName}.${subAttributeName}` : attributeName,
482
540
  };
483
541
  const tag = createTagPattern(tagData);
484
542
  return { isValid: true, tag, tagData };
@@ -3,7 +3,7 @@ import { css } from 'styled-components';
3
3
  import { isString } from 'lodash';
4
4
  // Constants
5
5
  import { globalToken } from '@antscorp/antsomi-ui/es/constants';
6
- import { DETECT_LINK, EMOJI, INVALID_TAG, MIN_H_WRAPPER, NO_VIEW_TAG, READONLY_TAG, REMOVED_TAG, SHORT_LINK, SHORT_LINK_TYPE, SHORT_LINK_V2, TAG_COLOR, TAG_H, TAG_TYPE, } from './constants';
6
+ import { DETECT_LINK, EMOJI, ERROR_TAG, MIN_H_WRAPPER, READONLY_TAG, SHORT_LINK, SHORT_LINK_TYPE, SHORT_LINK_V2, TAG_COLOR, TAG_H, TAG_TYPE, WARNING_TAG, } from './constants';
7
7
  export const getTagifyStyled = ({ $maxHeight, $tagifyFullWidth }) => css `
8
8
  ${$maxHeight &&
9
9
  css `
@@ -160,7 +160,7 @@ export const getTagifyTagStyled = (_wrapperProps) => css `
160
160
  cursor: not-allowed;
161
161
  }
162
162
 
163
- &[${REMOVED_TAG}='true'] {
163
+ &[${ERROR_TAG}='true'] {
164
164
  ${({ $tagErrorIcon }) => $tagErrorIcon &&
165
165
  css `
166
166
  > div {
@@ -189,37 +189,8 @@ export const getTagifyTagStyled = (_wrapperProps) => css `
189
189
  }
190
190
  `}
191
191
  }
192
- &[${NO_VIEW_TAG}='true'] {
193
- ${({ $tagInvalidIcon }) => $tagInvalidIcon &&
194
- css `
195
- > div {
196
- padding-right: 22px;
197
- position: relative;
198
192
 
199
- > span {
200
- &::after {
201
- content: '';
202
- position: absolute;
203
- top: 50%;
204
- right: 5px;
205
- transform: translateY(calc(-50%));
206
- width: 14px;
207
- height: 14px;
208
- display: inline-block;
209
- background-image: url(${$tagInvalidIcon});
210
- background-size: contain;
211
- background-repeat: no-repeat;
212
- }
213
- }
214
- }
215
- > div[data-tag-type] {
216
- background-color: white !important;
217
- border: 1px solid red;
218
- }
219
- `}
220
- }
221
-
222
- &[${INVALID_TAG}='true'] {
193
+ &[${WARNING_TAG}='true'] {
223
194
  ${({ $tagInvalidIcon }) => $tagInvalidIcon &&
224
195
  css `
225
196
  > div {
@@ -232,7 +203,7 @@ export const getTagifyTagStyled = (_wrapperProps) => css `
232
203
  position: absolute;
233
204
  top: 50%;
234
205
  right: 5px;
235
- transform: translateY(calc(-50% - 1px));
206
+ transform: translateY(calc(-50%));
236
207
  width: 14px;
237
208
  height: 14px;
238
209
  display: inline-block;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.934",
3
+ "version": "1.3.5-beta.936",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -61,7 +61,7 @@
61
61
  "not op_mini all"
62
62
  ],
63
63
  "dependencies": {
64
- "@antscorp/antsomi-locales": "1.0.17",
64
+ "@antscorp/antsomi-locales": "1.0.28",
65
65
  "@antscorp/icons": "0.27.54",
66
66
  "@antscorp/image-editor": "1.0.2",
67
67
  "@antscorp/processing-notification": "^1.0.3",