Skip to content

Commit

Permalink
fix: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Feb 23, 2024
1 parent 66c2978 commit d9c91a6
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/app/product-store/app-search/app-search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/>
<label for="app_search_app_id">{{ 'APP.APP_ID' | translate }}</label>
</span>
<span class="p-float-label">
<!--span class="p-float-label">
<input
id="app_search_app_name"
pInputText
Expand All @@ -33,7 +33,7 @@
[title]="'APP.APP_NAME' | translate"
/>
<label for="app_search_app_name">{{ 'APP.APP_NAME' | translate }}</label>
</span>
</span-->
<span class="p-float-label">
<input
id="app_search_product_name"
Expand All @@ -60,7 +60,7 @@
[rows]="viewMode === 'grid' ? 24 : 10"
[layout]="viewMode"
[emptyMessage]="'ACTIONS.SEARCH.NOT_FOUND' | translate"
filterBy="appId,appName,appType,productName,classifications"
filterBy="appId,appType,productName,classifications"
[sortField]="sortField"
[sortOrder]="sortOrder"
>
Expand All @@ -72,7 +72,6 @@
[initialViewMode]="viewMode"
[sortingOptions]="[
{ label: 'APP.APP_ID' | translate, value: 'appId' },
{ label: 'APP.APP_NAME' | translate, value: 'appName' },
{ label: 'APP.APP_TYPE' | translate, value: 'appType' },
{ label: 'APP.PRODUCT_NAME' | translate, value: 'productName' }
]"
Expand All @@ -82,7 +81,6 @@
(filterChange)="onFilterChange($event)"
[filterColumns]="[
'APP.APP_ID' | translate,
'APP.APP_NAME' | translate,
'APP.APP_TYPE' | translate,
'APP.PRODUCT_NAME' | translate,
'APP.CLASSIFICATIONS' | translate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MicrofrontendsAPIService } from 'src/app/shared/generated'

const form = new FormGroup<AppSearchCriteria>({
appId: new FormControl<string | null>(null, Validators.minLength(2)),
appName: new FormControl<string | null>(null),
//appName: new FormControl<string | null>(null),
productName: new FormControl<string | null>(null)
})

Expand Down
50 changes: 45 additions & 5 deletions src/app/product-store/app-search/app-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { limitText } from 'src/app/shared/utils'

export interface AppSearchCriteria {
appId: FormControl<string | null>
appName: FormControl<string | null>
// appType: FormControl<AppType | null>
// appName: FormControl<string | null>
// appType: FormControl<AppType | null>
productName: FormControl<string | null>
}
export type AppType = 'MS' | 'MFE'
Expand Down Expand Up @@ -69,12 +69,13 @@ export class AppSearchComponent implements OnInit, OnDestroy {
this.hasDeletePermission = this.user.hasPermission('APP#DELETE')
this.appSearchCriteriaGroup = new FormGroup<AppSearchCriteria>({
appId: new FormControl<string | null>(null),
appName: new FormControl<string | null>(null),
//appName: new FormControl<string | null>(null),
productName: new FormControl<string | null>(null)
})
}

ngOnInit(): void {
this.prepareDialogTranslations()
this.prepareActionButtons()
this.searchApps()
}
Expand All @@ -95,7 +96,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
.searchMicrofrontends({
mfeAndMsSearchCriteria: {
appId: this.appSearchCriteriaGroup.controls['appId'].value,
appName: this.appSearchCriteriaGroup.controls['appName'].value,
//appName: this.appSearchCriteriaGroup.controls['appName'].value,
productName: this.appSearchCriteriaGroup.controls['productName'].value,
pageSize: 100
}
Expand All @@ -114,7 +115,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
.searchMicroservice({
mfeAndMsSearchCriteria: {
appId: this.appSearchCriteriaGroup.controls['appId'].value,
appName: this.appSearchCriteriaGroup.controls['appName'].value,
// appName: this.appSearchCriteriaGroup.controls['appName'].value,
productName: this.appSearchCriteriaGroup.controls['productName'].value,
pageSize: 100
}
Expand Down Expand Up @@ -191,6 +192,45 @@ export class AppSearchComponent implements OnInit, OnDestroy {
)
}

private prepareDialogTranslations(): void {
this.translate
.get([
'APP.APP_ID',
'APP.APP_TYPE',
'PRODUCT.NAME',
'ACTIONS.DATAVIEW.VIEW_MODE_GRID',
'ACTIONS.DATAVIEW.VIEW_MODE_LIST',
'ACTIONS.DATAVIEW.VIEW_MODE_TABLE',
'ACTIONS.DATAVIEW.SORT_BY',
'ACTIONS.DATAVIEW.FILTER',
'ACTIONS.DATAVIEW.FILTER_OF',
'ACTIONS.DATAVIEW.SORT_DIRECTION_ASC',
'ACTIONS.DATAVIEW.SORT_DIRECTION_DESC'
])
.subscribe((data) => {
this.dataViewControlsTranslations = {
sortDropdownPlaceholder: data['ACTIONS.DATAVIEW.SORT_BY'],
filterInputPlaceholder: data['ACTIONS.DATAVIEW.FILTER'],
filterInputTooltip:
data['ACTIONS.DATAVIEW.FILTER_OF'] +
data['APP.APP_ID'] +
', ' +
data['APP.APP_TYPE'] +
', ' +
data['PRODUCT.NAME'],
viewModeToggleTooltips: {
grid: data['ACTIONS.DATAVIEW.VIEW_MODE_GRID'],
list: data['ACTIONS.DATAVIEW.VIEW_MODE_LIST']
},
sortOrderTooltips: {
ascending: data['ACTIONS.DATAVIEW.SORT_DIRECTION_ASC'],
descending: data['ACTIONS.DATAVIEW.SORT_DIRECTION_DESC']
},
sortDropdownTooltip: data['ACTIONS.DATAVIEW.SORT_BY']
}
})
}

public onLayoutChange(viewMode: string): void {
this.viewMode = viewMode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[rows]="viewMode === 'grid' ? 12 : 10"
[layout]="viewMode"
[emptyMessage]="'ACTIONS.SEARCH.NOT_FOUND' | translate"
filterBy="app_name"
filterBy="appId,appType"
[sortField]="sortField"
[sortOrder]="sortOrder"
>
Expand All @@ -23,12 +23,15 @@
[enableSorting]="true"
[supportedViews]="['grid']"
[initialViewMode]="viewMode"
[sortingOptions]="[{ label: 'APP.APP_NAME' | translate, value: 'app_name' }]"
[sortingOptions]="[
{ label: 'APP.APP_ID' | translate, value: 'appId' },
{ label: 'APP.APP_TYPE' | translate, value: 'appType' }
]"
[defaultSortOption]="sortField"
[defaultSortDirection]="sortOrder === 1"
(dataViewChange)="onLayoutChange($event)"
(filterChange)="onFilterChange($event)"
[filterColumns]="['APP.APP_NAME' | translate]"
[filterColumns]="['APP.APP_ID' | translate, 'APP.APP_TYPE' | translate]"
(sortChange)="onSortChange($event)"
(sortDirectionChange)="onSortDirChange($event)"
[translations]="dataViewControlsTranslations"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input, OnChanges, ViewChild } from '@angular/core'
import { SelectItem } from 'primeng/api'
import { combineLatest, finalize, map, of, Observable, startWith, catchError } from 'rxjs'
import { DataView } from 'primeng/dataview'

import { DataViewControlTranslations, UserService } from '@onecx/portal-integration-angular'
import {
Expand Down Expand Up @@ -35,16 +36,16 @@ export class ProductAppsComponent implements OnChanges {
public iconItems: SelectItem[] = [{ label: '', value: null }]
public filter: string | undefined
public viewMode = 'grid'
public sortField = 'name'
public sortField = 'appId'
public sortOrder = 1
public searchInProgress = false
public displayDetailDialog = false
public displayDeleteDialog = false
public hasCreatePermission = false
public hasDeletePermission = false

@ViewChild(DataView) dv: DataView | undefined
public dataViewControlsTranslations: DataViewControlTranslations = {}
@ViewChild(DataView) dv: DataView | undefined
public limitText = limitText

constructor(
Expand Down Expand Up @@ -123,7 +124,7 @@ export class ProductAppsComponent implements OnChanges {
}
public onFilterChange(filter: string): void {
this.filter = filter
//this.dv?.filter(filter, 'contains')
this.dv?.filter(filter, 'contains')
}
public onSortChange(field: string): void {
this.sortField = field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<div *ngIf="!loading && !product && changeMode !== 'CREATE'" class="card px-3 align-items-center">
<p-message severity="error" styleClass="p-2" [text]="'ACTIONS.SEARCH.PRODUCT.NOT_EXISTS' | translate"></p-message>
</div>
<p-tabView *ngIf="(product && !loading) || changeMode === 'CREATE'">
<p-tabView
*ngIf="(product && !loading) || changeMode === 'CREATE'"
(onChange)="onTabChange($event)"
[activeIndex]="selectedTabIndex"
>
<p-tabPanel id="product_detail_panel_props" class="p-0" [header]="'DIALOG.TABS.PROPERTIES' | translate">
<app-product-props
[product]="product"
Expand Down
10 changes: 8 additions & 2 deletions src/app/product-store/product-detail/product-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ProductDetailComponent implements OnInit {
public headerImageUrl?: string
public productDeleteVisible = false
public productDeleteMessage = ''
public selectedTabIndex = 0

constructor(
private router: Router,
Expand All @@ -54,6 +55,11 @@ export class ProductDetailComponent implements OnInit {
}
}

public onTabChange($event: any) {
this.selectedTabIndex = $event.index
this.prepareActionButtons()
}

public getProduct() {
this.loading = true
this.productApi
Expand Down Expand Up @@ -111,7 +117,7 @@ export class ProductDetailComponent implements OnInit {
icon: 'pi pi-pencil',
show: 'always',
conditional: true,
showCondition: this.changeMode === 'VIEW' && this.product !== undefined,
showCondition: this.changeMode === 'VIEW' && this.product !== undefined && this.selectedTabIndex === 0,
permission: 'PRODUCT#EDIT'
},
{
Expand All @@ -121,7 +127,7 @@ export class ProductDetailComponent implements OnInit {
icon: 'pi pi-copy',
show: 'always',
conditional: true,
showCondition: this.changeMode === 'VIEW' && this.product !== undefined,
showCondition: this.changeMode === 'VIEW' && this.product !== undefined && this.selectedTabIndex === 0,
permission: 'PRODUCT#CREATE'
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
:host ::ng-deep {
// correction for data-view-control component
.data-view-control-border.p-dropdown:last-of-type {
border-top-left-radius: var(--border-radius);
border-bottom-left-radius: var(--border-radius);
}

.p-dataview-content .p-grid > div {
min-height: 60px;
&.listview-row {
Expand Down

0 comments on commit d9c91a6

Please sign in to comment.