From dd53a1c5ceb96a6d529d25ff004ea06c92683465 Mon Sep 17 00:00:00 2001 From: KiruthigaManivannan <162679756+KiruthigaManivannan@users.noreply.github.com> Date: Thu, 23 May 2024 18:59:24 +0530 Subject: [PATCH] AC-2410 Migrate Events Component (#8970) * AC-2410 Migrate Events Component * AC-2410 Addressed a minor correction --- .../common/base.events.component.ts | 73 +++++---- .../manage/events.component.html | 46 ++---- .../organizations/manage/events.component.ts | 2 +- .../providers/manage/events.component.html | 147 +++++++++--------- .../providers/manage/events.component.ts | 2 +- .../service-accounts-events.component.html | 43 ++--- .../service-accounts-events.component.ts | 2 +- 7 files changed, 144 insertions(+), 171 deletions(-) diff --git a/apps/web/src/app/admin-console/common/base.events.component.ts b/apps/web/src/app/admin-console/common/base.events.component.ts index 7af7c3e70d..e14bb62a35 100644 --- a/apps/web/src/app/admin-console/common/base.events.component.ts +++ b/apps/web/src/app/admin-console/common/base.events.component.ts @@ -1,4 +1,5 @@ import { Directive } from "@angular/core"; +import { FormControl, FormGroup } from "@angular/forms"; import { EventResponse } from "@bitwarden/common/models/response/event.response"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; @@ -16,16 +17,16 @@ export abstract class BaseEventsComponent { loading = true; loaded = false; events: EventView[]; - start: string; - end: string; dirtyDates = true; continuationToken: string; - refreshPromise: Promise; - exportPromise: Promise; - morePromise: Promise; abstract readonly exportFileName: string; + protected eventsForm = new FormGroup({ + start: new FormControl(null), + end: new FormControl(null), + }); + constructor( protected eventService: EventService, protected i18nService: I18nService, @@ -39,8 +40,32 @@ export abstract class BaseEventsComponent { this.end = defaultDates[1]; } - async exportEvents() { - if (this.appApiPromiseUnfulfilled() || this.dirtyDates) { + get start(): string { + return this.eventsForm.value.start; + } + + set start(val: string) { + this.eventsForm.get("start").setValue(val); + } + + get end(): string { + return this.eventsForm.value.end; + } + + set end(val: string) { + this.eventsForm.get("end").setValue(val); + } + + loadMoreEvents = async () => { + await this.loadEvents(false); + }; + + refreshEvents = async () => { + await this.loadEvents(true); + }; + + exportEvents = async () => { + if (this.dirtyDates) { return; } @@ -51,23 +76,19 @@ export abstract class BaseEventsComponent { return; } + let promise: Promise; try { - this.exportPromise = this.export(dates[0], dates[1]); - - await this.exportPromise; + promise = this.export(dates[0], dates[1]); + await promise; } catch (e) { this.logService.error(`Handled exception: ${e}`); } - this.exportPromise = null; + promise = null; this.loading = false; - } - - async loadEvents(clearExisting: boolean) { - if (this.appApiPromiseUnfulfilled()) { - return; - } + }; + loadEvents = async (clearExisting: boolean) => { const dates = this.parseDates(); if (dates == null) { return; @@ -75,17 +96,14 @@ export abstract class BaseEventsComponent { this.loading = true; let events: EventView[] = []; + let promise: Promise; try { - const promise = this.loadAndParseEvents( + promise = this.loadAndParseEvents( dates[0], dates[1], clearExisting ? null : this.continuationToken, ); - if (clearExisting) { - this.refreshPromise = promise; - } else { - this.morePromise = promise; - } + const result = await promise; this.continuationToken = result.continuationToken; events = result.events; @@ -101,9 +119,8 @@ export abstract class BaseEventsComponent { this.dirtyDates = false; this.loading = false; - this.morePromise = null; - this.refreshPromise = null; - } + promise = null; + }; protected abstract requestEvents( startDate: string, @@ -161,10 +178,6 @@ export abstract class BaseEventsComponent { return dates; } - protected appApiPromiseUnfulfilled() { - return this.refreshPromise != null || this.morePromise != null || this.exportPromise != null; - } - private async export(start: string, end: string) { let continuationToken = this.continuationToken; let events = [].concat(this.events); diff --git a/apps/web/src/app/admin-console/organizations/manage/events.component.html b/apps/web/src/app/admin-console/organizations/manage/events.component.html index e5a848aacc..654020ec26 100644 --- a/apps/web/src/app/admin-console/organizations/manage/events.component.html +++ b/apps/web/src/app/admin-console/organizations/manage/events.component.html @@ -1,6 +1,6 @@ -
+
{{ "from" | i18n }} @@ -8,7 +8,7 @@ bitInput type="datetime-local" placeholder="{{ 'startDate' | i18n }}" - [(ngModel)]="start" + formControlName="start" (change)="dirtyDates = true" /> @@ -19,51 +19,44 @@ bitInput type="datetime-local" placeholder="{{ 'endDate' | i18n }}" - [(ngModel)]="end" + formControlName="end" (change)="dirtyDates = true" /> -
+
-
+
- {{ "loading" | i18n }} + {{ "loading" | i18n }}

{{ "noEventsInList" | i18n }}

@@ -90,21 +83,12 @@
diff --git a/apps/web/src/app/admin-console/organizations/manage/events.component.ts b/apps/web/src/app/admin-console/organizations/manage/events.component.ts index 9fb9015155..20af02a84f 100644 --- a/apps/web/src/app/admin-console/organizations/manage/events.component.ts +++ b/apps/web/src/app/admin-console/organizations/manage/events.component.ts @@ -108,7 +108,7 @@ export class EventsComponent extends BaseEventsComponent implements OnInit, OnDe } } - await this.loadEvents(true); + await this.refreshEvents(); this.loaded = true; } diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/events.component.html b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/events.component.html index 12182c4584..11d6dff0eb 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/events.component.html +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/events.component.html @@ -1,104 +1,97 @@ -
-
- - - - - - +
+
+ + {{ "startDate" | i18n }} + + + - + + {{ "endDate" | i18n }} + + +
+ +
+
+ +
-
- -
-
- -
- - {{ "loading" | i18n }} + {{ "loading" | i18n }}

{{ "noEventsInList" | i18n }}

- - + + - - - - + + + + - - - - - + + - - + - -
{{ "timestamp" | i18n }} - {{ "device" | i18n }} - {{ "user" | i18n }}{{ "event" | i18n }}{{ "timestamp" | i18n }}{{ "device" | i18n }}{{ "user" | i18n }}{{ "event" | i18n }}
{{ e.date | date: "medium" }} + + +
{{ e.date | date: "medium" }} - {{ e.appName }}, {{ e.ip }} + {{ e.appName }}, {{ e.ip }} + {{ e.userName }}
+ + -
+
- {{ "loading" | i18n }} + {{ "loading" | i18n }}

{{ "noEventsInList" | i18n }}

@@ -85,21 +77,12 @@
diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/event-logs/service-accounts-events.component.ts b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/event-logs/service-accounts-events.component.ts index 0547c4fcba..91f1a20c65 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/event-logs/service-accounts-events.component.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/event-logs/service-accounts-events.component.ts @@ -50,7 +50,7 @@ export class ServiceAccountEventsComponent extends BaseEventsComponent implement } async load() { - await this.loadEvents(true); + await this.refreshEvents(); this.loaded = true; }