]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix table filter 59781/head
authorIvo Almeida <ialmeida@redhat.com>
Fri, 13 Sep 2024 11:24:09 +0000 (12:24 +0100)
committerIvo Almeida <ialmeida@redhat.com>
Fri, 13 Sep 2024 13:27:30 +0000 (14:27 +0100)
Fixes: https://tracker.ceph.com/issues/68063
Signed-off-by: Ivo Almeida <ialmeida@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

index 97bcee3dfe34836dc02352d3ed37c63a2b93e472..5b2bd777dc7a00a9855f0197baf0a6672ac262e4 100644 (file)
@@ -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);
   }
@@ -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>;