web: clear out selecteds list after an API event to ensure a fresh copy of the policies-to-delete list (#8125)

* web: clear out selecteds list after an API event to ensure a fresh copy of the policies-to-delete list

* Prettier had opinions.

* web: A better fix

This fix creates a new property of Table, 'clearOnRefresh', which
automatically empties the `selectedElements` list when an EVENT_REFRESH
event completes.  Set this flag on any table that uses the
`selectedElements` list for bulk deletion; this ensures that stale
data in the `selectedElements` list will not persist and interfere
with future deletion events.
This commit is contained in:
Ken Sternberg
2024-01-25 10:18:59 -08:00
committed by GitHub
parent 5f1ba45966
commit 645f662e3e
40 changed files with 52 additions and 2 deletions

View File

@ -34,6 +34,7 @@ export class UserOAuthRefreshList extends Table<TokenModel> {
}
checkbox = true;
clearOnRefresh = true;
order = "-expires";
columns(): TableColumn[] {

View File

@ -29,6 +29,7 @@ export class RoleAssignedObjectPermissionTable extends Table<RoleAssignedObjectP
modelPermissions?: PaginatedPermissionList;
checkbox = true;
clearOnRefresh = true;
async apiEndpoint(page: number): Promise<PaginatedResponse<RoleAssignedObjectPermission>> {
const perms = await new RbacApi(DEFAULT_CONFIG).rbacPermissionsAssignedByRolesList({

View File

@ -29,6 +29,7 @@ export class UserAssignedObjectPermissionTable extends Table<UserAssignedObjectP
modelPermissions?: PaginatedPermissionList;
checkbox = true;
clearOnRefresh = true;
async apiEndpoint(page: number): Promise<PaginatedResponse<UserAssignedObjectPermission>> {
const perms = await new RbacApi(DEFAULT_CONFIG).rbacPermissionsAssignedByUsersList({

View File

@ -119,6 +119,14 @@ export abstract class Table<T> extends AKElement implements TableLike {
@property({ type: Number })
page = getURLParam("tablePage", 1);
/** @prop
*
* Set if your `selectedElements` use of the selection box is to enable bulk-delete, so that
* stale data is cleared out when the API returns a new list minus the deleted entries.
*/
@property({ attribute: "clear-on-refresh", type: Boolean, reflect: true })
clearOnRefresh = false;
@property({ type: String })
order?: string;
@ -178,8 +186,11 @@ export abstract class Table<T> extends AKElement implements TableLike {
constructor() {
super();
this.addEventListener(EVENT_REFRESH, () => {
this.fetch();
this.addEventListener(EVENT_REFRESH, async () => {
await this.fetch();
if (this.clearOnRefresh) {
this.selectedElements = [];
}
});
}

View File

@ -25,6 +25,7 @@ export class AuthenticatedSessionList extends Table<AuthenticatedSession> {
}
checkbox = true;
clearOnRefresh = true;
order = "-expires";
columns(): TableColumn[] {

View File

@ -25,6 +25,7 @@ export class UserConsentList extends Table<UserConsent> {
}
checkbox = true;
clearOnRefresh = true;
order = "-expires";
columns(): TableColumn[] {