@capillarytech/creatives-library 7.17.26 → 7.17.28
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
package/utils/common.js
CHANGED
|
@@ -288,37 +288,32 @@ export const isTraiDLTEnable = (isFullMode, smsRegister) => {
|
|
|
288
288
|
return isTraiDltFeature;
|
|
289
289
|
};
|
|
290
290
|
|
|
291
|
-
export const intlKeyGenerator = (value = "") =>
|
|
292
|
-
return value.replace(/[^a-zA-Z0-9_]/g, "");
|
|
293
|
-
};
|
|
291
|
+
export const intlKeyGenerator = (value = "") => String(value).replace(/[^a-zA-Z0-9_]/g, "");
|
|
294
292
|
|
|
295
293
|
export const handleInjectedData = (data, scope) => {
|
|
296
|
-
const temp = _.cloneDeep(data);
|
|
297
294
|
let tagType;
|
|
298
|
-
for (const tagKey in
|
|
299
|
-
if (
|
|
300
|
-
const tag =
|
|
301
|
-
|
|
295
|
+
for (const tagKey in data) {
|
|
296
|
+
if (data.hasOwnProperty(tagKey)) {
|
|
297
|
+
const tag = data[tagKey];
|
|
302
298
|
if (tag?.name === REGISTRATION_CUSTOM_FIELD) {
|
|
303
299
|
tagType = CUSTOM_TAG;
|
|
304
300
|
} else if (tag?.name === CUSTOMER_EXTENDED_FIELD) {
|
|
305
301
|
tagType = EXTENDED_TAG;
|
|
306
302
|
}
|
|
307
|
-
|
|
308
303
|
if (tag?.name) {
|
|
309
|
-
const name = tag
|
|
304
|
+
const name = tag.name;
|
|
310
305
|
const key = intlKeyGenerator(name);
|
|
311
306
|
const id = tagType
|
|
312
307
|
? `${scope}.${key}_name.${tagType}`
|
|
313
308
|
: `${scope}.${key}`;
|
|
314
309
|
|
|
315
|
-
tag
|
|
310
|
+
tag.name = apiMessageFormatHandler(id, name);
|
|
316
311
|
}
|
|
317
312
|
|
|
318
313
|
if (tag?.subtags) {
|
|
319
314
|
for (const subtagKey in tag.subtags) {
|
|
320
|
-
if (tag
|
|
321
|
-
const subtag = tag
|
|
315
|
+
if (tag.subtags.hasOwnProperty(subtagKey)) {
|
|
316
|
+
const subtag = tag.subtags[subtagKey];
|
|
322
317
|
if (subtag?.name) {
|
|
323
318
|
const name = subtag?.name;
|
|
324
319
|
const key = intlKeyGenerator(name);
|
|
@@ -326,7 +321,7 @@ export const handleInjectedData = (data, scope) => {
|
|
|
326
321
|
? `${scope}.${key}_name.${tagType}`
|
|
327
322
|
: `${scope}.${key}`;
|
|
328
323
|
|
|
329
|
-
subtag
|
|
324
|
+
subtag.name = apiMessageFormatHandler(id, name);
|
|
330
325
|
}
|
|
331
326
|
if (subtag?.desc) {
|
|
332
327
|
const desc = subtag?.desc;
|
|
@@ -335,7 +330,7 @@ export const handleInjectedData = (data, scope) => {
|
|
|
335
330
|
? `${scope}.${key}_desc.${tagType}`
|
|
336
331
|
: `${scope}.${key}`;
|
|
337
332
|
|
|
338
|
-
subtag
|
|
333
|
+
subtag.desc = apiMessageFormatHandler(id, desc);
|
|
339
334
|
}
|
|
340
335
|
}
|
|
341
336
|
}
|
|
@@ -343,5 +338,5 @@ export const handleInjectedData = (data, scope) => {
|
|
|
343
338
|
tagType = "";
|
|
344
339
|
}
|
|
345
340
|
}
|
|
346
|
-
return
|
|
341
|
+
return data;
|
|
347
342
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormattedMessage } from 'react-intl';
|
|
3
3
|
import "@testing-library/jest-dom";
|
|
4
|
-
import { filterTags, getTreeStructuredTags, handleInjectedData } from "../common";
|
|
4
|
+
import { filterTags, getTreeStructuredTags, handleInjectedData, intlKeyGenerator, bytes2Size, getUserNameById } from "../common";
|
|
5
5
|
import * as mockdata from "./common.mockdata";
|
|
6
6
|
|
|
7
7
|
describe("getTreeStructuredTags test", () => {
|
|
@@ -19,6 +19,27 @@ describe("getTreeStructuredTags test", () => {
|
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
describe("getUserNameById test", () => {
|
|
23
|
+
it("test for username is available or not", () => {
|
|
24
|
+
const data = [
|
|
25
|
+
{
|
|
26
|
+
userId: 1,
|
|
27
|
+
firstName: 'test1',
|
|
28
|
+
lastName: 'test2',
|
|
29
|
+
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
userId: 2,
|
|
33
|
+
firstName: 'test3',
|
|
34
|
+
lastName: 'test4',
|
|
35
|
+
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const expected = 'test1 test2';
|
|
39
|
+
expect(getUserNameById(1, data)).toEqual(expected);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
22
43
|
describe("handleInjectedData", () => {
|
|
23
44
|
it("replaces name with intl key for top level tag", () => {
|
|
24
45
|
const data = {
|
|
@@ -28,7 +49,8 @@ describe("handleInjectedData", () => {
|
|
|
28
49
|
};
|
|
29
50
|
|
|
30
51
|
const result = handleInjectedData(data, "scope");
|
|
31
|
-
|
|
52
|
+
const intlKey = intlKeyGenerator("scope");
|
|
53
|
+
expect(intlKey).toEqual('scope');
|
|
32
54
|
expect(result.tag1.name).toEqual(<FormattedMessage defaultMessage="Registration Fields" id="scope.RegistrationFields" values={{}} />);
|
|
33
55
|
});
|
|
34
56
|
|
|
@@ -59,22 +81,65 @@ describe("handleInjectedData", () => {
|
|
|
59
81
|
<FormattedMessage defaultMessage="Customer extended fields" id="scope.Customerextendedfields_name.ExtendedTagMessage" values={{}} />
|
|
60
82
|
);
|
|
61
83
|
});
|
|
84
|
+
it("adds tagType for Customer extended fields fields", () => {
|
|
85
|
+
const data = {
|
|
86
|
+
tag1: {
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const result = handleInjectedData(data, "scope");
|
|
91
|
+
|
|
92
|
+
expect(result.tag1.name).toEqual(undefined);
|
|
93
|
+
});
|
|
62
94
|
|
|
95
|
+
it("adds tagType for Customer with extended fields fields", () => {
|
|
96
|
+
const data = {
|
|
97
|
+
tag1: {
|
|
98
|
+
name: "mahaRaja",
|
|
99
|
+
subtag1: {
|
|
100
|
+
name: "First Name",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
63
104
|
|
|
105
|
+
const result = handleInjectedData(data, "scope");
|
|
106
|
+
|
|
107
|
+
expect(result.tag1.subtag1.name).toEqual("First Name");
|
|
108
|
+
});
|
|
64
109
|
it("replaces subtag name with intl key", () => {
|
|
65
110
|
const data = {
|
|
66
111
|
tag1: {
|
|
67
112
|
subtags: {
|
|
68
113
|
subtag1: {
|
|
69
114
|
name: "First Name",
|
|
115
|
+
hasOwnProperty: jest.fn(),
|
|
70
116
|
},
|
|
117
|
+
hasOwnProperty: jest.fn(),
|
|
71
118
|
},
|
|
72
119
|
},
|
|
73
120
|
};
|
|
74
121
|
|
|
75
122
|
const result = handleInjectedData(data, "scope");
|
|
76
123
|
|
|
77
|
-
expect(result.tag1.subtags.subtag1.name).toEqual(
|
|
124
|
+
expect(result.tag1.subtags.subtag1.name).toEqual("First Name");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("replaces subtag name with intl key test", () => {
|
|
128
|
+
const data = {
|
|
129
|
+
tag1: {
|
|
130
|
+
subtags: {
|
|
131
|
+
subtag1: {
|
|
132
|
+
name: "First Name",
|
|
133
|
+
hasOwnProperty: jest.fn(),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
hasOwnProperty: jest.fn(),
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const result = handleInjectedData(data, "scope");
|
|
141
|
+
|
|
142
|
+
expect(result.tag1.subtags.subtag1.name).toEqual("First Name");
|
|
78
143
|
});
|
|
79
144
|
|
|
80
145
|
it("replaces subtag desc with intl key", () => {
|
|
@@ -90,9 +155,48 @@ describe("handleInjectedData", () => {
|
|
|
90
155
|
|
|
91
156
|
const result = handleInjectedData(data, "scope");
|
|
92
157
|
|
|
158
|
+
expect(result.tag1.subtags.subtag1.desc).toEqual(
|
|
159
|
+
<FormattedMessage defaultMessage="Enter your first name" id="scope.Enteryourfirstname" values={{}} />
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
it("replaces subtag name desc with intl key", () => {
|
|
163
|
+
const data = {
|
|
164
|
+
tag1: {
|
|
165
|
+
subtags: {
|
|
166
|
+
subtag1: {
|
|
167
|
+
name: "mahaRaja",
|
|
168
|
+
desc: "Enter your first name",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const result = handleInjectedData(data, "scope");
|
|
175
|
+
|
|
93
176
|
expect(result.tag1.subtags.subtag1.desc).toEqual(
|
|
94
177
|
<FormattedMessage defaultMessage="Enter your first name" id="scope.Enteryourfirstname" values={{}} />
|
|
95
178
|
);
|
|
96
179
|
});
|
|
97
180
|
});
|
|
98
181
|
|
|
182
|
+
describe('bytes2Size', () => {
|
|
183
|
+
it('should convert bytes to the correct size string', () => {
|
|
184
|
+
// Test cases with different byte values
|
|
185
|
+
expect(bytes2Size(0)).toBe('0 Bytes');
|
|
186
|
+
expect(bytes2Size(1023)).toBe('1023 Bytes');
|
|
187
|
+
expect(bytes2Size(1024)).toBe('1 KB');
|
|
188
|
+
expect(bytes2Size(1048576)).toBe('1 MB');
|
|
189
|
+
expect(bytes2Size(1099511627776)).toBe('1 TB');
|
|
190
|
+
expect(bytes2Size(1125899906842624)).toBe('1 PB');
|
|
191
|
+
expect(bytes2Size(1152921504606846976)).toBe('1 EB');
|
|
192
|
+
expect(bytes2Size(1180591620717411303424)).toBe('1 ZB');
|
|
193
|
+
expect(bytes2Size(Number.MAX_SAFE_INTEGER)).toBe('8 PB'); // Test with the maximum safe integer value
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should handle negative decimals', () => {
|
|
197
|
+
// Test with negative decimal values
|
|
198
|
+
expect(bytes2Size(1024, -1)).toBe('1 KB'); // Decimals < 0 should round to 0
|
|
199
|
+
expect(bytes2Size(1024, -2)).toBe('1 KB');
|
|
200
|
+
expect(bytes2Size(1024, -3)).toBe('1 KB');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -55,10 +55,10 @@ export function SlideBoxHeader(props) {
|
|
|
55
55
|
|
|
56
56
|
const getChannelLabel = (currentChannel = '') => {
|
|
57
57
|
const labels = {
|
|
58
|
-
sms:
|
|
58
|
+
sms: <FormattedMessage {...messages.smsHeader} />,
|
|
59
59
|
email: <FormattedMessage {...messages.emailHeader} />,
|
|
60
|
-
mobilepush:
|
|
61
|
-
wechat:
|
|
60
|
+
mobilepush: <FormattedMessage {...messages.pushNotificationHeader} />,
|
|
61
|
+
wechat: <FormattedMessage {...messages.wechat} />,
|
|
62
62
|
no_communication: 'NO_COMMUNICATION',
|
|
63
63
|
ftp: 'FTP',
|
|
64
64
|
whatsapp: <FormattedMessage {...messages.whatsappTemplate} />,
|
|
@@ -325,5 +325,13 @@ export default defineMessages({
|
|
|
325
325
|
"templateNameEmpty": {
|
|
326
326
|
id: `${scope}.templateNameEmpty`,
|
|
327
327
|
defaultMessage: `Template name cannot be empty`
|
|
328
|
+
},
|
|
329
|
+
"pushNotificationHeader": {
|
|
330
|
+
id: `${scope}.pushNotificationHeader`,
|
|
331
|
+
defaultMessage: `Push notification`,
|
|
332
|
+
},
|
|
333
|
+
"wechat": {
|
|
334
|
+
id: `${scope}.wechat`,
|
|
335
|
+
defaultMessage: `Wechat`,
|
|
328
336
|
}
|
|
329
337
|
});
|
|
@@ -20,17 +20,18 @@ import * as globalActions from '../Cap/actions';
|
|
|
20
20
|
import CapTagList from '../../v2Components/CapTagList';
|
|
21
21
|
import './_tagList.scss';
|
|
22
22
|
import { selectCurrentOrgDetails } from '../Cap/selectors';
|
|
23
|
-
const TreeNode = Tree.TreeNode;
|
|
24
23
|
import { injectIntl } from 'react-intl';
|
|
25
24
|
import { scope } from './messages';
|
|
26
25
|
import { handleInjectedData } from '../../utils/common';
|
|
27
26
|
|
|
27
|
+
const TreeNode = Tree.TreeNode;
|
|
28
|
+
|
|
28
29
|
export class TagList extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
29
30
|
constructor(props) {
|
|
30
31
|
super(props);
|
|
31
32
|
this.state = {
|
|
32
33
|
loading: false,
|
|
33
|
-
tags: []
|
|
34
|
+
tags: [],
|
|
34
35
|
};
|
|
35
36
|
this.renderTags = this.renderTags.bind(this);
|
|
36
37
|
this.populateTags = this.populateTags.bind(this);
|
|
@@ -40,35 +41,7 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
componentDidMount() {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
componentDidUpdate(prevProps) {
|
|
47
|
-
if (this.props.tags !== prevProps.tags || this.props.injectedTags !== prevProps.injectedTags || this.props.selectedOfferDetails !== prevProps.selectedOfferDetails) {
|
|
48
|
-
this.setState({
|
|
49
|
-
tags: this.generateTags(this.props),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
generateTags(props) {
|
|
55
|
-
let tags = {};
|
|
56
|
-
let injectedTags = {};
|
|
57
|
-
if (props.injectedTags && !_.isEmpty(props.injectedTags)) {
|
|
58
|
-
const formattedInjectedTags = handleInjectedData(
|
|
59
|
-
props.injectedTags,
|
|
60
|
-
scope
|
|
61
|
-
);
|
|
62
|
-
injectedTags = this.transformInjectedTags(formattedInjectedTags);
|
|
63
|
-
}
|
|
64
|
-
if (props.tags && props.tags.length > 0) {
|
|
65
|
-
tags = this.populateTags(props.tags);
|
|
66
|
-
console.log('populating tags', Object.keys(tags || {}).length);
|
|
67
|
-
}
|
|
68
|
-
if (props.selectedOfferDetails && !_.isEmpty(props.selectedOfferDetails) && (tags && tags.coupon)) {
|
|
69
|
-
this.transformCouponTags(props.selectedOfferDetails, tags);
|
|
70
|
-
}
|
|
71
|
-
return _.merge( {}, tags, injectedTags);
|
|
44
|
+
this.generateTags(this.props);
|
|
72
45
|
}
|
|
73
46
|
|
|
74
47
|
componentWillReceiveProps(nextProps) {
|
|
@@ -76,33 +49,52 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
76
49
|
this.setState({loading: true});
|
|
77
50
|
}
|
|
78
51
|
if (!_.isEqual(nextProps.injectedTags, this.props.injectedTags)) {
|
|
79
|
-
|
|
52
|
+
|
|
80
53
|
this.setState({loading: false});
|
|
81
54
|
}
|
|
82
55
|
if (!_.isEqual(nextProps.tags, this.props.tags)) {
|
|
83
|
-
|
|
56
|
+
|
|
84
57
|
this.setState({loading: false});
|
|
85
58
|
}
|
|
86
59
|
|
|
87
60
|
}
|
|
88
|
-
|
|
61
|
+
componentDidUpdate(prevProps) {
|
|
62
|
+
if (this.props.tags !== prevProps.tags || this.props.injectedTags !== prevProps.injectedTags || this.props.selectedOfferDetails !== prevProps.selectedOfferDetails) {
|
|
63
|
+
this.generateTags(this.props);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
89
66
|
onSelect = (selectedKeys) => {
|
|
90
67
|
this.props.onTagSelect(selectedKeys[0]);
|
|
91
68
|
};
|
|
92
69
|
|
|
93
70
|
onClick = (e, data) => {
|
|
94
|
-
|
|
71
|
+
|
|
95
72
|
};
|
|
96
73
|
|
|
97
74
|
getTagsforContext = (data) => {
|
|
98
75
|
//this.setState({loading: true});
|
|
99
76
|
this.props.onContextChange(data);
|
|
100
77
|
}
|
|
101
|
-
|
|
78
|
+
generateTags = (props) => {
|
|
79
|
+
let tags = {};
|
|
80
|
+
let injectedTags = {};
|
|
81
|
+
if (props.injectedTags && !_.isEmpty(props.injectedTags)) {
|
|
82
|
+
const formattedInjectedTags = handleInjectedData(
|
|
83
|
+
props.injectedTags,
|
|
84
|
+
scope
|
|
85
|
+
);
|
|
86
|
+
injectedTags = this.transformInjectedTags(formattedInjectedTags);
|
|
87
|
+
}
|
|
88
|
+
if (props.tags && props.tags.length > 0) {
|
|
89
|
+
tags = this.populateTags(props.tags);
|
|
90
|
+
}
|
|
91
|
+
if (props.selectedOfferDetails && !_.isEmpty(props.selectedOfferDetails) && (tags && tags.coupon)) {
|
|
92
|
+
this.transformCouponTags(props.selectedOfferDetails, tags);
|
|
93
|
+
}
|
|
94
|
+
this.setState({tags: _.merge( {}, tags, injectedTags)});
|
|
95
|
+
}
|
|
102
96
|
populateTags(tagsList) {
|
|
103
|
-
console.log('populating tags', (tagsList || []).length);
|
|
104
97
|
const mainTags = {};
|
|
105
|
-
|
|
106
98
|
//Form tags object with tag headers
|
|
107
99
|
_.forEach(tagsList, (temp) => {
|
|
108
100
|
const tag = temp.definition;
|
|
@@ -115,7 +107,6 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
115
107
|
} else if (tag['tag-header'] && mainTags[tag.value]) {
|
|
116
108
|
mainTags[tag.value].subtags = _.concat(mainTags[tag.value].subtags, tag.subtags);
|
|
117
109
|
} else if (!mainTags[tag.value]) {
|
|
118
|
-
//
|
|
119
110
|
mainTags[tag.value] = {
|
|
120
111
|
'tag-header': true,
|
|
121
112
|
"name": tag?.label[userLocale] ? tag?.label[userLocale] : tag?.label?.en,
|