Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updates to table and table widget renderer #2411

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/components/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export * from './table/cells/data-parsers/table-cell-no-op-parser';
export * from './table/cells/data-parsers/table-cell-string-parser';
export * from './table/cells/data-parsers/table-cell-timestamp-parser';
export * from './table/cells/data-parsers/table-cell-icon-parser';
export * from './table/util/table-column.util';

// Table Controls
export * from './table/controls/table-controls.module';
Expand Down
49 changes: 36 additions & 13 deletions projects/components/src/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* eslint-disable @angular-eslint/component-max-inline-declarations */
import { ModalService } from '../modal/modal.service';
import {
TableEditColumnsModalConfig,
TableEditColumnsModalComponent
TableEditColumnsModalComponent,
TableEditColumnsModalConfig
} from './columns/table-edit-columns-modal.component';
import { CdkHeaderRow } from '@angular/cdk/table';
import {
Expand Down Expand Up @@ -33,9 +33,9 @@
NumberCoercer,
TypedSimpleChanges
} from '@hypertrace/common';
import { isNil, without } from 'lodash-es';
import { isNil, isUndefined, without } from 'lodash-es';
import { BehaviorSubject, combineLatest, merge, Observable, Subject } from 'rxjs';
import { switchMap, take, filter, map } from 'rxjs/operators';
import { filter, map, switchMap, take } from 'rxjs/operators';
import { FilterAttribute } from '../filtering/filter/filter-attribute';
import { LoadAsyncConfig } from '../load-async/load-async.service';
import { PageEvent } from '../paginator/page.event';
Expand Down Expand Up @@ -68,6 +68,7 @@
import { DOCUMENT } from '@angular/common';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { TableColumnWidthUtil } from './util/column-width.util';
import { TableColumnUtil } from './util/table-column.util';

@Component({
selector: 'ht-table',
Expand Down Expand Up @@ -547,7 +548,14 @@
this.isTableFullPage = this.display === TableStyle.FullPage;
}

if (changes.mode || changes.columnConfigs || changes.detailContent || changes.metadata) {
if (
changes.columnConfigs &&
this.hasNonStateColumnsChanged(changes.columnConfigs.previousValue, changes.columnConfigs.currentValue)
) {
this.initializeColumns();

Check warning on line 555 in projects/components/src/table/table.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/table/table.component.ts#L555

Added line #L555 was not covered by tests
}

if (changes.mode || changes.detailContent || changes.metadata) {
this.initializeColumns();
}

Expand All @@ -572,6 +580,17 @@
}
}

private hasNonStateColumnsChanged(previousValue?: TableColumnConfig[], currentValue?: TableColumnConfig[]): boolean {
if (previousValue === undefined || currentValue === undefined) {
return false;
}

const previousColumns = previousValue.filter(column => !this.isStateColumn(column));
const currentColumns = currentValue.filter(column => !this.isStateColumn(column));

Check warning on line 589 in projects/components/src/table/table.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/table/table.component.ts#L588-L589

Added lines #L588 - L589 were not covered by tests

return !isEqualIgnoreFunctions(previousColumns, currentColumns);

Check warning on line 591 in projects/components/src/table/table.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/table/table.component.ts#L591

Added line #L591 was not covered by tests
}

public ngAfterViewInit(): void {
setTimeout(() => {
!this.dataSource && this.initializeData();
Expand Down Expand Up @@ -714,7 +733,7 @@
this.checkColumnWidthCompatibilityOrThrow(column.width);
this.checkColumnWidthCompatibilityOrThrow(column.minWidth);
});
const columnConfigurations = this.buildColumnConfigExtendeds(columnConfigs ?? this.columnConfigs ?? []);
const columnConfigurations = this.buildColumnConfigExtended(columnConfigs ?? this.columnConfigs ?? []);
if (isNil(this.columnDefaultConfigs)) {
this.columnDefaultConfigs = columnConfigurations;
}
Expand All @@ -723,6 +742,7 @@
this.updateVisibleColumns(visibleColumns);

this.columnConfigsSubject.next(columnConfigurations);
this.columnConfigsChange.next(columnConfigurations);
}

private checkColumnWidthCompatibilityOrThrow(width?: TableColumnWidth): void {
Expand Down Expand Up @@ -789,12 +809,11 @@
return this.showColumnDivider(columns, index);
};

public isSelectionStateColumn = (column?: TableColumnConfig): boolean => column?.id === '$$selected';
protected isSelectionStateColumn = TableColumnUtil.isSelectionStateColumn;

public isExpansionStateColumn = (column?: TableColumnConfig): boolean => column?.id === '$$expanded';
protected isExpansionStateColumn = TableColumnUtil.isExpansionStateColumn;

public isStateColumn = (column?: TableColumnConfig): boolean =>
this.isSelectionStateColumn(column) || this.isExpansionStateColumn(column);
protected isStateColumn = TableColumnUtil.isStateColumn;

public isLastStateColumn = (columns: TableColumnConfig[], index: number): boolean => {
if (this.isStateColumn(columns[index]) && !this.isStateColumn(columns[index + 1])) {
Expand Down Expand Up @@ -828,6 +847,7 @@
this.updateVisibleColumns(updatedColumns.filter(c => c.visible));
this.distributeWidthToColumns(TableColumnWidthUtil.getColWidthInPx(column.width));
this.columnConfigsSubject.next(updatedColumns);
this.columnConfigsChange.next(updatedColumns);

Check warning on line 850 in projects/components/src/table/table.component.ts

View check run for this annotation

Codecov / codecov/patch

projects/components/src/table/table.component.ts#L850

Added line #L850 was not covered by tests
}

public showEditColumnsModal(): void {
Expand Down Expand Up @@ -913,14 +933,17 @@
return this.hasExpandableRows() ? index - 1 : index;
}

private buildColumnConfigExtendeds(columnConfigs: TableColumnConfig[]): TableColumnConfigExtended[] {
private buildColumnConfigExtended(columnConfigs: TableColumnConfig[]): TableColumnConfigExtended[] {
const stateColumns = [];

if (this.hasMultiSelect()) {
if (this.hasMultiSelect() && columnConfigs.find(TableColumnUtil.isSelectionStateColumn) === undefined) {
stateColumns.push(this.multiSelectRowColumnConfig);
}

if (this.hasExpandableRows()) {
if (
this.hasExpandableRows() &&
isUndefined(columnConfigs.find(TableColumnUtil.isExpansionStateColumn)) === undefined
) {
stateColumns.push(this.expandableToggleColumnConfig);
}

Expand Down
10 changes: 10 additions & 0 deletions projects/components/src/table/util/table-column.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TableColumnConfig } from '../table-api';

export abstract class TableColumnUtil {
public static isSelectionStateColumn = (column?: TableColumnConfig): boolean => column?.id === '$$selected';

public static isExpansionStateColumn = (column?: TableColumnConfig): boolean => column?.id === '$$expanded';

public static isStateColumn = (column?: TableColumnConfig): boolean =>
TableColumnUtil.isSelectionStateColumn(column) || TableColumnUtil.isExpansionStateColumn(column);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TableCheckboxControlOption,
TableCheckboxOptions,
TableColumnConfig,
TableColumnUtil,
TableControlOption,
TableControlOptionType,
TableDataSource,
Expand All @@ -33,7 +34,7 @@ import {
} from '@hypertrace/components';
import { WidgetRenderer } from '@hypertrace/dashboards';
import { Renderer } from '@hypertrace/hyperdash';
import { RendererApi, RENDERER_API } from '@hypertrace/hyperdash-angular';
import { RENDERER_API, RendererApi } from '@hypertrace/hyperdash-angular';
import { capitalize, isEmpty, isEqual, pick } from 'lodash-es';
import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs';
import {
Expand Down Expand Up @@ -517,7 +518,9 @@ export class TableWidgetRendererComponent
this.getLocalPreferences().subscribe(preferences =>
this.setLocalPreferences({
...preferences,
columns: columns.map(column => this.dehydratePersistedColumnConfig(column))
columns: columns
.filter(column => !TableColumnUtil.isStateColumn(column))
.map(column => this.dehydratePersistedColumnConfig(column))
})
);
}
Expand Down
Loading