@@ -7,7 +7,7 @@ import type {
77import dayjs from 'dayjs'
88import utc from 'dayjs/plugin/utc.js' ;
99
10- import { AdminForthPlugin , AllowedActionsEnum , AdminForthSortDirections , AdminForthDataTypes , HttpExtra , ActionCheckSource , Filters , afLogger , } from "adminforth" ;
10+ import { AdminForthPlugin , AllowedActionsEnum , AdminForthSortDirections , AdminForthDataTypes , HttpExtra , ActionCheckSource , Filters , afLogger , encodeRecordId , isCompositePrimaryKey , primaryKeyColumnNames , } from "adminforth" ;
1111import { PluginOptions } from "./types.js" ;
1212
1313dayjs . extend ( utc ) ;
@@ -103,8 +103,8 @@ export default class AuditLogPlugin extends AdminForthPlugin {
103103 return { ok : true } ;
104104 }
105105
106- const recordIdFieldName = resource . columns . find ( ( c ) => c . primaryKey === true ) ?. name ;
107- const recordId = data ?. [ recordIdFieldName ] || oldRecord ?. [ recordIdFieldName ] ;
106+ // record id is built from all primary key columns, so resources with composite primary key are supported
107+ const recordId = encodeRecordId ( resource , { ... ( oldRecord || { } ) , ... ( data || { } ) } ) ;
108108 const connector = this . adminforth . connectors [ resource . dataSource ] ;
109109
110110 const newRecord = action == AllowedActionsEnum . delete ? { } : ( await connector . getRecordByPrimaryKey ( resource , recordId ) ) || { } ;
@@ -276,6 +276,8 @@ export default class AuditLogPlugin extends AdminForthPlugin {
276276 auditLogResourceId : this . auditLogResource ,
277277 resourceColumns : this . options . resourceColumns ,
278278 pkName : resource . columns . find ( ( c ) => c . primaryKey ) ?. name || 'id' ,
279+ // all primary key columns, so component can build record id of composite primary key resource
280+ pkNames : primaryKeyColumnNames ( resource ) ,
279281 title : 'Edit History'
280282 }
281283 }
@@ -345,6 +347,8 @@ export default class AuditLogPlugin extends AdminForthPlugin {
345347 auditLogResourceId : this . auditLogResource ,
346348 resourceColumns : this . options . resourceColumns ,
347349 pkName : resource . columns . find ( ( c ) => c . primaryKey ) ?. name || 'id' ,
350+ // all primary key columns, so component can build record id of composite primary key resource
351+ pkNames : primaryKeyColumnNames ( resource ) ,
348352 title : 'Edit History'
349353 }
350354 } ) ;
@@ -353,9 +357,26 @@ export default class AuditLogPlugin extends AdminForthPlugin {
353357 } )
354358 columnToModify . enum = existingResources ;
355359
360+ // make resource id clickable in show view, so user can navigate to the list of that resource
361+ columnToModify . components = columnToModify . components || { } ;
362+ if ( ! columnToModify . components . show ) {
363+ columnToModify . components . show = {
364+ file : this . componentPath ( 'ResourceIdLink.vue' ) ,
365+ meta : {
366+ pluginInstanceId : this . pluginInstanceId ,
367+ }
368+ } ;
369+ }
370+
356371 const recordIdColumn = resourceConfig . columns . find ( ( c ) => c . name === this . options . resourceColumns . resourceRecordIdColumnName ) ;
357372 if ( ! recordIdColumn . foreignResource ) {
358373 for ( const resource of existingResources ) {
374+ // core does not support foreignResource pointing to resource with composite primary key yet,
375+ // so such resources are still logged, but their record id is not clickable
376+ const targetResource = this . adminforth . config . resources . find ( ( r ) => r . resourceId === resource . value ) ;
377+ if ( targetResource && isCompositePrimaryKey ( targetResource ) ) {
378+ continue ;
379+ }
359380 if ( ! recordIdColumn . foreignResource ?. polymorphicResources ) {
360381 recordIdColumn . foreignResource = {
361382 polymorphicResources : [ ] ,
0 commit comments