Skip to content

Commit

Permalink
Merge pull request ceph#59781 from ivoalmeida/table-filter-fix
Browse files Browse the repository at this point in the history
mgr/dashboard: fix table filter

Reviewed-by: Afreen Misbah <[email protected]>
  • Loading branch information
afreen23 authored Sep 16, 2024
2 parents e1934d5 + 86a0a80 commit 2b69864
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
* how the table is renderer a second time, we now clone that list into a
* local variable and only use the clone.
*/
localColumns: CdTableColumn[];
set localColumns(value: CdTableColumn[]) {
this._localColumns = this.getTableColumnsWithNames(value);
}

get localColumns(): CdTableColumn[] {
return this._localColumns;
}

private _localColumns: CdTableColumn[];

model: TableModel = new TableModel();

set tableColumns(value: CdTableColumn[]) {
// In case a name is not provided set it to the prop name if present or an empty string
const valuesWithNames = value.map((col: CdTableColumn) =>
col?.name ? col : { ...col, name: col?.prop ? _.capitalize(_.toString(col.prop)) : '' }
);
const valuesWithNames = this.getTableColumnsWithNames(value);
this._tableColumns = valuesWithNames;
this._tableHeaders.next(valuesWithNames);
}
Expand All @@ -307,6 +313,18 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
return this.localColumns?.filter?.((x) => !x.isHidden);
}

getTableColumnsWithNames(value: CdTableColumn[]): CdTableColumn[] {
return value.map((col: CdTableColumn) =>
col?.name ? col : { ...col, name: col?.prop ? this.deCamelCase(String(col?.prop)) : '' }
);
}

deCamelCase(str: string): string {
return str
.replace(/([A-Z])/g, (match) => ` ${match}`)
.replace(/^./, (match) => match.toUpperCase());
}

icons = Icons;
cellTemplates: {
[key: string]: TemplateRef<any>;
Expand Down

0 comments on commit 2b69864

Please sign in to comment.