Skip to content

Commit 2b69864

Browse files
authored
Merge pull request ceph#59781 from ivoalmeida/table-filter-fix
mgr/dashboard: fix table filter Reviewed-by: Afreen Misbah <[email protected]>
2 parents e1934d5 + 86a0a80 commit 2b69864

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,21 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
284284
* how the table is renderer a second time, we now clone that list into a
285285
* local variable and only use the clone.
286286
*/
287-
localColumns: CdTableColumn[];
287+
set localColumns(value: CdTableColumn[]) {
288+
this._localColumns = this.getTableColumnsWithNames(value);
289+
}
290+
291+
get localColumns(): CdTableColumn[] {
292+
return this._localColumns;
293+
}
294+
295+
private _localColumns: CdTableColumn[];
288296

289297
model: TableModel = new TableModel();
290298

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

316+
getTableColumnsWithNames(value: CdTableColumn[]): CdTableColumn[] {
317+
return value.map((col: CdTableColumn) =>
318+
col?.name ? col : { ...col, name: col?.prop ? this.deCamelCase(String(col?.prop)) : '' }
319+
);
320+
}
321+
322+
deCamelCase(str: string): string {
323+
return str
324+
.replace(/([A-Z])/g, (match) => ` ${match}`)
325+
.replace(/^./, (match) => match.toUpperCase());
326+
}
327+
310328
icons = Icons;
311329
cellTemplates: {
312330
[key: string]: TemplateRef<any>;

0 commit comments

Comments
 (0)