[Feature]: @adminjs/relations remove "delete record" option
lpbonomi opened this issue · comments
Description
This is the current dialog when you click the trash can in the relations package:
![Screenshot 2024-02-05 at 17 29 28](https://private-user-images.githubusercontent.com/38361000/302421723-f9ec1a89-73d2-4b0f-9c75-335d95d365ab.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTQ1MDgzMDIsIm5iZiI6MTcxNDUwODAwMiwicGF0aCI6Ii8zODM2MTAwMC8zMDI0MjE3MjMtZjllYzFhODktNzNkMi00YjBmLTljNzUtMzM1ZDk1ZDM2NWFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDMwVDIwMTMyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1MTI1MjA4MmMxMjllMzAzYmI2ZTQyODNkOGFkZDBhM2QxYzczMzYwZWI1OWY5N2FlOGI0YTBkNjJmNzBhNzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.J4YNvKp9T4myZKKscC85axA96yrEXGMQxpRKa-70tF0)
I think that it is not a very good idea to have the option to delete a record when managing relations and even less as the primary option
Suggested Solution
My suggestion is to have a normal "Remove relation" dialog with a cancel/yes button.
Alternatives
No response
Additional Context
No response
@lpbonomi I've released 1.1.0
of @adminjs/relations
which allows you to configure deleteOptions
for M:N
export interface ManyToManyRelationOptions extends BaseRelationOptions {
type: RelationType.ManyToMany;
junction?: {
joinKey: string;
inverseJoinKey: string;
throughResourceId: string;
};
target: {
resourceId: string;
};
/**
* Override default delete options.
*/
deleteOptions?: {
/**
* Whether user can delete a relation (record in junction table)
*/
enableDeleteRelation: boolean;
/**
* Whether user can delete related record (target record).
* If target record's delete action is disabled, you won't be able to delete the record even if this option is set to true.
*/
enableDeleteRelatedRecord: boolean;
};
}
By default, both options are enabled to match previous behaviour. You can configure it to only display "Remove relation" button though:
deleteOptions: {
enableDeleteRelation: true,
enableDeleteRelatedRecord: false,
}