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
></cc-select>
<mat-form-field>
<mat-label>RegExp patter</mat-label>
<mat-label>RegExp pattern</mat-label>
<input [formControl]="searchControl" matInput />
</mat-form-field>
</div>

View File

@ -37,7 +37,7 @@ export class DomainGroupComponent implements OnInit, AfterViewInit {
searchControl = new FormControl('');
typesControl = new FormControl(this.queryParamsService.params.types || []);
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 }))),
switchMap((data) =>
combineLatest(data.map((d) => this.metadataService.getDomainObjectType(d.ref))).pipe(

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
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 isNil from 'lodash-es/isNil';
import { isDominantSecretRole } from './is-dominant-secret-role';
import { reduceObject } from './reduce-object';
@ -19,16 +20,28 @@ export class DomainSecretService {
constructor(private keycloakService: KeycloakService) {}
reduceSnapshot(snapshot: Snapshot): Snapshot {
reduceDomain(domain: Domain): Domain {
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]);
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 cloneDeep from 'lodash-es/cloneDeep';
import isNil from 'lodash-es/isNil';
export const reduceObject = (objectName: string, o: DomainObject): DomainObject => ({
...o,
[objectName]: {
...o[objectName],
data: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...o[objectName].data,
options: undefined,
},
},
});
export const reduceObject = (objectName: string, o: DomainObject): DomainObject => {
if (isNil(o[objectName].data.options)) {
return o;
}
const result = cloneDeep(o);
delete result[objectName].data.options;
return result;
};

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
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 { BehaviorSubject, defer, Observable, of, ReplaySubject } from 'rxjs';
import { map, pluck, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators';
@ -13,19 +13,20 @@ import { getUnionKey } from '@cc/utils/get-union-key';
@UntilDestroy()
@Injectable()
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),
switchMap(() =>
this.repositoryService.Checkout({ head: {} }).pipe(progressTo(this.progress$))
),
map((s) => this.domainSecretService.reduceSnapshot(s)),
untilDestroyed(this),
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 progress$ = new BehaviorSubject(0);
@ -38,8 +39,15 @@ export class DomainStoreService {
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][]> {
return this.domain$.pipe(
return this.getDomain().pipe(
map((d) =>
Array.from(d.values())
.filter((o) => getUnionKey(o) === objectType)