diff --git a/src/Squidex/app/features/administration/state/users.state.spec.ts b/src/Squidex/app/features/administration/state/users.state.spec.ts index e4b6bf6f3..6743824c2 100644 --- a/src/Squidex/app/features/administration/state/users.state.spec.ts +++ b/src/Squidex/app/features/administration/state/users.state.spec.ts @@ -29,7 +29,7 @@ describe('UsersState', () => { const newUser = new UserDto('id3', 'mail3@mail.de', 'name3', false); let authService: IMock; - let dialogService: IMock; + let dialogs: IMock; let usersService: IMock; let usersState: UsersState; @@ -39,28 +39,44 @@ describe('UsersState', () => { authService.setup(x => x.user) .returns(() => { id: 'id2' }); - dialogService = Mock.ofType(); + dialogs = Mock.ofType(); usersService = Mock.ofType(); usersService.setup(x => x.getUsers(10, 0, undefined)) .returns(() => Observable.of(new UsersDto(200, oldUsers))); - usersState = new UsersState(authService.object, dialogService.object, usersService.object); + usersState = new UsersState(authService.object, dialogs.object, usersService.object); usersState.loadUsers().subscribe(); }); - it('should load apps', () => { + it('should load users', () => { expect(usersState.snapshot.users.values).toEqual(oldUsers); expect(usersState.snapshot.usersPager.numberOfItems).toEqual(200); usersService.verifyAll(); }); + it('should replace selected user when reloading', () => { + usersState.selectUser('id1').subscribe(); + + const newUsers = [ + new UserDto('id1', 'mail1@mail.de_new', 'name1_new', false), + new UserDto('id2', 'mail2@mail.de_new', 'name2_new', true) + ]; + + usersService.setup(x => x.getUsers(10, 0, undefined)) + .returns(() => Observable.of(new UsersDto(200, newUsers))); + + usersState.loadUsers().subscribe(); + + expect(usersState.snapshot.selectedUser).toBe(newUsers[0]); + }); + it('should raise notification on load when notify is true', () => { usersState.loadUsers(true).subscribe(); - dialogService.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); + dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); }); it('should not load user when already loaded', () => { @@ -140,7 +156,7 @@ describe('UsersState', () => { usersState.lockUser(oldUsers[0]).onErrorResumeNext().subscribe(); - dialogService.verify(x => x.notifyError(It.isAny()), Times.once()); + dialogs.verify(x => x.notifyError(It.isAny()), Times.once()); }); it('should unmark user as locked', () => { @@ -160,7 +176,7 @@ describe('UsersState', () => { usersState.unlockUser(oldUsers[1]).onErrorResumeNext().subscribe(); - dialogService.verify(x => x.notifyError(It.isAny()), Times.once()); + dialogs.verify(x => x.notifyError(It.isAny()), Times.once()); }); it('should update user on update', () => { @@ -185,7 +201,7 @@ describe('UsersState', () => { usersState.updateUser(oldUsers[0], request).onErrorResumeNext().subscribe(); - dialogService.verify(x => x.notifyError(It.isAny()), Times.never()); + dialogs.verify(x => x.notifyError(It.isAny()), Times.never()); }); it('should add user to state when created', () => { @@ -208,7 +224,7 @@ describe('UsersState', () => { usersState.createUser(request).onErrorResumeNext().subscribe(); - dialogService.verify(x => x.notifyError(It.isAny()), Times.never()); + dialogs.verify(x => x.notifyError(It.isAny()), Times.never()); }); it('should load next page and prev page when paging', () => { diff --git a/src/Squidex/app/features/administration/state/users.state.ts b/src/Squidex/app/features/administration/state/users.state.ts index d50f1a83f..5ab351e38 100644 --- a/src/Squidex/app/features/administration/state/users.state.ts +++ b/src/Squidex/app/features/administration/state/users.state.ts @@ -140,7 +140,17 @@ export class UsersState extends State { const users = ImmutableArray.of(dtos.items); const usersPager = s.usersPager.setCount(dtos.total); - return { ...s, users, usersPager, usersLoading: false }; + let selectedUser = s.selectedUser; + + if (selectedUser) { + const selectedFromResult = dtos.items.find(x => x.id === selectedUser!.id); + + if (selectedFromResult) { + selectedUser = selectedFromResult; + } + } + + return { ...s, users, usersPager, selectedUser, usersLoading: false }; }); }) .notify(this.dialogs); diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index 9fc54befd..c3da8326a 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts @@ -47,9 +47,9 @@ export class SchemasPageComponent implements OnDestroy, OnInit { constructor( public readonly appsState: AppsState, - private readonly schemasState: SchemasState, + private readonly messageBus: MessageBus, private readonly route: ActivatedRoute, - private readonly messageBus: MessageBus + private readonly schemasState: SchemasState ) { } diff --git a/src/Squidex/app/features/schemas/state/schemas.state.ts b/src/Squidex/app/features/schemas/state/schemas.state.ts index 8e3edbb77..f53613106 100644 --- a/src/Squidex/app/features/schemas/state/schemas.state.ts +++ b/src/Squidex/app/features/schemas/state/schemas.state.ts @@ -144,14 +144,6 @@ interface Snapshot { @Injectable() export class SchemasState extends State { - private get appName() { - return this.appsState.appName; - } - - private get user() { - return this.authState.user!.token; - } - public selectedSchema = this.changes.map(s => s.selectedSchema) .distinctUntilChanged(); @@ -160,6 +152,10 @@ export class SchemasState extends State { this.changes.map(s => s.schemas) .distinctUntilChanged(); + public get schemaName() { + return this.snapshot.selectedSchema!.name; + } + constructor( private readonly appsState: AppsState, private readonly authState: AuthService, @@ -339,6 +335,14 @@ export class SchemasState extends State { return { ...s, schemas, selectedSchema }; }); } + + private get appName() { + return this.appsState.appName; + } + + private get user() { + return this.authState.user!.token; + } } const setPublished = (schema: SchemaDto | SchemaDetailsDto, publish: boolean, user: string, version: Version, now?: DateTime) => { diff --git a/src/Squidex/app/framework/angular/forms/confirm-click.directive.ts b/src/Squidex/app/framework/angular/forms/confirm-click.directive.ts index 28aa2597b..52d3e140d 100644 --- a/src/Squidex/app/framework/angular/forms/confirm-click.directive.ts +++ b/src/Squidex/app/framework/angular/forms/confirm-click.directive.ts @@ -50,7 +50,7 @@ export class ConfirmClickDirective implements OnDestroy { public clickConfirmed = new DelayEventEmitter(); constructor( - private readonly dialogService: DialogService + private readonly dialogs: DialogService ) { } @@ -72,7 +72,7 @@ export class ConfirmClickDirective implements OnDestroy { this.isOpen = true; let subscription = - this.dialogService.confirm(this.confirmTitle, this.confirmText) + this.dialogs.confirm(this.confirmTitle, this.confirmText) .subscribe(result => { this.isOpen = false; diff --git a/src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts b/src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts index d29364ba3..31f1f8b9b 100644 --- a/src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts +++ b/src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts @@ -38,7 +38,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit { public position = 'bottomright'; constructor( - private readonly dialogService: DialogService + private readonly dialogs: DialogService ) { } @@ -57,7 +57,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit { }); this.notificationsSubscription = - this.dialogService.notifications.subscribe(notification => { + this.dialogs.notifications.subscribe(notification => { this.notifications.push(notification); if (notification.displayTime > 0) { @@ -68,7 +68,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit { }); this.dialogsSubscription = - this.dialogService.dialogs + this.dialogs.dialogs .subscribe(request => { this.cancel();