@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.38 → 9.2.0
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/constants/unified.js +4 -0
- package/index.js +13 -0
- package/package.json +1 -1
- package/services/getSchema.js +4 -1
- package/services/tests/getSchema.test.js +2 -2
- package/translations/en.json +1 -0
- package/translations/ja-JP.json +1 -0
- package/translations/zh.json +1 -0
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +33 -47
- package/utils/tagValidations.js +35 -4
- package/utils/templateVarUtils.js +49 -0
- package/utils/tests/createMobilePushPayload.test.js +8 -102
- package/utils/tests/tagValidations.test.js +48 -0
- package/utils/tests/templateVarUtils.test.js +89 -0
- package/v2Components/CapMpushCTA/index.js +9 -10
- package/v2Components/CapMpushCTA/index.scss +3 -29
- package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
- package/v2Components/CapTagList/constants.js +5 -0
- package/v2Components/CapTagList/index.js +46 -7
- package/v2Components/CapTagList/messages.js +44 -0
- package/v2Components/CapTagList/style.scss +113 -1
- package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
- package/v2Components/CapTagList/utils.js +17 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +13 -26
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +3 -2
- package/v2Components/CommonTestAndPreview/index.js +62 -62
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -79
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
- package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
- package/v2Components/CommonTestAndPreview/utils.js +42 -3
- package/v2Components/FormBuilder/Classic.js +24 -14
- package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
- package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
- package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
- package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
- package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +135 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +320 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +148 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +152 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
- package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
- package/v2Components/TemplatePreview/index.js +17 -30
- package/v2Components/TemplatePreview/tests/index.test.js +0 -61
- package/v2Containers/Cap/index.js +3 -0
- package/v2Containers/Cap/messages.js +4 -0
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +151 -70
- package/v2Containers/CreativesContainer/index.js +6 -3
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -29
- package/v2Containers/InApp/index.js +4 -1
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
- package/v2Containers/Line/Container/Text/index.js +3 -1
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
- package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +70 -0
- package/v2Containers/MobilePush/Create/actions.js +52 -0
- package/v2Containers/MobilePush/Create/constants.js +26 -0
- package/v2Containers/MobilePush/Create/index.js +2149 -0
- package/v2Containers/MobilePush/Create/messages.js +349 -0
- package/v2Containers/MobilePush/Create/reducer.js +72 -0
- package/v2Containers/MobilePush/Create/sagas.js +79 -0
- package/v2Containers/MobilePush/Create/selectors.js +29 -0
- package/v2Containers/MobilePush/Create/test/contentValidity.test.js +154 -0
- package/v2Containers/MobilePush/Create/test/saga.test.js +19 -0
- package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +80 -0
- package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +65 -0
- package/v2Containers/MobilePush/Edit/actions.js +94 -0
- package/v2Containers/MobilePush/Edit/constants.js +37 -0
- package/v2Containers/MobilePush/Edit/index.js +2407 -0
- package/v2Containers/MobilePush/Edit/messages.js +341 -0
- package/v2Containers/MobilePush/Edit/reducer.js +113 -0
- package/v2Containers/MobilePush/Edit/sagas.js +113 -0
- package/v2Containers/MobilePush/Edit/selectors.js +33 -0
- package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +149 -0
- package/v2Containers/MobilePush/Edit/test/saga.test.js +255 -0
- package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +60 -0
- package/v2Containers/MobilePush/commonMethods.js +333 -0
- package/v2Containers/MobilePush/eventsMap.js +130 -0
- package/v2Containers/MobilePush/tests/commonMethods.test.js +401 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +192 -207
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +121 -116
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +72 -316
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +16 -45
- package/v2Containers/MobilePushNew/constants.js +0 -5
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -38
- package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
- package/v2Containers/MobilePushNew/index.js +192 -454
- package/v2Containers/MobilePushNew/index.scss +4 -188
- package/v2Containers/MobilePushNew/messages.js +6 -86
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -450
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -25
- package/v2Containers/MobilePushNew/utils.js +0 -8
- package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +22 -0
- package/v2Containers/MobilepushWrapper/index.js +178 -0
- package/v2Containers/MobilepushWrapper/messages.js +29 -0
- package/v2Containers/Rcs/index.js +8 -1
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
- package/v2Containers/SmsTrai/Edit/index.js +17 -7
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +90 -84
- package/v2Containers/Templates/tests/index.test.js +0 -68
- package/v2Containers/Viber/index.js +3 -1
- package/v2Containers/WebPush/Create/utils/validation.js +6 -0
- package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
- package/v2Containers/Whatsapp/index.js +9 -5
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
- package/v2Containers/Zalo/index.js +4 -1
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
- /package/{v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js → v2Containers/MobilePush/initialSchema.js} +0 -0
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
isDltHashVarToken,
|
|
8
8
|
isAnyTemplateVarToken,
|
|
9
9
|
reconcileVarMapToSlotFormat,
|
|
10
|
+
collectDltSlotRuns,
|
|
11
|
+
resolveDltSmsTemplate,
|
|
10
12
|
} from '../templateVarUtils';
|
|
11
13
|
|
|
12
14
|
const MUSTACHE_VAR_REGEX = /\{\{\d+\}\}/g;
|
|
@@ -245,4 +247,91 @@ describe('templateVarUtils', () => {
|
|
|
245
247
|
});
|
|
246
248
|
});
|
|
247
249
|
});
|
|
250
|
+
|
|
251
|
+
describe('collectDltSlotRuns (editor slot model)', () => {
|
|
252
|
+
it('takes the slot token from the text and the index from the editor model', () => {
|
|
253
|
+
expect(collectDltSlotRuns('{#numeric#}')).toEqual([
|
|
254
|
+
{ token: '{#numeric#}', firstIndex: 0, endIndex: 1 },
|
|
255
|
+
]);
|
|
256
|
+
expect(collectDltSlotRuns('{#var|num|alpha|url#}')).toEqual([
|
|
257
|
+
{ token: '{#var|num|alpha|url#}', firstIndex: 0, endIndex: 1 },
|
|
258
|
+
]);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('joins a horizontal-whitespace-separated run into ONE slot', () => {
|
|
262
|
+
expect(collectDltSlotRuns('{#a#} {#b#}')).toEqual([
|
|
263
|
+
{ token: '{#a#}', firstIndex: 0, endIndex: 3 },
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('joins identical adjacent tokens, but NOT different ones', () => {
|
|
268
|
+
expect(collectDltSlotRuns('{#var#}{#var#}').map((r) => r.firstIndex)).toEqual([0]);
|
|
269
|
+
expect(collectDltSlotRuns('{#var#}{#numeric#}').map((r) => r.firstIndex)).toEqual([0, 1]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('treats a NEWLINE as a slot boundary (the editor joins horizontal whitespace only)', () => {
|
|
273
|
+
expect(collectDltSlotRuns('A {#var#}\n{#var#} B').map((r) => r.firstIndex)).toEqual([1, 3]);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('keeps tokens separated by real text as separate slots', () => {
|
|
277
|
+
expect(collectDltSlotRuns('Dear {#var#}, order {#var#} shipped').map((r) => r.firstIndex))
|
|
278
|
+
.toEqual([1, 3]);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('finds no runs in a mustache or plain body', () => {
|
|
282
|
+
expect(collectDltSlotRuns('Hi {{name}}')).toEqual([]);
|
|
283
|
+
expect(collectDltSlotRuns('plain')).toEqual([]);
|
|
284
|
+
expect(collectDltSlotRuns(null)).toEqual([]);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe('resolveDltSmsTemplate', () => {
|
|
289
|
+
it('resolves a fully mapped template keyed like the editor var-mapped (R1/R2)', () => {
|
|
290
|
+
expect(resolveDltSmsTemplate('Dear {#var#}, order {#var#} shipped', {
|
|
291
|
+
'{#var#}_1': 'Pat',
|
|
292
|
+
'{#var#}_3': 'A1',
|
|
293
|
+
})).toBe('Dear Pat, order A1 shipped');
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('keys typed tokens and mustache-mixed bodies by the editor segment index', () => {
|
|
297
|
+
expect(resolveDltSmsTemplate('Dear {#num#}, code {#url|ott#}', {
|
|
298
|
+
'{#var#}_1': '1',
|
|
299
|
+
'{#var#}_3': '2',
|
|
300
|
+
})).toBe('Dear 1, code 2');
|
|
301
|
+
expect(resolveDltSmsTemplate('{#var#} {{x}} {#var#}', {
|
|
302
|
+
'{#var#}_0': 'P',
|
|
303
|
+
'{#var#}_2': 'Q',
|
|
304
|
+
})).toBe('P {{x}} Q');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('keeps a blank slot as its raw token and never repeats a value (R4)', () => {
|
|
308
|
+
expect(resolveDltSmsTemplate('Dear {#var#}, order {#var#} shipped', {
|
|
309
|
+
'{#var#}_1': 'Pat',
|
|
310
|
+
'{#var#}_3': '',
|
|
311
|
+
})).toBe('Dear Pat, order {#var#} shipped');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('collapses a whitespace-separated run to its one value', () => {
|
|
315
|
+
expect(resolveDltSmsTemplate('{#var#}{#var#}', { '{#var#}_0': 'PQ' })).toBe('PQ');
|
|
316
|
+
// The separator the editor keeps between a run's tokens is retained (the editor blanks only
|
|
317
|
+
// the run's `{#var#}` tokens, not the whitespace between them).
|
|
318
|
+
expect(resolveDltSmsTemplate('{#var#} {#var#}', { '{#var#}_0': 'PQ' })).toBe('PQ ');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('resolves a typed token and a newline-separated pair as separate slots', () => {
|
|
322
|
+
expect(resolveDltSmsTemplate('A {#numeric#} B', { '{#var#}_1': '42' })).toBe('A 42 B');
|
|
323
|
+
expect(resolveDltSmsTemplate('Hi {#var|num|alpha|url#}', { '{#var#}_1': 'X' }))
|
|
324
|
+
.toBe('Hi X');
|
|
325
|
+
expect(resolveDltSmsTemplate('A {#var#}\n{#var#} B', { '{#var#}_1': 'P', '{#var#}_3': 'Q' }))
|
|
326
|
+
.toBe('A P\nQ B');
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('leaves a non-DLT body untouched (R5) and never blankens mustache in a mixed body', () => {
|
|
330
|
+
expect(resolveDltSmsTemplate('Hi {{name}}', { '{#var#}_1': 'x' })).toBe('Hi {{name}}');
|
|
331
|
+
expect(resolveDltSmsTemplate('Hi {{fn}}, code {#var#}', { '{#var#}_1': 'A1' }))
|
|
332
|
+
.toBe('Hi {{fn}}, code A1');
|
|
333
|
+
expect(resolveDltSmsTemplate('plain', {})).toBe('plain');
|
|
334
|
+
expect(resolveDltSmsTemplate(null, {})).toBe(null);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
248
337
|
});
|
|
@@ -235,10 +235,9 @@ export const CapMpushCTA = (props) => {
|
|
|
235
235
|
type="flex"
|
|
236
236
|
>
|
|
237
237
|
<CapColumn>
|
|
238
|
-
<CapRow
|
|
238
|
+
<CapRow className="mpush-cta-row">
|
|
239
239
|
<CapColumn>
|
|
240
|
-
|
|
241
|
-
<CapIcon size="s" type="open-in-new" />
|
|
240
|
+
<CapIcon size="s" type={'launch'} />
|
|
242
241
|
</CapColumn>
|
|
243
242
|
<CapColumn className="btn-text">
|
|
244
243
|
<CapLabel type="label2" className="mpush-saved-cta-button-text">
|
|
@@ -252,11 +251,13 @@ export const CapMpushCTA = (props) => {
|
|
|
252
251
|
<CapTag className="cta-type-label">{formatMessage(messages.urlDeepLink)}</CapTag>
|
|
253
252
|
: <CapTag className="cta-type-label">{formatMessage(messages.urlExternalLink)}</CapTag>}
|
|
254
253
|
</CapColumn>
|
|
255
|
-
<CapColumn
|
|
256
|
-
{urlType === DEEP_LINK ? selectedDeepLink?.label :
|
|
254
|
+
<CapColumn>
|
|
255
|
+
{urlType === DEEP_LINK ? selectedDeepLink?.label : ''}
|
|
256
|
+
</CapColumn>
|
|
257
|
+
<CapColumn>
|
|
257
258
|
</CapColumn>
|
|
258
259
|
<CapColumn>
|
|
259
|
-
<CapRow
|
|
260
|
+
<CapRow className="cta-action-grp">
|
|
260
261
|
<CapColumn
|
|
261
262
|
className="mpush-saved-cta-edit-icon"
|
|
262
263
|
onClick={() => isSavedCta(index, false)}
|
|
@@ -319,8 +320,6 @@ export const CapMpushCTA = (props) => {
|
|
|
319
320
|
</CapRow>
|
|
320
321
|
)}
|
|
321
322
|
{urlType === EXTERNAL_URL && (
|
|
322
|
-
// Wrapper lets the stylesheet size the label row to match "Type of link"
|
|
323
|
-
<div className="mpush-cta-external-link-field">
|
|
324
323
|
<CapTagListWithInput
|
|
325
324
|
inputId="mpush-cta-external-link"
|
|
326
325
|
inputValue={localUrlValues[index] || ''}
|
|
@@ -330,7 +329,8 @@ export const CapMpushCTA = (props) => {
|
|
|
330
329
|
inputMaxLength={URL_MAX_LENGTH}
|
|
331
330
|
inputErrorMessage={urlError}
|
|
332
331
|
headingText={formatMessage(messages.urlExternalLink)}
|
|
333
|
-
headingStyle={{
|
|
332
|
+
headingStyle={{ marginTop: '3%', marginRight: '50%'}}
|
|
333
|
+
containerStyle={{ width: '70%', marginTop: '-0.625rem' }}
|
|
334
334
|
moduleFilterEnabled={location?.query?.type !== "embedded"}
|
|
335
335
|
onTagSelect={onButtonTagSelect}
|
|
336
336
|
onContextChange={handleOnTagsContextChange}
|
|
@@ -340,7 +340,6 @@ export const CapMpushCTA = (props) => {
|
|
|
340
340
|
selectedOfferDetails={selectedOfferDetails}
|
|
341
341
|
inputProps={{ 'data-index': index }}
|
|
342
342
|
/>
|
|
343
|
-
</div>
|
|
344
343
|
)}
|
|
345
344
|
</CapColumn>
|
|
346
345
|
{urlType === DEEP_LINK && ctaDeepLinkValue && deepLinkKeysFromSelectionArray.length > 0 && (
|
|
@@ -31,18 +31,6 @@
|
|
|
31
31
|
margin-top: $CAP_SPACE_12;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// External link column: its label row (heading + "Add label") gets the height of the
|
|
35
|
-
// "Type of link" label plus its 8px gap, so the input lines up with the dropdown
|
|
36
|
-
.mpush-cta-external-link-field {
|
|
37
|
-
width: 70%;
|
|
38
|
-
|
|
39
|
-
> .ant-col > .ant-row:first-child {
|
|
40
|
-
height: 1.449rem; // CapHeading h4 line height
|
|
41
|
-
margin-bottom: $CAP_SPACE_08;
|
|
42
|
-
justify-content: space-between;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
34
|
.mpush-cta-save-delete-btn {
|
|
47
35
|
margin-top: $CAP_SPACE_16;
|
|
48
36
|
|
|
@@ -67,27 +55,13 @@
|
|
|
67
55
|
padding: $CAP_SPACE_08 $CAP_SPACE_12;
|
|
68
56
|
border-radius: $CAP_SPACE_04;
|
|
69
57
|
height: $CAP_SPACE_40;
|
|
70
|
-
gap: $CAP_SPACE_12;
|
|
71
58
|
|
|
72
59
|
.mpush-saved-cta-button-text {
|
|
73
60
|
font-weight: 500;
|
|
74
61
|
}
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
display: flex;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// URL fills the space up to the icons and ends in "..." when too long.
|
|
82
|
-
// contain: inline-size stops a long URL from widening the whole form.
|
|
83
|
-
.mpush-saved-cta-link {
|
|
84
|
-
flex: 1;
|
|
85
|
-
min-width: 0;
|
|
86
|
-
contain: inline-size;
|
|
87
|
-
white-space: nowrap;
|
|
88
|
-
overflow: hidden;
|
|
89
|
-
text-overflow: ellipsis;
|
|
90
|
-
color: $CAP_G04;
|
|
63
|
+
.mpush-saved-cta-edit-icon {
|
|
64
|
+
margin-left: 4.286rem;
|
|
91
65
|
}
|
|
92
66
|
}
|
|
93
67
|
.cta-label {
|
|
@@ -115,5 +89,5 @@
|
|
|
115
89
|
padding-left: 1rem;
|
|
116
90
|
}
|
|
117
91
|
.btn-text {
|
|
118
|
-
margin-left: $
|
|
92
|
+
margin-left: $CAP_SPACE_24;
|
|
119
93
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TagFallbackPanel
|
|
3
|
+
*
|
|
4
|
+
* Shown in the tag list after a tag is clicked, to choose what is sent when the tag has no value.
|
|
5
|
+
*/
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import CapButton from '@capillarytech/cap-ui-library/CapButton';
|
|
9
|
+
import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
|
|
10
|
+
import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
|
|
11
|
+
import CapInput from '@capillarytech/cap-ui-library/CapInput';
|
|
12
|
+
import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
13
|
+
import CapRadio from '@capillarytech/cap-ui-library/CapRadio';
|
|
14
|
+
import CapRadioGroup from '@capillarytech/cap-ui-library/CapRadioGroup';
|
|
15
|
+
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
16
|
+
import { injectIntl, intlShape } from 'react-intl';
|
|
17
|
+
import messages from './messages';
|
|
18
|
+
import { FALLBACK_OPTIONS } from './constants';
|
|
19
|
+
import { buildTagWithFallback, isValidFallbackValue } from './utils';
|
|
20
|
+
|
|
21
|
+
export class TagFallbackPanel extends React.Component {
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props);
|
|
24
|
+
this.state = {
|
|
25
|
+
option: FALLBACK_OPTIONS.NONE,
|
|
26
|
+
fallbackValue: '',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onOptionChange = (e) => {
|
|
31
|
+
this.setState({ option: e.target.value });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
onFallbackValueChange = (e) => {
|
|
35
|
+
this.setState({ fallbackValue: e.target.value });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
getTagValue = () => {
|
|
39
|
+
const { option, fallbackValue } = this.state;
|
|
40
|
+
return buildTagWithFallback(this.props.tagKey, option, fallbackValue);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
copyTag = () => {
|
|
44
|
+
navigator?.clipboard?.writeText(`{{${this.getTagValue()}}}`);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
onInsert = () => {
|
|
48
|
+
this.props.onInsert(this.getTagValue());
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
render() {
|
|
52
|
+
const {
|
|
53
|
+
intl: { formatMessage }, tagName, parentName, onBack,
|
|
54
|
+
} = this.props;
|
|
55
|
+
const { option, fallbackValue } = this.state;
|
|
56
|
+
const isCustomValue = option === FALLBACK_OPTIONS.CUSTOM_VALUE;
|
|
57
|
+
const isFallbackValueInvalid = isCustomValue && !isValidFallbackValue(fallbackValue);
|
|
58
|
+
const isInsertDisabled = isCustomValue && (!fallbackValue.trim() || isFallbackValueInvalid);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<CapRow className="tag-fallback-panel">
|
|
62
|
+
<CapRow className="tag-fallback-header">
|
|
63
|
+
<CapRow type="flex" align="middle" noWrap className="tag-fallback-title-row">
|
|
64
|
+
<CapIcon
|
|
65
|
+
type="back"
|
|
66
|
+
size="m"
|
|
67
|
+
className="tag-fallback-back"
|
|
68
|
+
aria-label={formatMessage(messages.back)}
|
|
69
|
+
onClick={onBack}
|
|
70
|
+
/>
|
|
71
|
+
<CapHeading type="h4" className="tag-fallback-tag-name">{tagName}</CapHeading>
|
|
72
|
+
</CapRow>
|
|
73
|
+
{parentName ? <CapLabel type="label2" className="tag-fallback-group-name">{parentName}</CapLabel> : null}
|
|
74
|
+
</CapRow>
|
|
75
|
+
<CapRow className="tag-fallback-body">
|
|
76
|
+
<CapHeading type="h4" className="tag-fallback-heading">{formatMessage(messages.fallbackBehaviour)}</CapHeading>
|
|
77
|
+
<CapLabel type="label2" className="tag-fallback-subtext">{formatMessage(messages.fallbackBehaviourDesc)}</CapLabel>
|
|
78
|
+
<CapRadioGroup className="tag-fallback-options" value={option} onChange={this.onOptionChange}>
|
|
79
|
+
<CapRadio value={FALLBACK_OPTIONS.NONE}>{formatMessage(messages.dontSendMessage)}</CapRadio>
|
|
80
|
+
<CapRadio value={FALLBACK_OPTIONS.NULL_VALUE}>{formatMessage(messages.sendWithNullValue)}</CapRadio>
|
|
81
|
+
<CapRadio value={FALLBACK_OPTIONS.CUSTOM_VALUE}>{formatMessage(messages.fallbackValue)}</CapRadio>
|
|
82
|
+
</CapRadioGroup>
|
|
83
|
+
{isCustomValue && (
|
|
84
|
+
<CapInput
|
|
85
|
+
className="tag-fallback-input"
|
|
86
|
+
value={fallbackValue}
|
|
87
|
+
onChange={this.onFallbackValueChange}
|
|
88
|
+
placeholder={formatMessage(messages.fallbackValuePlaceholder)}
|
|
89
|
+
errorMessage={isFallbackValueInvalid ? formatMessage(messages.fallbackValueInvalid) : ''}
|
|
90
|
+
size="default"
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
<CapLabel type="label2" className="tag-fallback-preview-label">{formatMessage(messages.addsToMessageAs)}</CapLabel>
|
|
94
|
+
<CapRow type="flex" align="middle" noWrap className="tag-fallback-preview-row">
|
|
95
|
+
<CapLabel className="tag-fallback-preview">{`{{${this.getTagValue()}}}`}</CapLabel>
|
|
96
|
+
<CapIcon
|
|
97
|
+
type="copy"
|
|
98
|
+
size="m"
|
|
99
|
+
className="tag-fallback-copy"
|
|
100
|
+
aria-label={formatMessage(messages.copy)}
|
|
101
|
+
onClick={this.copyTag}
|
|
102
|
+
/>
|
|
103
|
+
</CapRow>
|
|
104
|
+
</CapRow>
|
|
105
|
+
<CapRow type="flex" justify="end" className="tag-fallback-footer">
|
|
106
|
+
<CapButton type="primary" disabled={isInsertDisabled} onClick={this.onInsert}>
|
|
107
|
+
{formatMessage(messages.insertTag)}
|
|
108
|
+
</CapButton>
|
|
109
|
+
</CapRow>
|
|
110
|
+
</CapRow>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
TagFallbackPanel.propTypes = {
|
|
116
|
+
intl: intlShape.isRequired,
|
|
117
|
+
tagKey: PropTypes.string.isRequired,
|
|
118
|
+
tagName: PropTypes.node,
|
|
119
|
+
parentName: PropTypes.node,
|
|
120
|
+
onBack: PropTypes.func.isRequired,
|
|
121
|
+
onInsert: PropTypes.func.isRequired,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default injectIntl(TagFallbackPanel);
|
|
@@ -29,6 +29,7 @@ import _ from 'lodash';
|
|
|
29
29
|
import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
|
|
30
30
|
import { createStructuredSelector } from 'reselect';
|
|
31
31
|
import messages from './messages';
|
|
32
|
+
import TagFallbackPanel from './TagFallbackPanel';
|
|
32
33
|
import { makeSelectLoyaltyPromotionDisplay } from '../../v2Containers/Cap/selectors';
|
|
33
34
|
import { CARD_RELATED_TAGS, HOSPITALITY_RELATED_TAGS, CUSTOMER_BARCODE_TAG, GET_TRANSLATION_MAPPED ,JAPANESE_HELP_TEXT, TAG_TRANSLATION_DOC} from '../../constants/unified';
|
|
34
35
|
import { hasCardBasedScope, hasCustomerBarcodeFeatureEnabled, hasHospitalityBasedScope } from '../../utils/common';
|
|
@@ -38,7 +39,7 @@ import { hidingDateTagsForJpLocale } from '../../v2Containers/TagList/utils';
|
|
|
38
39
|
|
|
39
40
|
const {Search} = CapInput;
|
|
40
41
|
|
|
41
|
-
class CapTagList extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
42
|
+
export class CapTagList extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
42
43
|
constructor(props) {
|
|
43
44
|
super(props);
|
|
44
45
|
this.state = {
|
|
@@ -55,6 +56,8 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
55
56
|
selectedContext: 'Outbound',
|
|
56
57
|
isLoadingLoyaltyTags: false,
|
|
57
58
|
isLoadingContextChange: false,
|
|
59
|
+
// leaf tag clicked from the list, fallback panel is shown for it
|
|
60
|
+
selectedTag: null,
|
|
58
61
|
};
|
|
59
62
|
this.renderTags = this.renderTags.bind(this);
|
|
60
63
|
this.getSearchedExpandedKeys = this.getSearchedExpandedKeys.bind(this);
|
|
@@ -85,6 +88,11 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
// hidePopover mode: modal is closed by the parent, go back to the tag list for next open
|
|
92
|
+
if (prevProps.visibleTaglist && !this.props.visibleTaglist && this.state.selectedTag) {
|
|
93
|
+
this.setState({ selectedTag: null, selectedNodeKey: '' });
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
// Reset loading states when tags are received after context change
|
|
89
97
|
if ((this.state.isLoadingLoyaltyTags || this.state.isLoadingContextChange)
|
|
90
98
|
&& this.props.tags !== prevProps.tags) {
|
|
@@ -218,8 +226,15 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
218
226
|
if (ifDynamicTag) {
|
|
219
227
|
this.renderDynamicTagFlow();
|
|
220
228
|
} else {
|
|
221
|
-
|
|
222
|
-
this.setState({
|
|
229
|
+
const nodeData = selectedNode.props || selectedNode;
|
|
230
|
+
this.setState({
|
|
231
|
+
selectedTag: {
|
|
232
|
+
tagKey: selectedTagValue,
|
|
233
|
+
tagName: nodeData?.tagName,
|
|
234
|
+
parentName: nodeData?.parentName,
|
|
235
|
+
info,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
223
238
|
}
|
|
224
239
|
} else if (!isLeaf) {
|
|
225
240
|
this.handleOnExpand(selectedKeys[0]);
|
|
@@ -238,8 +253,18 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
238
253
|
this.setState({expandedKeys, autoExpandParent: false});
|
|
239
254
|
};
|
|
240
255
|
|
|
256
|
+
handleFallbackBack = () => {
|
|
257
|
+
this.setState({selectedTag: null, selectedNodeKey: ''});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
handleFallbackInsert = (tagValue) => {
|
|
261
|
+
const { info } = this.state.selectedTag || {};
|
|
262
|
+
this.props.onSelect([tagValue], info);
|
|
263
|
+
this.setState({visible: false, selectedTag: null, selectedNodeKey: ''});
|
|
264
|
+
};
|
|
265
|
+
|
|
241
266
|
togglePopoverVisibility = (visible) => {
|
|
242
|
-
this.setState({visible});
|
|
267
|
+
this.setState(visible ? {visible} : {visible, selectedTag: null, selectedNodeKey: ''});
|
|
243
268
|
// Call onVisibleChange callback if provided (for triggering API calls when popover opens)
|
|
244
269
|
if (this.props.onVisibleChange) {
|
|
245
270
|
this.props.onVisibleChange(visible);
|
|
@@ -250,7 +275,7 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
250
275
|
this.setState({showModal: true, visible: false});
|
|
251
276
|
};
|
|
252
277
|
|
|
253
|
-
renderTags = (tags, parentPath = '') => {
|
|
278
|
+
renderTags = (tags, parentPath = '', parentName = '') => {
|
|
254
279
|
const searchString = this.state.searchValue || '';
|
|
255
280
|
const {
|
|
256
281
|
disableRelatedTags, childTagsToDisable, parentTagstoDisable,
|
|
@@ -291,7 +316,7 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
291
316
|
|| tagNameWithoutUnderscore.includes(searchStringLower));
|
|
292
317
|
if (_.has(val, 'subtags')) {
|
|
293
318
|
const disabled = disableRelatedTags ? parentTagstoDisable.includes(key) : false;
|
|
294
|
-
const temp = this.renderTags(val?.subtags, nodeKey);
|
|
319
|
+
const temp = this.renderTags(val?.subtags, nodeKey, val?.name);
|
|
295
320
|
if (temp?.length) {
|
|
296
321
|
const node = {
|
|
297
322
|
title: disabled ? <CapTooltip title={loyaltyAttrDisableText}>{val?.name}</CapTooltip> : val?.name,
|
|
@@ -324,6 +349,8 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
324
349
|
key: nodeKey,
|
|
325
350
|
tag: val,
|
|
326
351
|
tagKey: rawKey,
|
|
352
|
+
tagName: val?.desc || val?.name,
|
|
353
|
+
parentName,
|
|
327
354
|
isLeaf: true,
|
|
328
355
|
disabled: childDisabled,
|
|
329
356
|
};
|
|
@@ -369,12 +396,24 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
369
396
|
key: 'loyalty',
|
|
370
397
|
},
|
|
371
398
|
];
|
|
372
|
-
const
|
|
399
|
+
const { selectedTag } = this.state;
|
|
400
|
+
const contentSection = selectedTag ? (
|
|
401
|
+
<CapRow useLegacy className="cap-tag-list-popover-inner">
|
|
402
|
+
<TagFallbackPanel
|
|
403
|
+
tagKey={selectedTag?.tagKey}
|
|
404
|
+
tagName={selectedTag?.tagName}
|
|
405
|
+
parentName={selectedTag?.parentName}
|
|
406
|
+
onBack={this.handleFallbackBack}
|
|
407
|
+
onInsert={this.handleFallbackInsert}
|
|
408
|
+
/>
|
|
409
|
+
</CapRow>
|
|
410
|
+
) : (
|
|
373
411
|
<CapRow useLegacy className="cap-tag-list-popover-inner">
|
|
374
412
|
<CapSpin tip={formatMessage(messages.gettingTags)} spinning={shouldShowLoading}>
|
|
375
413
|
<Search
|
|
376
414
|
style={{ marginBottom: 8, width: '250px'}}
|
|
377
415
|
placeholder={formatMessage(messages.search)}
|
|
416
|
+
value={this.state.searchValue}
|
|
378
417
|
onChange={this.onChange} />
|
|
379
418
|
{moduleFilterEnabled ? (
|
|
380
419
|
<CapSelect
|
|
@@ -58,4 +58,48 @@ export default defineMessages({
|
|
|
58
58
|
id: `creatives.componentsV2.CapTagList.labelFetchErrorMsg`,
|
|
59
59
|
defaultMessage: 'Unable to fetch the labels. Please try again later'
|
|
60
60
|
},
|
|
61
|
+
fallbackBehaviour: {
|
|
62
|
+
id: `creatives.componentsV2.CapTagList.fallbackBehaviour`,
|
|
63
|
+
defaultMessage: 'Fallback behaviour',
|
|
64
|
+
},
|
|
65
|
+
fallbackBehaviourDesc: {
|
|
66
|
+
id: `creatives.componentsV2.CapTagList.fallbackBehaviourDesc`,
|
|
67
|
+
defaultMessage: 'If the tag has no value for a customer',
|
|
68
|
+
},
|
|
69
|
+
dontSendMessage: {
|
|
70
|
+
id: `creatives.componentsV2.CapTagList.dontSendMessage`,
|
|
71
|
+
defaultMessage: 'Don’t send message',
|
|
72
|
+
},
|
|
73
|
+
sendWithNullValue: {
|
|
74
|
+
id: `creatives.componentsV2.CapTagList.sendWithNullValue`,
|
|
75
|
+
defaultMessage: 'Send with null value',
|
|
76
|
+
},
|
|
77
|
+
fallbackValue: {
|
|
78
|
+
id: `creatives.componentsV2.CapTagList.fallbackValue`,
|
|
79
|
+
defaultMessage: 'Fallback value',
|
|
80
|
+
},
|
|
81
|
+
fallbackValuePlaceholder: {
|
|
82
|
+
id: `creatives.componentsV2.CapTagList.fallbackValuePlaceholder`,
|
|
83
|
+
defaultMessage: 'Enter fallback value',
|
|
84
|
+
},
|
|
85
|
+
fallbackValueInvalid: {
|
|
86
|
+
id: `creatives.componentsV2.CapTagList.fallbackValueInvalid`,
|
|
87
|
+
defaultMessage: 'Fallback value cannot contain { } or both single and double quotes',
|
|
88
|
+
},
|
|
89
|
+
addsToMessageAs: {
|
|
90
|
+
id: `creatives.componentsV2.CapTagList.addsToMessageAs`,
|
|
91
|
+
defaultMessage: 'Adds to the message as',
|
|
92
|
+
},
|
|
93
|
+
insertTag: {
|
|
94
|
+
id: `creatives.componentsV2.CapTagList.insertTag`,
|
|
95
|
+
defaultMessage: 'Insert tag',
|
|
96
|
+
},
|
|
97
|
+
back: {
|
|
98
|
+
id: `creatives.componentsV2.CapTagList.back`,
|
|
99
|
+
defaultMessage: 'Back',
|
|
100
|
+
},
|
|
101
|
+
copy: {
|
|
102
|
+
id: `creatives.componentsV2.CapTagList.copy`,
|
|
103
|
+
defaultMessage: 'Copy',
|
|
104
|
+
},
|
|
61
105
|
});
|
|
@@ -56,4 +56,116 @@
|
|
|
56
56
|
|
|
57
57
|
.ant-popover-container.tag-list-popover-container.tag-list-popover-container {
|
|
58
58
|
background-color: $CAP_WHITE;
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
|
+
.tag-fallback-panel {
|
|
61
|
+
width: 20rem;
|
|
62
|
+
max-width: 100%;
|
|
63
|
+
|
|
64
|
+
.tag-fallback-header {
|
|
65
|
+
padding-bottom: $CAP_SPACE_16;
|
|
66
|
+
margin-bottom: $CAP_SPACE_16;
|
|
67
|
+
border-bottom: 1px solid $CAP_G07;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.tag-fallback-title-row {
|
|
71
|
+
gap: $CAP_SPACE_16;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.tag-fallback-back {
|
|
75
|
+
flex-shrink: 0;
|
|
76
|
+
color: $FONT_COLOR_02;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.tag-fallback-tag-name {
|
|
81
|
+
margin: 0;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
word-break: break-word;
|
|
84
|
+
font-size: 1rem;
|
|
85
|
+
font-weight: $FONT_WEIGHT_MEDIUM;
|
|
86
|
+
line-height: 1.5rem;
|
|
87
|
+
color: $FONT_COLOR_01;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// indented by back icon width + gap, so it starts below the tag name
|
|
91
|
+
.tag-fallback-group-name {
|
|
92
|
+
margin: $CAP_SPACE_02 0 0 calc(#{$CAP_SPACE_24} + #{$CAP_SPACE_16});
|
|
93
|
+
word-break: break-word;
|
|
94
|
+
font-size: 0.8rem;
|
|
95
|
+
font-weight: $FONT_WEIGHT_REGULAR;
|
|
96
|
+
color: $FONT_COLOR_02;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.tag-fallback-heading {
|
|
100
|
+
margin: 0;
|
|
101
|
+
font-size: $FONT_SIZE_M;
|
|
102
|
+
font-weight: $FONT_WEIGHT_MEDIUM;
|
|
103
|
+
line-height: 1.43rem;
|
|
104
|
+
color: $FONT_COLOR_01;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.tag-fallback-subtext {
|
|
108
|
+
margin-top: $CAP_SPACE_02;
|
|
109
|
+
font-size: $FONT_SIZE_S;
|
|
110
|
+
font-weight: $FONT_WEIGHT_REGULAR;
|
|
111
|
+
color: $FONT_COLOR_02;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.tag-fallback-options {
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
margin: $CAP_SPACE_16 0;
|
|
118
|
+
|
|
119
|
+
.ant-radio-wrapper,
|
|
120
|
+
.ant-radio-wrapper span {
|
|
121
|
+
font-size: $FONT_SIZE_M;
|
|
122
|
+
font-weight: $FONT_WEIGHT_REGULAR;
|
|
123
|
+
color: $FONT_COLOR_01;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.tag-fallback-input {
|
|
128
|
+
margin-bottom: $CAP_SPACE_16;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.tag-fallback-preview-label {
|
|
132
|
+
margin: $CAP_SPACE_24 0 $CAP_SPACE_08;
|
|
133
|
+
font-size: $FONT_SIZE_S;
|
|
134
|
+
font-weight: $FONT_WEIGHT_REGULAR;
|
|
135
|
+
color: $FONT_COLOR_02;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.tag-fallback-preview-row {
|
|
139
|
+
gap: $CAP_SPACE_12;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.tag-fallback-preview {
|
|
143
|
+
flex: 1;
|
|
144
|
+
min-width: 0;
|
|
145
|
+
padding: $CAP_SPACE_08 $CAP_SPACE_12;
|
|
146
|
+
border: 1px solid $CAP_COLOR_01;
|
|
147
|
+
border-radius: $CAP_SPACE_04;
|
|
148
|
+
background: $BG_08;
|
|
149
|
+
color: map-get($CAP_PRIMARY, hover);
|
|
150
|
+
font-family: 'Roboto Mono', Menlo, Consolas, monospace;
|
|
151
|
+
font-size: $FONT_SIZE_S;
|
|
152
|
+
line-height: 1.143rem;
|
|
153
|
+
word-break: break-all;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.tag-fallback-copy {
|
|
157
|
+
flex-shrink: 0;
|
|
158
|
+
color: $FONT_COLOR_02;
|
|
159
|
+
cursor: pointer;
|
|
160
|
+
|
|
161
|
+
&:hover {
|
|
162
|
+
color: $FONT_COLOR_01;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.tag-fallback-footer {
|
|
167
|
+
margin-top: $CAP_SPACE_16;
|
|
168
|
+
padding-top: $CAP_SPACE_12;
|
|
169
|
+
border-top: 1px solid $CAP_G07;
|
|
170
|
+
}
|
|
171
|
+
}
|