@capillarytech/creatives-library 8.0.60-alpha.2 → 8.0.60-alpha.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.60-alpha.2",
4
+ "version": "8.0.60-alpha.3",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -294,4 +294,36 @@ export const getTagMapValue = (object = {}) => {
294
294
  ).reduce((acc, current) => {
295
295
  return { ...acc?.subtags ?? {}, ...current?.subtags ?? {} };
296
296
  }, {});
297
+ };
298
+
299
+
300
+ /**
301
+ * Extracts and merges all subtags and top-level keys from the provided object into a single flat map.
302
+ *
303
+ * @param {Object} object - The input object containing top-level keys with optional subtags.
304
+ * @returns {Object} - A flat map containing all top-level keys and their subtags.
305
+ */
306
+ export const getForwardedMapValues = (object = {}) => {
307
+ return Object?.entries(object)?.reduce((acc, [key, current]) => {
308
+ // Check if current has 'subtags' and it's an object
309
+ if (current && current?.subtags && typeof current?.subtags === 'object') {
310
+ // Add the top-level key with its 'name' and 'desc'
311
+ acc[key] = {
312
+ name: current?.name,
313
+ desc: current?.desc,
314
+ };
315
+
316
+ // Merge the subtags into the accumulator
317
+ acc = { ...acc, ...current?.subtags };
318
+ } else if (current && typeof current === 'object') {
319
+ // If no 'subtags', add the top-level key with its 'name' and 'desc'
320
+ acc[key] = {
321
+ name: current?.name,
322
+ desc: current?.desc,
323
+ };
324
+ }
325
+
326
+ // If the current entry is not an object or lacks 'name'/'desc', skip it
327
+ return acc;
328
+ }, {});
297
329
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import '@testing-library/jest-dom';
3
- import { checkSupport, extractNames, getTagMapValue, preprocessHtml, validateIfTagClosed,validateTags, skipTags } from '../tagValidations';
3
+ import { checkSupport, extractNames, getTagMapValue,getForwardedMapValues, preprocessHtml, validateIfTagClosed,validateTags, skipTags } from '../tagValidations';
4
4
  import { eventContextTags } from '../../v2Containers/TagList/tests/mockdata';
5
5
 
6
6
  describe("check if curly brackets are balanced", () => {
@@ -496,4 +496,273 @@ describe("skipTags", () => {
496
496
  const result = skipTags(tag);
497
497
  expect(result).toEqual(true);
498
498
  });
499
+ });
500
+
501
+
502
+ describe('getForwardedMapValues', () => {
503
+ test('should return an empty object when input is empty', () => {
504
+ const input = {};
505
+ const expected = {};
506
+ expect(getForwardedMapValues(input)).toEqual(expected);
507
+ });
508
+
509
+ test('should correctly process objects with subtags', () => {
510
+ const input = {
511
+ customer: {
512
+ name: 'Customer',
513
+ desc: 'Customer Description',
514
+ subtags: {
515
+ cumulative_points_currency: {
516
+ name: 'Lifetime Points (in ₹)',
517
+ desc: 'Lifetime Points in ₹ Description',
518
+ },
519
+ mobile_number: {
520
+ name: 'Mobile Number',
521
+ desc: 'Mobile Number Description',
522
+ },
523
+ },
524
+ },
525
+ store: {
526
+ name: 'Store',
527
+ desc: 'Store Description',
528
+ subtags: {
529
+ store_name: {
530
+ name: 'Store Name',
531
+ desc: 'Store Name Description',
532
+ },
533
+ store_address: {
534
+ name: 'Store Address',
535
+ desc: 'Store Address Description',
536
+ },
537
+ },
538
+ },
539
+ };
540
+
541
+ const expected = {
542
+ customer: {
543
+ name: 'Customer',
544
+ desc: 'Customer Description',
545
+ },
546
+ cumulative_points_currency: {
547
+ name: 'Lifetime Points (in ₹)',
548
+ desc: 'Lifetime Points in ₹ Description',
549
+ },
550
+ mobile_number: {
551
+ name: 'Mobile Number',
552
+ desc: 'Mobile Number Description',
553
+ },
554
+ store: {
555
+ name: 'Store',
556
+ desc: 'Store Description',
557
+ },
558
+ store_name: {
559
+ name: 'Store Name',
560
+ desc: 'Store Name Description',
561
+ },
562
+ store_address: {
563
+ name: 'Store Address',
564
+ desc: 'Store Address Description',
565
+ },
566
+ };
567
+
568
+ expect(getForwardedMapValues(input)).toEqual(expected);
569
+ });
570
+
571
+ test('should correctly process objects without subtags', () => {
572
+ const input = {
573
+ points_on_event: {
574
+ name: 'Points on event',
575
+ desc: 'Points on event Description',
576
+ },
577
+ unsubscribe: {
578
+ name: 'Unsubscribe',
579
+ desc: 'Unsubscribe Description',
580
+ },
581
+ };
582
+
583
+ const expected = {
584
+ points_on_event: {
585
+ name: 'Points on event',
586
+ desc: 'Points on event Description',
587
+ },
588
+ unsubscribe: {
589
+ name: 'Unsubscribe',
590
+ desc: 'Unsubscribe Description',
591
+ },
592
+ };
593
+
594
+ expect(getForwardedMapValues(input)).toEqual(expected);
595
+ });
596
+
597
+ test('should handle a mix of entries with and without subtags', () => {
598
+ const input = {
599
+ customer: {
600
+ name: 'Customer',
601
+ desc: 'Customer Description',
602
+ subtags: {
603
+ cumulative_points_currency: {
604
+ name: 'Lifetime Points (in ₹)',
605
+ desc: 'Lifetime Points in ₹ Description',
606
+ },
607
+ },
608
+ },
609
+ points_on_event: {
610
+ name: 'Points on event',
611
+ desc: 'Points on event Description',
612
+ },
613
+ store: {
614
+ name: 'Store',
615
+ desc: 'Store Description',
616
+ subtags: {
617
+ store_name: {
618
+ name: 'Store Name',
619
+ desc: 'Store Name Description',
620
+ },
621
+ },
622
+ },
623
+ };
624
+
625
+ const expected = {
626
+ customer: {
627
+ name: 'Customer',
628
+ desc: 'Customer Description',
629
+ },
630
+ cumulative_points_currency: {
631
+ name: 'Lifetime Points (in ₹)',
632
+ desc: 'Lifetime Points in ₹ Description',
633
+ },
634
+ points_on_event: {
635
+ name: 'Points on event',
636
+ desc: 'Points on event Description',
637
+ },
638
+ store: {
639
+ name: 'Store',
640
+ desc: 'Store Description',
641
+ },
642
+ store_name: {
643
+ name: 'Store Name',
644
+ desc: 'Store Name Description',
645
+ },
646
+ };
647
+
648
+ expect(getForwardedMapValues(input)).toEqual(expected);
649
+ });
650
+
651
+ test('should ignore entries that are not objects', () => {
652
+ const input = {
653
+ valid_entry: {
654
+ name: 'Valid Entry',
655
+ desc: 'Valid Entry Description',
656
+ },
657
+ invalid_entry: 'This is a string, not an object',
658
+ another_invalid_entry: null,
659
+ };
660
+
661
+ const expected = {
662
+ valid_entry: {
663
+ name: 'Valid Entry',
664
+ desc: 'Valid Entry Description',
665
+ },
666
+ };
667
+
668
+ expect(getForwardedMapValues(input)).toEqual(expected);
669
+ });
670
+
671
+ test('should handle entries missing name or desc', () => {
672
+ const input = {
673
+ incomplete_entry1: {
674
+ name: 'Incomplete Entry 1',
675
+ // desc is missing
676
+ subtags: {
677
+ subtag1: {
678
+ name: 'Subtag 1',
679
+ desc: 'Subtag 1 Description',
680
+ },
681
+ },
682
+ },
683
+ incomplete_entry2: {
684
+ // name is missing
685
+ desc: 'Incomplete Entry 2 Description',
686
+ },
687
+ };
688
+
689
+ const expected = {
690
+ incomplete_entry1: {
691
+ name: 'Incomplete Entry 1',
692
+ desc: undefined,
693
+ },
694
+ subtag1: {
695
+ name: 'Subtag 1',
696
+ desc: 'Subtag 1 Description',
697
+ },
698
+ incomplete_entry2: {
699
+ name: undefined,
700
+ desc: 'Incomplete Entry 2 Description',
701
+ },
702
+ };
703
+
704
+ expect(getForwardedMapValues(input)).toEqual(expected);
705
+ });
706
+
707
+ test('should handle deeply nested subtags by only flattening one level', () => {
708
+ const input = {
709
+ parent: {
710
+ name: 'Parent',
711
+ desc: 'Parent Description',
712
+ subtags: {
713
+ child: {
714
+ name: 'Child',
715
+ desc: 'Child Description',
716
+ subtags: {
717
+ grandchild: {
718
+ name: 'Grandchild',
719
+ desc: 'Grandchild Description',
720
+ },
721
+ },
722
+ },
723
+ },
724
+ },
725
+ };
726
+
727
+ const expected = {
728
+ parent: {
729
+ name: 'Parent',
730
+ desc: 'Parent Description',
731
+ },
732
+ child: {
733
+ name: 'Child',
734
+ desc: 'Child Description',
735
+ subtags: {
736
+ grandchild: {
737
+ name: 'Grandchild',
738
+ desc: 'Grandchild Description',
739
+ },
740
+ },
741
+ },
742
+ };
743
+
744
+ expect(getForwardedMapValues(input)).toEqual(expected);
745
+ });
746
+
747
+
748
+ test('should not mutate the original input object', () => {
749
+ const input = {
750
+ customer: {
751
+ name: 'Customer',
752
+ desc: 'Customer Description',
753
+ subtags: {
754
+ cumulative_points_currency: {
755
+ name: 'Lifetime Points (in ₹)',
756
+ desc: 'Lifetime Points in ₹ Description',
757
+ },
758
+ },
759
+ },
760
+ };
761
+
762
+ const inputCopy = JSON.parse(JSON.stringify(input)); // Deep copy
763
+
764
+ getForwardedMapValues(input);
765
+
766
+ expect(input).toEqual(inputCopy);
767
+ });
499
768
  });
@@ -7,7 +7,7 @@ import * as types from './constants';
7
7
  import initialState from '../../initialState';
8
8
  import { FAILURE } from '../App/constants';
9
9
  import { TAG } from '../Whatsapp/constants';
10
- import { getTagMapValue } from '../../utils/tagValidations';
10
+ import { getTagMapValue, getForwardedMapValues } from '../../utils/tagValidations';
11
11
 
12
12
  function capReducer(state = fromJS(initialState.cap), action) {
13
13
  switch (action.type) {
@@ -117,7 +117,8 @@ function capReducer(state = fromJS(initialState.cap), action) {
117
117
  const combinedTagMap = {
118
118
  ...standardTagMap,
119
119
  ...customSubtags,
120
- ...extendedSubtags
120
+ ...extendedSubtags,
121
+ ...state.getIn(['metaEntities', 'tagLookupMap'])?.toJS(),
121
122
  };
122
123
  const stateMeta = state.get("metaEntities");
123
124
  return state
@@ -142,26 +143,15 @@ function capReducer(state = fromJS(initialState.cap), action) {
142
143
  metaEntities.tags.custom = _.filter(state.get('metaEntities').tags.custom, (tag) => action.tagList.indexOf(tag.name) === -1);
143
144
  return state.setIn(['metaEntities'], metaEntities);
144
145
  case types.SET_INJECTED_TAGS:
145
- const getTagMapValues = (object = {}) => {
146
- return Object.values(object).reduce((acc, current) => {
147
- // Check if current has 'subtags' and it's an object
148
- if (current && current.subtags && typeof current.subtags === 'object') {
149
- return { ...acc, ...current.subtags };
150
- }
151
- // If no 'subtags', return accumulator as is
152
- return acc;
153
- }, {});
154
- };
155
- console.log('SET_INJECTED_TAGS',action.injectedTags,getTagMapValues(action?.injectedTags));
146
+
156
147
  // Deep clone the tagLookupMap to avoid direct mutations
157
148
  let updatedMetaEntitiesTagLookUp = _.cloneDeep(state.getIn(['metaEntities', 'tagLookupMap']));
158
- const formattedInjuectedTags = getTagMapValues(action?.injectedTags);
149
+ const formattedInjectedTags = getForwardedMapValues(action?.injectedTags);
159
150
  // Merge the injectedTags with the existing tagLookupMap
160
151
  updatedMetaEntitiesTagLookUp = {
161
- ...formattedInjuectedTags|| {},
152
+ ...formattedInjectedTags || {},
162
153
  ...updatedMetaEntitiesTagLookUp || {},
163
154
  };
164
- // console.log('updatedMetaEntitiesTagLookUp',fromJS(updatedMetaEntitiesTagLookUp));
165
155
  return state
166
156
  .set('injectedTags', action.injectedTags)
167
157
  .setIn(['metaEntities', 'tagLookupMap'], fromJS(updatedMetaEntitiesTagLookUp));