wusamzong commented on code in PR #148:
URL: https://github.com/apache/yunikorn-web/pull/148#discussion_r1406443142


##########
src/app/components/nodes-view/nodes-view.component.ts:
##########
@@ -188,6 +188,20 @@ export class NodesViewComponent implements OnInit {
     return this.allocDataSource.data && this.allocDataSource.data.length === 0;
   }
 
+  formatColumn(){
+    if(this.nodeDataSource.data.length==0){
+      return
+    }
+    this.nodeColumnIds.forEach((colId)=>{
+      let emptyCell=this.nodeDataSource.data.filter((node)=>{
+        return (node as any)[colId]=="" || (node as any)[colId]=="n/a"
+      })
+      if (emptyCell.length==this.nodeDataSource.data.length){
+        this.nodeColumnIds = this.nodeColumnIds.filter(el => el!==colId)
+      }
+    })

Review Comment:
   Thank you for your clarification! I understand your concern about safety 
issues.
   
   In the provided code, `colId` is a string variable that stores column 
headers such as `'nodeId'`, `'rackName'`, `'hostName'`, etc. This occurs during 
the iteration of `this.nodeColumnIds.forEach((colId)=>{})`. The objective is to 
retrieve attributes from the node, such as `node['nodeId']`.
   
   However, attempting to directly use `node['nodeId']` in TypeScript triggers 
an error:
   `No index signature with a parameter of type 'string' was found on type 
'NodeInfo'.ts(7053).`
   Therefore, I use `(node as any)[colId]`.
   
   To address safety issues, we can handle it by adding a check to determine 
whether colId is included in NodeInfo.:
   ```javascript
   let emptyCell=this.nodeDataSource.data.filter((node)=>{
     if (!(colId in node)) {
       console.error(`Property '${colId}' does not exist on NodeInfo.`);
       return false;
     }
     return (node as any)[colId]==="" || (node as any)[colId]==="n/a"
   })
   ```
   If there's a better alternative, please feel free to share it!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to