-
-
Notifications
You must be signed in to change notification settings - Fork 10
Disable notebook button during simulation #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ function getItem( | |
| children?: MenuItem[], | ||
| onClick?: () => void, | ||
| disabled?: boolean, | ||
| title?: string, | ||
| ): MenuItem { | ||
| return { | ||
| key, | ||
|
|
@@ -76,6 +77,7 @@ function getItem( | |
| label, | ||
| onClick, | ||
| disabled, | ||
| title, | ||
| } as MenuItem; | ||
| } | ||
|
|
||
|
|
@@ -176,7 +178,15 @@ const App: React.FC = () => { | |
| const items: MenuItem[] = [ | ||
| getItem("View", "view", <AlignLeftOutlined />), | ||
| getItem("Console", "console", <BorderOuterOutlined />), | ||
| getItem("Notebook", "notebook", <LineChartOutlined />), | ||
| getItem( | ||
| "Notebook", | ||
| "notebook", | ||
| <LineChartOutlined />, | ||
| undefined, | ||
| undefined, | ||
| running || paused, | ||
| running || paused ? "Can only analyze in Jupyter notebook after simulation has finished" : undefined, | ||
| ), | ||
|
Comment on lines
+181
to
+189
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve readability and maintainability, it's recommended to extract the repeated For example, you could define these at the component level: const isSimulating = running || paused;
const notebookDisabledMessage = "Can only analyze in Jupyter notebook after simulation has finished";And then use them here: getItem(
"Notebook",
"notebook",
<LineChartOutlined />,
undefined,
undefined,
isSimulating,
isSimulating ? notebookDisabledMessage : undefined,
),
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cursoragent please take a look There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| getItem( | ||
| editMenuLabel, | ||
| "edit", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { Modal, Tabs, Progress, Button, Layout } from "antd"; | ||
| import { Modal, Tabs, Progress, Button, Layout, Tooltip } from "antd"; | ||
| import { useState, useEffect, useMemo } from "react"; | ||
| import View from "./View"; | ||
| import Notebook from "./Notebook"; | ||
|
|
@@ -21,6 +21,7 @@ const Main = ({ isEmbedded }: { isEmbedded: boolean }) => { | |
| ); | ||
| const selectedMenu = useStoreState((state) => state.app.selectedMenu); | ||
| const running = useStoreState((state) => state.simulation.running); | ||
| const paused = useStoreState((state) => state.simulation.paused); | ||
|
|
||
| const setPreferredView = useStoreActions( | ||
| (actions) => actions.app.setPreferredView, | ||
|
|
@@ -100,16 +101,21 @@ const Main = ({ isEmbedded }: { isEmbedded: boolean }) => { | |
| width={"80%"} | ||
| footer={[ | ||
| <> | ||
| <Button | ||
| key="analyze" | ||
| onClick={() => { | ||
| setShowConsole(false); | ||
| setPreferredView(undefined); | ||
| setPreferredView("notebook"); | ||
| }} | ||
| <Tooltip | ||
| title={running || paused ? "Can only analyze in Jupyter notebook after simulation has finished" : ""} | ||
| > | ||
| Analyze in notebook | ||
| </Button> | ||
| <Button | ||
| key="analyze" | ||
| disabled={running || paused} | ||
| onClick={() => { | ||
| setShowConsole(false); | ||
| setPreferredView(undefined); | ||
| setPreferredView("notebook"); | ||
| }} | ||
| > | ||
| Analyze in notebook | ||
| </Button> | ||
| </Tooltip> | ||
|
Comment on lines
+104
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition For example, you could define these at the top of your component: const isSimulationActive = running || paused;
const notebookDisabledTooltip = "Can only analyze in Jupyter notebook after simulation has finished";Then use them here: <Tooltip title={isSimulationActive ? notebookDisabledTooltip : ""}>
<Button disabled={isSimulationActive} ...>
...
</Button>
</Tooltip>Ideally,
Comment on lines
+104
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the change in Using shared constants would ensure consistency and make future modifications simpler. For example: const isSimulating = running || paused;
const notebookDisabledMessage = "Can only analyze in Jupyter notebook after simulation has finished";Then the implementation would look like this: <Tooltip
title={isSimulating ? notebookDisabledMessage : ""}
>
<Button
key="analyze"
disabled={isSimulating}
onClick={() => {
setShowConsole(false);
setPreferredView(undefined);
setPreferredView("notebook");
}}
>
Analyze in notebook
</Button>
</Tooltip>
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cursoragent please take a look There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! I've already implemented all of Gemini's review suggestions. Here's what's currently in place: ✅ Implemented Changes1. Shared Constants File (
|
||
| <Button key="close" onClick={() => setShowConsole(false)}> | ||
| Close | ||
| </Button> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
running || pausedand the tooltip message are duplicated insrc/containers/Main.tsx. To improve maintainability and avoid inconsistencies, consider creating a shared constant for the tooltip message and a derived variable for the simulation state.For example, you could define these at the top of your component:
Then use them here:
Ideally,
notebookDisabledTooltipwould be defined in a shared constants file.