wip actions documentation

This commit is contained in:
Mads Rasmussen
2023-02-22 20:16:09 +01:00
parent 6a6a0f2ab1
commit c354586173
2 changed files with 71 additions and 1 deletions

View File

@@ -3,3 +3,73 @@ import { Meta } from '@storybook/addon-docs';
<Meta title="Guides/Extending the Backoffice/Actions" parameters={{ previewTabs: { canvas: { hidden: true } } }} />
# Actions
TODO: introduction to actions
- **Entity Action:**
Relates to an entity type: (document, media, etc.). Performs the action on a specific item.
- **Entity Bulk Action:**
Relates to an entity type: document, media, etc. Performs the action on a selection of items.
- **Workspace Action:**
Relates to a workspace alias (Umb.Workspace.Document). Performs the action on the workspace draft state.
TODO: graphically show the different types of actions
### Registering an Entity Action
TODO: can we show the typescript interface for the manifest?
```javascript
{
type: 'entityAction',
alias: 'Umb.EntityAction.Document.Trash',
name: 'Trash Document Entity Action',
weight: 10,
meta: {
entityType: 'document',
icon: 'umb:trash',
label: 'Trash',
repositoryAlias: 'Umb.Repository.Documents',
api: UmbTrashEntityAction,
},
}
```
### Api Class
As part of the manifest you can attach a class that will be instanciated as part of the action. It will have access to the host element, a repository with the given alias and the unique (key etc) of the entity. When the action is clicked the `execute` method on the api class will be run. When the action is completed, an event on the host element will be dispatched to notify any surrounding elements.
```typescript
import { UmbEntityActionBase } from '..';
import { UmbExecutedEvent } from '../../../../core/events';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbMyEntityAction extends UmbEntityActionBase<UmbMyRepository> {
constructor(host: UmbControllerHostInterface, repositoryAlias: string, unique: string) {
super(host, repositoryAlias, unique);
}
async execute() {
console.log(`execute for: ${this.unique}`);
await this.repository.method();
}
}
```
If any additional contexts are needed, these can be consumed from the host element:
```typescript
constructor(host: UmbControllerHostInterface, repositoryAlias: string, unique: string) {
super(host, repositoryAlias, unique);
new UmbContextConsumerController(this.host, UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
this.#modalService = instance;
});
}
```
We currently have a couple of generic actions that can be used across silos, so we don't have to write the same logic again: copy, move, trash, delete, etc. We can add more as we discover the needs.
TODO: List generic actions

View File

@@ -4,7 +4,7 @@ import { Meta } from '@storybook/addon-docs';
# UI Extensions
Something about the extendable UI
TODO: introduction to the extendable UI
The Umbraco Backoffice currently support the following extension types: