Fix dmt commit with reduced object (#140)

This commit is contained in:
Ildar Galeev 2022-09-19 17:22:05 +03:00 committed by GitHub
parent 41fefd4dfa
commit cc9f829473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 41 deletions

View File

@ -7,7 +7,7 @@
multiple multiple
></cc-select> ></cc-select>
<mat-form-field> <mat-form-field>
<mat-label>RegExp patter</mat-label> <mat-label>RegExp pattern</mat-label>
<input [formControl]="searchControl" matInput /> <input [formControl]="searchControl" matInput />
</mat-form-field> </mat-form-field>
</div> </div>

View File

@ -37,7 +37,7 @@ export class DomainGroupComponent implements OnInit, AfterViewInit {
searchControl = new FormControl(''); searchControl = new FormControl('');
typesControl = new FormControl(this.queryParamsService.params.types || []); typesControl = new FormControl(this.queryParamsService.params.types || []);
dataSource$: Observable<MatTableDataSource<DataSourceItem>> = defer(() => this.init$).pipe( dataSource$: Observable<MatTableDataSource<DataSourceItem>> = defer(() => this.init$).pipe(
switchMap(() => this.domainStoreService.domain$), switchMap(() => this.domainStoreService.getDomain()),
map((domain) => Array.from(domain).map(([ref, obj]) => ({ ref, obj }))), map((domain) => Array.from(domain).map(([ref, obj]) => ({ ref, obj }))),
switchMap((data) => switchMap((data) =>
combineLatest(data.map((d) => this.metadataService.getDomainObjectType(d.ref))).pipe( combineLatest(data.map((d) => this.metadataService.getDomainObjectType(d.ref))).pipe(

View File

@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { from } from 'rxjs'; import { from } from 'rxjs';
@ -50,7 +49,6 @@ export class DomainObjModificationComponent implements OnInit {
constructor( constructor(
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private snackBar: MatSnackBar,
private domainObjModService: DomainObjModificationService, private domainObjModService: DomainObjModificationService,
private modifiedDomainObjectService: ModifiedDomainObjectService, private modifiedDomainObjectService: ModifiedDomainObjectService,
private domainMetadataFormExtensionsService: DomainMetadataFormExtensionsService, private domainMetadataFormExtensionsService: DomainMetadataFormExtensionsService,

View File

@ -4,6 +4,8 @@ import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';
import { switchMap } from 'rxjs'; import { switchMap } from 'rxjs';
import { first, withLatestFrom } from 'rxjs/operators'; import { first, withLatestFrom } from 'rxjs/operators';
import { DomainSecretService } from '@cc/app/shared/services/domain-secret-service';
import { getUnionKey } from '../../../utils'; import { getUnionKey } from '../../../utils';
import { ErrorService } from '../../shared/services/error'; import { ErrorService } from '../../shared/services/error';
import { NotificationService } from '../../shared/services/notification'; import { NotificationService } from '../../shared/services/notification';
@ -32,7 +34,8 @@ export class DomainObjReviewComponent {
private domainStoreService: DomainStoreService, private domainStoreService: DomainStoreService,
private notificationService: NotificationService, private notificationService: NotificationService,
private errorService: ErrorService, private errorService: ErrorService,
private domainNavigateService: DomainNavigateService private domainNavigateService: DomainNavigateService,
private domainSecretService: DomainSecretService
) { ) {
if (!modifiedDomainObjectService.domainObject) { if (!modifiedDomainObjectService.domainObject) {
this.back(); this.back();
@ -50,16 +53,15 @@ export class DomainObjReviewComponent {
{ {
update: { update: {
old_object, old_object,
new_object: { new_object: this.domainSecretService.restoreDomain(old_object, {
[getUnionKey(old_object)]: this.modifiedObject, [getUnionKey(old_object)]: this.modifiedObject,
}, }),
}, },
}, },
], ],
}) })
), ),
withLatestFrom(this.type$), withLatestFrom(this.type$),
// progressTo(this.progress$),
untilDestroyed(this) untilDestroyed(this)
) )
.subscribe({ .subscribe({

View File

@ -13,11 +13,9 @@ import { MetadataService } from './metadata.service';
@Injectable() @Injectable()
export class DomainObjModificationService { export class DomainObjModificationService {
progress$ = new BehaviorSubject(0); progress$ = new BehaviorSubject(0);
fullObject$ = defer(() => this.ref$).pipe( fullObject$ = defer(() => this.ref$).pipe(switchMap((ref) => this.getDomainObject(ref, true)));
switchMap((ref) => this.getDomainObject(ref).pipe(progressTo(this.progress$))), object$ = defer(() => this.ref$).pipe(
shareReplay({ refCount: true, bufferSize: 1 }) switchMap((ref) => this.getDomainObject(ref, false).pipe(progressTo(this.progress$))),
);
object$ = this.fullObject$.pipe(
map((obj) => getUnionValue(obj)), map((obj) => getUnionValue(obj)),
shareReplay({ refCount: true, bufferSize: 1 }) shareReplay({ refCount: true, bufferSize: 1 })
); );
@ -44,8 +42,8 @@ export class DomainObjModificationService {
private errorService: ErrorService private errorService: ErrorService
) {} ) {}
private getDomainObject(ref: Reference): Observable<DomainObject> { private getDomainObject(ref: Reference, rawDomain: boolean): Observable<DomainObject> {
return this.domainStoreService.domain$.pipe( return this.domainStoreService.getDomain(rawDomain).pipe(
first(), first(),
map((domain) => { map((domain) => {
const searchRef = JSON.stringify(ref); const searchRef = JSON.stringify(ref);

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Snapshot } from '@vality/domain-proto/lib/domain_config'; import { Domain, DomainObject } from '@vality/domain-proto';
import { KeycloakService } from 'keycloak-angular'; import { KeycloakService } from 'keycloak-angular';
import isNil from 'lodash-es/isNil';
import { isDominantSecretRole } from './is-dominant-secret-role'; import { isDominantSecretRole } from './is-dominant-secret-role';
import { reduceObject } from './reduce-object'; import { reduceObject } from './reduce-object';
@ -19,16 +20,28 @@ export class DomainSecretService {
constructor(private keycloakService: KeycloakService) {} constructor(private keycloakService: KeycloakService) {}
reduceSnapshot(snapshot: Snapshot): Snapshot { reduceDomain(domain: Domain): Domain {
if (this.isDominantSecret) { if (this.isDominantSecret) {
return snapshot; return domain;
} }
for (const [key, value] of snapshot.domain) { const result = new Map(domain);
for (const [key, value] of result) {
const found = EXCLUDE_OBJECTS.find((term) => value[term]); const found = EXCLUDE_OBJECTS.find((term) => value[term]);
if (found) { if (found) {
snapshot.domain.set(key, reduceObject(found, value)); result.set(key, reduceObject(found, value));
} }
} }
return snapshot; return result;
}
restoreDomain(raw: DomainObject, reduced: DomainObject): DomainObject {
if (this.isDominantSecret) {
return raw;
}
const found = EXCLUDE_OBJECTS.find((term) => raw[term]);
if (found && !isNil(reduced[found]) && !isNil(raw[found].data.options)) {
reduced[found].data.options = raw[found].data.options;
}
return reduced;
} }
} }

View File

@ -1,14 +1,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { DomainObject } from '@vality/domain-proto'; import { DomainObject } from '@vality/domain-proto';
import cloneDeep from 'lodash-es/cloneDeep';
import isNil from 'lodash-es/isNil';
export const reduceObject = (objectName: string, o: DomainObject): DomainObject => ({ export const reduceObject = (objectName: string, o: DomainObject): DomainObject => {
...o, if (isNil(o[objectName].data.options)) {
[objectName]: { return o;
...o[objectName], }
data: { const result = cloneDeep(o);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access delete result[objectName].data.options;
...o[objectName].data, return result;
options: undefined, };
},
},
});

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { DomainObject } from '@vality/domain-proto/lib/domain'; import { Domain, DomainObject } from '@vality/domain-proto/lib/domain';
import { Commit, Snapshot, Version } from '@vality/domain-proto/lib/domain_config'; import { Commit, Snapshot, Version } from '@vality/domain-proto/lib/domain_config';
import { BehaviorSubject, defer, Observable, of, ReplaySubject } from 'rxjs'; import { BehaviorSubject, defer, Observable, of, ReplaySubject } from 'rxjs';
import { map, pluck, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators'; import { map, pluck, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators';
@ -13,19 +13,20 @@ import { getUnionKey } from '@cc/utils/get-union-key';
@UntilDestroy() @UntilDestroy()
@Injectable() @Injectable()
export class DomainStoreService { export class DomainStoreService {
snapshot$: Observable<Snapshot> = defer(() => this.reload$).pipe( version$ = defer(() => this.snapshot$).pipe(pluck('version'));
isLoading$ = inProgressFrom(
() => this.progress$,
defer(() => this.snapshot$)
);
private snapshot$: Observable<Snapshot> = defer(() => this.reload$).pipe(
startWith(undefined), startWith(undefined),
switchMap(() => switchMap(() =>
this.repositoryService.Checkout({ head: {} }).pipe(progressTo(this.progress$)) this.repositoryService.Checkout({ head: {} }).pipe(progressTo(this.progress$))
), ),
map((s) => this.domainSecretService.reduceSnapshot(s)),
untilDestroyed(this), untilDestroyed(this),
shareReplay(1) shareReplay(1)
); );
domain$ = this.snapshot$.pipe(pluck('domain'));
version$ = this.snapshot$.pipe(pluck('version'));
isLoading$ = inProgressFrom(() => this.progress$, this.snapshot$);
private reload$ = new ReplaySubject<void>(1); private reload$ = new ReplaySubject<void>(1);
private progress$ = new BehaviorSubject(0); private progress$ = new BehaviorSubject(0);
@ -38,8 +39,15 @@ export class DomainStoreService {
this.reload$.next(); this.reload$.next();
} }
getDomain(raw = false): Observable<Domain> {
return this.snapshot$.pipe(
pluck('domain'),
map((d) => (raw ? d : this.domainSecretService.reduceDomain(d)))
);
}
getObjects<T extends keyof DomainObject>(objectType: T): Observable<DomainObject[T][]> { getObjects<T extends keyof DomainObject>(objectType: T): Observable<DomainObject[T][]> {
return this.domain$.pipe( return this.getDomain().pipe(
map((d) => map((d) =>
Array.from(d.values()) Array.from(d.values())
.filter((o) => getUnionKey(o) === objectType) .filter((o) => getUnionKey(o) === objectType)