Skip to content

Commit

Permalink
fix: UI state custom group column selector (#544)
Browse files Browse the repository at this point in the history
* fix: displayed column component state

* fix: correct custom column selection and fixed issue with translations when opening data table filter

* fix: lint issue

* fix: persist displayed columns after page reload for column groups

* fix: remove customkey input in html interactive data view

* fix: customgroupkey remove the correct one

---------

Co-authored-by: kim.tran <[email protected]>
  • Loading branch information
KimFFVII and kim.tran authored Oct 18, 2024
1 parent 3cb9069 commit e2cecf3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export class ColumnGroupSelectionComponent implements OnInit {
.filter((value, index, self) => self.indexOf(value) === index && value != null)
)
)
const activeColumns = this.columns.filter((c) =>
c.predefinedGroupKeys?.includes(this.selectedGroupKey$.getValue() ?? this.defaultGroupKey)
)
this.componentStateChanged.emit({
activeColumnGroupKey: this.selectedGroupKey,
displayedColumns: this.columns,
displayedColumns: activeColumns,
})
}

Expand All @@ -65,7 +68,7 @@ export class ColumnGroupSelectionComponent implements OnInit {
this.groupSelectionChanged.emit({ activeColumns, groupKey: event.value })
this.componentStateChanged.emit({
activeColumnGroupKey: event.value,
displayedColumns: activeColumns
displayedColumns: activeColumns,
})
}

Expand All @@ -77,7 +80,7 @@ export class ColumnGroupSelectionComponent implements OnInit {
this.groupSelectionChanged.emit({ activeColumns, groupKey: this.defaultGroupKey })
this.componentStateChanged.emit({
activeColumnGroupKey: this.defaultGroupKey,
displayedColumns: activeColumns
displayedColumns: activeColumns,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ export interface CustomGroupColumnSelectorComponentState {
})
export class CustomGroupColumnSelectorComponent implements OnInit {
@Input() columns: DataTableColumn[] = []
@Input() displayedColumns: DataTableColumn[] = []
private _displayedColumns: DataTableColumn[] = []
@Input()
get displayedColumns() {
return this._displayedColumns
}
set displayedColumns(value: DataTableColumn[]) {
this._displayedColumns = value
this.componentStateChanged.emit({
actionColumnConfig: {
frozen: this.frozenActionColumn,
position: this.actionColumnPosition,
},
displayedColumns: this._displayedColumns,
})
}
@Input() dialogTitle = ''
@Input() dialogTitleKey = ''
@Input() openButtonTitle = ''
Expand Down Expand Up @@ -108,11 +122,6 @@ export class CustomGroupColumnSelectorComponent implements OnInit {
this.columnSelectionChanged.emit({ activeColumns: [...this.displayedColumnsModel] })
this.componentStateChanged.emit({
displayedColumns: [...this.displayedColumnsModel],
actionColumnConfig: {
frozen: this.frozenActionColumnModel,
position: this.actionColumnPositionModel,
},
activeColumnGroupKey: undefined,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
const columnValues = rows.map((row) => row[currentFilterColumn?.id])
const translateObservable =
this.columns.find((c) => c.id === currentFilterColumn?.id)?.columnType === ColumnType.TRANSLATION_KEY
? this.translateService.get(columnValues as string[])
? this.translateColumnValues(columnValues as string[])
: of(Object.fromEntries(columnValues.map((cv) => [cv, cv])))
return translateObservable.pipe(
map((translatedValues) => {
Expand Down Expand Up @@ -501,6 +501,10 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
this.emitComponentStateChanged()
}

translateColumnValues(columnValues: string[]): Observable<any> {
return columnValues.length ? this.translateService.get(columnValues as string[]) : of({})
}

emitComponentStateChanged(state: DataTableComponentState = {}) {
this.displayedPageSize$
.pipe(withLatestFrom(this._selectionIds$, this._rows$), first())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
*ngIf="layout === 'table'"
[selectedGroupKey]="selectedGroupKey ?? defaultGroupKey"
[columns]="columns"
[defaultGroupKey]="defaultGroupKey"
[defaultGroupKey]="defaultGroupKey !== customGroupKey ? defaultGroupKey : ''"
[customGroupKey]="customGroupKey"
[placeholderKey]="groupSelectionNoGroupSelectedKey"
(groupSelectionChanged)="onColumnGroupSelectionChange($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class InteractiveDataViewComponent implements OnInit, AfterContentInit {
if (!this.displayedColumns || this.displayedColumns.length === 0) {
this.displayedColumnKeys = this.columns.map((column) => column.id)
}
if (this.defaultGroupKey) {
if (this.defaultGroupKey && this.defaultGroupKey !== this.customGroupKey) {
this.displayedColumnKeys = this.columns
.filter((column) => column.predefinedGroupKeys?.includes(this.defaultGroupKey))
.map((column) => column.id)
Expand Down Expand Up @@ -417,8 +417,22 @@ export class InteractiveDataViewComponent implements OnInit, AfterContentInit {
if (this.layout === 'table') {
dataListGridSortingComponentState$ = dataListGridSortingComponentState$.pipe(startWith({}))
} else {
columnGroupSelectionComponentState$ = columnGroupSelectionComponentState$.pipe(startWith({}))
customGroupColumnSelectorComponentState$ = customGroupColumnSelectorComponentState$.pipe(startWith({}))
columnGroupSelectionComponentState$ = columnGroupSelectionComponentState$.pipe(
startWith({
activeColumnGroupKey: this.selectedGroupKey,
displayedColumns: this.displayedColumns,
})
)
customGroupColumnSelectorComponentState$ = customGroupColumnSelectorComponentState$.pipe(
startWith({
actionColumnConfig: {
frozen: this.frozenActionColumn,
position: this.actionColumnPosition,
},
displayedColumns: this.displayedColumns,
activeColumnGroupKey: this.selectedGroupKey,
})
)
}

combineLatest([
Expand Down

0 comments on commit e2cecf3

Please sign in to comment.