Skip to content

Commit

Permalink
Fixing series cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Jan 9, 2025
1 parent c51cf87 commit bfcfdd1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
39 changes: 25 additions & 14 deletions ecc/blocks/series-creation-form/data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@
let responseCache = {};
let payloadCache = {};

const submissionFilter = [
// from payload and response
'seriesName',
'seriesDescription',
'seriesStatus',
'susiContextId',
'externalThemeId',
'cloudType',
'templateId',
'relatedDomain',
'modificationTime',
];
const filters = {
submission: [
'seriesName',
'seriesDescription',
'seriesStatus',
'susiContextId',
'externalThemeId',
'cloudType',
'templateId',
'relatedDomain',
'modificationTime',
],
clone: [
'seriesName',
'seriesDescription',
'seriesStatus',
'susiContextId',
'externalThemeId',
'cloudType',
'templateId',
'relatedDomain',
],
}

function isValidAttribute(attr) {
return attr !== undefined && attr !== null;
}

export function quickFilter(obj) {
export function quickFilter(obj, filter = 'submission') {
const output = {};

submissionFilter.forEach((attr) => {
filters[filter].forEach((attr) => {
if (isValidAttribute(obj[attr])) {
output[attr] = obj[attr];
}
Expand Down
6 changes: 3 additions & 3 deletions ecc/blocks/series-dashboard/series-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function initMoreOptions(props, config, seriesObj, row) {

if (resp.error) {
row.classList.remove('pending');
showToast(props, resp.error, { variant: 'negative' });
showToast(props, resp.error.message || 'Unknown error while archiving the series.', { variant: 'negative' });
return;
}

Expand All @@ -258,15 +258,15 @@ function initMoreOptions(props, config, seriesObj, row) {
// clone
clone.addEventListener('click', async (e) => {
e.preventDefault();
const payload = { ...quickFilter(seriesObj), seriesStatus: 'draft' };
const payload = { ...quickFilter(seriesObj, 'clone'), seriesStatus: 'draft' };
payload.seriesName = `${seriesObj.seriesName} - copy`;
toolBox.remove();
row.classList.add('pending');
const newSeriesObj = await createSeries(payload);

if (newSeriesObj.error) {
row.classList.remove('pending');
showToast(props, newSeriesObj.error, { variant: 'negative' });
showToast(props, newSeriesObj.error.message || 'Unknown error while cloning the series.', { variant: 'negative' });
return;
}

Expand Down

0 comments on commit bfcfdd1

Please sign in to comment.