* [ACS-8694] Updated occurrences of visible in extensions.json to use arrays instead of single strings. Cleaned up rules in aca-content.module.ts * [ACS-8694] Removed extra commas * [ACS-8694] Broke down canDelete rule into seperate entities * [ACS-8694] Fixed typo for notEmpty rule * [ACS-8694] Fixed rule for edit offline * [ACS-8694] Updated extension.schema.json * [ACS-8694] Updated extension.schema.json * [ACS-8694] Fixed rule for manage versions context menu item * [ACS-8694] Fixed rule for manage versions and manage permissions * [ACS-8694] Added rules.canManageFolderRules * [ACS-8694] Fixed typo * [ACS-8694] Updated visibility rules for folder rules and AOS plugin * [ACS-8694] Updated extension.schema.json * [ACS-8694] Updated existing rules to use !isTrashcan() instead of isNotTrashcan() * [ACS-8694] folder-rules.plugin.json now uses arrays for controlling visibility * [ACS-8694] Updated app.extensions.schema * [ACS-8694] Removed unused rules * [ACS-8694] Added unit tests for canToggleFileLock * [ACS-8694] Added rules-list.md * [ACS-8694] Revert unneeded project.json change * [ACS-8694] Fixed toggleEditOffline rule * [ACS-8694] Added migration guide (#4139) * [ACS-8694] Added migration guide * [ACS-8694] Fixed typo * [ACS-8694] Added missing rule migration. Fixed incorrect rule migration. Fixed typos * [ACS-8694] Code review finding - Replaced instance of any * [ACS-8694] Code review finding - Updated rules.md. Removed duplication of rules list from rules-list.md. Added pointer to rules-list.md under tips section * [ACS-8694] Fixed build issue * [ACS-8694] Removed unneeded isNotDetails rule
5.6 KiB
Title
Title |
---|
Rules |
Rules
Rules allow you to evaluate conditions for extension components, so you can disable or hide elements based on certain rules, for example.
Every rule is backed by a condition evaluator.
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"rules": [
{
"id": "app.trashcan",
"type": "app.navigation.isTrashcan"
}
]
}
Rules can accept other rules as parameters:
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"rules": [
{
"id": "app.toolbar.favorite.canAdd",
"type": "core.every",
"parameters": [
{ "type": "rule", "value": "app.selection.canAddFavorite" },
{ "type": "rule", "value": "app.navigation.isNotRecentFiles" },
{ "type": "rule", "value": "app.navigation.isNotSharedFiles" },
{ "type": "rule", "value": "app.navigation.isNotSearchResults" }
]
}
]
}
Tip: You can also negate any rule by utilizing a !
prefix:
!app.navigation.isTrashcan
is the opposite of the app.navigation.isTrashcan
.
It is also possible to use inline references to registered evaluators without declaring rules, in case you do not need providing extra parameters, or chaining multiple rules together.
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"features": {
"toolbar": [
{
"id": "app.toolbar.share",
"rules": {
"visible": "app.record.canShareRecord"
}
}
]
}
}
Handling Multiple Extensions
When multiple extensions rely on the same component, the visibility rules from all extensions should be passed as an array. This way, the rules will be merged and evaluated, ensuring that all conditions from different extensions are considered.
For example, if the app.toolbar.share
component is modified by both the Extension1
and
Extension2
extensions, the visibility rules will be combined:
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "Extension1",
"features": {
"toolbar": [
{
"id": "app.toolbar.share",
"rules": {
"visible": ["extension1.rule1"]
}
}
]
}
}
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "Extension2",
"features": {
"toolbar": [
{
"id": "app.toolbar.share",
"rules": {
"visible": ["extension2.rule2"]
}
}
]
}
}
In this case, the component will be visible only if both extension1.rule1 and extension2.rule2 evaluate to true.
Core Evaluators
You can create new rules by chaining other rules and evaluators.
Version | Key | Description |
---|---|---|
1.7.0 | core.every | Evaluates to true if all chained rules evaluate to true . |
1.7.0 | core.some | Evaluates to true if at least one of the chained rules evaluates to true . |
1.7.0 | core.not | Evaluates to true if all chained rules evaluate to false . |
Below is an example of the composite rule definition that combines the following conditions:
- user has selected a single file
- user is not using the Trashcan page
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"rules": [
{
"id": "app.toolbar.canViewFile",
"type": "core.every",
"parameters": [
{
"type": "rule",
"value": "app.selection.file"
},
{
"type": "rule",
"value": "core.not",
"parameters": [
{
"type": "rule",
"value": "app.navigation.isTrashcan"
}
]
}
]
}
]
}
You can now declare a toolbar button action that is based on the rule above.
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"features": {
"toolbar": [
{
"id": "app.toolbar.preview",
"type": "button",
"title": "View File",
"icon": "open_in_browser",
"actions": {
"click": "VIEW_FILE"
},
"rules": {
"visible": "app.toolbar.canViewFile"
}
}
]
}
}
The button will be visible only when the linked rule evaluates to true
.
Tips:
- You can also negate any rule by utilizing a
!
prefix:!app.navigation.isTrashcan
is the opposite of theapp.navigation.isTrashcan
. - See the Registration section for more details on how to register your own entries to be re-used at runtime.
- See Rules List for a full list of rules available with the Alfresco Content Application
Example
The rule in the example below evaluates to true
if all the conditions are met:
- user has selected node(s)
- user is not using the Trashcan page
- user is not using a Libraries page (My Libraries, Favorite Libraries or Libraries Search Results pages)
{
"$schema": "../../../extension.schema.json",
"$version": "1.0.0",
"$name": "plugin1",
"rules": [
{
"id": "app.toolbar.canCopyNode",
"type": "core.every",
"parameters": [
{ "type": "rule", "value": "app.selection.notEmpty" },
{ "type": "rule", "value": "app.navigation.isNotTrashcan" },
{ "type": "rule", "value": "app.navigation.isNotLibraries" }
]
}
]
}