Skip to content

Commit

Permalink
Pro 4260 export modal (#4)
Browse files Browse the repository at this point in the history
* Style modal

* Backend route for related modules

* Export modal related types

* Export modal styling

* Export modal checkboxes layout

* Add icon for export button
Search relationships in widgets

* Export modal with fixed size

* Modal export: add section for page's children
  • Loading branch information
falkodev authored Aug 10, 2023
1 parent 5fe2d20 commit 6211403
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 163 deletions.
9 changes: 8 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"export": "Export",
"exporting": "Exporting",
"exportModalDescription": "You've selected {{ count }} {{ type }} for export"
"exportModalDescription": "You've selected {{ count }} {{ type }} for export",
"exportModalRelatedDocumentDescription": "Include the following document types where applicable",
"exportModalSettingsLabel": "Export Settings",
"exportModalDocumentFormat": "Document Format",
"exportModalIncludeRelated": "Include related documents",
"exportModalIncludeChildren": "Include children of this page",
"exportModalIncludeRelatedSettings": "Related Documents Settings",
"exportModalNoRelatedTypes": "No Related Types"
}
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@ module.exports = {
ns: 'aposImportExport',
browser: true
}
},

init(self) {
self.apos.asset.iconMap['apos-import-export-download-icon'] = 'Download';
},

apiRoutes(self) {
return {
get: {
async related(req) {
if (!req.user) {
throw self.apos.error('forbidden');
}

const type = self.apos.launder.string(req.query.type);
if (!type) {
throw self.apos.error('invalid');
}

const { schema = [] } = self.apos.modules[type];
const relatedTypes = schema.flatMap(searchRelationships).filter(Boolean);

return [ ...new Set(relatedTypes) ];

function searchRelationships(obj) {
if (obj.type === 'relationship') {
return obj.withType;
} else if (obj.type === 'array' || obj.type === 'object') {
return obj.schema.flatMap(searchRelationships);
} else if (obj.type === 'area') {
return Object.keys(obj.options.widgets).flatMap(widget => {
const { schema = [] } = self.apos.modules[`${widget}-widget`];
return schema.map(searchRelationships);
});
}
}
}
}
};
}
};

Expand Down
2 changes: 1 addition & 1 deletion modules/@apostrophecms/import-export-doc-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
action: 'export',
context: 'update',
label: 'aposImportExport:export',
modal: 'AposExportPiecesModal'
modal: 'AposExportModal'
};

if (self.options.export === false) {
Expand Down
2 changes: 1 addition & 1 deletion modules/@apostrophecms/import-export-piece-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
messages: {
progress: 'aposImportExport:exporting'
},
modal: 'AposExportPiecesModal'
modal: 'AposExportModal'
}
},
group: {
Expand Down
Loading

0 comments on commit 6211403

Please sign in to comment.