Skip to content

Commit

Permalink
Merge pull request #304 from catenax-ng/main
Browse files Browse the repository at this point in the history
Added filtering for table views
  • Loading branch information
ds-mwesener authored Oct 4, 2023
2 parents fd0d456 + 1a5740e commit 24b237e
Show file tree
Hide file tree
Showing 41 changed files with 3,527 additions and 1,028 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- archunit tests as preparation for good quality architecture checks
- safety and security doc including roles matrix
- handling for duplicate shellDescriptor ids when refreshing registry
- Extendend testdata to reflect better overview of assets
- Filter for each assetAsBuilt table attribute
- Filter for each assetAsPlanned table attribute
- Extended testdata to reflect better overview of assets
- Extended testdata to reflect better overview of assets
- Support for TractionBatteryCode

### Changed
Expand Down
11 changes: 11 additions & 0 deletions frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
}
]
},
"authE2eB": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.authE2eB.ts"
}
]
},
"authLocal": {
"fileReplacements": [
{
Expand Down Expand Up @@ -184,6 +192,9 @@
"authE2eA": {
"browserTarget": "trace-x:build:dev,authE2eA"
},
"authE2eB": {
"browserTarget": "trace-x:build:dev,authE2eB"
},
"authLocal": {
"browserTarget": "trace-x:build:dev,authLocal"
},
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"start:auth:dev": "ng serve --configuration=dev,authDev",
"start:auth:test": "ng serve --configuration=dev,authTest",
"start:auth:e2ea": "ng serve --configuration=dev,authE2eA",
"start:auth:e2eb": "ng serve --configuration=dev,authE2eB",
"start:auth:mock": "ng serve --configuration=authMock",
"start:auth:local": "ng serve --configuration=authLocal",
"start:auth:localBe": "ng serve --configuration=localBackend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,62 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { OtherPartsFacade } from '@page/other-parts/core/other-parts.facade';
import { OtherPartsService } from '@page/other-parts/core/other-parts.service';
import { OtherPartsState } from '@page/other-parts/core/other-parts.state';
import { MainAspectType } from '@page/parts/model/mainAspectType.enum';
import { PartsAssembler } from '@shared/assembler/parts.assembler';
import { PartsService } from '@shared/service/parts.service';
import { waitFor } from '@testing-library/angular';
import { BehaviorSubject, firstValueFrom, of } from 'rxjs';
import { map } from 'rxjs/operators';
import {
mockAssetList,
mockAssets,
} from '../../../../mocks/services/parts-mock/partsAsPlanned/partsAsPlanned.test.model';
import {OtherPartsFacade} from '@page/other-parts/core/other-parts.facade';
import {OtherPartsService} from '@page/other-parts/core/other-parts.service';
import {OtherPartsState} from '@page/other-parts/core/other-parts.state';
import {MainAspectType} from '@page/parts/model/mainAspectType.enum';
import {PartsAssembler} from '@shared/assembler/parts.assembler';
import {PartsService} from '@shared/service/parts.service';
import {waitFor} from '@testing-library/angular';
import {firstValueFrom, of} from 'rxjs';
import {map} from 'rxjs/operators';
import {mockAssets,} from '../../../../mocks/services/parts-mock/partsAsPlanned/partsAsPlanned.test.model';

describe('OtherPartsFacade', () => {
let otherPartsFacade: OtherPartsFacade, otherPartsState: OtherPartsState, partsServiceMok: PartsService, otherPartsServiceMock: OtherPartsService;
let otherPartsFacade: OtherPartsFacade, otherPartsState: OtherPartsState, partsServiceMok: PartsService,
otherPartsServiceMock: OtherPartsService;

beforeEach(() => {
partsServiceMok = {
getPart: id => new BehaviorSubject(mockAssetList[id]).pipe(map(part => PartsAssembler.assemblePart(part, MainAspectType.AS_BUILT))),
getPartsAsBuilt: (_page, _pageSize, _sorting) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_BUILT))),
getPartsAsPlanned: (_page, _pageSize, _sorting) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_PLANNED))),
} as PartsService;
beforeEach(() => {
otherPartsServiceMock = {
getOtherPartsAsBuilt: (_page, _pageSize, _sorting, _owner) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_BUILT))),
getOtherPartsAsPlanned: (_page, _pageSize, _sorting, _owner) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_PLANNED))),
} as OtherPartsService;

otherPartsServiceMock = {
getOtherPartsAsBuilt: (_page, _pageSize, _sorting, _owner) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_BUILT))),
getOtherPartsAsPlanned: (_page, _pageSize, _sorting, _owner) =>
of(mockAssets).pipe(map(parts => PartsAssembler.assembleParts(parts, MainAspectType.AS_PLANNED))),
} as OtherPartsService;

otherPartsState = new OtherPartsState();
otherPartsFacade = new OtherPartsFacade(otherPartsServiceMock, partsServiceMok, otherPartsState);
});
otherPartsState = new OtherPartsState();
otherPartsFacade = new OtherPartsFacade(otherPartsServiceMock, otherPartsState);
});

describe('setActiveInvestigationForParts', () => {
it('should set parts if request is successful', async () => {
describe('setActiveInvestigationForParts', () => {
it('should set parts if request is successful', async () => {

const otherParts = PartsAssembler.assembleOtherParts(mockAssets, MainAspectType.AS_BUILT);
otherPartsState.supplierPartsAsBuilt = { data: otherParts};
const otherParts = PartsAssembler.assembleOtherParts(mockAssets, MainAspectType.AS_BUILT);
otherPartsState.supplierPartsAsBuilt = {data: otherParts};

otherParts.content = otherParts.content.map(part => {
const activeInvestigation = otherParts.content.some(currentPart => currentPart.id === part.id);
return { ...part, activeInvestigation };
});
otherParts.content = otherParts.content.map(part => {
const activeInvestigation = otherParts.content.some(currentPart => currentPart.id === part.id);
return {...part, activeInvestigation};
});

const parts = await firstValueFrom(otherPartsState.supplierPartsAsBuilt$);
await waitFor(() =>
expect(parts).toEqual({
error: undefined,
loader: undefined,
data: otherParts,
}),
);
});
const parts = await firstValueFrom(otherPartsState.supplierPartsAsBuilt$);
await waitFor(() =>
expect(parts).toEqual({
error: undefined,
loader: undefined,
data: otherParts,
}),
);
});

it('should not set parts if no data in state', async () => {
it('should not set parts if no data in state', async () => {

const parts = await firstValueFrom(otherPartsState.supplierPartsAsBuilt$);
await waitFor(() =>
expect(parts).toEqual({
loader: true,
}),
);
const parts = await firstValueFrom(otherPartsState.supplierPartsAsBuilt$);
await waitFor(() =>
expect(parts).toEqual({
loader: true,
}),
);
});
});
});
});
130 changes: 64 additions & 66 deletions frontend/src/app/modules/page/other-parts/core/other-parts.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,86 +19,84 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { Injectable } from '@angular/core';
import { Pagination } from '@core/model/pagination.model';
import { OtherPartsService } from '@page/other-parts/core/other-parts.service';
import { OtherPartsState } from '@page/other-parts/core/other-parts.state';
import { Owner } from '@page/parts/model/owner.enum';
import { Part } from '@page/parts/model/parts.model';
import { TableHeaderSort } from '@shared/components/table/table.model';
import { View } from '@shared/model/view.model';
import { PartsService } from '@shared/service/parts.service';
import { Observable, Subscription } from 'rxjs';
import {Injectable} from '@angular/core';
import {Pagination} from '@core/model/pagination.model';
import {OtherPartsService} from '@page/other-parts/core/other-parts.service';
import {OtherPartsState} from '@page/other-parts/core/other-parts.state';
import {Owner} from '@page/parts/model/owner.enum';
import {AssetAsBuiltFilter, AssetAsPlannedFilter, Part} from '@page/parts/model/parts.model';
import {TableHeaderSort} from '@shared/components/table/table.model';
import {View} from '@shared/model/view.model';
import {Observable, Subscription} from 'rxjs';

@Injectable()
export class OtherPartsFacade {
private customerPartsAsBuiltSubscription: Subscription;
private customerPartsAsPlannedSubscription: Subscription;
private customerPartsAsBuiltSubscription: Subscription;
private customerPartsAsPlannedSubscription: Subscription;

private supplierPartsAsBuiltSubscription: Subscription;
private supplierPartsAsPlannedSubscription: Subscription;
private supplierPartsAsBuiltSubscription: Subscription;
private supplierPartsAsPlannedSubscription: Subscription;

constructor(
private readonly otherPartsService: OtherPartsService,
private readonly partsService: PartsService,
private readonly otherPartsState: OtherPartsState,
) {}
constructor(
private readonly otherPartsService: OtherPartsService,
private readonly otherPartsState: OtherPartsState,
) {
}

public get customerPartsAsBuilt$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.customerPartsAsBuilt$;
}
public get customerPartsAsBuilt$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.customerPartsAsBuilt$;
}

public get customerPartsAsPlanned$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.customerPartsAsPlanned$;
}
public get customerPartsAsPlanned$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.customerPartsAsPlanned$;
}

public get supplierPartsAsBuilt$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.supplierPartsAsBuilt$;
}
public get supplierPartsAsBuilt$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.supplierPartsAsBuilt$;
}

public get supplierPartsAsPlanned$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.supplierPartsAsPlanned$;
}
public get supplierPartsAsPlanned$(): Observable<View<Pagination<Part>>> {
return this.otherPartsState.supplierPartsAsPlanned$;
}

// TODO: remove OtherPartsService and integrate in PartService
public setCustomerPartsAsBuilt(page = 0, pageSize = 50, sorting: TableHeaderSort[] = []): void {
this.customerPartsAsBuiltSubscription?.unsubscribe();
this.customerPartsAsBuiltSubscription = this.otherPartsService.getOtherPartsAsBuilt(page, pageSize, sorting, Owner.CUSTOMER).subscribe({
next: data => (this.otherPartsState.customerPartsAsBuilt = { data }),
error: error => (this.otherPartsState.customerPartsAsBuilt = { error }),
});
}
public setCustomerPartsAsBuilt(page = 0, pageSize = 50, sorting: TableHeaderSort[] = [], filter?: AssetAsBuiltFilter): void {
this.customerPartsAsBuiltSubscription?.unsubscribe();
this.customerPartsAsBuiltSubscription = this.otherPartsService.getOtherPartsAsBuilt(page, pageSize, sorting, Owner.CUSTOMER, filter).subscribe({
next: data => (this.otherPartsState.customerPartsAsBuilt = {data}),
error: error => (this.otherPartsState.customerPartsAsBuilt = {error}),
});
}

public setCustomerPartsAsPlanned(page = 0, pageSize = 50, sorting: TableHeaderSort[] = []): void {
this.customerPartsAsPlannedSubscription?.unsubscribe();
this.customerPartsAsPlannedSubscription = this.otherPartsService.getOtherPartsAsPlanned(page, pageSize, sorting, Owner.CUSTOMER).subscribe({
next: data => (this.otherPartsState.customerPartsAsPlanned = { data }),
error: error => (this.otherPartsState.customerPartsAsPlanned = { error }),
});
}
public setCustomerPartsAsPlanned(page = 0, pageSize = 50, sorting: TableHeaderSort[] = [], filter?: AssetAsPlannedFilter): void {
this.customerPartsAsPlannedSubscription?.unsubscribe();
this.customerPartsAsPlannedSubscription = this.otherPartsService.getOtherPartsAsPlanned(page, pageSize, sorting, Owner.CUSTOMER, filter).subscribe({
next: data => (this.otherPartsState.customerPartsAsPlanned = {data}),
error: error => (this.otherPartsState.customerPartsAsPlanned = {error}),
});
}

public setSupplierPartsAsBuilt(page = 0, pageSize = 50, sorting: TableHeaderSort[] = []): void {
this.supplierPartsAsBuiltSubscription?.unsubscribe();
this.supplierPartsAsBuiltSubscription = this.otherPartsService.getOtherPartsAsBuilt(page, pageSize, sorting, Owner.SUPPLIER).subscribe({
next: data => (this.otherPartsState.supplierPartsAsBuilt = { data }),
error: error => (this.otherPartsState.supplierPartsAsBuilt = { error }),
});
}
public setSupplierPartsAsBuilt(page = 0, pageSize = 50, sorting: TableHeaderSort[] = [], filter?: AssetAsBuiltFilter): void {
this.supplierPartsAsBuiltSubscription?.unsubscribe();
this.supplierPartsAsBuiltSubscription = this.otherPartsService.getOtherPartsAsBuilt(page, pageSize, sorting, Owner.SUPPLIER, filter).subscribe({
next: data => (this.otherPartsState.supplierPartsAsBuilt = {data}),
error: error => (this.otherPartsState.supplierPartsAsBuilt = {error}),
});
}

public setSupplierPartsAsPlanned(page = 0, pageSize = 50, sorting: TableHeaderSort[] = []): void {
this.supplierPartsAsPlannedSubscription?.unsubscribe();
this.supplierPartsAsPlannedSubscription = this.otherPartsService.getOtherPartsAsPlanned(page, pageSize, sorting, Owner.SUPPLIER).subscribe({
next: data => (this.otherPartsState.supplierPartsAsPlanned = { data }),
error: error => (this.otherPartsState.supplierPartsAsPlanned = { error }),
});
}
public setSupplierPartsAsPlanned(page = 0, pageSize = 50, sorting: TableHeaderSort[] = [], filter?: AssetAsPlannedFilter): void {
this.supplierPartsAsPlannedSubscription?.unsubscribe();
this.supplierPartsAsPlannedSubscription = this.otherPartsService.getOtherPartsAsPlanned(page, pageSize, sorting, Owner.SUPPLIER, filter).subscribe({
next: data => (this.otherPartsState.supplierPartsAsPlanned = {data}),
error: error => (this.otherPartsState.supplierPartsAsPlanned = {error}),
});
}



public unsubscribeParts(): void {
this.customerPartsAsBuiltSubscription?.unsubscribe();
this.customerPartsAsPlannedSubscription?.unsubscribe();
this.supplierPartsAsBuiltSubscription?.unsubscribe();
this.supplierPartsAsPlannedSubscription?.unsubscribe();
}
public unsubscribeParts(): void {
this.customerPartsAsBuiltSubscription?.unsubscribe();
this.customerPartsAsPlannedSubscription?.unsubscribe();
this.supplierPartsAsBuiltSubscription?.unsubscribe();
this.supplierPartsAsPlannedSubscription?.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import {Pagination} from '@core/model/pagination.model';
import {environment} from '@env';
import {MainAspectType} from '@page/parts/model/mainAspectType.enum';
import {Owner} from '@page/parts/model/owner.enum';
import {Part, PartsResponse} from '@page/parts/model/parts.model';
import {AssetAsBuiltFilter, AssetAsPlannedFilter, Part, PartsResponse} from '@page/parts/model/parts.model';
import {PartsAssembler} from '@shared/assembler/parts.assembler';
import {TableHeaderSort} from '@shared/components/table/table.model';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {enrichFilterAndGetUpdatedParams} from "@shared/helper/filter-helper";

@Injectable()
export class OtherPartsService {
Expand All @@ -40,7 +41,7 @@ export class OtherPartsService {
}


public getOtherPartsAsBuilt(page: number, pageSize: number, sorting: TableHeaderSort[], owner: Owner): Observable<Pagination<Part>> {
public getOtherPartsAsBuilt(page: number, pageSize: number, sorting: TableHeaderSort[], owner: Owner, filter?: AssetAsBuiltFilter): Observable<Pagination<Part>> {
let sort = sorting.map(sortingItem => PartsAssembler.mapSortToApiSort(sortingItem));
let params = new HttpParams()
.set('page', page)
Expand All @@ -51,12 +52,15 @@ export class OtherPartsService {
params = params.append('sort', sortingItem);
})

if (filter) {
params = enrichFilterAndGetUpdatedParams(filter, params);
}
return this.apiService
.getBy<PartsResponse>(`${this.url}/assets/as-built`, params)
.pipe(map(parts => PartsAssembler.assembleOtherParts(parts, MainAspectType.AS_BUILT)));
}

public getOtherPartsAsPlanned(page: number, pageSize: number, sorting: TableHeaderSort[], owner: Owner): Observable<Pagination<Part>> {
public getOtherPartsAsPlanned(page: number, pageSize: number, sorting: TableHeaderSort[], owner: Owner, filter?: AssetAsPlannedFilter): Observable<Pagination<Part>> {
let sort = sorting.map(sortingItem => PartsAssembler.mapSortToApiSort(sortingItem));
let params = new HttpParams()
.set('page', page)
Expand All @@ -66,10 +70,13 @@ export class OtherPartsService {
sort.forEach(sortingItem => {
params = params.append('sort', sortingItem);
})
if (filter) {
params = enrichFilterAndGetUpdatedParams(filter, params);
}

return this.apiService
.getBy<PartsResponse>(`${this.url}/assets/as-planned`, params)
.pipe(map(parts => PartsAssembler.assembleOtherParts(parts, MainAspectType.AS_BUILT)));
.pipe(map(parts => PartsAssembler.assembleOtherParts(parts, MainAspectType.AS_PLANNED)));
}

}
Loading

0 comments on commit 24b237e

Please sign in to comment.