Skip to content

Commit 1e41e53

Browse files
committed
- show hook is now called as it was when user edits the page
1 parent 373a552 commit 1e41e53

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- now you should use import adminforth from '@/adminforth' instead of window.adminforth. It has type hints and is more reliable
1313

14+
### Fixed
15+
- show hook is now called as it was when user edits the page
1416

1517
## [v1.5.8]
1618

adminforth/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
IWebSocketBroker,
2121
HttpExtra,
2222
BeforeCreateSaveFunction,
23+
AdminForthInputConfig,
2324
} from './types/Back.js';
2425

2526
import {
@@ -93,7 +94,7 @@ class AdminForth implements IAdminForth {
9394
dbDiscover: 'running' | 'done',
9495
}
9596

96-
constructor(config: AdminForthConfig) {
97+
constructor(config: AdminForthInputConfig) {
9798
this.codeInjector = new CodeInjector(this);
9899
this.configValidator = new ConfigValidator(this, config);
99100
this.restApi = new AdminForthRestAPI(this);

adminforth/modules/restApi.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,13 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
574574
return { error };
575575
}
576576

577-
for (const hook of listify(resource.hooks?.[source]?.beforeDatasourceRequest)) {
577+
const hookSource = {
578+
'show': 'show',
579+
'list': 'list',
580+
'edit': 'show',
581+
}[source];
582+
583+
for (const hook of listify(resource.hooks?.[hookSource]?.beforeDatasourceRequest)) {
578584
const resp = await hook({
579585
resource,
580586
query: body,
@@ -596,17 +602,17 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
596602

597603
for (const filter of (filters || [])) {
598604
if (!Object.values(AdminForthFilterOperators).includes(filter.operator)) {
599-
throw new Error(`Operator '${filter.operator}' is not allowed`);
605+
throw new Error(`Operator '${filter.operator}' is not allowed`);
600606
}
601607

602608
if (!resource.columns.some((col) => col.name === filter.field)) {
603-
throw new Error(`Field '${filter.field}' is not in resource '${resource.resourceId}'. Available fields: ${resource.columns.map((col) => col.name).join(', ')}`);
609+
throw new Error(`Field '${filter.field}' is not in resource '${resource.resourceId}'. Available fields: ${resource.columns.map((col) => col.name).join(', ')}`);
604610
}
605611

606612
if (filter.operator === AdminForthFilterOperators.IN || filter.operator === AdminForthFilterOperators.NIN) {
607-
if (!Array.isArray(filter.value)) {
608-
throw new Error(`Value for operator '${filter.operator}' should be an array`);
609-
}
613+
if (!Array.isArray(filter.value)) {
614+
throw new Error(`Value for operator '${filter.operator}' should be an array`);
615+
}
610616
}
611617

612618

@@ -674,7 +680,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
674680
}
675681

676682
// only after adminforth made all post processing, give user ability to edit it
677-
for (const hook of listify(resource.hooks?.[source]?.afterDatasourceResponse)) {
683+
for (const hook of listify(resource.hooks?.[hookSource]?.afterDatasourceResponse)) {
678684
const resp = await hook({
679685
resource,
680686
response:

0 commit comments

Comments
 (0)