Browse Source

redundant transfer state usages removed

pull/23416/head
erdemcaygor 1 year ago
parent
commit
810459a843
  1. 28
      npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts
  2. 24
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  3. 25
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

28
npm/ng-packs/packages/account/src/lib/components/manage-profile/manage-profile.component.ts

@ -1,12 +1,12 @@
import { ProfileService } from '@abp/ng.account.core/proxy'; import { ProfileService } from '@abp/ng.account.core/proxy';
import { fadeIn, LoadingDirective } from '@abp/ng.theme.shared'; import { fadeIn, LoadingDirective } from '@abp/ng.theme.shared';
import { transition, trigger, useAnimation } from '@angular/animations'; import { transition, trigger, useAnimation } from '@angular/animations';
import { Component, inject, makeStateKey, OnInit, TransferState } from '@angular/core'; import { Component, inject, OnInit } from '@angular/core';
import { eAccountComponents } from '../../enums/components'; import { eAccountComponents } from '../../enums/components';
import { ManageProfileStateService } from '../../services/manage-profile.state.service'; import { ManageProfileStateService } from '../../services/manage-profile.state.service';
import { NgClass, AsyncPipe } from '@angular/common'; import { NgClass, AsyncPipe } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms';
import { LocalizationPipe, ReplaceableTemplateDirective, SSRService } from '@abp/ng.core'; import { LocalizationPipe, ReplaceableTemplateDirective } from '@abp/ng.core';
import { PersonalSettingsComponent } from '../personal-settings/personal-settings.component'; import { PersonalSettingsComponent } from '../personal-settings/personal-settings.component';
import { ChangePasswordComponent } from '../change-password/change-password.component'; import { ChangePasswordComponent } from '../change-password/change-password.component';
@ -37,7 +37,6 @@ export class ManageProfileComponent implements OnInit {
protected profileService = inject(ProfileService); protected profileService = inject(ProfileService);
protected manageProfileState = inject(ManageProfileStateService); protected manageProfileState = inject(ManageProfileStateService);
protected readonly ssrService = inject(SSRService);
selectedTab = 0; selectedTab = 0;
changePasswordKey = eAccountComponents.ChangePassword; changePasswordKey = eAccountComponents.ChangePassword;
@ -47,32 +46,17 @@ export class ManageProfileComponent implements OnInit {
profile$ = this.manageProfileState.getProfile$(); profile$ = this.manageProfileState.getProfile$();
hideChangePasswordTab?: boolean; hideChangePasswordTab?: boolean;
PROFILE_SETTINGS_KEY = makeStateKey<any>('profileSettings');
constructor( constructor(
private transferState: TransferState
) {} ) {}
ngOnInit() { ngOnInit() {
if (this.transferState.hasKey(this.PROFILE_SETTINGS_KEY)) { this.profileService.get().subscribe(profile => {
const profileSettings = this.transferState.get(this.PROFILE_SETTINGS_KEY, null); this.manageProfileState.setProfile(profile);
this.manageProfileState.setProfile(profileSettings); if (profile.isExternal) {
if (profileSettings.isExternal) {
this.hideChangePasswordTab = true; this.hideChangePasswordTab = true;
this.selectedTab = 1; this.selectedTab = 1;
} }
this.transferState.remove(this.PROFILE_SETTINGS_KEY); });
} else {
this.profileService.get().subscribe(profile => {
this.manageProfileState.setProfile(profile);
if (profile.isExternal) {
this.hideChangePasswordTab = true;
this.selectedTab = 1;
}
if (this.ssrService.isServer) {
this.transferState.set(this.PROFILE_SETTINGS_KEY, profile);
}
});
}
} }
} }

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

@ -27,7 +27,7 @@ import {
FormPropData, FormPropData,
generateFormFromProps, generateFormFromProps,
} from '@abp/ng.components/extensible'; } from '@abp/ng.components/extensible';
import { Component, inject, Injector, makeStateKey, OnInit, TransferState } from '@angular/core'; import { Component, inject, Injector, OnInit } from '@angular/core';
import { ReactiveFormsModule, UntypedFormGroup } from '@angular/forms'; import { ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
import { eIdentityComponents } from '../../enums/components'; import { eIdentityComponents } from '../../enums/components';
@ -67,7 +67,6 @@ export class RolesComponent implements OnInit {
protected readonly service = inject(IdentityRoleService); protected readonly service = inject(IdentityRoleService);
protected readonly ssrService = inject(SSRService); protected readonly ssrService = inject(SSRService);
ROLES_KEY = makeStateKey<any>('roles');
data: PagedResultDto<IdentityRoleDto> = { items: [], totalCount: 0 }; data: PagedResultDto<IdentityRoleDto> = { items: [], totalCount: 0 };
form!: UntypedFormGroup; form!: UntypedFormGroup;
selected?: IdentityRoleDto; selected?: IdentityRoleDto;
@ -77,7 +76,7 @@ export class RolesComponent implements OnInit {
modalBusy = false; modalBusy = false;
permissionManagementKey = ePermissionManagementComponents.PermissionManagement; permissionManagementKey = ePermissionManagementComponents.PermissionManagement;
constructor(private transferState: TransferState) {} constructor() {}
onVisiblePermissionChange = (event: boolean) => { onVisiblePermissionChange = (event: boolean) => {
this.visiblePermissions = event; this.visiblePermissions = event;
@ -140,22 +139,11 @@ export class RolesComponent implements OnInit {
} }
private hookToQuery() { private hookToQuery() {
if (this.transferState.hasKey(this.ROLES_KEY)) { this.list
this.data = this.transferState.get<PagedResultDto<IdentityRoleDto>>(this.ROLES_KEY, { .hookToQuery(query => this.service.getList(query))
items: [], .subscribe(res => {
totalCount: 0, this.data = res;
}); });
this.transferState.remove(this.ROLES_KEY);
} else {
this.list
.hookToQuery(query => this.service.getList(query))
.subscribe(res => {
this.data = res;
if (this.ssrService.isServer) {
this.transferState.set(this.ROLES_KEY, res);
}
});
}
} }
openPermissionsModal(providerKey: string) { openPermissionsModal(providerKey: string) {

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

@ -4,7 +4,6 @@ import {
LocalizationPipe, LocalizationPipe,
PagedResultDto, PagedResultDto,
ReplaceableTemplateDirective, ReplaceableTemplateDirective,
SSRService,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { import {
GetIdentityUsersInput, GetIdentityUsersInput,
@ -37,7 +36,6 @@ import {
Component, Component,
inject, inject,
Injector, Injector,
makeStateKey,
OnInit, OnInit,
TemplateRef, TemplateRef,
TrackByFunction, TrackByFunction,
@ -94,7 +92,6 @@ export class UsersComponent implements OnInit {
protected readonly toasterService = inject(ToasterService); protected readonly toasterService = inject(ToasterService);
private readonly fb = inject(UntypedFormBuilder); private readonly fb = inject(UntypedFormBuilder);
private readonly injector = inject(Injector); private readonly injector = inject(Injector);
USERS_KEY = makeStateKey<any>('users');
data: PagedResultDto<IdentityUserDto> = { items: [], totalCount: 0 }; data: PagedResultDto<IdentityUserDto> = { items: [], totalCount: 0 };
@ -125,9 +122,7 @@ export class UsersComponent implements OnInit {
trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index; trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index;
public ssrService = inject(SSRService); constructor() {}
constructor(private transferState: TransferState) {}
onVisiblePermissionChange = (event: boolean) => { onVisiblePermissionChange = (event: boolean) => {
this.visiblePermissions = event; this.visiblePermissions = event;
@ -240,19 +235,11 @@ export class UsersComponent implements OnInit {
} }
private hookToQuery() { private hookToQuery() {
if (this.transferState.hasKey(this.USERS_KEY)) { this.list
this.data = this.transferState.get(this.USERS_KEY, { items: [], totalCount: 0 }); .hookToQuery(query => this.service.getList(query))
this.transferState.remove(this.USERS_KEY); .subscribe(res => {
} else { this.data = res;
this.list });
.hookToQuery(query => this.service.getList(query))
.subscribe(res => {
this.data = res;
if (this.ssrService.isServer) {
this.transferState.set(this.USERS_KEY, res);
}
});
}
} }
openPermissionsModal(providerKey: string, entityDisplayName?: string) { openPermissionsModal(providerKey: string, entityDisplayName?: string) {

Loading…
Cancel
Save