Skip to content

Commit 33f7829

Browse files
committed
docs: update docs for the hooks
1 parent 7e9937e commit 33f7829

File tree

1 file changed

+19
-11
lines changed
  • adminforth/documentation/docs/tutorial/03-Customization

1 file changed

+19
-11
lines changed

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,29 @@ Let's limit it:
189189
```ts title='./resources/apartments.ts'
190190
{
191191
...
192-
hooks: {
193-
dropdownList: {
194-
beforeDatasourceRequest: async ({ adminUser, query }: { adminUser: AdminUser, query: any }) => {
195-
if (adminUser.dbUser.role !== "superadmin") {
196-
query.filtersTools.replaceOrAddTopFilter(Filters.EQ("id", adminUser.dbUser.id));
197-
};
198-
return {
199-
"ok": true,
200-
};
201-
}
192+
193+
foreignResource: {
194+
195+
...
196+
197+
hooks: {
198+
dropdownList: {
199+
beforeDatasourceRequest: async ({ adminUser, query }: { adminUser: AdminUser, query: any }) => {
200+
if (adminUser.dbUser.role !== "superadmin") {
201+
query.filtersTools.replaceOrAddTopFilter(Filters.EQ("id", adminUser.dbUser.id));
202+
};
203+
return {
204+
"ok": true,
205+
};
206+
}
207+
},
202208
},
203-
},
209+
}
204210
}
205211
```
206212
213+
> ☝️☝️☝️ This hooks should be written only inside column. If you'll add it in resource hooks - it won't work
214+
207215
In our case we limit the dropdown list to show only the current user, however you can use same sample to list only objects who are related to the current user in case if you will have relation configurations which require to show related objects which belongs to the current user.
208216
209217
Flow diagram for dropdown list:

0 commit comments

Comments
 (0)