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: UI state custom group column selector #544

Merged
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
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
Loading