Skip to content

Commit

Permalink
Merge pull request #1156 from ORCID/eventServiceRefactor
Browse files Browse the repository at this point in the history
removed unused payload field from event
  • Loading branch information
auumgn authored Apr 11, 2024
2 parents 966e123 + 65c789a commit 828d44d
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ui/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LoginComponent implements AfterViewInit, OnDestroy {
private ngZone: NgZone
) {
this.sub = this.eventService.on(EventType.LOG_IN_SUCCESS).subscribe((e) => {

Check warning on line 40 in ui/src/app/account/login/login.component.ts

View workflow job for this annotation

GitHub Actions / format

'e' is defined but never used
console.log(e.payload)
console.log('login success')
})
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export class LoginComponent implements AfterViewInit, OnDestroy {
this.router.navigate([''])
})

this.eventService.broadcast(new Event(EventType.LOG_IN_SUCCESS, 'logged in'))
this.eventService.broadcast(new Event(EventType.LOG_IN_SUCCESS))

// previousState was set in the authExpiredInterceptor before being redirected to login modal.
// since login is successful, go to stored previousState and clear previousState
Expand Down
8 changes: 2 additions & 6 deletions ui/src/app/affiliation/affiliation-delete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ describe('AffiliationDeleteComponent', () => {
affiliationService.delete.and.returnValue(of(true))
component.confirmDelete('id')

expect(eventService.broadcast).toHaveBeenCalledWith(
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Deleted an affiliation')
)
expect(eventService.broadcast).toHaveBeenCalledWith(new Event(EventType.AFFILIATION_LIST_MODIFICATION))
})

it('should fail to delete the affiliation', () => {
affiliationService.delete.and.returnValue(of(false))
component.confirmDelete('id')

expect(eventService.broadcast).toHaveBeenCalledWith(
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Failed to delete an affiliation')
)
expect(eventService.broadcast).toHaveBeenCalledWith(new Event(EventType.AFFILIATION_LIST_MODIFICATION))
})

it('should not call the assertion service without an id', () => {
Expand Down
6 changes: 2 additions & 4 deletions ui/src/app/affiliation/affiliation-delete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ export class AffiliationDeleteDialogComponent implements OnInit {
if (id) {
this.affiliationService.delete(id).subscribe((response) => {
if (response) {
this.eventService.broadcast(new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Deleted an affiliation'))
this.eventService.broadcast(new Event(EventType.AFFILIATION_LIST_MODIFICATION))
this.alertService.broadcast(AlertType.AFFILIATION_DELETED)
} else {
this.eventService.broadcast(
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Failed to delete an affiliation')
)
this.eventService.broadcast(new Event(EventType.AFFILIATION_LIST_MODIFICATION))
this.alertService.broadcast(AlertType.AFFILIATION_DELETE_FAILURE)
}
this.activeModal.dismiss(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AffiliationImportDialogComponent {
}

close() {
this.eventService.broadcast(new Event(EventType.IMPORT_AFFILIATIONS, ''))
this.eventService.broadcast(new Event(EventType.IMPORT_AFFILIATIONS))
this.activeModal.dismiss(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class SendNotificationsDialogComponent implements OnInit {
close() {
this.eventService.broadcast({
type: EventType.SEND_NOTIFICATIONS,
payload: 'Send notifications',
})
this.activeModal.dismiss(true)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/member/member-import-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class MemberImportDialogComponent {
this.csvErrors = JSON.parse(res)
this.loading = false
if (this.csvErrors.length === 0) {
this.eventService.broadcast(new Event(EventType.MEMBER_LIST_MODIFICATION, 'New member uploaded'))
this.eventService.broadcast(new Event(EventType.MEMBER_LIST_MODIFICATION))
this.activeModal.dismiss(true)
}
}
Expand Down
5 changes: 1 addition & 4 deletions ui/src/app/shared/model/event.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { EventType } from 'src/app/app.constants'

export class Event {
constructor(
public type: EventType,
public payload: string
) {}
constructor(public type: EventType) {}
}
4 changes: 1 addition & 3 deletions ui/src/app/shared/service/event.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('EventService', () => {
it('should broadcast events', () => {
const event: Event = {
type: EventType.LOG_IN_SUCCESS,
payload: 'Login successful',
}
let receivedEvent: Event | undefined

Expand All @@ -30,10 +29,9 @@ describe('EventService', () => {
})

it('should filter events by type', () => {
const event1: Event = { type: EventType.LOG_IN_SUCCESS, payload: 'data 1' }
const event1: Event = { type: EventType.LOG_IN_SUCCESS }
const event2: Event = {
type: EventType.AFFILIATION_CREATED,
payload: 'data 2',
}
let receivedEvent: Event | undefined

Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/user/user-delete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('UserDeleteComponent', () => {
userServiceSpy.delete.and.returnValue(of(true))
component.confirmDelete('id')

expect(eventServiceSpy.broadcast).toHaveBeenCalledWith(new Event(EventType.USER_LIST_MODIFIED, 'Deleted a user'))
expect(eventServiceSpy.broadcast).toHaveBeenCalledWith(new Event(EventType.USER_LIST_MODIFIED))
})

it('should not call the userservice without a provided id', () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/user/user-delete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class UserDeleteDialogComponent implements OnInit {
confirmDelete(id: string | undefined) {
if (id) {
this.userService.delete(id).subscribe(() => {
this.eventService.broadcast(new Event(EventType.USER_LIST_MODIFIED, 'Deleted a user'))
this.eventService.broadcast(new Event(EventType.USER_LIST_MODIFIED))
this.activeModal.dismiss(true)
this.alertService.broadcast(AlertType.USER_DELETED)
})
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/user/user-import-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class UserImportDialogComponent {
this.csvErrors = JSON.parse(res)
this.loading = false
if (this.csvErrors.length === 0) {
this.eventService.broadcast(new Event(EventType.USER_LIST_MODIFIED, 'New user settings uploaded'))
this.eventService.broadcast(new Event(EventType.USER_LIST_MODIFIED))
this.activeModal.dismiss(true)
}
}
Expand Down

0 comments on commit 828d44d

Please sign in to comment.