Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix routes and events to avoid conflicts with the old modules #50

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": [ "apostrophe", "plugin:vue/vue3-recommended" ],
"globals": {
"apos": true
},
"rules": {
"max-len": "off"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing this is just not in the scope of that PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that rule just added after having upgraded the dev deps

}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Changes

* Prefix routes and events to avoid conflicts with the old [`@apostrophecms/piece-type-importer`](https://github.com/apostrophecms/piece-type-importer) and [`@apostrophecms/piece-type-exporter`](https://github.com/apostrophecms/piece-type-exporter) modules.

## 1.2.0 (2023-11-29)

### Adds
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ module.exports = self => {
icon: 'database-export-icon',
type: 'success',
event: {
name: 'export-download',
name: 'import-export-export-download',
data: {
url: downloadUrl
}
Expand Down
6 changes: 3 additions & 3 deletions lib/methods/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = self => {
await self.apos.notify(req, ' ', {
type: 'warning',
event: {
name: 'import-locale-differs',
name: 'import-export-import-locale-differs',
data: {
moduleName,
exportPath,
Expand Down Expand Up @@ -95,7 +95,7 @@ module.exports = self => {
icon: 'database-import-icon',
type: failedIds.length ? 'danger' : 'success',
event: {
name: 'import-ended'
name: 'import-export-import-ended'
}
});

Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports = self => {
await self.apos.notify(req, ' ', {
type: 'warning',
event: {
name: 'import-duplicates',
name: 'import-export-import-duplicates',
data: results
},
classes: [ 'apos-notification--hidden' ]
Expand Down
4 changes: 2 additions & 2 deletions modules/@apostrophecms/import-export-doc-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {

init(self) {
const operation = {
action: 'export',
action: 'import-export-export',
context: 'update',
label: 'aposImportExport:export',
modal: 'AposExportModal',
props: {
action: 'export'
action: 'import-export-export'
}
};

Expand Down
8 changes: 4 additions & 4 deletions modules/@apostrophecms/import-export-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {

return {
add: {
import: {
'import-export-import': {
label: 'aposImportExport:import',
modalOptions: {
modal: 'AposImportModal'
Expand All @@ -24,16 +24,16 @@ module.exports = {
return {
post: {
...self.options.importExport?.import !== false && {
import: [
importExportImport: [
multiparty(),
async (req) => {
return self.apos.modules['@apostrophecms/import-export'].import(req, self.__meta.name);
}
]
},
...self.options.importExport?.export !== false && {
export(req) {
// Add the page label to req.body for notifications.
importExportExport(req) {
// Add the page label to req.body for notifications.
req.body.type = req.t('apostrophe:page');

return self.apos.modules['@apostrophecms/import-export'].export(req, self);
Expand Down
14 changes: 7 additions & 7 deletions modules/@apostrophecms/import-export-piece-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {

return {
add: {
import: {
'import-export-import': {
label: 'aposImportExport:import',
modalOptions: {
modal: 'AposImportModal'
Expand All @@ -26,21 +26,21 @@ module.exports = {

return {
add: {
'export-batch': {
'import-export-export-batch': {
label: 'aposImportExport:export',
messages: {
progress: 'aposImportExport:exporting',
completed: 'aposImportExport:exported',
icon: 'database-export-icon',
resultsEventName: 'export-download'
resultsEventName: 'import-export-export-download'
},
modal: 'AposExportModal'
}
},
group: {
more: {
icon: 'dots-vertical-icon',
operations: [ 'export-batch' ]
operations: [ 'import-export-export-batch' ]
}
}
};
Expand All @@ -49,7 +49,7 @@ module.exports = {
return {
post: {
...self.options.importExport?.import !== false && {
import: [
importExportImport: [
multiparty(),
async (req) => {
return self.apos.modules['@apostrophecms/import-export'].import(req, self.__meta.name);
Expand All @@ -58,7 +58,7 @@ module.exports = {
},

...self.options.importExport?.export !== false && {
export(req) {
importExportExport(req) {
// Add the piece type label to req.body for notifications.
req.body.type = req.t(self.options.label);

Expand All @@ -68,7 +68,7 @@ module.exports = {
// in order to make the job work with the progress notification.
// The other 'export' routes that are used by context operations on each doc
// are also POST for consistency.
exportBatch(req) {
importExportExportBatch(req) {
// Add the piece type label to req.body for notifications.
// Should be done before calling the job's `run` method.
req.body.type = req.body._ids.length === 1
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
"devDependencies": {
"apostrophe": "github:apostrophecms/apostrophe",
"eslint": "^8.44.0",
"eslint-config-apostrophe": "^4.0.0",
"eslint-config-apostrophe": "^4.2.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
Copy link
Contributor Author

@ETLaurent ETLaurent Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated, keeping it made npm i fail

"eslint-plugin-vue": "^9.15.1",
"eslint-plugin-vue": "^9.19.2",
"mocha": "^10.2.0",
"stylelint": "^15.9.0",
"stylelint-config-apostrophe": "^3.0.0",
"vue-eslint-parser": "^9.3.1"
"vue-eslint-parser": "^9.3.2"
},
"dependencies": {
"bluebird": "^3.7.2",
Expand All @@ -38,4 +37,4 @@
"lodash": "^4.17.21",
"tar-stream": "^3.1.6"
}
}
}
10 changes: 5 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ describe('@apostrophecms/import-export', function () {
};
};
apos.notify = async (req, message, options) => {
if (options?.event?.name === 'import-locale-differs') {
if (options?.event?.name === 'import-export-import-locale-differs') {
throw new Error('should not have been called with event "import-locale-differ"');
}
return {};
Expand Down Expand Up @@ -824,7 +824,7 @@ describe('@apostrophecms/import-export', function () {
};
};
apos.notify = async (req, message, options) => {
if (options?.event?.name === 'import-locale-differs') {
if (options?.event?.name === 'import-export-import-locale-differs') {
throw new Error('should not have been called with event "import-locale-differ"');
}
return {};
Expand Down Expand Up @@ -948,7 +948,7 @@ describe('@apostrophecms/import-export', function () {
};
};
apos.notify = async (req, message, options) => {
if (options?.event?.name === 'import-locale-differs') {
if (options?.event?.name === 'import-export-import-locale-differs') {
throw new Error('should not have been called with event "import-locale-differ"');
}
return {};
Expand Down Expand Up @@ -980,7 +980,7 @@ describe('@apostrophecms/import-export', function () {
throw new Error('should not have been called');
};
apos.notify = async (req, message, options) => {
assert.equal(options.event.name, 'import-locale-differs');
assert.equal(options.event.name, 'import-export-import-locale-differs');
};

await importExportManager.import(req);
Expand Down Expand Up @@ -1040,7 +1040,7 @@ describe('@apostrophecms/import-export', function () {
};
};
apos.notify = async (req, message, options) => {
if (options?.event?.name === 'import-locale-differs') {
if (options?.event?.name === 'import-export-import-locale-differs') {
throw new Error('should not have been called with event "import-locale-differ"');
}
return {};
Expand Down
12 changes: 6 additions & 6 deletions ui/apos/apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export default () => {
apos.util.onReady(() => {
if (!ready) {
ready = true;
apos.bus.$on('export-download', openUrl);
apos.bus.$on('import-started', addBeforeUnloadListener);
apos.bus.$on('import-ended', removeBeforeUnloadListener);
apos.bus.$on('import-locale-differs', handleDifferentLocale);
apos.bus.$on('import-duplicates', handleDuplicates);
apos.bus.$on('import-export-export-download', openUrl);
apos.bus.$on('import-export-import-started', addBeforeUnloadListener);
apos.bus.$on('import-export-import-ended', removeBeforeUnloadListener);
apos.bus.$on('import-export-import-locale-differs', handleDifferentLocale);
apos.bus.$on('import-export-import-duplicates', handleDuplicates);
}
});

Expand All @@ -33,7 +33,7 @@ export default () => {
try {
const moduleAction = apos.modules[event.moduleName].action;

await apos.http.post(`${moduleAction}/import`, {
await apos.http.post(`${moduleAction}/import-export-import`, {
body: {
overrideLocale: true,
exportPath: event.exportPath
Expand Down
2 changes: 1 addition & 1 deletion ui/apos/components/AposDuplicateImportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
}
});
} finally {
apos.bus.$emit('import-ended');
apos.bus.$emit('import-export-import-ended');
}
},
ready() {
Expand Down
4 changes: 2 additions & 2 deletions ui/apos/components/AposImportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export default {
const formData = new FormData();
formData.append('file', this.selectedFile);

apos.bus.$emit('import-started');
apos.bus.$emit('import-export-import-started');
apos.http.post(`${this.moduleAction}/${this.action}`, {
body: formData
}).catch(() => {
apos.notify('aposImportExport:importFailed', {
type: 'danger',
dismiss: true
});
apos.bus.$emit('import-ended');
apos.bus.$emit('import-export-import-ended');
});

this.modal.showModal = false;
Expand Down