Skip to content

Commit aec692b

Browse files
committed
feat: pass resource to the listTableClickUrl prop
1 parent 2b797a4 commit aec692b

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

adminforth/documentation/docs/tutorial/03-Customization/13-standardPagesTuning.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export default {
360360
options: {
361361
...
362362
//diff-add
363-
listTableClickUrl: async (record, adminUser) => null,
363+
listTableClickUrl: async (record, adminUser, resource) => null,
364364
}
365365
}
366366
]
@@ -372,7 +372,7 @@ To open a custom page, return URL to the custom page (can start with https://, o
372372
options: {
373373
...
374374
//diff-add
375-
listTableClickUrl: async (record, adminUser) => {
375+
listTableClickUrl: async (record, adminUser, resource) => {
376376
//diff-add
377377
return `https://google.com/search?q=${record.title}`;
378378
//diff-add
@@ -386,14 +386,28 @@ If you wish to open the page in a new tab, add `target=_blank` get param to the
386386
options: {
387387
...
388388
//diff-add
389-
listTableClickUrl: async (record, adminUser) => {
389+
listTableClickUrl: async (record, adminUser, resource) => {
390390
//diff-add
391391
return `https://google.com/search?q=${record.name}&target=_blank`;
392392
//diff-add
393393
}
394394
}
395395
```
396396

397+
### How to open edit instead of show by click in list table
398+
By using `options.listTableClickUrl` you can open edit view by clicking record, instead of show view:
399+
400+
```ts
401+
options: {
402+
...
403+
//diff-add
404+
listTableClickUrl: async (record, adminUser, resource) => {
405+
//diff-add
406+
return `/resource/${resource.resourceId}/edit/${record[pkFileldName]}`;
407+
//diff-add
408+
}
409+
}
410+
```
397411

398412
### Auto-refresh records
399413

adminforth/modules/restApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
925925
if (source === 'list' && resource.options.listTableClickUrl) {
926926
await Promise.all(
927927
data.data.map(async (item) => {
928-
item._clickUrl = await resource.options.listTableClickUrl(item, adminUser);
928+
item._clickUrl = await resource.options.listTableClickUrl(item, adminUser, resource);
929929
})
930930
);
931931
}

adminforth/types/Common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export interface AdminForthComponentDeclarationFull {
296296
[key: string]: any,
297297
}
298298
}
299-
import { type AdminForthActionInput } from './Back.js'
299+
import { type AdminForthActionInput, type AdminForthResource } from './Back.js'
300300
export { type AdminForthActionInput } from './Back.js'
301301

302302
export type AdminForthComponentDeclaration = AdminForthComponentDeclarationFull | string;
@@ -447,7 +447,7 @@ export interface AdminForthResourceInputCommon {
447447
* If you wish to open page in new tab, add `target=_blank` get param to returned URL, example:
448448
*
449449
* ```ts
450-
* listTableClickUrl: async (record, adminUser) => {
450+
* listTableClickUrl: async (record, adminUser, resource) => {
451451
* return `https://google.com/search?q=${record.name}&target=_blank`;
452452
* }
453453
* ```
@@ -457,7 +457,7 @@ export interface AdminForthResourceInputCommon {
457457
* Example:
458458
*
459459
* ```ts
460-
* listTableClickUrl: async (record, adminUser) => {
460+
* listTableClickUrl: async (record, adminUser, resource) => {
461461
* return null;
462462
* }
463463
* ```
@@ -466,7 +466,7 @@ export interface AdminForthResourceInputCommon {
466466
* @param adminUser - user who clicked
467467
* @returns
468468
*/
469-
listTableClickUrl?: (record: any, adminUser: AdminUser) => Promise<string | null>,
469+
listTableClickUrl?: (record: any, adminUser: AdminUser, resource: AdminForthResource) => Promise<string | null>,
470470

471471
/**
472472
* Whether to refresh existing list rows automatically every N seconds.

dev-demo/resources/carsResourseTemplate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ export default function carsResourseTemplate(resourceId: string, dataSource: str
347347
show: true,
348348
filter: true,
349349
},
350+
listTableClickUrl: async (record, adminUser, resource) => {
351+
return `/resource/${resource.resourceId}/edit/${record[pkFileldName]}`;
352+
},
350353
actions: [
351354
{
352355
name: 'Approve Listing',

0 commit comments

Comments
 (0)