Skip to content

add run-norewrite button #229

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

Merged
merged 1 commit into from
Mar 1, 2023
Merged
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
15 changes: 15 additions & 0 deletions ui/src/components/nodes/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import ContentCutIcon from "@mui/icons-material/ContentCut";
import Grid from "@mui/material/Grid";
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
import PlayDisabledIcon from "@mui/icons-material/PlayDisabled";
import DeleteIcon from "@mui/icons-material/Delete";
import ViewComfyIcon from "@mui/icons-material/ViewComfy";
import { CopyToClipboard } from "react-copy-to-clipboard";
Expand Down Expand Up @@ -228,6 +229,7 @@ function FloatingToolbar({ id }) {
const devMode = useStore(store, (state) => state.devMode);
// const pod = useStore(store, (state) => state.pods[id]);
const wsRun = useStore(store, (state) => state.wsRun);
const wsRunNoRewrite = useStore(store, (state) => state.wsRunNoRewrite);
const clearResults = useStore(store, (s) => s.clearResults);
// right, bottom
const [layout, setLayout] = useState("bottom");
Expand Down Expand Up @@ -278,6 +280,19 @@ function FloatingToolbar({ id }) {
</IconButton>
</Tooltip>
)}
{!isGuest && (
<Tooltip title="Run without rewrite">
<IconButton
size="small"
onClick={() => {
clearResults(id);
wsRunNoRewrite(id);
}}
>
<PlayDisabledIcon fontSize="inherit" />
</IconButton>
</Tooltip>
)}
<CopyToClipboard
text="dummy"
options={{ debug: true, format: "text/plain", onCopy } as any}
Expand Down
30 changes: 29 additions & 1 deletion ui/src/lib/store/runtimeSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export interface RuntimeSlice {
parseAllPods: () => void;
resolvePod: (id) => void;
resolveAllPods: () => void;
wsRun: (id) => void;
wsRun: (id: string) => void;
wsRunNoRewrite: (id: string) => void;
wsInterruptKernel: ({ lang }) => void;
clearResults: (id) => void;
clearAllResults: () => void;
Expand Down Expand Up @@ -265,6 +266,33 @@ export const createRuntimeSlice: StateCreator<MyState, [], [], RuntimeSlice> = (
get().resolvePod(id);
// rewrite the code
const newcode = rewriteCode(id, get);

// Run the code in remote kernel.
get().setRunning(id);
let pod = get().pods[id];
get().socket?.send(
JSON.stringify({
type: "runCode",
payload: {
lang: pod.lang,
code: newcode,
raw: true,
podId: pod.id,
sessionId: get().sessionId,
},
})
);
},
wsRunNoRewrite: async (id) => {
if (!get().socket) {
get().addError({
type: "error",
msg: "Runtime not connected",
});
return;
}
const newcode = get().pods[id].content;

// Run the code in remote kernel.
get().setRunning(id);
let pod = get().pods[id];
Expand Down