Browse Source

Merge pull request #2085 from abpframework/refactor/update-actions

refactor(identity): remove redundant getById dispatch in update actions
pull/2090/head
Mehmet Erim 7 years ago
committed by GitHub
parent
commit
9c91a8609d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  2. 1
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  3. 14
      npm/ng-packs/packages/identity/src/lib/states/identity.state.ts

2
npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts

@ -87,7 +87,7 @@ export class RolesComponent implements OnInit {
this.store
.dispatch(
this.selected.id
? new UpdateRole({ ...this.form.value, id: this.selected.id })
? new UpdateRole({ ...this.selected, ...this.form.value, id: this.selected.id })
: new CreateRole(this.form.value),
)
.subscribe(() => {

1
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -176,6 +176,7 @@ export class UsersComponent implements OnInit {
.dispatch(
this.selected.id
? new UpdateUser({
...this.selected,
...this.form.value,
id: this.selected.id,
roleNames: mappedRoleNames,

14
npm/ng-packs/packages/identity/src/lib/states/identity.state.ts

@ -77,10 +77,9 @@ export class IdentityState {
@Action(UpdateRole)
updateRole({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateRole) {
return dispatch(new GetRoleById(payload.id)).pipe(
switchMap(() => this.identityService.updateRole({ ...getState().selectedRole, ...payload })),
switchMap(() => dispatch(new GetRoles())),
);
return this.identityService
.updateRole({ ...getState().selectedRole, ...payload })
.pipe(switchMap(() => dispatch(new GetRoles())));
}
@Action(GetUsers)
@ -117,10 +116,9 @@ export class IdentityState {
@Action(UpdateUser)
updateUser({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateUser) {
return dispatch(new GetUserById(payload.id)).pipe(
switchMap(() => this.identityService.updateUser({ ...getState().selectedUser, ...payload })),
switchMap(() => dispatch(new GetUsers())),
);
return this.identityService
.updateUser({ ...getState().selectedUser, ...payload })
.pipe(switchMap(() => dispatch(new GetUsers())));
}
@Action(GetUserRoles)

Loading…
Cancel
Save