From 8c35abb84b7aaa029d9cd25f1f07075cf49a20ab Mon Sep 17 00:00:00 2001 From: CopyDemon Date: Mon, 1 Apr 2024 10:41:39 -0700 Subject: [PATCH] fixed when event dispatch error when stream table not show --- .../flowsheet_functions/mainFV.tsx | 16 +++++++++++++--- .../flowsheet_functions/paper.tsx | 6 ++++-- .../flowsheet_functions/stream_table.tsx | 6 ++++-- .../flowsheet_wrapper.tsx | 3 ++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/mainFV.tsx b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/mainFV.tsx index 6858cb02..00848578 100644 --- a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/mainFV.tsx +++ b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/mainFV.tsx @@ -44,14 +44,24 @@ export class MainFV { stream_table:any; toolbar: any; cleanToolBarEvent: any; + viewInLogPanel:any; - constructor (flowsheetId:any, port:string | number, isFvShow:boolean, isVariablesShow:boolean, isStreamTableShow:boolean) { + constructor ( + flowsheetId:any, + port:string | number, + isFvShow:boolean, + isVariablesShow:boolean, + isStreamTableShow:boolean, + viewInLogPanel: {streamTable:boolean, diagnosticsLogs:boolean} + ) { this.flowsheetId = flowsheetId; - //which panel is show + // which panel is show this.isFvShow = isFvShow; // this.isVariablesShow = isVariablesShow; this.isStreamTableShow = isStreamTableShow; + // check if bottom log panel show stream table or diagnostics log + this.viewInLogPanel = viewInLogPanel; //Gerneate url for fetch data this.baseUrl = `http://localhost:${port}` @@ -92,7 +102,7 @@ export class MainFV { if(isFvShow) this.renderModel(this.model); //this only run when fv is show //render stream table //if statment control when stream table not show the stream table should not render - if(isStreamTableShow) this.stream_table = new StreamTable(this, this.model); + if(isStreamTableShow) this.stream_table = new StreamTable(this, this.model, this.viewInLogPanel); // new this.toolbar this.toolbar = new Toolbar(this, this.paper, this.stream_table, this.flowsheetId, this.getFSUrl,this.putFSUrl, this.isFvShow); // get toolbar event cleanup function diff --git a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/paper.tsx b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/paper.tsx index c6389ee2..4b048217 100644 --- a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/paper.tsx +++ b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/paper.tsx @@ -261,8 +261,10 @@ export class Paper { } } ); - idaesCanvas!.dispatchEvent(removeHighlightStreamEvent); - streamTable!.dispatchEvent(removeHighlightStreamEvent); + + if(idaesCanvas) idaesCanvas!.dispatchEvent(removeHighlightStreamEvent); + if(streamTable) streamTable!.dispatchEvent(removeHighlightStreamEvent); + }); // Link labels will appear and disappear on right click. Replaces browser context menu diff --git a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/stream_table.tsx b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/stream_table.tsx index 7fc39c62..73b9c456 100644 --- a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/stream_table.tsx +++ b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_component/flowsheet_functions/stream_table.tsx @@ -50,10 +50,12 @@ export class StreamTable { gridCellMouseLeaveFn : any; existing_var_types: any; _gridOptions:any; + viewInLogPanel: any; - constructor(app:any, model:any) { + constructor(app:any, model:any, viewInLogPanel:any) { this._app = app; + this.viewInLogPanel = viewInLogPanel // Define brushing event handlers this.defineTableBrushingFns(); this.initTable(model); @@ -280,7 +282,7 @@ export class StreamTable { let streamTable = document.querySelector('#stream-table-data'); let idaesCanvas = document.querySelector('#fv'); - if(!streamTable || !idaesCanvas) return; + if(!streamTable || !idaesCanvas || !this.viewInLogPanel.streamTable) return; // Function to highlight a stream table column this.highlightFn = (event:any) => { let streamGridCells = streamTable!.querySelectorAll( diff --git a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_wrapper.tsx b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_wrapper.tsx index 46d0ad33..f2dea649 100644 --- a/IDAES-UI/src/components/flowsheet_main_component/flowsheet_wrapper.tsx +++ b/IDAES-UI/src/components/flowsheet_main_component/flowsheet_wrapper.tsx @@ -22,12 +22,13 @@ export default function FlowsheetWrapper(){ //get server port base on UI port number, vite running on 5173 on dev server_port == "5173" ? server_port = 8000 : server_port = server_port; //when template loaded then render flowsheet, variable, stream table to page with minFV class. - fv = new MainFV(fv_id, server_port, isFvShow, false, isStreamTableShow); //The false is placeholder for isVariableShow, now variable panel is not show + fv = new MainFV(fv_id, server_port, isFvShow, false, isStreamTableShow, viewInLogPanel); //The false is placeholder for isVariableShow, now variable panel is not show }else{ fv = undefined; } return ()=>{ + // clean up event handler if (fv && typeof fv.cleanToolBarEvent === 'function') { fv.cleanToolBarEvent(); }