adminforth 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/AdminForthConfig.ts +95 -92
package/package.json
CHANGED
|
@@ -651,12 +651,101 @@ export type BeforeLoginConfirmationFunction = (params?: {
|
|
|
651
651
|
}
|
|
652
652
|
}>;
|
|
653
653
|
|
|
654
|
+
|
|
655
|
+
export type AdminForthBulkAction = {
|
|
656
|
+
id?: string,
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Label for action button which will be displayed in the list view
|
|
660
|
+
*/
|
|
661
|
+
label: string,
|
|
662
|
+
state: string,
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Icon for action button which will be displayed in the list view
|
|
666
|
+
*/
|
|
667
|
+
icon?: string,
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Callback which will be called on backend when user clicks on action button.
|
|
671
|
+
* It should return Promise which will be resolved when action is done.
|
|
672
|
+
*/
|
|
673
|
+
action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<void>,
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Confirmation message which will be displayed to user before action is executed.
|
|
677
|
+
*/
|
|
678
|
+
confirm?: string,
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Allowed callback called to check whether action is allowed for user.
|
|
682
|
+
* 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
|
|
683
|
+
* 2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed.
|
|
684
|
+
* In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional
|
|
685
|
+
* checks ( for example to check if user has permission for certain records ).
|
|
686
|
+
*
|
|
687
|
+
* Example:
|
|
688
|
+
*
|
|
689
|
+
* ```ts
|
|
690
|
+
* allowed: async ({ resource, adminUser, selectedIds }) => {
|
|
691
|
+
* if (adminUser.isRoot || adminUser.dbUser.role !== 'superadmin') {
|
|
692
|
+
* return false;
|
|
693
|
+
* }
|
|
694
|
+
* return true;
|
|
695
|
+
* }
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
*/
|
|
699
|
+
allowed?: ({ resource, adminUser, selectedIds, allowedActions }: {
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* recordIds will be passed only once user tries to perform bulk action by clicking on button
|
|
703
|
+
*/
|
|
704
|
+
selectedIds?: Array<any>,
|
|
705
|
+
resource: AdminForthResource,
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Admin user object
|
|
709
|
+
*/
|
|
710
|
+
adminUser: AdminUser,
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Allowed standard actions for current user resolved by calling allowedActions callbacks if they are passed.
|
|
714
|
+
* You can use this variable to rely on standard actions permissions. E.g. if you have custom actions "Mark as read", you
|
|
715
|
+
* might want to allow it only for users who have "edit" action allowed:
|
|
716
|
+
*
|
|
717
|
+
* Example:
|
|
718
|
+
*
|
|
719
|
+
* ```ts
|
|
720
|
+
*
|
|
721
|
+
* options: \{
|
|
722
|
+
* bulkActions: [
|
|
723
|
+
* \{
|
|
724
|
+
* label: 'Mark as read',
|
|
725
|
+
* action: async (\{ resource, recordIds \}) => \{
|
|
726
|
+
* await markAsRead(recordIds);
|
|
727
|
+
* \},
|
|
728
|
+
* allowed: (\{ allowedActions \}) => allowedActions.edit,
|
|
729
|
+
* \}
|
|
730
|
+
* ],
|
|
731
|
+
* allowedActions: \{
|
|
732
|
+
* edit: (\{ resource, adminUser, recordIds \}) => \{
|
|
733
|
+
* return adminUser.isRoot || adminUser.dbUser.role === 'superadmin';
|
|
734
|
+
* \}
|
|
735
|
+
* \}
|
|
736
|
+
* \}
|
|
737
|
+
* ```
|
|
738
|
+
*
|
|
739
|
+
*/
|
|
740
|
+
allowedActions: AllowedActionsResolved,
|
|
741
|
+
}) => Promise<boolean>,
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
|
|
654
745
|
/**
|
|
655
746
|
* Resource describes one table or collection in database.
|
|
656
747
|
* AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
|
|
657
748
|
*/
|
|
658
|
-
|
|
659
|
-
|
|
660
749
|
export type AdminForthResource = {
|
|
661
750
|
/**
|
|
662
751
|
* Unique identifier of resource. By default it equals to table name in database.
|
|
@@ -764,97 +853,11 @@ export type AdminForthResource = {
|
|
|
764
853
|
direction: AdminForthSortDirections | string,
|
|
765
854
|
}
|
|
766
855
|
|
|
767
|
-
/**
|
|
768
|
-
* Custom bulk actions list
|
|
856
|
+
/**
|
|
857
|
+
* Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
|
|
858
|
+
* using checkboxes.
|
|
769
859
|
*/
|
|
770
|
-
bulkActions?:
|
|
771
|
-
id?: string,
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* Label for action button which will be displayed in the list view
|
|
775
|
-
*/
|
|
776
|
-
label: string,
|
|
777
|
-
state: string,
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Icon for action button which will be displayed in the list view
|
|
781
|
-
*/
|
|
782
|
-
icon?: string,
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
* Callback which will be called on backend when user clicks on action button.
|
|
786
|
-
* It should return Promise which will be resolved when action is done.
|
|
787
|
-
*/
|
|
788
|
-
action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<void>,
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* Confirmation message which will be displayed to user before action is executed.
|
|
792
|
-
*/
|
|
793
|
-
confirm?: string,
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* Allowed callback called to check whether action is allowed for user.
|
|
797
|
-
* 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
|
|
798
|
-
* 2. This same callback called second time when user clicks an action button. If callback returns false, action will not be executed.
|
|
799
|
-
* In second time selectedIds will be passed to callback (because checkbox for items are selected), so you can use this to make additional
|
|
800
|
-
* checks ( for example to check if user has permission for certain records ).
|
|
801
|
-
*
|
|
802
|
-
* Example:
|
|
803
|
-
*
|
|
804
|
-
* ```ts
|
|
805
|
-
* allowed: async ({ resource, adminUser, selectedIds }) => {
|
|
806
|
-
* if (adminUser.isRoot || adminUser.dbUser.role !== 'superadmin') {
|
|
807
|
-
* return false;
|
|
808
|
-
* }
|
|
809
|
-
* return true;
|
|
810
|
-
* }
|
|
811
|
-
* ```
|
|
812
|
-
*
|
|
813
|
-
*/
|
|
814
|
-
allowed?: ({ resource, adminUser, selectedIds, allowedActions }: {
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* recordIds will be passed only once user tries to perform bulk action by clicking on button
|
|
818
|
-
*/
|
|
819
|
-
selectedIds?: Array<any>,
|
|
820
|
-
resource: AdminForthResource,
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Admin user object
|
|
824
|
-
*/
|
|
825
|
-
adminUser: AdminUser,
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Allowed standard actions for current user resolved by calling allowedActions callbacks if they are passed.
|
|
829
|
-
* You can use this variable to rely on standard actions permissions. E.g. if you have custom actions "Mark as read", you
|
|
830
|
-
* might want to allow it only for users who have "edit" action allowed:
|
|
831
|
-
*
|
|
832
|
-
* Example:
|
|
833
|
-
*
|
|
834
|
-
* ```ts
|
|
835
|
-
*
|
|
836
|
-
* options: {
|
|
837
|
-
* bulkActions: [
|
|
838
|
-
* {
|
|
839
|
-
* label: 'Mark as read',
|
|
840
|
-
* action: async ({ resource, recordIds }) => {
|
|
841
|
-
* await markAsRead(recordIds);
|
|
842
|
-
* },
|
|
843
|
-
* allowed: ({ allowedActions }) => allowedActions.edit,
|
|
844
|
-
* }
|
|
845
|
-
* ],
|
|
846
|
-
* allowedActions: {
|
|
847
|
-
* edit: ({ resource, adminUser, recordIds }) => {
|
|
848
|
-
* return adminUser.isRoot || adminUser.dbUser.role === 'superadmin';
|
|
849
|
-
* }
|
|
850
|
-
* }
|
|
851
|
-
* }
|
|
852
|
-
* ```
|
|
853
|
-
*
|
|
854
|
-
*/
|
|
855
|
-
allowedActions: AllowedActionsResolved,
|
|
856
|
-
}) => Promise<boolean>,
|
|
857
|
-
}[],
|
|
860
|
+
bulkActions?: AdminForthBulkAction[],
|
|
858
861
|
|
|
859
862
|
/**
|
|
860
863
|
* Allowed actions for resource.
|