-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add module draggable tools component (#732)
* RM#82774
- Loading branch information
1 parent
9ba063e
commit da28374
Showing
14 changed files
with
516 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"title": "Module: add new system to manage quick actions with a global toolbox", | ||
"type": "feat", | ||
"packages": "core" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
id: toolManagement | ||
sidebar_position: 10 | ||
sidebar_class_name: icon tools | ||
--- | ||
|
||
# Quick actions management | ||
|
||
It is sometimes necessary to add quick actions on a number of screens, but it is very costly to overload each screen to add the various tools. To simplify these additions, the application's base contains a toolbox that each module can enhance with quick actions. These actions can then be displayed on all screens according to the given configuration. | ||
|
||
When exported, each module can enter a list of tools in its _globalTools_ attribute: | ||
|
||
```tsx | ||
interface ToolData { | ||
dispatch: Dispatch<any>; | ||
storeState: any; | ||
screenContext: any; | ||
} | ||
|
||
interface ActionToolData extends ToolData { | ||
navigation: any; | ||
} | ||
|
||
export interface Tool { | ||
key: string; | ||
order?: number; | ||
title?: string; | ||
iconName: string; | ||
color?: string; | ||
hideIf?: (data: ToolData) => boolean; | ||
disabledIf?: (data: ToolData) => boolean; | ||
onPress: (data: ActionToolData) => void; | ||
} | ||
|
||
export interface Module { | ||
name: string; | ||
... | ||
globalTools?: Tool[]; | ||
} | ||
``` | ||
|
||
A tool is defined with the following properties: | ||
|
||
- _key_: action identifier to enable overloading between modules. | ||
- _order_: action order in the list. The action with the lowest order will appear at the top of the toolbox. | ||
- _title_: translation key to be used for the title displayed in the toolbox next to the action. | ||
- _iconName_ : name of the [Bootstrap](https://icons.getbootstrap.com/) icon to be displayed on the button. | ||
- _color_ : color key to be displayed. The default color is `'primaryColor'`. | ||
- _hideIf_ : function used to define the tool's display condition. This function takes as arguments the state of the application's store and the current screen context. | ||
- _disabledIf_ : function for defining the tool's activation condition. This function takes as arguments the state of the application's store and the current screen context. | ||
- _onPress_: function for defining tool behavior. This function takes as arguments the state of the store, the screen context and the dispatch & navigation tools for making an API call or navigating to a specific screen. | ||
|
||
Here's an example of how to define a tool in the Sales module to add a product to the user's cart: | ||
|
||
```tsx | ||
export const SaleModule: Module = { | ||
name: 'app-sale', | ||
... | ||
globalTools: [ | ||
{ | ||
key: 'sale_activeCart_addProduct', | ||
iconName: 'cart-plus-fill', | ||
hideIf: ({screenContext, storeState}) => { | ||
return ( | ||
!storeState.appConfig?.sale?.isCartManagementEnabled || | ||
screenContext?.productId == null | ||
); | ||
}, | ||
onPress: ({dispatch, screenContext, storeState}) => { | ||
dispatch( | ||
addProductToUserCart({ | ||
productId: screenContext.productId, | ||
userId: storeState.auth?.userId, | ||
}), | ||
); | ||
}, | ||
}, | ||
], | ||
}; | ||
``` | ||
|
||
To define the context of a screen, simply use the `useContextRegister` hook and pass the associated data as arguments: | ||
|
||
```tsx | ||
import React from 'react'; | ||
import {Screen} from '@axelor/aos-mobile-ui'; | ||
import {useContextRegister} from '@axelor/aos-mobile-core'; | ||
|
||
const ProductDetailsScreen = ({route}) => { | ||
const {productId} = route.params.productId; | ||
|
||
useContextRegister({productId}); | ||
|
||
... | ||
|
||
return (...); | ||
}; | ||
|
||
export default ProductDetailsScreen; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
id: toolManagement | ||
sidebar_position: 10 | ||
sidebar_class_name: icon tools | ||
--- | ||
|
||
# Gestion des actions rapides | ||
|
||
Il est parfois nécessaire d'ajouter des actions rapides sur un certain nombre d'écrans mais cela est très coûteux de surcharger chaque écran pour ajouter les différents outils. Pour simplifier ces ajouts, la base de l'application contient donc une boîte à outils que chaque module peut venir agrémenter d'actions rapides. Ces actions pourront alors être affichées sur tous les écrans en fonction de la configuration donnée. | ||
|
||
Chaque module lors de son export peut venir renseigner une liste d'outils dans son attribut _globalTools_ : | ||
|
||
```tsx | ||
interface ToolData { | ||
dispatch: Dispatch<any>; | ||
storeState: any; | ||
screenContext: any; | ||
} | ||
|
||
interface ActionToolData extends ToolData { | ||
navigation: any; | ||
} | ||
|
||
export interface Tool { | ||
key: string; | ||
order?: number; | ||
title?: string; | ||
iconName: string; | ||
color?: string; | ||
hideIf?: (data: ToolData) => boolean; | ||
disabledIf?: (data: ToolData) => boolean; | ||
onPress: (data: ActionToolData) => void; | ||
} | ||
|
||
export interface Module { | ||
name: string; | ||
... | ||
globalTools?: Tool[]; | ||
} | ||
``` | ||
|
||
Un outil est défini avec les propriétés suivantes : | ||
|
||
- _key_ : identifiant de l'action pour permettre la surcharge entre les modules. | ||
- _order_ : ordre de l'action dans la liste. L'action avec l'ordre le plus bas apparaîtra au plus haut dans la boîte à outils. | ||
- _title_ : clé de traduction à utiliser pour le titre affiché dans la boîte à outils à côté de l'action. | ||
- _iconName_ : nom de l'icon [Bootstrap](https://icons.getbootstrap.com/) à afficher sur le bouton. | ||
- _color_ : clé de la couleur à afficher. La couleur par défaut est `'primaryColor'`. | ||
- _hideIf_ : fonction permettant de définir la condition d'affichage de l'outil. Cette fonction prend en arguments l'état du store de l'application et le contexte de l'écran actuel. | ||
- _disabledIf_ : fonction permettant de définir la condition d'activation de l'outil. Cette fonction prend en arguments l'état du store de l'application et le contexte de l'écran actuel. | ||
- _onPress_ : fonction permettant de définir le comportement de l'outil. Cette fonction prend en arguments l'état du store, le contexte de l'écran et les outils dispatch & navigation pour réaliser un appel API ou une navigation vers un écran spécifique. | ||
|
||
Voici un exemple de définition d'un outil dans le module Ventes pour ajouter un produit dans le panier de l'utilisateur : | ||
|
||
```tsx | ||
export const SaleModule: Module = { | ||
name: 'app-sale', | ||
... | ||
globalTools: [ | ||
{ | ||
key: 'sale_activeCart_addProduct', | ||
iconName: 'cart-plus-fill', | ||
hideIf: ({screenContext, storeState}) => { | ||
return ( | ||
!storeState.appConfig?.sale?.isCartManagementEnabled || | ||
screenContext?.productId == null | ||
); | ||
}, | ||
onPress: ({dispatch, screenContext, storeState}) => { | ||
dispatch( | ||
addProductToUserCart({ | ||
productId: screenContext.productId, | ||
userId: storeState.auth?.userId, | ||
}), | ||
); | ||
}, | ||
}, | ||
], | ||
}; | ||
``` | ||
|
||
Pour définir le contexte d'un écran, il suffit d'utiliser le hook `useContextRegister` et de transmettre les données associées en arguments : | ||
|
||
```tsx | ||
import React from 'react'; | ||
import {Screen} from '@axelor/aos-mobile-ui'; | ||
import {useContextRegister} from '@axelor/aos-mobile-core'; | ||
|
||
const ProductDetailsScreen = ({route}) => { | ||
const {productId} = route.params.productId; | ||
|
||
useContextRegister({productId}); | ||
|
||
... | ||
|
||
return (...); | ||
}; | ||
|
||
export default ProductDetailsScreen; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.