Skip to content

Commit 1a1fc7b

Browse files
authored
Merge pull request #3 from SoftwareBrothers/feat/rebrand
chore: rebrand AdminBro to AdminJS
2 parents 3be3d46 + a9e734f commit 1a1fc7b

File tree

16 files changed

+4485
-4732
lines changed

16 files changed

+4485
-4732
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Setup
1111
uses: actions/setup-node@v1
1212
with:
13-
node-version: '10.x'
13+
node-version: '14'
1414
- uses: actions/cache@v1
1515
id: yarn-cache
1616
with:

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
registry=https://npm.pkg.github.com/SoftwareBrothers
1+
access=public

.releaserc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"semantic-release-slack-bot",
2020
{
2121
"notifyOnSuccess": true,
22-
"notifyOnFail": true
22+
"notifyOnFail": false
2323
}
2424
]
2525
]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2018 SoftwareBrothers.co
1+
Copyright 2021 SoftwareBrothers.co
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Logger Feature for AdminBro
1+
# Logger Feature for AdminJS
22

3-
This is an official [AdminBro](https://github.com/SoftwareBrothers/admin-bro) feature which logs changes to resources.
3+
This is an official [AdminJS](https://github.com/SoftwareBrothers/adminjs) feature which logs changes to resources.
44

5-
## AdminBro
5+
## AdminJS
66

7-
AdminBro is an automatic admin interface which can be plugged into your application. You, as a developer, provide database models (like posts, comments, stores, products or whatever else your application uses), and AdminBro generates UI which allows you (or other trusted users) to manage content.
7+
AdminJS is an automatic admin interface which can be plugged into your application. You, as a developer, provide database models (like posts, comments, stores, products or whatever else your application uses), and AdminJS generates UI which allows you (or other trusted users) to manage content.
88

99
Check out the example application with mongo and postgres models here: https://admin-bro-example-app-staging.herokuapp.com/admin
1010

11-
Or visit [AdminBro](https://github.com/SoftwareBrothers/admin-bro) github page.
11+
Or visit [AdminJS](https://github.com/SoftwareBrothers/adminjs) github page.
1212

1313
## Usage
1414

1515

1616
## License
1717

18-
AdminBro is Copyright © 2020 SoftwareBrothers.co. It is free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE.md) file.
18+
AdminJS is Copyright © 2021 SoftwareBrothers.co. It is free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE.md) file.
1919

2020
## About SoftwareBrothers.co
2121

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "@softwarebrothers/admin-bro-logger",
2+
"name": "@adminjs/logger",
33
"version": "1.0.1",
44
"main": "lib/index.js",
55
"types": "types/index.d.ts",
66
"private": false,
7-
"repository": "[email protected]:SoftwareBrothers/admin-bro-logger.git",
7+
"repository": "[email protected]:SoftwareBrothers/adminjs-logger.git",
88
"license": "MIT",
99
"scripts": {
1010
"release": "semantic-release",
@@ -20,16 +20,18 @@
2020
}
2121
},
2222
"peerDependencies": {
23-
"admin-bro": ">=3.3.0-beta.13"
23+
"adminjs": "^5.3.1",
24+
"@adminjs/design-system": "^2.0.2"
2425
},
2526
"devDependencies": {
27+
"@adminjs/design-system": "^2.0.2",
2628
"@commitlint/cli": "^8.3.5",
2729
"@commitlint/config-conventional": "^8.3.4",
2830
"@semantic-release/git": "^9.0.0",
2931
"@types/jest": "^26.0.14",
3032
"@typescript-eslint/eslint-plugin": "^3.7.0",
3133
"@typescript-eslint/parser": "^3.7.0",
32-
"admin-bro": "3.3.0-beta.13",
34+
"adminjs": "^5.3.1",
3335
"eslint": "^7.5.0",
3436
"eslint-config-prettier": "^6.10.1",
3537
"eslint-plugin-import": "^2.22.0",

src/components/RecordDifference.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FC } from 'react';
2-
import { BasePropertyProps, flat } from 'admin-bro';
2+
import { BasePropertyProps, flat } from 'adminjs';
33
import {
44
FormGroup,
55
Label,
@@ -8,7 +8,7 @@ import {
88
TableBody,
99
TableHead,
1010
TableRow,
11-
} from '@admin-bro/design-system';
11+
} from '@adminjs/design-system';
1212
import styled from 'styled-components';
1313

1414
const Cell = styled(TableCell)`
@@ -31,6 +31,7 @@ const Table = styled(AdminTable)`
3131

3232
const RecordDifference: FC<BasePropertyProps> = ({ record, property }) => {
3333
const differences = JSON.parse(
34+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3435
(flat.unflatten(record?.params ?? {}) as any)?.[property.name] ?? {}
3536
);
3637
if (!differences) {

src/components/RecordLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC } from 'react';
2-
import { BasePropertyProps, ViewHelpers } from 'admin-bro';
3-
import { FormGroup, Link } from '@admin-bro/design-system';
2+
import { BasePropertyProps, ViewHelpers } from 'adminjs';
3+
import { FormGroup, Link } from '@adminjs/design-system';
44

55
const viewHelpers = new ViewHelpers();
66
const RecordLink: FC<BasePropertyProps> = ({ record }) => {

src/components/bundle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import AdminBro from 'admin-bro';
1+
import AdminJS from 'adminjs';
22

33
export const bundleComponents = (): {
44
RECORD_DIFFERENCE: string;
55
RECORD_LINK: string;
66
} => {
77
return {
8-
RECORD_DIFFERENCE: AdminBro.bundle('../../src/components/RecordDifference'),
9-
RECORD_LINK: AdminBro.bundle('../../src/components/RecordLink'),
8+
RECORD_DIFFERENCE: AdminJS.bundle('../../src/components/RecordDifference'),
9+
RECORD_LINK: AdminJS.bundle('../../src/components/RecordLink'),
1010
};
1111
};

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @module @admin-bro/logger
2+
* @module @adminjs/logger
33
* @subcategory Features
44
* @section modules
55
*/

src/log.action.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActionResponse, After, Before, flat } from 'admin-bro';
1+
import { ActionResponse, After, Before, flat } from 'adminjs';
22
import { merge } from 'lodash';
33
import { difference } from './utils/difference';
44

@@ -25,55 +25,55 @@ const getRecordTitle = modifiedRecord => {
2525
);
2626
};
2727

28-
export const createLogAction = ({
29-
onlyForPostMethod = false,
30-
}: CreateLogActionParams = {}): After<ActionResponse> => async (
31-
response,
32-
request,
33-
context
34-
) => {
35-
const { currentAdmin, _admin } = context;
36-
const { params, method } = request;
37-
const Log = _admin.findResource('Log');
38-
const ModifiedResource = _admin.findResource(params.resourceId);
28+
export const createLogAction =
29+
({
30+
onlyForPostMethod = false,
31+
}: CreateLogActionParams = {}): After<ActionResponse> =>
32+
async (response, request, context) => {
33+
const { currentAdmin, _admin } = context;
34+
const { params, method } = request;
35+
const Log = _admin.findResource('Log');
36+
const ModifiedResource = _admin.findResource(params.resourceId);
3937

40-
if (!params.recordId || (onlyForPostMethod && !(method === 'post'))) {
41-
return response;
42-
}
43-
44-
const currentUser = currentAdmin?.id ?? currentAdmin?._id ?? currentAdmin;
45-
46-
try {
47-
const modifiedRecord = merge(
48-
JSON.parse(JSON.stringify(context.record)),
49-
await ModifiedResource.findOne(params.recordId)
50-
);
51-
if (!modifiedRecord) {
38+
if (!params.recordId || (onlyForPostMethod && !(method === 'post'))) {
5239
return response;
5340
}
5441

55-
const newParamsToCompare =
56-
params.action === 'delete'
57-
? {}
58-
: flat.flatten(JSON.parse(JSON.stringify(modifiedRecord.params)));
59-
await Log.create({
60-
recordTitle: getRecordTitle(modifiedRecord),
61-
resource: params.resourceId,
62-
action: params.action,
63-
recordId:
64-
params.recordId ?? typeof modifiedRecord.id === 'string'
65-
? modifiedRecord.id
66-
: modifiedRecord.id?.(),
67-
user: currentUser,
68-
difference: JSON.stringify(
69-
difference(
70-
newParamsToCompare,
71-
flat.flatten(JSON.parse(JSON.stringify(context.initialRecord.params)))
72-
)
73-
),
74-
});
75-
} catch (e) {
76-
console.error(e);
77-
}
78-
return response;
79-
};
42+
const currentUser = currentAdmin?.id ?? currentAdmin?._id ?? currentAdmin;
43+
44+
try {
45+
const modifiedRecord = merge(
46+
JSON.parse(JSON.stringify(context.record)),
47+
await ModifiedResource.findOne(params.recordId)
48+
);
49+
if (!modifiedRecord) {
50+
return response;
51+
}
52+
53+
const newParamsToCompare =
54+
params.action === 'delete'
55+
? {}
56+
: flat.flatten(JSON.parse(JSON.stringify(modifiedRecord.params)));
57+
await Log.create({
58+
recordTitle: getRecordTitle(modifiedRecord),
59+
resource: params.resourceId,
60+
action: params.action,
61+
recordId:
62+
params.recordId ?? typeof modifiedRecord.id === 'string'
63+
? modifiedRecord.id
64+
: modifiedRecord.id?.(),
65+
user: currentUser,
66+
difference: JSON.stringify(
67+
difference(
68+
newParamsToCompare,
69+
flat.flatten(
70+
JSON.parse(JSON.stringify(context.initialRecord.params))
71+
)
72+
)
73+
),
74+
});
75+
} catch (e) {
76+
console.error(e);
77+
}
78+
return response;
79+
};

src/logger.feature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildFeature, FeatureType } from 'admin-bro';
1+
import { buildFeature, FeatureType } from 'adminjs';
22
import { createLogAction, rememberInitialRecord } from './log.action';
33

44
const loggerFeature = (): FeatureType => {

src/logger.resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ResourceWithOptions } from 'admin-bro';
1+
import { ResourceWithOptions } from 'adminjs';
22
import { bundleComponents } from './components/bundle';
33

44
const { RECORD_DIFFERENCE, RECORD_LINK } = bundleComponents();

src/utils/with-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action, ActionResponse, After, Before } from 'admin-bro';
1+
import { Action, ActionResponse, After, Before } from 'adminjs';
22
import { createLogAction, rememberInitialRecord } from '../log.action';
33

44
export const withLogger = (

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"baseUrl": "./",
1616
"outDir": "lib",
1717
"declarationDir": "types",
18+
"skipLibCheck": true,
1819
"allowSyntheticDefaultImports": true
1920
},
2021
"exclude": ["test", "lib", "types"]

0 commit comments

Comments
 (0)