SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js

Home Page:https://adminjs.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[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

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,
}

Amazing @dziraf , you've been making my whole week, thanks!