Skip to content

Commit

Permalink
fix: optimize loading of product pathes for home page selection (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG authored Nov 6, 2024
1 parent 6e782e2 commit 7e852a7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@
</label>
</div>

<div class="p-inputgroup mb-1" controlErrorAnchor>
<div *ngIf="(productPaths$ | async) ?? [] as paths" class="p-inputgroup mb-1" controlErrorAnchor>
<span class="p-float-label">
<p-dropdown
#inputHomePage
id="ws_detail_props_item_home_page"
formControlName="homePage"
styleClass="w-full inputgroup-dropdown-with-link input-field-correction"
[options]="(productPaths$ | async) ?? []"
(onClick)="onOpenProductPathes($event, paths)"
[options]="paths"
[editable]="true"
[showClear]="true"
[ariaLabel]="'WORKSPACE.HOME_PAGE' | translate"
[pTooltip]="'WORKSPACE.TOOLTIPS.HOME_PAGE' | translate"
tooltipPosition="top"
Expand All @@ -128,7 +130,7 @@
tabindex="0"
id="ws_detail_props_item_homePage_link"
class="p-inputgroup-addon bg-primary pseudo-button pi pi-link"
[ngClass]="!editMode && !workspace?.disabled && workspace?.homePage ? 'cursor-pointer' : 'p-disabled'"
[ngClass]="!editMode && !workspace?.disabled && inputHomePage.value ? 'cursor-pointer' : 'p-disabled'"
target="_blank"
[href]="prepareProductUrl(inputHomePage.value)"
(click)="$event.stopPropagation()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
} from 'src/app/shared/generated'

const workspace = {
id: 'id',
disabled: false,
name: 'name',
displayName: 'name',
theme: 'theme',
baseUrl: '/some/base/url',
id: 'id',
disabled: false
homePage: '/welcome'
}

const formGroup = new FormGroup({
Expand Down Expand Up @@ -119,22 +120,24 @@ describe('WorkspacePropsComponent', () => {

expect(component).toBeTruthy()
})

describe('loadProductPaths', () => {
/*
fdescribe('loadProductPaths', () => {
beforeEach(() => {
spyOn(component as any, 'loadThemes')
})
it('should load product urls', () => {
wProductServiceSpy.getProductsByWorkspaceId.and.returnValue(of([{ baseUrl: '/baseUrl' }, { baseUrl: undefined }]))
wProductServiceSpy.getProductsByWorkspaceId.and.returnValue(
of([{ baseUrl: '/baseUrl' }, { baseUrl: '/baseUrl2' }])
)
component.ngOnInit()
component.productPaths$.subscribe((paths) => {
expect(paths).toContain('/baseUrl')
expect(paths).toContain(workspace.homePage)
})
})
})
})*/

describe('prepareProductUrl', () => {
it('should return a joined URL when workspace.baseUrl and val are valid', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnInit, OnChanges, Output } from '@angu
import { Location } from '@angular/common'
import { Router } from '@angular/router'
import { FormControl, FormGroup, Validators } from '@angular/forms'
import { map, Observable, Subject } from 'rxjs'
import { map, Observable, of, Subject } from 'rxjs'

import { PortalMessageService, WorkspaceService } from '@onecx/angular-integration-interface'

Expand All @@ -29,7 +29,7 @@ export class WorkspacePropsComponent implements OnInit, OnChanges {

private readonly destroy$ = new Subject()
public formGroup: FormGroup
public productPaths$!: Observable<string[]>
public productPaths$: Observable<string[]> = of([])
public themeProductRegistered$!: Observable<boolean>
public themes$!: Observable<string[]>
public urlPattern = '/base-path-to-workspace'
Expand Down Expand Up @@ -75,17 +75,17 @@ export class WorkspacePropsComponent implements OnInit, OnChanges {

public ngOnInit(): void {
if (!this.isLoading) {
this.loadProductPaths()
this.loadThemes()
}
}

public ngOnChanges(): void {
if (this.workspace) {
this.setFormData()
if (this.editMode) {
this.formGroup.enable()
} else this.formGroup.disable()
if (this.editMode) this.formGroup.enable()
else this.formGroup.disable()
// if a home page value exists then fill it into drop down list for displaying
if (this.workspace.homePage) this.productPaths$ = of([this.workspace.homePage])
} else {
this.formGroup.reset()
this.formGroup.disable()
Expand Down Expand Up @@ -203,21 +203,26 @@ export class WorkspacePropsComponent implements OnInit, OnChanges {
} else return undefined
}

private loadProductPaths(): void {
public onOpenProductPathes(ev: any, paths: string[]) {
ev.stopPropagation()
// if paths already filled then prevent doing twice
if (paths.length > (this.workspace?.homePage ? 1 : 0)) return
if (this.workspace) {
this.productPaths$ = this.wProductApi.getProductsByWorkspaceId({ id: this.workspace.id! }).pipe(
map((val: any[]) => {
const paths: string[] = []
if (val.length > 0) {
for (const p of val) paths.push(p.baseUrl ?? '')
paths.sort(sortByLocale)
paths.unshift('')
}
return paths
})
)
}
}
public onGoToHomePage(ev: any) {
ev.stopPropagation()
}

private loadThemes(): void {
this.themes$ = this.workspaceApi.getAllThemes().pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('WorkspaceSlotsComponent', () => {

component.loadData()

expect(component.exceptionKey).toBe('EXCEPTIONS.HTTP_STATUS_' + err.status + '.SLOTS')
expect(component.exceptionKey).toBe('EXCEPTIONS.HTTP_STATUS_' + err.status + '.PRODUCTS')
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WorkspaceSlotsComponent implements OnInit, OnChanges, OnDestroy {
// data
private readonly destroy$ = new Subject()
public wProducts$!: Observable<string[]>
public wProductNames!: string[]
public wProductNames: string[] = []
public wSlots$!: Observable<string[]>
public wSlots!: CombinedSlot[] // registered workspace slots
public wSlotsIntern!: CombinedSlot[] // temporary used ws slot array, final assigned to wSlots
Expand Down Expand Up @@ -262,7 +262,7 @@ export class WorkspaceSlotsComponent implements OnInit, OnChanges, OnDestroy {
return []
}),
catchError((err) => {
this.exceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + err.status + '.SLOTS'
this.exceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + err.status + '.PRODUCTS'
console.error('searchAvailableProducts():', err)
return of([])
}),
Expand Down
14 changes: 7 additions & 7 deletions src/assets/api/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ paths:
post:
x-onecx:
permissions:
workspace:
product:
- write
tags:
- workspaceProduct
Expand Down Expand Up @@ -483,7 +483,7 @@ paths:
get:
x-onecx:
permissions:
workspace:
product:
- read
tags:
- workspaceProduct
Expand All @@ -504,7 +504,7 @@ paths:
delete:
x-onecx:
permissions:
workspace:
product:
- delete
tags:
- workspaceProduct
Expand All @@ -525,7 +525,7 @@ paths:
put:
x-onecx:
permissions:
workspace:
product:
- write
tags:
- workspaceProduct
Expand Down Expand Up @@ -558,7 +558,7 @@ paths:
get:
x-onecx:
permissions:
workspace:
product:
- read
tags:
- workspaceProduct
Expand All @@ -579,7 +579,7 @@ paths:
/products:
x-onecx:
permissions:
workspace:
product:
- read
post:
tags:
Expand Down Expand Up @@ -957,7 +957,7 @@ paths:
get:
x-onecx:
permissions:
workspace:
product:
- read
tags:
- imagesInternal
Expand Down

0 comments on commit 7e852a7

Please sign in to comment.