Skip to content

Commit

Permalink
[Alfresco#7604] Allow cache content-actions clearing of DocumentListC…
Browse files Browse the repository at this point in the history
…omponent
  • Loading branch information
nf807942 authored and DenysVuika committed Dec 15, 2023
1 parent 7c924e0 commit afdd964
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/content-services/components/content-action.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ funcName = (parameters): boolean => {
}
```

#### Clearing actions cache

The actions visibility and disabled states are evaluated once for each node and then cached by [Document List component](document-list.component.md) for futurs uses. If your actions states might have changed since the first evaluation of the node, you should call `clearActionsCache()`.

### Customizing built-in actions

The built-in actions are defined in the [Document Actions service](../services/document-actions.service.md) and
Expand Down
2 changes: 2 additions & 0 deletions docs/content-services/components/document-list.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ export class MyView {
This single extra line in the template enables context menu items for documents and folders.
The actions visibility and disabled states are evaluated once for each node and then cached by [Document List component](document-list.component.md) for futurs uses. If your actions states might have changed since the first evaluation of the node, you should call `clearActionsCache()`.
### Navigation mode
By default, the [Document List component](document-list.component.md) uses 'double-click' mode for navigation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,56 @@ describe('DocumentList', () => {
expect(actions[1].disabled).toBe(false);
});

it('should revaluate conditional disabled state for content action after cache clearing', () => {
documentList.actions = [
new ContentActionModel({
target: 'document',
title: 'Action1',
disabled: (node): boolean => node.entry.name === 'custom'
})
];

let actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'xyz' } });

expect(actions.length).toBe(1);
expect(actions[0].disabled).toBe(false);

actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'custom' } });

expect(actions.length).toBe(1);
expect(actions[0].disabled).toBe(false);

documentList.clearActionsCache();

actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'custom' } });
expect(actions.length).toBe(1);
expect(actions[0].disabled).toBe(true);
});

it('should revaluate conditional visibility state for content action after cache clearing', () => {
documentList.actions = [
new ContentActionModel({
target: 'document',
title: 'Action1',
visible: (node): boolean => node.entry.name === 'custom'
})
];

let actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'xyz' } });

expect(actions.length).toBe(0);

actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'custom' } });

expect(actions.length).toBe(0);

documentList.clearActionsCache();

actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'custom' } });
expect(actions.length).toBe(1);
expect(actions[0].visible).toBe(true);
});

it('should not disable the action if there is copy permission', () => {
const documentMenu = new ContentActionModel({
disableWithNoPermission: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
return [];
}

/**
* Clear the actions cache. This should be called before .reload() when the actions available on the nodes might have changed.
*/
clearActionsCache(): void {
this.rowMenuCache = {};
}

private refreshAction(action: ContentActionModel, node: NodeEntry) {
action.disabled = this.isActionDisabled(action, node);
action.visible = this.isActionVisible(action, node);
Expand Down

0 comments on commit afdd964

Please sign in to comment.