Browse Source

transferState added to tenants management

feature/ssr-migration-schematic
erdemcaygor 1 year ago
parent
commit
8ad91a506d
  1. 25
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

25
npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

@ -3,6 +3,7 @@ import {
LocalizationPipe, LocalizationPipe,
PagedResultDto, PagedResultDto,
ReplaceableTemplateDirective, ReplaceableTemplateDirective,
SSRService,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { import {
eFeatureManagementComponents, eFeatureManagementComponents,
@ -24,7 +25,7 @@ import {
FormPropData, FormPropData,
generateFormFromProps, generateFormFromProps,
} from '@abp/ng.components/extensible'; } from '@abp/ng.components/extensible';
import { Component, inject, Injector, OnInit } from '@angular/core'; import { Component, inject, Injector, makeStateKey, OnInit, TransferState } from '@angular/core';
import { import {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
@ -68,6 +69,7 @@ export class TenantsComponent 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);
private readonly ssrService = inject(SSRService);
data: PagedResultDto<TenantDto> = { items: [], totalCount: 0 }; data: PagedResultDto<TenantDto> = { items: [], totalCount: 0 };
@ -84,11 +86,14 @@ export class TenantsComponent implements OnInit {
modalBusy = false; modalBusy = false;
featureManagementKey = eFeatureManagementComponents.FeatureManagement; featureManagementKey = eFeatureManagementComponents.FeatureManagement;
TENANTS_KEY = makeStateKey<PagedResultDto<TenantDto>>('tenants');
get hasSelectedTenant(): boolean { get hasSelectedTenant(): boolean {
return Boolean(this.selected.id); return Boolean(this.selected.id);
} }
constructor(private transferState: TransferState) {}
onVisibleFeaturesChange = (value: boolean) => { onVisibleFeaturesChange = (value: boolean) => {
this.visibleFeatures = value; this.visibleFeatures = value;
}; };
@ -152,11 +157,19 @@ export class TenantsComponent implements OnInit {
} }
hookToQuery() { hookToQuery() {
this.list if (this.transferState.hasKey(this.TENANTS_KEY)) {
.hookToQuery(query => this.service.getList(query)) this.data = this.transferState.get(this.TENANTS_KEY, { items: [], totalCount: 0 });
.subscribe(res => { this.transferState.remove(this.TENANTS_KEY);
this.data = res; } else {
}); this.list
.hookToQuery(query => this.service.getList(query))
.subscribe(res => {
this.data = res;
if (this.ssrService.isSsr) {
this.transferState.set(this.TENANTS_KEY, res);
}
});
}
} }
onSharedDatabaseChange(value: boolean) { onSharedDatabaseChange(value: boolean) {

Loading…
Cancel
Save