Skip to content

Commit

Permalink
Change portal to workspace, repair tests (#23)
Browse files Browse the repository at this point in the history
* fix: fix menu import, work on menu create api error

* fix: fix routing after ws name edit, put back themes in props

* fix: fix a lot of test compilation issues

* fix: fix menu import

* fix: tree order issue

* fix: take out image tab, fix menu permission

* fix: change vars etc to workspace in detail, search

* fix: change vars etc to workspace in whole import

* fix: change vars everywhere but menu

* fix: change vars everywhere to workspace

* fix: some translations with type

---------

Co-authored-by: Christian Badura <[email protected]>
  • Loading branch information
cbadura and Christian Badura authored Feb 19, 2024
1 parent a3375f9 commit 8f1f4f2
Show file tree
Hide file tree
Showing 39 changed files with 730 additions and 812 deletions.
6 changes: 1 addition & 5 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": [],
"codeCoverageExclude": [
"**/*.module.ts",
"src/app/environments/**",
"src/app/shared/generated/**"
]
"codeCoverageExclude": ["**/*.module.ts", "src/app/environments/**", "src/app/shared/generated/**"]
}
},
"lint": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/menu-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface MenuState {
treeExpansionState: Map<string, boolean>
menuTableFilters?: Map<string, string>
pageSize: number
portalMenuItems?: MenuItem[]
workspaceMenuItems?: MenuItem[]
sortColumn?: { sortField: string; sortOrder: number }
}

Expand Down
30 changes: 19 additions & 11 deletions src/app/services/menu-tree.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'
import { TreeNode } from 'primeng/api'

import { MenuTreeService } from './menu-tree.service'
import { MenuItemDetailsDTO, MenuItemStructureDTO } from '../shared/generated'
import { /* MenuItemDetailsDTO, MenuItemStructureDTO, */ MenuItem } from '../shared/generated'

describe('MenuTreeService', () => {
let service: MenuTreeService
Expand Down Expand Up @@ -71,52 +71,60 @@ describe('MenuTreeService', () => {
})

it('should parse items from structure correctly', () => {
const structure: MenuItemStructureDTO[] = [
const structure: MenuItem[] = [
{
name: '1',
url: '/1',
id: 'id',
children: [
{
name: 'Sub 1.1',
url: '/1/sub1'
url: '/1/sub1',
id: 'id'
},
{
name: 'Sub 1.2',
url: '/1/sub2'
url: '/1/sub2',
id: 'id'
}
]
},
{
name: '2',
url: '/2'
url: '/2',
id: 'id'
}
]
const list: MenuItemDetailsDTO[] = []
const list: MenuItem[] = []

const result = service.parseItemsFromStructure(structure, list)

expect(result).toEqual([
{
name: '1',
url: '/1'
url: '/1',
id: 'id'
},
{
name: 'Sub 1.1',
url: '/1/sub1'
url: '/1/sub1',
id: 'id'
},
{
name: 'Sub 1.2',
url: '/1/sub2'
url: '/1/sub2',
id: 'id'
},
{
name: '2',
url: '/2'
url: '/2',
id: 'id'
}
])
})

it('should map items to TreeNodes correctly', () => {
const items: MenuItemStructureDTO[] = [
const items: MenuItem[] = [
{
id: 'item1',
name: 'Item 1',
Expand Down
11 changes: 5 additions & 6 deletions src/app/shared/theme-color-box/theme-color-box.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
import { HttpClient } from '@angular/common/http'
// import { HttpClient } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'
// import { TranslateLoader, TranslateModule } from '@ngx-translate/core'

import { HttpLoaderFactory } from '../shared.module'
import { ThemeColorBoxComponent } from './theme-color-box.component'

describe('ThemeColorBoxComponent', () => {
Expand All @@ -15,14 +14,14 @@ describe('ThemeColorBoxComponent', () => {
TestBed.configureTestingModule({
declarations: [ThemeColorBoxComponent],
imports: [
HttpClientTestingModule,
TranslateModule.forRoot({
HttpClientTestingModule
/* TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
}) */
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents()
Expand Down
14 changes: 7 additions & 7 deletions src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export function limitText(text: string, limit: number): string {
}

/**
* Clones a given portal and converts its microfrontends Set to an array.
* Clones a given workspace and converts its microfrontends Set to an array.
*
* Used to avoid serialization issues caused by Sets when sending a portal to the backend.
* @param portal Workspace that should be cloned
* @returns Clone of the portal which contains the portal microfrontends as an array.
* Used to avoid serialization issues caused by Sets when sending a workspace to the backend.
* @param workspace Workspace that should be cloned
* @returns Clone of the workspace which contains the workspace microfrontends as an array.
*/
export function clonePortalWithMicrofrontendsArray(portal: Workspace): Workspace {
const updatedPortal: Workspace = { ...portal }
export function cloneWorkspaceWithMicrofrontendsArray(workspace: Workspace): Workspace {
const updatedPortal: Workspace = { ...workspace }
// updatedPortal.microfrontendRegistrations = Array.from(
// portal.microfrontendRegistrations ?? []
// workspace.microfrontendRegistrations ?? []
// ) as unknown as Set<MicrofrontendDTO>
return updatedPortal
}
Expand Down
36 changes: 18 additions & 18 deletions src/app/workspace/workspace-create/workspace-create.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<input
pInputText
type="text"
id="portal_create_item_name"
id="workspace_create_item_name"
class="w-full pt-3 pb-2"
formControlName="name"
[pTooltip]="'PORTAL.ITEM.PORTAL_NAME' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label class="ocx-required-label" for="portal_create_item_name">
<label class="ocx-required-label" for="workspace_create_item_name">
{{ 'PORTAL.ITEM.PORTAL_NAME' | translate }}
</label>
</span>
Expand All @@ -23,21 +23,21 @@
<input
pInputText
type="text"
id="portal_create_item_tenantId"
id="workspace_create_item_tenantId"
class="w-full pt-3 pb-2"
formControlName="tenantId"
[pTooltip]="'PORTAL.ITEM.TENANT_ID' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_create_item_tenantId"> {{ 'PORTAL.ITEM.TENANT_ID' | translate }} </label>
<label for="workspace_create_item_tenantId"> {{ 'PORTAL.ITEM.TENANT_ID' | translate }} </label>
</span>
</div>

<!-- <div>
<span class="p-float-label">
<p-dropdown
id="portal_create_item_themeName"
id="workspace_create_item_themeName"
formControlName="themeName"
styleClass="w-full"
[options]="(themes$ | async) || []"
Expand All @@ -46,7 +46,7 @@
tooltipEvent="focus"
>
</p-dropdown>
<label class="ocx-required-label" for="portal_create_item_themeName">
<label class="ocx-required-label" for="workspace_create_item_themeName">
{{ 'PORTAL.ITEM.THEME' | translate }}
</label>
</span>
Expand All @@ -57,14 +57,14 @@
<input
pInputText
type="text"
id="portal_create_item_homePage"
id="workspace_create_item_homePage"
class="w-full pt-3 pb-2"
formControlName="homePage"
[pTooltip]="'PORTAL.ITEM.HOME_PAGE' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_create_item_homePage"> {{ 'PORTAL.ITEM.HOME_PAGE' | translate }} </label>
<label for="workspace_create_item_homePage"> {{ 'PORTAL.ITEM.HOME_PAGE' | translate }} </label>
</span>
</div>

Expand All @@ -73,14 +73,14 @@
<input
pInputText
type="text"
id="portal_create_item_baseUrl"
id="workspace_create_item_baseUrl"
class="w-full pt-3 pb-2"
formControlName="baseUrl"
[pTooltip]="'PORTAL.ITEM.BASE_URL' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label class="ocx-required-label" for="portal_create_item_baseUrl">
<label class="ocx-required-label" for="workspace_create_item_baseUrl">
{{ 'PORTAL.ITEM.BASE_URL' | translate }}</label
>
</span>
Expand All @@ -92,18 +92,18 @@
<!-- <div class="flex flex-wrap sm:flex-nowrap align-items-center row-gap-2 column-gap-4">
<input hidden type="file" accept=".png,.svg" #selectedFileInputLogo (change)="onFileUpload($event, 'logo')" />
<app-image-container
[id]="'portal_create_item_logo_image'"
[id]="'workspace_create_item_logo_image'"
[imageUrl]="fetchingLogoUrl"
[small]="true"
[title]="'LOGO.TOOLTIPS.' + (fetchingLogoUrl ? 'IMAGE' : 'PLACEHOLDER') | translate"
></app-image-container>
<div class="p-inputgroup" controlErrorAnchor>
<span class="p-float-label">
<input pInputText type="text" id="portal_create_item_logo" formControlName="logoUrl" />
<label for="portal_create_item_logo"> {{ 'LOGO.LOGO_URL' | translate }} </label>
<input pInputText type="text" id="workspace_create_item_logo" formControlName="logoUrl" />
<label for="workspace_create_item_logo"> {{ 'LOGO.LOGO_URL' | translate }} </label>
</span>
<span
id="portal_create_item_logo_upload"
id="workspace_create_item_logo_upload"
class="p-inputgroup-addon bg-primary"
[title]="'LOGO.TOOLTIPS.UPLOAD' | translate"
(click)="selectedFileInputLogo.click()"
Expand All @@ -118,14 +118,14 @@
<input
pInputText
type="text"
id="portal_create_item_footerLabel"
id="workspace_create_item_footerLabel"
class="w-full pt-3 pb-2"
formControlName="footerLabel"
[pTooltip]="'PORTAL.ITEM.FOOTER_LABEL' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_create_item_footerLabel"> {{ 'PORTAL.ITEM.FOOTER_LABEL' | translate }} </label>
<label for="workspace_create_item_footerLabel"> {{ 'PORTAL.ITEM.FOOTER_LABEL' | translate }} </label>
</span>
</div>

Expand All @@ -136,10 +136,10 @@
pInputTextarea
autoresize="true"
rows="4"
id="portal_create_item_description"
id="workspace_create_item_description"
formControlName="description"
></textarea>
<label for="portal_create_item_description"> {{ 'PORTAL.ITEM.DESCRIPTION' | translate }} </label>
<label for="workspace_create_item_description"> {{ 'PORTAL.ITEM.DESCRIPTION' | translate }} </label>
</span>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/app/workspace/workspace-create/workspace-create.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class WorkspaceCreateComponent {

themes$: Observable<SelectItem<string>[]> = of([])
public formGroup: FormGroup
private portalDto!: Workspace
private workspace!: Workspace
public hasPermission = false
public selectedLogoFile: File | undefined
public preview = false
Expand All @@ -34,7 +34,7 @@ export class WorkspaceCreateComponent {
public minimumImageHeight = 150
public LogoState = LogoState
public logoState = LogoState.INITIAL
public portalCreationValiationMsg = false
public workspaceCreationValidationMsg = false
public fetchingLogoUrl?: string
public urlPattern = '/base-path-to-workspace'

Expand Down Expand Up @@ -83,13 +83,13 @@ export class WorkspaceCreateComponent {
this.createPortalDto()
this.workspaceApi
.createWorkspace({
createWorkspaceRequest: { resource: this.portalDto }
createWorkspaceRequest: { resource: this.workspace }
})
.pipe()
.subscribe({
next: (fetchedPortal) => {
this.message.success({ summaryKey: 'ACTIONS.CREATE.MESSAGE.CREATE_OK' })
this.portalCreationValiationMsg = false
this.workspaceCreationValidationMsg = false
this.closeDialog()
this.router.navigate(['./' + fetchedPortal.resource?.name], { relativeTo: this.route })
},
Expand All @@ -100,7 +100,7 @@ export class WorkspaceCreateComponent {
}

private createPortalDto(): void {
this.portalDto = { ...this.formGroup.value }
this.workspace = { ...this.formGroup.value }
}

// former used to check the size of the image
Expand Down
Loading

0 comments on commit 8f1f4f2

Please sign in to comment.