Skip to content

Commit caebcb8

Browse files
committed
Merge remote-tracking branch 'origin/feat/v5' into beta
2 parents c6fed34 + 12a9260 commit caebcb8

File tree

11 files changed

+1073
-1889
lines changed

11 files changed

+1073
-1889
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
}
2727
},
2828
"peerDependencies": {
29-
"@adminjs/design-system": "^3.0.4",
30-
"adminjs": "^6.4.1"
29+
"@adminjs/design-system": "^4.0.0-beta-v4.8",
30+
"adminjs": "^7.0.0-beta-v7.4"
3131
},
3232
"devDependencies": {
33-
"@adminjs/design-system": "^4.0.0-beta-v4.1",
33+
"@adminjs/design-system": "^4.0.0-beta-v4.8",
3434
"@commitlint/cli": "^17.4.4",
3535
"@commitlint/config-conventional": "^17.4.4",
3636
"@semantic-release/git": "^10.0.1",
3737
"@types/jest": "^29.5.0",
3838
"@types/lodash": "^4.14.191",
3939
"@typescript-eslint/eslint-plugin": "^5.56.0",
4040
"@typescript-eslint/parser": "^5.56.0",
41-
"adminjs": "^7.0.0-beta-v7.1",
41+
"adminjs": "^7.0.0-beta-v7.4",
4242
"dotenv-cli": "^7.1.0",
4343
"eslint": "^8.36.0",
4444
"eslint-config-prettier": "^8.8.0",

src/components/RecordDifference.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import React, { FC } from 'react';
2-
import { BasePropertyProps, flat } from 'adminjs';
31
import {
42
FormGroup,
53
Label,
64
Table as AdminTable,
7-
TableCell,
85
TableBody,
6+
TableCell,
97
TableHead,
108
TableRow,
119
} from '@adminjs/design-system';
12-
import { styled } from 'styled-components';
10+
import { BasePropertyProps, flat } from 'adminjs';
11+
import React, { FC } from 'react';
12+
import { styled } from '@adminjs/design-system/styled-components';
1313

1414
const Cell = styled(TableCell)`
1515
width: 100%;
@@ -44,9 +44,11 @@ const RecordDifference: FC<BasePropertyProps> = ({ record, property }) => {
4444
<Label>{property.label}</Label>
4545
<Table>
4646
<Head>
47-
<Cell>Property name</Cell>
48-
<Cell>Before</Cell>
49-
<Cell>After</Cell>
47+
<Row>
48+
<Cell>Property name</Cell>
49+
<Cell>Before</Cell>
50+
<Cell>After</Cell>
51+
</Row>
5052
</Head>
5153
<TableBody>
5254
{Object.entries(

src/components/bundle.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import loggerFeature from './logger.feature.js';
88

9-
export { bundleComponents } from './components/bundle.js';
109
export * from './constants.js';
1110
export { createLoggerResource } from './logger.resource.js';
1211
export * from './types.js';

src/log.action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111

1212
import { ADMINJS_LOGGER_DEFAULT_RESOURCE_ID } from './constants.js';
1313
import { MISSING_USER_ID_ERROR } from './errors.js';
14-
import { CreateLogActionParams, LoggerFeatureOptions } from './types.js';
14+
import { CreateLogActionParams, LoggerActionOptions } from './types.js';
1515
import { difference } from './utils/difference.js';
1616
import { getLogPropertyName } from './utils/get-log-property-name.js';
1717

@@ -145,7 +145,7 @@ const createPersistLogAction =
145145
(
146146
request: ActionRequest,
147147
context: ActionContext,
148-
options: LoggerFeatureOptions
148+
options: LoggerActionOptions
149149
) =>
150150
async ({ recordId, record, initialRecord }: CreatePersistLogParams) => {
151151
const { currentAdmin, _admin, action } = context;
@@ -204,7 +204,7 @@ const createPersistLogAction =
204204
await Log.create(logParams);
205205
} catch (e) {
206206
/* The action should not fail nor display a message to the end-user
207-
but we must log the error in server's console for developers */
207+
but we must log the error in server's console for developers */
208208
console.error(e);
209209
}
210210
};

src/logger.resource.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import { ResourceWithOptions } from 'adminjs';
1+
import { ComponentLoader, ResourceWithOptions } from 'adminjs';
22

3-
import { bundleComponents } from './components/bundle.js';
3+
import { bundleComponent } from './utils/bundle-component.js';
44
import { ADMINJS_LOGGER_DEFAULT_RESOURCE_ID } from './constants.js';
55
import { LoggerFeatureOptions } from './types.js';
66
import { getLogPropertyName } from './utils/get-log-property-name.js';
77

8-
const { RECORD_DIFFERENCE, RECORD_LINK } = bundleComponents();
9-
108
export const createLoggerResource = <T = unknown>({
9+
componentLoader,
1110
resource,
1211
featureOptions,
1312
}: {
13+
componentLoader: ComponentLoader;
1414
resource: T;
1515
featureOptions?: LoggerFeatureOptions;
1616
}): ResourceWithOptions => {
1717
const { resourceOptions = {}, propertiesMapping = {} } = featureOptions ?? {};
1818
const { resourceId, navigation, actions = {} } = resourceOptions;
19-
19+
const recordDifferenceComponent = bundleComponent(
20+
componentLoader,
21+
'RecordDifference'
22+
);
23+
const recordLinkComponent = bundleComponent(componentLoader, 'RecordLink');
2024
return {
2125
resource,
2226
options: {
@@ -55,7 +59,7 @@ export const createLoggerResource = <T = unknown>({
5559
},
5660
[getLogPropertyName('difference', propertiesMapping)]: {
5761
components: {
58-
show: RECORD_DIFFERENCE,
62+
show: recordDifferenceComponent,
5963
},
6064
custom: {
6165
propertiesMapping,
@@ -64,8 +68,8 @@ export const createLoggerResource = <T = unknown>({
6468
},
6569
[getLogPropertyName('recordId', propertiesMapping)]: {
6670
components: {
67-
list: RECORD_LINK,
68-
show: RECORD_LINK,
71+
list: recordLinkComponent,
72+
show: recordLinkComponent,
6973
},
7074
custom: {
7175
propertiesMapping,

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Action,
3+
ComponentLoader,
34
ListActionResponse,
45
RecordActionResponse,
56
ResourceOptions,
@@ -53,7 +54,7 @@ export type LoggerPropertiesMapping = {
5354

5455
export type CreateLogActionParams = {
5556
onlyForPostMethod?: boolean;
56-
options?: LoggerFeatureOptions;
57+
options?: LoggerActionOptions;
5758
};
5859

5960
/**
@@ -78,6 +79,10 @@ export type LoggerResourceOptions = {
7879
* @alias LoggerFeatureOptions
7980
*/
8081
export type LoggerFeatureOptions = {
82+
/**
83+
* Your ComponentLoader instance. It is required for the feature to add it's components.
84+
*/
85+
componentLoader: ComponentLoader;
8186
/**
8287
* For the feature to work you must define a model using an ORM of your choice.
8388
* In case you want to use different attribute names, you can use this
@@ -93,3 +98,5 @@ export type LoggerFeatureOptions = {
9398
*/
9499
resourceOptions?: LoggerResourceOptions;
95100
};
101+
102+
export type LoggerActionOptions = Omit<LoggerFeatureOptions, 'componentLoader'>;

src/utils/bundle-component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'path';
2+
import * as url from 'url';
3+
4+
import type { ComponentLoader } from 'adminjs';
5+
6+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
7+
8+
export const bundleComponent = (
9+
loader: ComponentLoader,
10+
componentName: string
11+
) => {
12+
const componentPath = path.join(__dirname, `../components/${componentName}`);
13+
return loader.add(componentName, componentPath);
14+
};

src/utils/with-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CreateLogActionParams } from '../types.js';
55

66
export const withLogger = (
77
action: Partial<Action<ActionResponse>>,
8-
{ onlyForPostMethod, options = {} }: CreateLogActionParams
8+
{ onlyForPostMethod, options }: CreateLogActionParams
99
): Partial<Action<ActionResponse>> => ({
1010
...action,
1111
before: (Array.isArray(action.before)

test/utils/with-logger.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ describe('withLogger', () => {
88
before: [stubFunction],
99
};
1010
const mergedAction = withLogger(initialAction, {});
11-
1211
expect(mergedAction.after).toContain(stubFunction);
1312
expect(mergedAction.after?.length).toEqual(2);
1413
expect(mergedAction.before).toContain(stubFunction);

0 commit comments

Comments
 (0)