Commit fa33cd5f authored by William Arsac's avatar William Arsac Committed by Florent POITTEVIN
Browse files

perf: first pass with simple changes

parent 88cab571
......@@ -5,6 +5,7 @@
}"
>
</ng-template>
<ng-template #tableTemplate
let-isSmallerOrEqualThanMd="isSmallerOrEqualThanMd"
let-isBiggerThanMd="isBiggerThanMd"
......@@ -43,7 +44,7 @@
</button>
</ng-template>
</div>
<div *ngIf="(isColumnFilterable() && isFilterApplied()) || (queryParameters && isDatasPresent === true)"
<div *ngIf="(queryParameters && isDatasPresent) || (isColumnFilterable() && isFilterApplied())"
class="header-button-and-pagination"
>
<div class="button-wrapper">
......@@ -402,4 +403,4 @@
<span class="message">{{'table.nodata' | translate}}</span>
</div>
</div>
</ng-template>
\ No newline at end of file
</ng-template>
......@@ -7,6 +7,7 @@ import {
OnChanges,
Output,
SimpleChanges,
TrackByFunction,
ViewChild,
ViewEncapsulation,
} from "@angular/core";
......@@ -37,7 +38,10 @@ import {
DateUtil,
isEmptyArray,
isEmptyString,
isNonEmptyArray,
isNonEmptyString,
isNullOrUndefined,
isString,
isTrue,
MappingObject,
MappingObjectUtil,
......@@ -86,7 +90,7 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
return this._datas;
}
trackByFunction = (index: number, item: TResource) => index;
trackByFunction: TrackByFunction<TResource> = (index: number, item: TResource) => index;
@Input()
isMultiSelectable: boolean = false;
......@@ -262,7 +266,7 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
return;
}
this.actions.forEach(action => {
this.context.mapAtLeastOneActionToDisplay.set(action, this._datas.some(data => !isNullOrUndefined(action.displayOnCondition) && isTrue(action.displayOnCondition(data))));
this.context.mapAtLeastOneActionToDisplay.set(action, this._datas.some(data => action.displayOnCondition && action.displayOnCondition(data)));
});
}
......@@ -299,7 +303,8 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
getCellData(row: TResource, column: DataTableColumns): any {
const data = this.getData(row, column);
if (column.translate && column.filterEnum) {
const enumValue = column.filterEnum.find(f => f.key === data + "");
const dataStr = data + "";
const enumValue = column.filterEnum.find(f => f.key === dataStr);
if (enumValue) {
return enumValue.value;
}
......@@ -407,18 +412,15 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
getValue(col: DataTableColumns<TResource>): string | null {
const value = MappingObjectUtil.get(this.queryParameters.search.searchItems, this.getFilterableField(col));
if (value === null || value === undefined || value === StringUtil.stringEmpty) {
return null;
}
return value;
return isNonEmptyString(value) ? value : null;
}
private getFilterableField(col: DataTableColumns<TResource>): string {
return isNullOrUndefined(col.filterableField) ? col.field : col.filterableField;
return isString(col.filterableField) ? col.filterableField : col.field;
}
private getSortableField(col: DataTableColumns): string {
return isNullOrUndefined(col.sortableField) ? col.field : col.sortableField;
return isString(col.filterableField) ? col.filterableField : col.field;
}
getSortableFieldByFieldName(fieldName: string): string {
......@@ -434,7 +436,7 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
}
const searchItems: Map<string, string> = MappingObjectUtil.toMap(this.queryParameters.search.searchItems);
searchItems.forEach((value: string, key: string) => {
if (this.columnsSkippedToClear.some(c => c.includes(key)) === false) {
if (!toSkip && this.columnsSkippedToClear.some(c => c.includes(key)) === false) {
toSkip = true;
}
});
......@@ -489,33 +491,27 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
}
isHighlighting(rowData: TResource): boolean {
if (isEmptyArray(this.listHighlightingId) && isEmptyArray(this.multiSelectionValueOnAllPages)) {
return false;
}
if (this.listHighlightingId.includes(rowData.resId)) {
return true;
}
return this.multiSelectionValueOnAllPages.includes(rowData.resId);
return this.listHighlightingId.includes(rowData.resId) || this.multiSelectionValueOnAllPages.includes(rowData.resId);
}
displayActionOnCondition(action: DataTableActions<TResource>, resource: TResource = undefined): boolean | Observable<boolean> {
// console.error("TEST");
// return true;
if (isNullOrUndefined(resource) || isNullOrUndefined(action.displayOnCondition)) {
if (!resource || !action.displayOnCondition) {
return this.atLeastOneActionRowDisplayed(action);
}
return action.displayOnCondition(resource);
}
private atLeastOneActionRowDisplayed(action: DataTableActions<TResource>): boolean | Observable<boolean> {
if (isNullOrUndefined(this._datas) || isEmptyArray(this._datas)) {
if (!isNonEmptyArray(this._datas)) {
return false;
}
if (isNullOrUndefined(action.displayOnCondition)) {
return true;
}
const atLeastOnActionToDisplay = this.context.mapAtLeastOneActionToDisplay.get(action);
if (isTrue(atLeastOnActionToDisplay)) {
if (atLeastOnActionToDisplay) {
return true;
}
// TODO Find a way to merge all observable
......@@ -523,7 +519,7 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
}
getWidth(column: DataTableColumns<TResource>): string {
if (!isNullOrUndefined(column.width)) {
if (isString(column.width)) {
return column.width;
}
if (column.component === DataTableComponentEnum.conformityLevelStar) {
......@@ -540,7 +536,7 @@ export class SharedDataTablePresentational<TResource extends BaseResource> exten
}
isColumnFilterable(): boolean {
return !isNullOrUndefined(this.columns.find(c => isTrue(c.isFilterable)));
return this.columns.some(c => c.isFilterable);
}
toggleCheckbox($event: MatCheckboxChange, rowData: TResource): void {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment