Skip to content

Commit

Permalink
Merge pull request #58 from CopyDemon/issue-56-update-notification-co…
Browse files Browse the repository at this point in the history
…mponent-behavior

Updates the style and behavior of the green notification box in the UI.  Ignoring stochastic looking failure
  • Loading branch information
dangunter authored Nov 18, 2024
2 parents 06b513b + 95b5f85 commit 9394254
Show file tree
Hide file tree
Showing 10 changed files with 942 additions and 60 deletions.
35 changes: 20 additions & 15 deletions IDAES-UI/src/components/MessageBar/MessageBar.module.css
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
.message_bar_container{
position: fixed;
width: 100vw;
height:0px;
width: 250px;
height:25px;
min-width: fit-content;
bottom: 0;
right: 0;
z-index: 10000;
}

.messageBarTextContainer{
position: absolute;
left: 50%;
top: 100%;
transform: translateX(-50%);
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 300px;
height: 100px;
padding: 10px;
border-radius: 6px;
animation: messageBarShowUp .8s ease-in-out forwards;
animation: messageBarShowUp .5s ease-in-out forwards;
background-color: #333333;
border-radius: 1px solid blue;
border-top-left-radius: 5px;
}

.messageBarTextContainer >p{
.messageBarTextContainer > p{
margin: 0;
padding: 0;
font-size: 12px;
color: white;
text-align: center;
text-wrap: nowrap;
border-top-left-radius: 20px;

}

@keyframes messageBarShowUp {
1%{
top: 100%;
opacity: 0;
}

100%{
top:-120px;
opacity: 1;
}
}

.bg_successful{
background-color: rgb(0, 158, 32);
background-color: #333333;
}

.bg_error{
Expand Down
40 changes: 21 additions & 19 deletions IDAES-UI/src/components/MessageBar/MessageBarTemplateGenerator.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
import css from "./MessageBar.module.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleCheck } from "@fortawesome/free-solid-svg-icons";
export function messageBarTemplateGenerator(whichCalled: string, succeed: boolean, error?: any) {

export function messageBarTemplateGenerator(whichCalled:string, succeed:boolean, error?:any){

let templateBgClass:string = "bg-successful";
let templateBgClass: string = "bg-successful";
succeed ? templateBgClass = "bg-successful" : templateBgClass = "bg-error";
// initial message and conditionally render message
let message:string = "loading...";
let message: string = "loading...";

// refresh flowsheet
if(whichCalled == "refreshFS" && succeed){
if (whichCalled == "refreshFS" && succeed) {
message = "Flowsheet refreshed.";
}

if(whichCalled == "refreshFS" && !succeed){
if (whichCalled == "refreshFS" && !succeed) {
message = "Flowsheet refresh failed! Please reload the page!";
}

// userSave flowsheet
if(whichCalled == "userSave" && succeed){
if (whichCalled == "userSave" && succeed) {
message = "Flowsheet saved.";
}

if(whichCalled == "userSave" && !succeed){
if (whichCalled == "userSave" && !succeed) {
message = "Flowsheet save failed! Please restart the server!";
}

// diagnostics refresh
if(whichCalled == "diagnosticRefresh" && succeed){
if (whichCalled == "diagnosticRefresh" && succeed) {
message = "Diagnostics refreshed.";
}

if(whichCalled == "diagnosticRefresh" && !succeed){
if (whichCalled == "diagnosticRefresh" && !succeed) {
message = "Diagnostics refresh failed! Please restart the server!";
}

// diagnostics fn run
if(whichCalled == "diagnosticFNRunError" && !succeed){
let currentError:string | undefined = undefined;
error ? message = error : message = `Run diagnostics failed, please check your python terminal.`
if (whichCalled == "diagnosticFNRunError" && !succeed) {
let currentError: string | undefined = undefined;
// error ? message = error : message = `
message = `Diagnostics failed, check your terminal.`;
}

// initial template
const messageBarTemplate = `
<div id='messageBarTextContainer'
class="${css.messageBarTextContainer} ${succeed ? css.bg_successful : css.bg_error}"
class="${css.messageBarTextContainer} ${!succeed ? css.bg_error : css.bg_successful}"
>
<i class="fa-solid fa-circle-check"></i>
<p>${message}</p>
</div>
`;
Expand All @@ -54,14 +57,13 @@ export function messageBarTemplateGenerator(whichCalled:string, succeed:boolean,
messageBarContainer.innerHTML = messageBarTemplate;

// timeout 1.5 sec remove template
const timeOut = setTimeout(()=>{
const timeOut = setTimeout(() => {
const readMessageBarTemplate = document.getElementById('messageBarTextContainer');
console.log(readMessageBarTemplate)
if(readMessageBarTemplate){
if (readMessageBarTemplate) {
messageBarContainer.removeChild(readMessageBarTemplate)
}else{
} else {
console.log(`Child node message bar is not found!`)
}
clearTimeout(timeOut)
},3000)
}, 3000)
}
46 changes: 23 additions & 23 deletions IDAES-UI/src/diagnostics/Diagnostics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect, useState} from "react";
import { useContext, useEffect, useState } from "react";
import { AppContext } from "@/AppContext";
import axios from "axios";
import { messageBarTemplateGenerator } from "@/components/MessageBar/MessageBarTemplateGenerator";
Expand All @@ -9,60 +9,60 @@ import DiagnosticsDisplay from "./DiagnosticsDisplay";
import "./Diagnostics.css";

interface DiagnosticsDataInterface {
config: {key:any, value:any},
issues:{issues:any}
statistics:any
config: { key: any, value: any },
issues: { issues: any }
statistics: any
}

export default function Diagnostics(){
let {server_port, diagnosticsRefreshState} = useContext(AppContext);
export default function Diagnostics() {
let { server_port, diagnosticsRefreshState } = useContext(AppContext);
// this use to hold all diagnostic data fetched from api end point pass down to sub components
const [diagnosticData, setDiagnosticsData] = useState<DiagnosticsDataInterface | null>(null);
// use to hold which issue currently is displayed on screen setWhichIssue to update diagnostics display
const [whichIssue, setWhichIssue] = useState<string | null>("structural");
const [whichIssue, setWhichIssue] = useState<string | null>("structural");

const toggleIssueHandler = (issue:any) =>{
const toggleIssueHandler = (issue: any) => {
// this function use in issues component's each issue tab
// use for when each issue tab click and toggle current displayed issue
setWhichIssue(issue)
}

useEffect(()=>{
useEffect(() => {
// const getDiagnosticUrl = `http://127.0.0.1:${server_port}/api/get_diagnostics`;
const windowURL = new URL(window.location.href);
const id = windowURL.searchParams.get("id");
const getDiagnosticUrl = `http://localhost:${server_port}/diagnostics?id=${id}`;

const fetchDiagnosticData = async (url:string) =>{
const fetchDiagnosticData = async (url: string) => {
// fetch diagnostic data from end point and update to state
try{
try {
const res = await axios.get(url);
const data = res.data
messageBarTemplateGenerator("diagnosticRefresh", true);
setDiagnosticsData(data);
}catch(error){
} catch (error) {
console.error("Fetch diagnostic data error", error)
messageBarTemplateGenerator("diagnosticRefresh", false);
}
}
fetchDiagnosticData(getDiagnosticUrl);
},
/**
* useEffect triggers:
* 1. onload
* 2. on diagnosticsRefreshState changed (click handler in mosaic to toggle this bool state)
*/
[diagnosticsRefreshState]);
/**
* useEffect triggers:
* 1. onload
* 2. on diagnosticsRefreshState changed (click handler in mosaic to toggle this bool state)
*/
[diagnosticsRefreshState]);

return (
<>
<DiagnosticHeader
diagnosticData={diagnosticData}
toggleIssue={toggleIssueHandler}
<DiagnosticHeader
diagnosticData={diagnosticData}
toggleIssue={toggleIssueHandler}
whichIssue={whichIssue}
/>
<DiagnosticsDisplay
diagnosticData={diagnosticData}
<DiagnosticsDisplay
diagnosticData={diagnosticData}
whichIssue={whichIssue}
/>
</>
Expand Down
1 change: 1 addition & 0 deletions idaes_ui/fv/static/assets/allPaths-4a93b574.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions idaes_ui/fv/static/assets/allPathsLoader-8041c61d.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions idaes_ui/fv/static/assets/index-64ee1e34.css

Large diffs are not rendered by default.

Loading

0 comments on commit 9394254

Please sign in to comment.