mirror of
https://github.com/valitydev/control-center.git
synced 2024-11-06 02:25:17 +00:00
Revert domain store service (#392)
This commit is contained in:
parent
8da6c5ab04
commit
0f2441a130
@ -1,27 +1,23 @@
|
||||
import { Injectable, DestroyRef } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { DomainObject, Reference } from '@vality/domain-proto/domain';
|
||||
import { Domain, 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 {
|
||||
domain$ = defer(() => this.rawDomain$).pipe(
|
||||
map((d) => this.domainSecretService.reduceDomain(d)),
|
||||
shareReplay({ refCount: true, bufferSize: 1 }),
|
||||
);
|
||||
version$ = defer(() => this.loadedSnapshot$).pipe(
|
||||
version$ = combineLatest([defer(() => this.snapshot$), defer(() => this.progress$)]).pipe(
|
||||
filter(([, p]) => !p),
|
||||
map(([s]) => s.version),
|
||||
shareReplay({ refCount: true, bufferSize: 1 }),
|
||||
);
|
||||
isLoading$ = inProgressFrom(
|
||||
() => this.progress$,
|
||||
@ -38,31 +34,8 @@ 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<void>(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,
|
||||
@ -75,9 +48,17 @@ export class DomainStoreService {
|
||||
this.reload$.next();
|
||||
}
|
||||
|
||||
getDomain(raw = false): Observable<Domain> {
|
||||
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<DomainObject> {
|
||||
return this.objects$.pipe(
|
||||
map((objects) => objects.get(createObjectHash(ref))?.[raw ? 'raw' : 'reduced']),
|
||||
return this.getDomain(raw).pipe(
|
||||
map((domain) => Array.from(domain).find(([r]) => isEqual(ref, r))?.[1]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -88,7 +69,7 @@ export class DomainStoreService {
|
||||
getObjectsRefs<T extends keyof DomainObject>(
|
||||
objectType: T,
|
||||
): Observable<[Reference, DomainObject][]> {
|
||||
return this.domain$.pipe(
|
||||
return this.getDomain().pipe(
|
||||
map((d) => Array.from(d).filter(([, o]) => getUnionKey(o) === objectType)),
|
||||
);
|
||||
}
|
||||
|
@ -92,10 +92,8 @@
|
||||
Change status
|
||||
</button>
|
||||
<button mat-raised-button (click)="createWallet()">Add wallet modification</button>
|
||||
<button mat-raised-button (click)="createShop(false)">Add shop modifications</button>
|
||||
<button color="accent" mat-raised-button (click)="createShop(true)">
|
||||
Add shop modifications without payout
|
||||
</button>
|
||||
<!-- <button mat-raised-button (click)="createShop(false)">Add shop modifications</button>-->
|
||||
<button mat-raised-button (click)="createShop(true)">Add shop modifications</button>
|
||||
<button color="primary" mat-raised-button (click)="addModification()">
|
||||
Add modification
|
||||
</button>
|
||||
|
@ -59,7 +59,7 @@ export class DomainObjectsTableComponent implements OnInit {
|
||||
(this.qp.params.types as (keyof DomainObject)[]) || [],
|
||||
);
|
||||
objects$: Observable<DomainObjectData[]> = combineLatest([
|
||||
this.domainStoreService.domain$,
|
||||
this.domainStoreService.getDomain(),
|
||||
this.typesControl.valueChanges.pipe(startWith(this.typesControl.value)),
|
||||
]).pipe(
|
||||
switchMap(([objects, types]) =>
|
||||
|
@ -34,7 +34,7 @@ export class DomainObjectCardComponent implements OnChanges {
|
||||
|
||||
ref$ = new ReplaySubject<Reference>(1);
|
||||
progress$ = this.domainStoreService.isLoading$;
|
||||
domainObject$ = combineLatest([this.domainStoreService.domain$, this.ref$]).pipe(
|
||||
domainObject$ = combineLatest([this.domainStoreService.getDomain(), this.ref$]).pipe(
|
||||
map(([domain, ref]) =>
|
||||
domain.get(Array.from(domain.keys()).find((k) => isEqualThrift(k, ref))),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user