@capillarytech/creatives-library 7.9.13 → 7.9.14

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.
@@ -10,7 +10,7 @@ import React from 'react';
10
10
  import { Card } from 'antd';
11
11
  import './_customCard.scss';
12
12
 
13
- class CustomCard extends React.Component { // eslint-disable-line react/prefer-stateless-function
13
+ export class CustomCard extends React.Component { // eslint-disable-line react/prefer-stateless-function
14
14
  constructor(props) {
15
15
  super(props);
16
16
  this.handleMouseHover = this.handleMouseHover.bind(this);
@@ -0,0 +1,22 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RestrictionPlainInput test Test 1 should render default component when a retriction constant is passed 1`] = `
4
+ <Card
5
+ className="custom-card"
6
+ onClick={[Function]}
7
+ onMouseEnter={[Function]}
8
+ onMouseLeave={[Function]}
9
+ style={
10
+ Object {
11
+ "height": undefined,
12
+ "width": undefined,
13
+ }
14
+ }
15
+ >
16
+ <div>
17
+ <div
18
+ className="content-wrapper"
19
+ />
20
+ </div>
21
+ </Card>
22
+ `;
@@ -1,10 +1,22 @@
1
- // import React from 'react';
2
- // import { shallow } from 'enzyme';
1
+ import React from 'react';
2
+ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
3
+ import { CustomCard } from '../index';
3
4
 
4
- // import Card from '../index';
5
+ describe('RestrictionPlainInput test', () => {
6
+
7
+ let renderedComponent;
8
+
9
+ const renderFunc = () => {
10
+ renderedComponent = shallowWithIntl(
11
+ <CustomCard />
12
+ );
13
+ }
14
+
15
+ describe('Test 1', () => {
16
+ it('should render default component when a retriction constant is passed', () => {
17
+ renderFunc();
18
+ expect(renderedComponent).toMatchSnapshot();
19
+ })
20
+ });
5
21
 
6
- describe('<Card />', () => {
7
- it('Expect to have unit tests specified', () => {
8
- expect(true).toEqual(false);
9
- });
10
22
  });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Components using the react-intl module require access to the intl context.
3
+ * This is not available when mounting single components in Enzyme.
4
+ * These helper functions aim to address that and wrap a valid,
5
+ * English-locale intl context around them.
6
+ */
7
+
8
+ import React from 'react';
9
+ import { IntlProvider, intlShape } from 'react-intl';
10
+ import { mount, shallow, configure } from 'enzyme';
11
+ import Adapter from 'enzyme-adapter-react-16';
12
+
13
+ configure({ adapter: new Adapter() });
14
+ // You can pass your messages to the IntlProvider. Optional: remove if unneeded.
15
+ const messages = require('../translations/en.json'); // en.json
16
+
17
+ // Create the IntlProvider to retrieve context for wrapping around.
18
+ const intlProvider = new IntlProvider({ locale: 'en', messages }, {});
19
+ const { intl } = intlProvider.getChildContext();
20
+
21
+ /**
22
+ * When using React-Intl `injectIntl` on components, props.intl is required.
23
+ */
24
+ function nodeWithIntlProp(node) {
25
+ return React.cloneElement(node, { intl });
26
+ }
27
+
28
+ /**
29
+ * Export these methods.
30
+ */
31
+ export function shallowWithIntl(node) {
32
+ return shallow(nodeWithIntlProp(node), { context: { intl } });
33
+ }
34
+
35
+ export function mountWithIntl(node) {
36
+ return mount(nodeWithIntlProp(node), {
37
+ context: { intl },
38
+ childContextTypes: { intl: intlShape },
39
+ });
40
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.9.13",
4
+ "version": "7.9.14",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/utils/common.js CHANGED
@@ -38,9 +38,11 @@ export const hasStore2DoorFeature = Auth.hasFeatureAccess.bind(
38
38
  STORE2DOOR_PLUS_ENABLED,
39
39
  );
40
40
 
41
- export function getTreeStructuredTags({tagsList, userLocale = 'en', offerDetails = []}) {
41
+ export function getTreeStructuredTags({tagsList, userLocale = 'en', offerDetails = [], disableTagsDetails = {}}) {
42
42
  console.log('populating tags', (tagsList || []).length);
43
43
  const mainTags = {};
44
+ const { disableRelatedTags, childTagsToDisable, parentTagstoDisable} = disableTagsDetails;
45
+
44
46
 
45
47
  _.forEach(tagsList, (temp) => {
46
48
  const tag = temp.definition;
@@ -48,6 +50,7 @@ export function getTreeStructuredTags({tagsList, userLocale = 'en', offerDetails
48
50
  mainTags[tag.value] = {
49
51
  name: tag.label[userLocale] || tag.label.en,
50
52
  value: tag.value,
53
+ disabled: disableRelatedTags ? childTagsToDisable.includes(tag.value) : false,
51
54
  };
52
55
  } else if (tag['tag-header'] && mainTags[tag.value]) {
53
56
  // to check it this tag header is already available in mainTags object,
@@ -60,6 +63,7 @@ export function getTreeStructuredTags({tagsList, userLocale = 'en', offerDetails
60
63
  "name": tag.label[userLocale] || tag.label.en,
61
64
  "subtags": tag.subtags,
62
65
  "value": tag.value,
66
+ "disabled": disableRelatedTags ? parentTagstoDisable.includes(tag.value) : false,
63
67
  };
64
68
  }
65
69
  });
@@ -175,17 +179,19 @@ function populateTagForChildren(targetTag, tagsObject, tagValue) {
175
179
  function getTreeStructureData(data) {
176
180
  const result = [];
177
181
  _.forOwn(data, (mainTag) => {
178
- const { name, value, subtags = [] } = mainTag;
182
+ const { name, value, subtags = [], disabled } = mainTag;
179
183
  if (!mainTag['tag-header']) {
180
184
  result.push({
181
185
  title: name,
182
186
  value: `{{${value}}}`,
187
+ disabled,
183
188
  });
184
189
  } else {
185
190
  const obj = {
186
191
  title: name,
187
192
  value: `{{${value}}}`,
188
193
  selectable: false,
194
+ disabled,
189
195
  };
190
196
  obj.children = getSubTags(subtags);
191
197
  result.push(obj);
@@ -197,17 +203,19 @@ function getTreeStructureData(data) {
197
203
  function getSubTags(subtagsParam) {
198
204
  const result = [];
199
205
  _.forOwn(subtagsParam, (subTag) => {
200
- const { name, value, subtags = [] } = subTag;
206
+ const { name, value, subtags = [], disabled } = subTag;
201
207
  if (_.isEmpty(subtags)) {
202
208
  result.push({
203
209
  title: name,
204
210
  value: `{{${value}}}`,
211
+ disabled,
205
212
  });
206
213
  } else {
207
214
  const obj = {
208
215
  title: name,
209
216
  value: `{{${value}}}`,
210
217
  selectable: false,
218
+ disabled,
211
219
  };
212
220
  obj.children = getSubTags(subtags);
213
221
  result.push(obj);
@@ -5,19 +5,20 @@
5
5
  */
6
6
 
7
7
  import PropTypes from 'prop-types';
8
-
9
8
  import React from 'react';
9
+ import { connect } from 'react-redux';
10
10
  // import styled from 'styled-components';
11
- import { CapSpin, CapModal, CapButton, CapPopover, CapInput, CapTree, CapSelect } from '@capillarytech/cap-ui-library';
11
+ import { CapSpin, CapModal, CapButton, CapPopover, CapInput, CapTree, CapSelect, CapTooltip } from '@capillarytech/cap-ui-library';
12
12
 
13
13
  import _ from 'lodash';
14
- import { injectIntl, intlShape } from 'react-intl';
14
+ import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
15
+ import { createStructuredSelector } from 'reselect';
15
16
  import messages from './messages';
17
+ import { makeSelectLoyaltyPromotionDisplay } from '../../v2Containers/Cap/selectors';
16
18
 
17
19
  const {Search} = CapInput;
18
20
  const {CapTreeNode} = CapTree;
19
21
  class CapTagList extends React.Component { // eslint-disable-line react/prefer-stateless-function
20
-
21
22
  constructor(props) {
22
23
  super(props);
23
24
  this.state = {
@@ -132,23 +133,39 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
132
133
  };
133
134
 
134
135
  renderTags(tags, searchString = '') {
136
+ const { disableRelatedTags, childTagsToDisable, parentTagstoDisable} = this.props.disableTagsDetails;
135
137
  const list = [];
138
+ const loyaltyAttrDisableText = <FormattedMessage {...messages.loyaltyAttributeDisable} />;
136
139
  _.forEach(tags, (val = '', key) => {
137
140
  let supportedTagsString = '';
138
141
  _.forEach(val.supportedTags, (supportedTag) => {
139
142
  supportedTagsString += `${supportedTag} ,`;
140
143
  });
141
144
  supportedTagsString = supportedTagsString.replace(/,\s*$/, "");
142
-
143
145
  if (_.has(val, 'subtags')) {
144
- const temp = this.renderTags(val.subtags);
146
+ const disabled = disableRelatedTags ? parentTagstoDisable.includes(key) : false;
147
+ const temp = this.renderTags(val.subtags, '', disabled);
145
148
  list.push((
146
- <CapTreeNode title={val.name} tag={val} key={val.couponSeriesId ? `${key}(${val.couponSeriesId})` : `${key}`}>
149
+ <CapTreeNode
150
+ title={disabled ? <CapTooltip title={loyaltyAttrDisableText}>{val.name}</CapTooltip> : val.name}
151
+ tag={val}
152
+ key={val.couponSeriesId ? `${key}(${val.couponSeriesId})` : `${key}`}
153
+ disabled={disabled}
154
+ >
147
155
  {temp}
148
156
  </CapTreeNode>
149
157
  ));
150
158
  } else if (searchString === '' || !searchString || ((val.name || '').toLowerCase().indexOf(searchString.toLowerCase()) !== -1)) {
151
- const tempNode = (<CapTreeNode title={val.desc || val.name} tag={val} isLeaf key={val.couponSeriesId ? `${key}(${val.couponSeriesId})` : `${key}`}></CapTreeNode>);
159
+ const childDisabled = disableRelatedTags ? childTagsToDisable.includes(key) : false;
160
+ const tempNode = (
161
+ <CapTreeNode
162
+ title={childDisabled ? <CapTooltip title={loyaltyAttrDisableText}>{val.desc || val.name}</CapTooltip> : (val.desc || val.name)}
163
+ tag={val}
164
+ isLeaf
165
+ key={val.couponSeriesId ? `${key}(${val.couponSeriesId})` : `${key}`}
166
+ disabled={childDisabled}
167
+ >
168
+ </CapTreeNode>);
152
169
  list.push(tempNode);
153
170
  }
154
171
  });
@@ -253,10 +270,22 @@ CapTagList.propTypes = {
253
270
  visibleTaglist: PropTypes.bool,
254
271
  hidePopover: PropTypes.bool,
255
272
  modalProps: PropTypes.any,
273
+ disableTagsDetails: PropTypes.object,
256
274
  };
257
275
 
258
276
  CapTagList.defaultValue = {
259
277
  hidePopover: false,
260
278
  };
261
279
 
262
- export default injectIntl(CapTagList);
280
+ function mapDispatchToProps() {
281
+ return {
282
+ };
283
+ }
284
+
285
+ const mapStateToProps = createStructuredSelector({
286
+ disableTagsDetails: makeSelectLoyaltyPromotionDisplay(),
287
+ });
288
+
289
+
290
+ export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(CapTagList));
291
+
@@ -42,4 +42,8 @@ export default defineMessages({
42
42
  id: 'creatives.componentsV2.CapTagList.search',
43
43
  defaultMessage: 'Search',
44
44
  },
45
+ "loyaltyAttributeDisable": {
46
+ id: `creatives.componentsV2.CapTagList.loyaltyAttributeDisable`,
47
+ defaultMessage: 'You won’t be able to add loyalty related attributes since the loyalty program/ card series is None.',
48
+ },
45
49
  });
@@ -28,6 +28,8 @@ export const GET_TOPBAR_MENU_DATA_SUCCESS = 'creatives/cap/GET_TOPBAR_MENU_DATA_
28
28
  export const GET_TOPBAR_MENU_DATA_FAILURE = 'creatives/cap/GET_TOPBAR_MENU_DATA_FAILURE';
29
29
  export const CLEAR_TOPBAR_MENU_DATA = 'creatives/cap/CLEAR_TOPBAR_MENU_DATA';
30
30
 
31
+ export const SET_LOYALTY_PROMOTION_RELATED_CREATIVE_TAGS_DISPLAY = 'SET_LOYALTY_PROMOTION_RELATED_CREATIVE_TAGS_DISPLAY';
32
+
31
33
  export const CAMPAIGN_SETTINGS_URL = '/creatives/settings/message';
32
34
  export const ORG_SETTINGS_URL = '/org/index';
33
35
  export const HELP_URL = 'https://support.capillarytech.com/en/support/solutions/4000007853';
@@ -82,7 +82,6 @@ function capReducer(state = fromJS(initialState.cap), action) {
82
82
  .set('fetchingSchema', false);
83
83
  case types.GET_SCHEMA_FOR_ENTITY_SUCCESS: {
84
84
  const stateMeta = state.get('metaEntities');
85
-
86
85
  return state
87
86
  .set('fetchingSchema', false)
88
87
  .set('metaEntities', {
@@ -117,6 +116,11 @@ function capReducer(state = fromJS(initialState.cap), action) {
117
116
  );
118
117
  case types.CLEAR_TOPBAR_MENU_DATA:
119
118
  return state.set('topbarMenuData', fromJS({}));
119
+ case types.SET_LOYALTY_PROMOTION_RELATED_CREATIVE_TAGS_DISPLAY: {
120
+ return state.set('disableLoyaltyPromotionRelatedTags', action.disable)
121
+ .set('tagsToDisable', action.tagsToDisable)
122
+ .set('parentTagsToDisable', action.parentTagsToDisable);
123
+ }
120
124
  default:
121
125
  return state;
122
126
  }
@@ -31,7 +31,6 @@ const setInjectedTags = () => createSelector(
31
31
  const { tags } = metaEntities;
32
32
  const customTags = tags && (tags.custom || {});
33
33
  const extendedTags = tags && (tags.extended || {});
34
-
35
34
  return (injectedTags = _.merge({}, injectedTags, customTags, extendedTags));
36
35
  }
37
36
  );
@@ -74,6 +73,15 @@ const makeSelectFetchingSchema = () => createSelector(
74
73
  (globalState) => globalState.get('fetchingSchema')
75
74
  );
76
75
 
76
+ const makeSelectLoyaltyPromotionDisplay = () => createSelector(
77
+ selectCapDomain,
78
+ (globalState) => ({
79
+ disableRelatedTags: globalState.get('disableLoyaltyPromotionRelatedTags'),
80
+ childTagsToDisable: globalState.get('tagsToDisable') || [],
81
+ parentTagstoDisable: globalState.get('parentTagsToDisable') || [],
82
+ }),
83
+ );
84
+
77
85
  export {
78
86
  makeSelectLocationState,
79
87
  makeSelectAuthenticated,
@@ -85,4 +93,5 @@ export {
85
93
  isLoadingMetaEntities,
86
94
  makeSelectFetchingSchema,
87
95
  setInjectedTags,
96
+ makeSelectLoyaltyPromotionDisplay,
88
97
  };
@@ -25,7 +25,7 @@ import { FONT_SIZE_L } from '@capillarytech/cap-ui-library/styled/variables';
25
25
  import { find, cloneDeep, findIndex, isEmpty, isEqual, filter, flattenDeep, replace } from 'lodash';
26
26
  import * as actions from './actions';
27
27
  import { makeSelectFTP, makeSelectMetaEntities } from './selectors';
28
- import { setInjectedTags } from '../Cap/selectors';
28
+ import { makeSelectLoyaltyPromotionDisplay, setInjectedTags } from '../Cap/selectors';
29
29
  import withCreatives from '../../hoc/withCreatives';
30
30
  import messages from './messages';
31
31
  import './_FTP.scss';
@@ -132,7 +132,11 @@ export class FTP extends React.Component {
132
132
  ) || !isEqual(injectedTags, thisInjectedTags)
133
133
  ) {
134
134
  const tags = _.concat(
135
- getTreeStructuredTags({ tagsList: ((metaEntities.tags || {}).standard || []), offerDetails: selectedOfferDetails }),
135
+ getTreeStructuredTags({
136
+ tagsList: ((metaEntities.tags || {}).standard || []),
137
+ offerDetails: selectedOfferDetails,
138
+ disableTagsDetails: this.props.disableTagsDetails,
139
+ }),
136
140
  this.getTreeStructuredInjectedTags(injectedTags)
137
141
  );
138
142
  this.setState({ tagsTree: tags}, () => this.disableUsedColumns());
@@ -491,9 +495,13 @@ export class FTP extends React.Component {
491
495
 
492
496
  disableUsedColumns = () => {
493
497
  const { headerTagList = [] } = this.state;
494
- const { selectedOfferDetails = [], metaEntities = {}, injectedTags } = this.props;
498
+ const { selectedOfferDetails = [], metaEntities = {}, injectedTags, disableTagsDetails } = this.props;
495
499
  const tags = _.concat(
496
- getTreeStructuredTags({ tagsList: ((metaEntities.tags || {}).standard || []), offerDetails: selectedOfferDetails }),
500
+ getTreeStructuredTags({
501
+ tagsList: ((metaEntities.tags || {}).standard || []),
502
+ offerDetails: selectedOfferDetails,
503
+ disableTagsDetails,
504
+ }),
497
505
  this.getTreeStructuredInjectedTags(injectedTags)
498
506
  );
499
507
  const clonnedTagsTree = cloneDeep(tags);
@@ -636,6 +644,7 @@ FTP.propTypes = {
636
644
  contents: PropTypes.array,
637
645
  metaEntities: PropTypes.object,
638
646
  selectedOfferDetails: PropTypes.array,
647
+ disableTagsDetails: PropTypes.func,
639
648
  };
640
649
 
641
650
 
@@ -650,6 +659,7 @@ const mapStateToProps = createStructuredSelector({
650
659
  FTP: makeSelectFTP(),
651
660
  metaEntities: makeSelectMetaEntities(),
652
661
  injectedTags: setInjectedTags(),
662
+ disableTagsDetails: makeSelectLoyaltyPromotionDisplay(),
653
663
  });
654
664
 
655
665
  export default withCreatives({
@@ -207,26 +207,11 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
207
207
  if (this.props.location.query.type === 'embedded') {
208
208
  this.props.actions.resetAccount();
209
209
  }
210
- if ((['line', VIBER_CHANNEL, FACEBOOK_CHANNEL, 'sms', 'email', 'ebill'].includes((this.state.channel || '').toLowerCase())) || ((['wechat', 'mobilepush'].includes(this.state.channel.toLowerCase()) && !isEmpty(this.props.Templates.selectedWeChatAccount)))) {
210
+ if (['line', VIBER_CHANNEL, FACEBOOK_CHANNEL, 'sms', 'email', 'ebill'].includes((this.state.channel || '').toLowerCase())) {
211
211
  const queryParams = {
212
212
  // name: this.state.searchText,
213
213
  // sortBy: this.state.sortBy,
214
214
  };
215
- if (this.state.channel.toLowerCase() === 'wechat' && get(this.props, 'Templates.selectedWeChatAccount.configs', false)) {
216
- queryParams.wecrmId = this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id;
217
- queryParams.wecrmToken = this.props.Templates.selectedWeChatAccount.configs.wecrm_token;
218
- queryParams.originalId = this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier;
219
- }
220
- if (this.state.channel.toLowerCase() === "mobilepush" && !isEmpty(this.props.Templates.selectedWeChatAccount)) {
221
- const account = this.props.Templates.selectedWeChatAccount;
222
- queryParams.accountId = account.id;
223
- const isAndroidSupported = get(account, "configs.android") === '1';
224
- const isIosSupported = get(account, "configs.ios") === '1';
225
- if (!(isAndroidSupported || isIosSupported)) {
226
- this.props.actions.resetAccount();
227
- return;
228
- }
229
- }
230
215
  queryParams.page = this.state.page;
231
216
  queryParams.perPage = this.state.perPageLimit;
232
217
  const channel = this.state.channel;