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

feat: replaced AdminJS.bundle to ComponentLoader #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"adminjs": "^6.0.0"
},
"devDependencies": {
"@adminjs/design-system": "^3.1.0",
"@adminjs/design-system": "^3.1.8",
"@adminjs/express": "^4.0.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
Expand All @@ -36,7 +36,7 @@
"@types/xml2js": "^0.4.5",
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/parser": "^4.6.0",
"adminjs": "^6.0.0",
"adminjs": "^6.8.7",
"date-fns": "^2.16.1",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
Expand All @@ -47,20 +47,20 @@
"express-formidable": "^1.2.0",
"express-session": "^1.17.2",
"husky": "^4.3.0",
"jest": "^26.6.1",
"jest": "^29.5.0",
"prettier": "^2.7.1",
"semantic-release": "^17.2.2",
"ts-jest": "^26.4.3",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.0.2"
},
"dependencies": {
"@adminjs/mongoose": "^2.0.0",
"@types/mongoose": "^5.7.37",
"@adminjs/mongoose": "^3.0.3",
"@types/mongoose": "^5.11.97",
"csvtojson": "^2.0.10",
"file-saver": "^2.0.2",
"json2csv": "^5.0.3",
"mongoose": "^5.10.11",
"file-saver": "^2.0.5",
"json2csv": "^6.0.0-alpha.2",
"mongoose": "^7.0.3",
"xml": "^1.0.1",
"xml2js": "^0.4.23"
}
Expand Down
13 changes: 13 additions & 0 deletions src/bundle-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from 'path';

import type { ComponentLoader } from 'adminjs';

// const dirname = __dirname;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const bundleComponent = (
loader: ComponentLoader,
componentName: string
) => {
const componentPath = path.join(__dirname, `../components/${componentName}`);
return loader.add(componentName, componentPath);
};
15 changes: 0 additions & 15 deletions src/components/bundleComponents.ts

This file was deleted.

23 changes: 17 additions & 6 deletions src/importExportFeature.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { buildFeature, FeatureType } from 'adminjs';
import { bundleComponents } from './components/bundleComponents';
import { buildFeature, FeatureType, ComponentLoader } from 'adminjs';
import { postActionHandler } from './utils';
import { exportHandler } from './export.handler';
import { importHandler } from './import.handler';
import { bundleComponent } from './bundle-component';

const { EXPORT_COMPONENT, IMPORT_COMPONENT } = bundleComponents();
type ImportExportFeatureOptions = {
/**
* Your ComponentLoader instance. It is required for the feature to add it's components.
*/
componentLoader: ComponentLoader;
};

const importExportFeature = (
options: ImportExportFeatureOptions
): FeatureType => {
const { componentLoader } = options;
const importComponent = bundleComponent(componentLoader, 'ImportComponent');
const exportComponent = bundleComponent(componentLoader, 'ExportComponent');

const importExportFeature = (): FeatureType => {
return buildFeature({
actions: {
export: {
handler: postActionHandler(exportHandler),
component: EXPORT_COMPONENT,
component: exportComponent,
actionType: 'resource',
},
import: {
handler: postActionHandler(importHandler),
component: IMPORT_COMPONENT,
component: importComponent,
actionType: 'resource',
},
},
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

import importExportFeature from './importExportFeature';

export * from './components/bundleComponents';

export default importExportFeature;
8 changes: 5 additions & 3 deletions test/export-csv.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AdminJS from 'adminjs';
import AdminJS, { ComponentLoader } from 'adminjs';
import importExportFeature from '../src';
import mongoose from 'mongoose';
import MongooseAdapter from '@adminjs/mongoose';
Expand All @@ -12,6 +12,8 @@ const userSchema = new mongoose.Schema({
name: String,
});

const componentLoader = new ComponentLoader()

const User = mongoose.model('User', userSchema);
AdminJS.registerAdapter(MongooseAdapter);

Expand All @@ -27,7 +29,7 @@ class API extends ApiClient {
}

describe('CSV Export', () => {
it.skip('should assert true is ok', async function () {
it.skip('should assert true is ok', async function() {
const adminJs = new AdminJS({
resources: [
{
Expand All @@ -38,7 +40,7 @@ describe('CSV Export', () => {
name: 'Users',
},
},
features: [importExportFeature()],
features: [importExportFeature({ componentLoader })],
},
],
});
Expand Down
Loading