Skip to content

Commit

Permalink
fix: tuning product apps tab
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Mar 1, 2024
1 parent f0b81b7 commit ac8fa3b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 46 deletions.
55 changes: 19 additions & 36 deletions src/app/product-store/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class AppDetailComponent implements OnChanges {
@Input() dateFormat = 'medium'
@Input() changeMode: ChangeMode = 'VIEW'
@Input() displayDialog = false
@Output() displayDialogChange = new EventEmitter<boolean>()
@Output() appChanged = new EventEmitter<boolean>()

private debug = true
Expand Down Expand Up @@ -119,12 +118,6 @@ export class AppDetailComponent implements OnChanges {
if (this.appAbstract.appType === 'MS') this.getMs()
}
}
// private log(text: string, obj?: object): void {
// if (this.debug) {
// if (obj) console.log('app detail: ' + text, obj)
// else console.log('app detail: ' + text)
// }
// }

public allowEditing(): boolean {
return (
Expand Down Expand Up @@ -225,7 +218,6 @@ export class AppDetailComponent implements OnChanges {
}

public onDialogHide() {
this.displayDialogChange.emit(false)
this.appChanged.emit(false)
}

Expand All @@ -236,43 +228,37 @@ export class AppDetailComponent implements OnChanges {
return
}
this.mfe = { ...this.formGroupMfe.value, id: this.mfe?.id }
// manage classifications => is string array
if (this.mfe?.classifications) {
const a: string = this.formGroupMfe.controls['classifications'].value
let ar: Array<string> | undefined = []
if (ar && a?.length > 0) {
a.toString()
.split(',')
.map((a) => ar?.push(a.trim()))
} else ar = undefined
this.mfe.classifications = ar?.sort()
} else if (this.mfe) {
this.mfe.classifications = undefined
}
if (this.changeMode === 'CREATE') {
this.createMfe()
} else if (this.changeMode === 'EDIT') {
this.updateMfe()
}
} else if (this.appAbstract?.appType === 'MS') {
if (this.mfe)
this.mfe.classifications = this.makeStringArrayUnique(this.formGroupMfe.controls['classifications'].value)
this.changeMode === 'CREATE' ? this.createMfe() : this.updateMfe()
}
if (this.appAbstract?.appType === 'MS') {
if (!this.formGroupMs.valid) {
this.msgService.error({ summaryKey: 'VALIDATION.FORM_INVALID' })
return
}
this.ms = { ...this.formGroupMs.value, id: this.ms?.id }
if (this.changeMode === 'CREATE') {
this.createMs()
} else if (this.changeMode === 'EDIT') {
this.updateMs()
}
this.changeMode === 'CREATE' ? this.createMs() : this.updateMs()
}
}

private makeStringArrayUnique(unsorted: string | undefined): string[] | undefined {
if (!unsorted || unsorted?.length === 0) return undefined
let ar: Array<string> = []
unsorted
.toString()
.split(',')
.map((a) => ar?.push(a.trim()))
return ar.sort(this.sortStrings)
}
private sortStrings(a: string, b: string): number {
return (a as String).toUpperCase().localeCompare((b as String).toUpperCase())
}

private createMfe() {
this.mfeApi.createMicrofrontend({ createMicrofrontendRequest: this.mfe as CreateMicrofrontendRequest }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.CREATE.APP.OK' })
this.displayDialogChange.emit(true)
this.appChanged.emit(true)
},
error: (err) => {
Expand All @@ -284,7 +270,6 @@ export class AppDetailComponent implements OnChanges {
this.msApi.createMicroservice({ createMicroserviceRequest: this.ms as CreateMicroserviceRequest }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.CREATE.APP.OK' })
this.displayDialogChange.emit(true)
this.appChanged.emit(true)
},
error: (err) => {
Expand All @@ -302,7 +287,6 @@ export class AppDetailComponent implements OnChanges {
.subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.EDIT.APP.OK' })
//this.displayDialogChange.emit(false)
this.appChanged.emit(true)
},
error: (err) => {
Expand All @@ -319,7 +303,6 @@ export class AppDetailComponent implements OnChanges {
.subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.EDIT.APP.OK' })
this.displayDialogChange.emit(true)
this.appChanged.emit(true)
},
error: (err) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<div *ngIf="!apps$">
<div class="surface-section my-3">
<p-message severity="error" styleClass="p-2" [text]="'ACTIONS.SEARCH.APP.NOT_FOUND' | translate"></p-message>
</div>
</div>
<ng-container *ngIf="apps$ | async as apps">
<p-dataView
id="product_detail_apps_dataview"
[value]="(apps$ | async) ?? []"
[value]="apps"
[paginator]="true"
[alwaysShowPaginator]="false"
[rowsPerPageOptions]="[10, 20, 50]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
[disabled]="changeMode !== 'VIEW'"
[header]="'DIALOG.TABS.APPS' | translate"
>
<app-product-apps [product]="product" [changeMode]="changeMode"></app-product-apps>
<app-product-apps [product]="product_for_apps" [changeMode]="changeMode"></app-product-apps>
</p-tabPanel>
</p-tabView>
</ocx-page-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ProductDetailComponent implements OnInit {
public actions$: Observable<Action[]> | undefined
public productName: string
public product: ProductAndWorkspaces | undefined
public product_for_apps: ProductAndWorkspaces | undefined
public changeMode: ChangeMode = 'CREATE'
public loading = false
public dateFormat = 'medium'
Expand Down Expand Up @@ -56,6 +57,7 @@ export class ProductDetailComponent implements OnInit {
public onTabChange($event: any) {
this.selectedTabIndex = $event.index
this.prepareActionButtons()
if (this.selectedTabIndex === 2) this.product_for_apps = this.product // lazy load
}

public getProduct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ describe('ProductDetailComponent', () => {
expect(component.dateFormat).toEqual('dd.MM.yyyy HH:mm:ss')
})

it('should behave correctly onTabChange: 1', () => {
component.onTabChange({ index: 1 })
it('should behave correctly onTabChange: 2', () => {
component.product = product
component.onTabChange({ index: 2 })

expect(component.selectedTabIndex).toEqual(1)
expect(component.selectedTabIndex).toEqual(2)
expect(component.product_for_apps).toEqual(product)
})
})

0 comments on commit ac8fa3b

Please sign in to comment.