Notes
Notes - notes.io |
import handleError from '../utils/handleError';
import api from '../api/api';
import appState from './appState';
class AggregationMarketingContext {
marketingContexts = [];
selectedRows = {};
constructor() {
this.appState = appState;
makeObservable(this, {
initialize: action,
updateValue: action,
deleteRows: action,
selectedRows: observable,
marketingContexts: observable,
reset: action
});
}
updateValue({key, value}) {
this[key] = value;
}
reset() {
runInAction(() => {
this.marketingContexts = [];
this.selectedRows = {};
});
}
initialize = async () => {
appState.isFetching = true;
try {
//const marketingContexts = await api.fetchAggregationMarketingContexts().data;
const marketingContexts = {
'consumer|US|en-us|retail': [
{
id: '1',
category: 'GLOBAL_MARKETING_CONTEXT',
enabled: true,
feedType: 'PD',
outcome:
'{"cacheKey":"consumer|US|en-us|retail|-|-|-","marketingContext":{"segment":"consumer","geo":"US","channel":"retail","language":"en-us"}}',
sortOrder: 0,
description: 'Inclusion mc rule:consumer|US|en-us|retail|-|-|-',
createdBy: '[email protected]',
createdDate: '',
version: 0
},
{
id: '4',
category: 'GLOBAL_PART',
enabled: true,
feedType: 'PD',
condition:
" (partFeed.cacheKey LIKE 'consumer|US|en-us|retail|.*|.*|.*' AND partFeed.parts[].partNumber IN ('Test123','test2')) ",
sortOrder: 0,
description: 'Inclusion part rule:consumer|US|en-us|retail|-|-|-',
createdBy: '[email protected]',
createdDate: '',
version: 0
}
],
'consumer|CN|zh-cn|retail': [
{
id: '2',
category: 'GLOBAL_MARKETING_CONTEXT',
enabled: true,
feedType: 'PD',
outcome:
'{"cacheKey":"consumer|CN|zh-cn|retail|-|-|-","marketingContext":{"segment":"consumer","geo":"CN","channel":"retail","language":"zh-cn"}}',
sortOrder: 0,
description: 'Inclusion mc rule:consumer|CN|zh-cn|retail|-|-|-',
createdBy: '[email protected]',
createdDate: '',
version: 0
}
]
};
const formattedData = Object.keys(marketingContexts).map(key => {
const [segment, geo, language, channel] = key.split('|');
const marketingContext = marketingContexts[key].find(item => item.category === 'GLOBAL_MARKETING_CONTEXT');
const globalPart = marketingContexts[key].find(item => item.category === 'GLOBAL_PART');
const assortmentsMatch =
globalPart && globalPart.condition ? globalPart.condition.match(/partNumber IN (([^)]+))/) : null;
const assortments = assortmentsMatch
? assortmentsMatch[1]
.replace(/'/g, '')
.replace(/s/g, '')
.split(',')
: '-';
return {
id: marketingContext.id,
segment: segment,
geo: geo,
channel: channel,
language: language,
assortments: Array.isArray(assortments) ? assortments.join(', ') : 'ALL',
modifiedBy: marketingContext.createdBy,
modifiedDate: marketingContext.createdDate
};
});
runInAction(() => {
this.marketingContexts = formattedData;
appState.isFetching = false;
});
} catch (err) {
handleError(err, err.message || 'Unable to fetch Feed Attribute Explorer. Please try again', () => {
runInAction(() => {
appState.isFetching = false;
});
});
}
};
async deleteRows(selectedRows) {
try {
await api.deleteMarketingContexts(selectedRows);
runInAction(() => {
this.selectedRows = {};
this.appState.isRemoveConfirmModalOpen = false;
});
this.appState.addNotification({
message: `${compatibilityMappingIds.length} row${
this.selectedRows.length > 0 ? 's' : ''
} of Marketing Cntexts has been deleted successfully.`,
levelType: 'success'
});
this.initialize();
} catch (error) {
console.log(error, 'error');
runInAction(() => {
this.selectedRows = {};
this.appState.isRemoveConfirmModalOpen = false;
});
this.appState.addNotification({
error,
message: 'Unable to delete Marketing Contexts. Please try again.'
});
}
}
}
export default new AggregationMarketingContext();
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team