I need to implement a button in a ListView Command Set extension that is only visible if the user has edit permissions for the selected item in a list. Therefore I have to make an async api call in the onListViewUpdated() method, but I does not seem to work, because onListViewUpdated() cannot be used as a aync function. Does anyone have a solution to that problem?
0
votes
1 Answers
0
votes
Check this thread.
@override
public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
// Get commands
const commandOne: Command = this.tryGetCommand('COMMAND_1');
const commandTwo: Command = this.tryGetCommand('COMMAND_2');
// Command checks
if (commandOne) {
this._hideCommandByPermissionSet(commandOne, SPPermission.editListItems);
}
if (commandTwo) {
this._hideCommandByPermissionSet(commandTwo, SPPermission.approveItems);
}
}
private _hideCommandByPermissionSet(crntCommand: Command, permission: SPPermission) {
if (this.context.pageContext.list.permissions.hasPermission(permission)) {
crntCommand.visible = true;
} else {
crntCommand.visible = false;
}
}