bulk-action.mdx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. ---
  2. title: "BulkAction"
  3. generated: true
  4. ---
  5. <GenerationInfo sourceFile="packages/admin-ui/src/lib/core/src/providers/bulk-action-registry/bulk-action-types.ts" sourceLine="99" packageName="@vendure/admin-ui" since="1.8.0" />
  6. Configures a bulk action which can be performed on all selected items in a list view.
  7. For a full example, see the <DocsLink href="/reference/admin-ui-api/bulk-actions/register-bulk-action#registerbulkaction">registerBulkAction</DocsLink> docs.
  8. ```ts title="Signature"
  9. interface BulkAction<ItemType = any, ComponentType = any> {
  10. location: BulkActionLocationId;
  11. label: string;
  12. getTranslationVars?: (
  13. context: BulkActionFunctionContext<ItemType, ComponentType>,
  14. ) => Record<string, string | number> | Promise<Record<string, string | number>>;
  15. icon?: string;
  16. iconClass?: string;
  17. onClick: (context: BulkActionClickContext<ItemType, ComponentType>) => void;
  18. isVisible?: (context: BulkActionFunctionContext<ItemType, ComponentType>) => boolean | Promise<boolean>;
  19. requiresPermission?: string | ((userPermissions: string[]) => boolean);
  20. }
  21. ```
  22. <div className="members-wrapper">
  23. ### location
  24. <MemberInfo kind="property" type={`<a href='/reference/admin-ui-api/bulk-actions/bulk-action#bulkactionlocationid'>BulkActionLocationId</a>`} />
  25. ### label
  26. <MemberInfo kind="property" type={`string`} />
  27. ### getTranslationVars
  28. <MemberInfo kind="property" type={`( context: <a href='/reference/admin-ui-api/bulk-actions/bulk-action#bulkactionfunctioncontext'>BulkActionFunctionContext</a><ItemType, ComponentType>, ) => Record<string, string | number> | Promise<Record<string, string | number>>`} />
  29. An optional function that should resolve to a map of translation variables which can be
  30. used when translating the `label` string.
  31. ### icon
  32. <MemberInfo kind="property" type={`string`} />
  33. A valid [Clarity Icons](https://core.clarity.design/foundation/icons/shapes/) icon shape, e.g.
  34. "cog", "user", "info-standard".
  35. ### iconClass
  36. <MemberInfo kind="property" type={`string`} />
  37. A class to be added to the icon element. Examples:
  38. - is-success
  39. - is-danger
  40. - is-warning
  41. - is-info
  42. - is-highlight
  43. ### onClick
  44. <MemberInfo kind="property" type={`(context: <a href='/reference/admin-ui-api/bulk-actions/bulk-action#bulkactionclickcontext'>BulkActionClickContext</a><ItemType, ComponentType>) => void`} />
  45. Defines the logic that executes when the bulk action button is clicked.
  46. ### isVisible
  47. <MemberInfo kind="property" type={`(context: <a href='/reference/admin-ui-api/bulk-actions/bulk-action#bulkactionfunctioncontext'>BulkActionFunctionContext</a><ItemType, ComponentType>) => boolean | Promise<boolean>`} />
  48. A function that determines whether this bulk action item should be displayed in the menu.
  49. If not defined, the item will always be displayed.
  50. This function will be invoked each time the selection is changed, so try to avoid expensive code
  51. running here.
  52. *Example*
  53. ```ts
  54. import { registerBulkAction, DataService } from '@vendure/admin-ui/core';
  55. registerBulkAction({
  56. location: 'product-list',
  57. label: 'Assign to channel',
  58. // Only display this action if there are multiple channels
  59. isVisible: ({ injector }) => injector.get(DataService).client
  60. .userStatus()
  61. .mapSingle(({ userStatus }) => 1 < userStatus.channels.length)
  62. .toPromise(),
  63. // ...
  64. });
  65. ```
  66. ### requiresPermission
  67. <MemberInfo kind="property" type={`string | ((userPermissions: string[]) => boolean)`} />
  68. Control the display of this item based on the user permissions.
  69. *Example*
  70. ```ts
  71. registerBulkAction({
  72. // Can be specified as a simple string
  73. requiresPermission: Permission.UpdateProduct,
  74. // Or as a function that returns a boolean if permissions are satisfied
  75. requiresPermission: userPermissions =>
  76. userPermissions.includes(Permission.UpdateCatalog) ||
  77. userPermissions.includes(Permission.UpdateProduct),
  78. // ...
  79. })
  80. ```
  81. </div>
  82. <GenerationInfo sourceFile="packages/admin-ui/src/lib/core/src/providers/bulk-action-registry/bulk-action-types.ts" sourceLine="12" packageName="@vendure/admin-ui" since="1.8.0" />
  83. A valid location of a list view that supports the bulk actions API.
  84. ```ts title="Signature"
  85. type BulkActionLocationId = | 'product-list'
  86. | 'facet-list'
  87. | 'collection-list'
  88. | 'customer-list'
  89. | 'customer-group-list'
  90. | 'customer-group-members-list'
  91. | 'customer-group-members-picker-list'
  92. | 'promotion-list'
  93. | 'seller-list'
  94. | 'channel-list'
  95. | 'administrator-list'
  96. | 'role-list'
  97. | 'shipping-method-list'
  98. | 'stock-location-list'
  99. | 'payment-method-list'
  100. | 'tax-category-list'
  101. | 'tax-rate-list'
  102. | 'zone-list'
  103. | 'zone-members-list'
  104. | string
  105. ```
  106. <GenerationInfo sourceFile="packages/admin-ui/src/lib/core/src/providers/bulk-action-registry/bulk-action-types.ts" sourceLine="43" packageName="@vendure/admin-ui" since="1.8.0" />
  107. This is the argument which gets passed to the `getTranslationVars` and `isVisible` functions
  108. of the BulkAction definition.
  109. ```ts title="Signature"
  110. interface BulkActionFunctionContext<ItemType, ComponentType> {
  111. selection: ItemType[];
  112. hostComponent: ComponentType;
  113. injector: Injector;
  114. route: ActivatedRoute;
  115. }
  116. ```
  117. <div className="members-wrapper">
  118. ### selection
  119. <MemberInfo kind="property" type={`ItemType[]`} />
  120. An array of the selected items from the list.
  121. ### hostComponent
  122. <MemberInfo kind="property" type={`ComponentType`} />
  123. The component instance that is hosting the list view. For instance,
  124. `ProductListComponent`. This can be used to call methods on the instance,
  125. e.g. calling `hostComponent.refresh()` to force a list refresh after
  126. deleting the selected items.
  127. ### injector
  128. <MemberInfo kind="property" type={`<a href='/reference/typescript-api/common/injector#injector'>Injector</a>`} />
  129. The Angular [Injector](https://angular.io/api/core/Injector) which can be used
  130. to get service instances which might be needed in the click handler.
  131. ### route
  132. <MemberInfo kind="property" type={`ActivatedRoute`} />
  133. </div>
  134. <GenerationInfo sourceFile="packages/admin-ui/src/lib/core/src/providers/bulk-action-registry/bulk-action-types.ts" sourceLine="74" packageName="@vendure/admin-ui" since="1.8.0" />
  135. This is the argument which gets passed to the `onClick` function of a BulkAction.
  136. ```ts title="Signature"
  137. interface BulkActionClickContext<ItemType, ComponentType> extends BulkActionFunctionContext<ItemType, ComponentType> {
  138. clearSelection: () => void;
  139. event: MouseEvent;
  140. }
  141. ```
  142. * Extends: <DocsLink href="/reference/admin-ui-api/bulk-actions/bulk-action#bulkactionfunctioncontext">`BulkActionFunctionContext`</DocsLink><ItemType, ComponentType>
  143. <div className="members-wrapper">
  144. ### clearSelection
  145. <MemberInfo kind="property" type={`() => void`} />
  146. Clears the selection in the active list view.
  147. ### event
  148. <MemberInfo kind="property" type={`MouseEvent`} />
  149. The click event itself.
  150. </div>