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: table component should emit column change when columns are updated #2399

Merged
merged 6 commits into from
Sep 15, 2023
Merged
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
28 changes: 28 additions & 0 deletions projects/components/src/table/table.component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,34 @@ describe('Table component', () => {
flush();
}));

test('should emit correctly on column changes', fakeAsync(() => {
const mockColumnConfigsChange = jest.fn();
const columns = buildColumns();
const spectator = createHost(
`<ht-table [columnConfigs]="columnConfigs" [data]="data" [selectionMode]="selectionMode"
[mode]="mode" (columnConfigsChange)="mockColumnConfigsChange($event)"></ht-table>`,
{
hostProps: {
columnConfigs: columns,
data: buildData(),
selectionMode: TableSelectionMode.Multiple,
mode: TableMode.Flat,
mockColumnConfigsChange: mockColumnConfigsChange
}
}
);

// Hiding a column
spectator.component.onHideColumn(columns[0]);
expect(mockColumnConfigsChange).toHaveBeenLastCalledWith(
expect.arrayContaining([
expect.objectContaining({ ...columns[0], visible: false }),
expect.objectContaining({ ...columns[1] })
])
);
flush();
}));

test('should select only selected rows', fakeAsync(() => {
const columns = buildColumns();
const rows = buildData();
Expand Down
15 changes: 10 additions & 5 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 @@ -35,7 +35,7 @@
} from '@hypertrace/common';
import { isNil, 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 @@ -719,7 +719,7 @@
this.initialColumnConfigIdWidthMap = new Map(visibleColumns.map(column => [column.id, column.width ?? -1]));
this.updateVisibleColumns(visibleColumns);

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

private checkColumnWidthCompatibilityOrThrow(width?: TableColumnWidth): void {
Expand Down Expand Up @@ -823,7 +823,7 @@
const updatedColumns = this.columnConfigsSubject.value;
this.updateVisibleColumns(updatedColumns.filter(c => c.visible));
this.distributeWidthToColumns(TableColumnWidthUtil.getColWidthInPx(column.width));
this.columnConfigsSubject.next(updatedColumns);
this.propagateUpdatedColumns(updatedColumns);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L826 was not covered by tests
}

public showEditColumnsModal(): void {
Expand Down Expand Up @@ -909,6 +909,11 @@
return this.hasExpandableRows() ? index - 1 : index;
}

private propagateUpdatedColumns(updatedColumns: TableColumnConfigExtended[]): void {
this.columnConfigsSubject.next(updatedColumns);
this.columnConfigsChange.next(updatedColumns);
}

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

Expand Down
Loading