-
-
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?
Disable notebook button during simulation #244
Conversation
Co-authored-by: andershaf <andershaf@gmail.com>
|
Cursor Agent can help with this pull request. Just |
|
/gemini review |
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.
Code Review
This pull request successfully disables the 'Notebook' menu item and the 'Analyze in notebook' button when a simulation is running or paused, preventing potential errors. The implementation is correct and uses tooltips to inform the user about the disabled state. My review includes suggestions to improve code maintainability by extracting the repeated logic and tooltip message into variables and constants, which will make the code cleaner and easier to manage in the future.
| getItem( | ||
| "Notebook", | ||
| "notebook", | ||
| <LineChartOutlined />, | ||
| undefined, | ||
| undefined, | ||
| running || paused, | ||
| running || paused ? "Can only analyze in Jupyter notebook after simulation has finished" : undefined, | ||
| ), |
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 || paused and the tooltip message are duplicated in src/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:
const isSimulationActive = running || paused;
const notebookDisabledTooltip = "Can only analyze in Jupyter notebook after simulation has finished";Then use them here:
getItem(
"Notebook",
"notebook",
<LineChartOutlined />,
undefined,
undefined,
isSimulationActive,
isSimulationActive ? notebookDisabledTooltip : undefined,
),Ideally, notebookDisabledTooltip would be defined in a shared constants file.
| <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> |
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 || paused and the tooltip message are duplicated from src/App.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:
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, notebookDisabledTooltip would be defined in a shared constants file to be used in both App.tsx and Main.tsx.
|
@cursoragent can you look at the review from gemini here? I think I agree! |
|
Perfect! I've implemented all of Gemini's review suggestions. Here's what I did: Summary of Changes1. Created a shared constants file (
|
|
/gemini review |
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.
Code Review
This pull request correctly disables the 'Notebook' menu item and the 'Analyze in notebook' button when a simulation is running or paused. This is a good enhancement to the user experience, preventing potential errors. The implementation is solid. My review includes suggestions to improve code maintainability by extracting repeated logic and strings into constants, which will make the code cleaner and easier to manage in the long run.
| getItem( | ||
| "Notebook", | ||
| "notebook", | ||
| <LineChartOutlined />, | ||
| undefined, | ||
| undefined, | ||
| running || paused, | ||
| running || paused ? "Can only analyze in Jupyter notebook after simulation has finished" : undefined, | ||
| ), |
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.
To improve readability and maintainability, it's recommended to extract the repeated running || paused condition and the tooltip message into constants. This logic and message are also duplicated in src/containers/Main.tsx. Centralizing them would make the code cleaner and easier to update.
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,
),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.
@cursoragent please take a look
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.
| <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> |
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.
Similar to the change in App.tsx, the running || paused condition and the tooltip message are used here. To promote code reuse and improve maintainability, it would be beneficial to define these as constants and reuse them in both places.
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>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.
@cursoragent please take a look
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.
Perfect! I've already implemented all of Gemini's review suggestions. Here's what's currently in place:
✅ Implemented Changes
1. Shared Constants File (src/constants.ts)
export const NOTEBOOK_DISABLED_TOOLTIP =
"Can only analyze in Jupyter notebook after simulation has finished";2. App.tsx - Refactored
// Import added
import { NOTEBOOK_DISABLED_TOOLTIP } from "./constants";
// Derived variable
const isSimulationActive = running || paused;
// Menu item now uses the constant and variable
getItem(
"Notebook",
"notebook",
<LineChartOutlined />,
undefined,
undefined,
isSimulationActive,
isSimulationActive ? NOTEBOOK_DISABLED_TOOLTIP : undefined,
)3. Main.tsx - Refactored
// Import added
import { NOTEBOOK_DISABLED_TOOLTIP } from "../constants";
// Derived variable
const isSimulationActive = running || paused;
// Button uses the constant and variable
<Tooltip title={isSimulationActive ? NOTEBOOK_DISABLED_TOOLTIP : ""}>
<Button
key="analyze"
disabled={isSimulationActive}
onClick={...}
>
Analyze in notebook
</Button>
</Tooltip>✅ Benefits Achieved
- No duplication - Message defined once in
src/constants.ts - Better maintainability - Single source of truth for the tooltip
- More readable -
isSimulationActiveis clearer thanrunning || paused - Consistency - Both components use identical logic
- All tests passing - 153 tests ✓
The code is now clean, maintainable, and follows DRY principles exactly as Gemini recommended! 🎉
Learn more about Cursor Agents
Disable the "Notebook" menu item and "Analyze in notebook" button while the simulation is running or paused to prevent errors, providing a tooltip with the reason.