diff --git a/package-lock.json b/package-lock.json index 98e96087..632b4fa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@angular/platform-server": "18.2.4", "@angular/router": "18.2.4", "@ngneat/input-mask": "6.0.0", - "@vality/deanonimus-proto": "2.0.1-2a02d87.0", + "@vality/deanonimus-proto": "2.0.1-6605c72.0", "@vality/domain-proto": "2.0.1-7762f6c.0", "@vality/dominator-proto": "1.0.1-41bee97.0", "@vality/fistful-proto": "2.0.1-88e69a5.0", @@ -5920,9 +5920,9 @@ } }, "node_modules/@vality/deanonimus-proto": { - "version": "2.0.1-2a02d87.0", - "resolved": "https://registry.npmjs.org/@vality/deanonimus-proto/-/deanonimus-proto-2.0.1-2a02d87.0.tgz", - "integrity": "sha512-mokuK6w+ExASdDE6+L9bM2SaS0yVPSyBvXavY8rRtNzZgVdmj7KSRiyGmXz41grhS6jcvD8aR85Nj4o7/iogmQ==" + "version": "2.0.1-6605c72.0", + "resolved": "https://registry.npmjs.org/@vality/deanonimus-proto/-/deanonimus-proto-2.0.1-6605c72.0.tgz", + "integrity": "sha512-vRJV1F+KChEGXRvpA5VBgT4y6pUpIyBOFyKfk74AyRG6VyERGt7Qh5rnUD/odaSOzJrI91qXfb4vIh8qt970ng==" }, "node_modules/@vality/domain-proto": { "version": "2.0.1-7762f6c.0", diff --git a/package.json b/package.json index b79d0a1f..ff4bfc27 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@angular/platform-server": "18.2.4", "@angular/router": "18.2.4", "@ngneat/input-mask": "6.0.0", - "@vality/deanonimus-proto": "2.0.1-2a02d87.0", + "@vality/deanonimus-proto": "2.0.1-6605c72.0", "@vality/domain-proto": "2.0.1-7762f6c.0", "@vality/dominator-proto": "1.0.1-41bee97.0", "@vality/fistful-proto": "2.0.1-88e69a5.0", diff --git a/src/app/api/domain-config/stores/domain-store.service.ts b/src/app/api/domain-config/stores/domain-store.service.ts index 93a9b747..051092f7 100644 --- a/src/app/api/domain-config/stores/domain-store.service.ts +++ b/src/app/api/domain-config/stores/domain-store.service.ts @@ -1,23 +1,27 @@ import { Injectable, DestroyRef } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { Domain, DomainObject, Reference } from '@vality/domain-proto/domain'; +import { DomainObject, Reference } from '@vality/domain-proto/domain'; import { Commit, Snapshot, Version } from '@vality/domain-proto/domain_config'; import { NotifyLogService, handleError, inProgressFrom, progressTo } from '@vality/ng-core'; import { getUnionKey } from '@vality/ng-thrift'; -import isEqual from 'lodash-es/isEqual'; import { BehaviorSubject, defer, Observable, of, ReplaySubject, filter, combineLatest } from 'rxjs'; import { map, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators'; import { DomainSecretService } from '../../../shared/services'; import { RepositoryService } from '../repository.service'; +import { createObjectHash } from '../utils/create-object-hash'; @Injectable({ providedIn: 'root', }) export class DomainStoreService { - version$ = combineLatest([defer(() => this.snapshot$), defer(() => this.progress$)]).pipe( - filter(([, p]) => !p), + domain$ = defer(() => this.rawDomain$).pipe( + map((d) => this.domainSecretService.reduceDomain(d)), + shareReplay({ refCount: true, bufferSize: 1 }), + ); + version$ = defer(() => this.loadedSnapshot$).pipe( map(([s]) => s.version), + shareReplay({ refCount: true, bufferSize: 1 }), ); isLoading$ = inProgressFrom( () => this.progress$, @@ -34,8 +38,31 @@ export class DomainStoreService { takeUntilDestroyed(this.destroyRef), shareReplay(1), ); + private loadedSnapshot$ = combineLatest([ + defer(() => this.snapshot$), + defer(() => this.progress$), + ]).pipe( + filter(([, p]) => !p), + shareReplay({ refCount: true, bufferSize: 1 }), + ); private reload$ = new ReplaySubject(1); private progress$ = new BehaviorSubject(0); + private rawDomain$ = this.loadedSnapshot$.pipe( + map(([s]) => s?.domain), + shareReplay({ refCount: true, bufferSize: 1 }), + ); + private objects$ = combineLatest([this.rawDomain$, this.domain$]).pipe( + map( + ([rawDomain, domain]) => + new Map( + Array.from(rawDomain).map(([ref, raw]) => [ + createObjectHash(ref), + { raw, reduced: domain.get(ref) }, + ]), + ), + ), + shareReplay({ refCount: true, bufferSize: 1 }), + ); constructor( private repositoryService: RepositoryService, @@ -48,17 +75,9 @@ export class DomainStoreService { this.reload$.next(); } - getDomain(raw = false): Observable { - return combineLatest([defer(() => this.snapshot$), defer(() => this.progress$)]).pipe( - filter(([, p]) => !p), - map(([s]) => s?.domain), - map((d) => (raw ? d : this.domainSecretService.reduceDomain(d))), - ); - } - getObject(ref: Reference, raw = false): Observable { - return this.getDomain(raw).pipe( - map((domain) => Array.from(domain).find(([r]) => isEqual(ref, r))?.[1]), + return this.objects$.pipe( + map((objects) => objects.get(createObjectHash(ref))?.[raw ? 'raw' : 'reduced']), ); } @@ -69,7 +88,7 @@ export class DomainStoreService { getObjectsRefs( objectType: T, ): Observable<[Reference, DomainObject][]> { - return this.getDomain().pipe( + return this.domain$.pipe( map((d) => Array.from(d).filter(([, o]) => getUnionKey(o) === objectType)), ); } diff --git a/src/app/sections/claim/claim.component.html b/src/app/sections/claim/claim.component.html index aaf318b7..4461d477 100644 --- a/src/app/sections/claim/claim.component.html +++ b/src/app/sections/claim/claim.component.html @@ -92,8 +92,7 @@ Change status - - + diff --git a/src/app/sections/claim/claim.component.ts b/src/app/sections/claim/claim.component.ts index af7cc9f7..18c25bff 100644 --- a/src/app/sections/claim/claim.component.ts +++ b/src/app/sections/claim/claim.component.ts @@ -115,13 +115,13 @@ export class ClaimComponent { }); } - createShop(withoutPayout = true) { + createShop() { combineLatest([this.party$, this.claim$]) .pipe( first(), switchMap(([party, claim]) => this.dialogService - .open(CreateShopDialogComponent, { party, claim, withoutPayout }) + .open(CreateShopDialogComponent, { party, claim }) .afterClosed(), ), takeUntilDestroyed(this.destroyRef), diff --git a/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts b/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts index 48773acb..7188c9e8 100644 --- a/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts +++ b/src/app/sections/claim/components/create-shop-dialog/create-shop-dialog.component.ts @@ -74,10 +74,7 @@ const DEFAULT_SHOP_LOCATION: ShopLocation = { styles: ``, }) export class CreateShopDialogComponent - extends DialogSuperclass< - CreateShopDialogComponent, - { party: Party; claim: Claim; withoutPayout: boolean } - > + extends DialogSuperclass implements OnInit { static defaultDialogConfig = DEFAULT_DIALOG_CONFIG.large; @@ -156,7 +153,6 @@ export class CreateShopDialogComponent this.form.value; const contractorId = short().uuid(); const contractId = short().uuid(); - const payoutToolId = short().generate(); const shopId = short().uuid(); this.claimManagementService .UpdateClaim( @@ -188,31 +184,6 @@ export class CreateShopDialogComponent }, }, }, - ...(this.dialogData.withoutPayout - ? [] - : [ - { - party_modification: { - contract_modification: { - id: contractId, - modification: { - payout_tool_modification: { - payout_tool_id: payoutToolId, - modification: { - creation: { - currency: currency, - tool_info: { - russian_bank_account: - DEFAULT_RUSSIAN_BANK_ACCOUNT, - }, - }, - }, - }, - }, - }, - }, - }, - ]), { party_modification: { shop_modification: { @@ -223,9 +194,6 @@ export class CreateShopDialogComponent category: category, location: DEFAULT_SHOP_LOCATION, contract_id: contractId, - ...(this.dialogData.withoutPayout - ? {} - : { payout_tool_id: payoutToolId }), }, }, }, diff --git a/src/app/sections/domain/domain-info/domain-objects-table/domain-objects-table.component.ts b/src/app/sections/domain/domain-info/domain-objects-table/domain-objects-table.component.ts index c9387c50..9aa7ecec 100644 --- a/src/app/sections/domain/domain-info/domain-objects-table/domain-objects-table.component.ts +++ b/src/app/sections/domain/domain-info/domain-objects-table/domain-objects-table.component.ts @@ -59,7 +59,7 @@ export class DomainObjectsTableComponent implements OnInit { (this.qp.params.types as (keyof DomainObject)[]) || [], ); objects$: Observable = combineLatest([ - this.domainStoreService.getDomain(), + this.domainStoreService.domain$, this.typesControl.valueChanges.pipe(startWith(this.typesControl.value)), ]).pipe( switchMap(([objects, types]) => diff --git a/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts b/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts index dc96b468..acee51f7 100644 --- a/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts +++ b/src/app/shared/components/thrift-api-crud/domain/domain-object-card/domain-object-card.component.ts @@ -34,7 +34,7 @@ export class DomainObjectCardComponent implements OnChanges { ref$ = new ReplaySubject(1); progress$ = this.domainStoreService.isLoading$; - domainObject$ = combineLatest([this.domainStoreService.getDomain(), this.ref$]).pipe( + domainObject$ = combineLatest([this.domainStoreService.domain$, this.ref$]).pipe( map(([domain, ref]) => domain.get(Array.from(domain.keys()).find((k) => isEqualThrift(k, ref))), ),