Skip to content
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

Prevent running of model with non-parseable data.json. #230

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions gui/src/app/RunPanel/CompiledRunPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import Box from "@mui/material/Box";
import LinearProgress, {
LinearProgressProps,
} from "@mui/material/LinearProgress";
import Tooltip from "@mui/material/Tooltip";
import Typography from "@mui/material/Typography";
import { FunctionComponent } from "react";
import { FunctionComponent, useMemo } from "react";

import Button from "@mui/material/Button";
import { SamplingOpts } from "@SpCore/ProjectDataModel";
import { Progress } from "@SpStanSampler/StanModelWorker";
import { StanSamplerStatus } from "@SpStanSampler/StanSampler";

type CompiledRunPanelProps = {
handleRun: () => Promise<void>;
handleRun: undefined | (() => Promise<void>);
cancelRun: () => void;
runStatus: StanSamplerStatus;
progress: Progress | undefined;
Expand Down Expand Up @@ -72,16 +73,31 @@ const CompiledRunPanel: FunctionComponent<CompiledRunPanelProps> = ({
</div>
);

const tooltip = useMemo(() => {
if (handleRun === undefined) return "Data must be validly formatted JSON";
if (runStatus === "sampling") return "Sampling is in progress";
if (runStatus === "loading") return "Model is currently loading";
return "Run sampling";
}, [handleRun, runStatus]);

return (
<div>
<Button
variant="contained"
color="success"
onClick={handleRun}
disabled={runStatus === "sampling" || runStatus === "loading"}
>
run sampling
</Button>
<Tooltip title={tooltip}>
<span>
<Button
variant="contained"
color="success"
onClick={handleRun}
disabled={
runStatus === "sampling" ||
runStatus === "loading" ||
handleRun === undefined
}
>
run sampling
</Button>
</span>
</Tooltip>
&nbsp;
{runStatus === "loading" ? (
loadingDiv
Expand Down
11 changes: 8 additions & 3 deletions gui/src/app/RunPanel/RunPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import { FunctionComponent, useCallback, useContext, useMemo } from "react";

import Button from "@mui/material/Button";
import CircularProgress from "@mui/material/CircularProgress";
import Tooltip from "@mui/material/Tooltip";
import { CompileContext } from "@SpCompilation/CompileContext";
import { ProjectContext } from "@SpCore/ProjectContextProvider";
import { SamplingOpts, modelHasUnsavedChanges } from "@SpCore/ProjectDataModel";
import StanSampler from "@SpStanSampler/StanSampler";
import { StanRun } from "@SpStanSampler/useStanSampler";
import CompiledRunPanel from "./CompiledRunPanel";
import CircularProgress from "@mui/material/CircularProgress";
import Tooltip from "@mui/material/Tooltip";

type RunPanelProps = {
sampler?: StanSampler;
Expand All @@ -33,6 +33,11 @@ const RunPanel: FunctionComponent<RunPanelProps> = ({
sampler.sample(data, samplingOpts);
}, [sampler, data, samplingOpts]);

const possiblyHandleRun = useMemo(() => {
if (data === undefined) return undefined;
return handleRun;
}, [data, handleRun])

const cancelRun = useCallback(() => {
if (!sampler) return;
sampler.cancel();
Expand Down Expand Up @@ -82,7 +87,7 @@ const RunPanel: FunctionComponent<RunPanelProps> = ({
<div className="RunPanelPadded">
{compileStatus === "compiled" ? (
<CompiledRunPanel
handleRun={handleRun}
handleRun={possiblyHandleRun}
cancelRun={cancelRun}
runStatus={runStatus}
progress={progress}
Expand Down