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

✨ Remote Run Revamp #356

Merged
merged 21 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0383ab6
refactor RunDialog style
MFA-X-AI Aug 22, 2024
949da78
fix run dialog unable to handle camelCase
MFA-X-AI Aug 22, 2024
67dc602
fix arguments form spawning multiple times when toggling run type
MFA-X-AI Aug 22, 2024
514d400
enable remote run template notation
MFA-X-AI Aug 23, 2024
be15bf9
enable keyword substitution in remote run
MFA-X-AI Aug 24, 2024
4c9aafe
collect all args and remove duplicates
MFA-X-AI Aug 27, 2024
00f3baa
enable presetting values in remote run config templates
MFA-X-AI Aug 28, 2024
4b3a69c
seperate between argument and placeholders in remote run
MFA-X-AI Aug 28, 2024
5b5ef67
make remote run 'msg' and 'url' optional
MFA-X-AI Aug 29, 2024
8c35989
fix placeholder inputs lingering after remote run
MFA-X-AI Aug 29, 2024
3f8649d
display formatted placeholders, pass formatted cmd to remote
MFA-X-AI Aug 29, 2024
e01d0e1
add open config.ini in Settings menu
MFA-X-AI Sep 3, 2024
bef34bd
refactor run dialog into local run and remote run
MFA-X-AI Sep 4, 2024
18a6061
fetch remote configs on run, reset previous connfig if remote config …
MFA-X-AI Sep 4, 2024
a133096
fix remote run not spawning the arguments when running first time
MFA-X-AI Sep 4, 2024
8cd3528
append arguments after placeholders in remote run execution
MFA-X-AI Sep 4, 2024
c259494
add example remote usage in config.ini, clean remaining remote code
MFA-X-AI Sep 4, 2024
1b72607
fix normal run not running, refine remote output
MFA-X-AI Sep 4, 2024
fb22c59
trigger remote run config fetch on config.ini save
MFA-X-AI Sep 4, 2024
03cdc5e
enable remote run section collapse, improve css and make template pre…
MFA-X-AI Sep 4, 2024
c62eef4
add alert if config cannot be opened from settings
MFA-X-AI Sep 5, 2024
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
3 changes: 3 additions & 0 deletions src/XircuitsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
commands: any;
serviceManager: ServiceManager;
fetchComponentsSignal: Signal<this, any>;
fetchRemoteRunConfigSignal: Signal<this, any>;
saveXircuitSignal: Signal<this, any>;
compileXircuitSignal: Signal<this, any>;
runXircuitSignal: Signal<this, any>;
Expand All @@ -55,6 +56,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
this.commands = options.commands;
this.serviceManager = options.serviceManager;
this.fetchComponentsSignal = new Signal<this, any>(this);
this.fetchRemoteRunConfigSignal = new Signal<this, any>(this);
this.saveXircuitSignal = new Signal<this, any>(this);
this.compileXircuitSignal = new Signal<this, any>(this);
this.runXircuitSignal = new Signal<this, any>(this);
Expand All @@ -76,6 +78,7 @@ export class XircuitsFactory extends ABCWidgetFactory<DocumentWidget> {
context: context,
serviceManager: this.serviceManager,
fetchComponentsSignal: this.fetchComponentsSignal,
fetchRemoteRunConfigSignal: this.fetchRemoteRunConfigSignal,
saveXircuitSignal: this.saveXircuitSignal,
compileXircuitSignal: this.compileXircuitSignal,
runXircuitSignal: this.runXircuitSignal,
Expand Down
3 changes: 3 additions & 0 deletions src/XircuitsWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class XircuitsPanel extends ReactWidget {
xircuitsApp: XircuitsApplication;
serviceManager: ServiceManager;
fetchComponentsSignal: Signal<this,any>;
fetchRemoteRunConfigSignal: Signal<this,any>;
saveXircuitSignal: Signal<this, any>;
compileXircuitSignal: Signal<this, any>;
runXircuitSignal: Signal<this, any>;
Expand All @@ -38,6 +39,7 @@ export class XircuitsPanel extends ReactWidget {
this.context = options.context;
this.serviceManager = options.serviceManager;
this.fetchComponentsSignal = options.fetchComponentsSignal;
this.fetchRemoteRunConfigSignal = options.fetchRemoteRunConfigSignal;
this.saveXircuitSignal = options.saveXircuitSignal;
this.compileXircuitSignal = options.compileXircuitSignal;
this.runXircuitSignal = options.runXircuitSignal;
Expand Down Expand Up @@ -89,6 +91,7 @@ export class XircuitsPanel extends ReactWidget {
widgetId={this.parent?.id}
serviceManager={this.serviceManager}
fetchComponentsSignal={this.fetchComponentsSignal}
fetchRemoteRunConfigSignal={this.fetchRemoteRunConfigSignal}
saveXircuitSignal={this.saveXircuitSignal}
compileXircuitSignal={this.compileXircuitSignal}
runXircuitSignal={this.runXircuitSignal}
Expand Down
4 changes: 3 additions & 1 deletion src/commands/CommandIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export const commandIDs = {
createNewComponentLibrary: "Xircuit-editor:new-component-library",
refreshComponentList: "xircuits-sidebar:refresh-component-list",
toggleDisplayNodesInLibrary: "xircuits-sidebar:toggle-display-nodes-in-library",
helpOpenResource: "xircuits-help:open-resource"
helpOpenResource: "xircuits-help:open-resource",
openXircuitsConfiguration: "xircuits-config:open-config",
fetchRemoteRunConfig: "xircuits-config:fetch-remote-config"
};
173 changes: 108 additions & 65 deletions src/components/XircuitsBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { formDialogWidget } from "../dialog/formDialogwidget";
import { showFormDialog } from "../dialog/FormDialog";
import { inputDialog } from "../dialog/LiteralInputDialog";
import { getItsLiteralType } from "../dialog/input-dialogues/VariableInput";
import { RunDialog } from "../dialog/RunDialog";
import { LocalRunDialog } from "../dialog/LocalRunDialog";
import { RemoteRunDialog } from "../dialog/RemoteRunDialog";
import { requestAPI } from "../server/handler";
import ComponentsPanel from "../context-menu/ComponentsPanel";
import {
Expand All @@ -29,7 +30,7 @@ import { cancelDialog, GeneralComponentLibrary } from "../tray_library/GeneralCo
import { AdvancedComponentLibrary, fetchNodeByName } from "../tray_library/AdvanceComponentLib";
import { lowPowerMode, setLowPowerMode } from "./state/powerModeState";
import { startRunOutputStr } from "./runner/RunOutput";
import { doRemoteRun } from "./runner/RemoteRun";
import { buildRemoteRunCommand } from "./runner/RemoteRun";

import styled from "@emotion/styled";
import { commandIDs } from "../commands/CommandIDs";
Expand All @@ -43,6 +44,7 @@ export interface BodyWidgetProps {
widgetId?: string;
serviceManager: ServiceManager;
fetchComponentsSignal: Signal<XircuitsPanel, any>;
fetchRemoteRunConfigSignal: Signal<XircuitsPanel, any>;
saveXircuitSignal: Signal<XircuitsPanel, any>;
compileXircuitSignal: Signal<XircuitsPanel, any>;
runXircuitSignal: Signal<XircuitsPanel, any>;
Expand Down Expand Up @@ -80,6 +82,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
commands,
widgetId,
fetchComponentsSignal,
fetchRemoteRunConfigSignal,
saveXircuitSignal,
compileXircuitSignal,
runXircuitSignal,
Expand All @@ -94,7 +97,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
const [saved, setSaved] = useState(false);
const [compiled, setCompiled] = useState(false);
const [initialize, setInitialize] = useState(true);
const [runConfigs, setRunConfigs] = useState<any>("");
const [remoteRunConfigs, setRemoteRunConfigs] = useState<any>("");
const [lastConfig, setLastConfigs] = useState<any>("");
const [stringNodes, setStringNodes] = useState<string[]>([]);
const [intNodes, setIntNodes] = useState<string[]>([]);
Expand All @@ -107,7 +110,8 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
const [inDebugMode, setInDebugMode] = useState<boolean>(false);
const [currentIndex, setCurrentIndex] = useState<number>(-1);
const [runType, setRunType] = useState<string>("run");
const [runTypesCfg, setRunTypesCfg] = useState<string>("");
const [prevRemoteConfiguration, setPrevRemoteConfiguration] = useState(null);
const [remoteRunTypesCfg, setRemoteRunTypesCfg] = useState<string>("");
const initialRender = useRef(true);
const contextRef = useRef(context);
const notInitialRender = useRef(false);
Expand Down Expand Up @@ -600,24 +604,28 @@ export const BodyWidget: FC<BodyWidgetProps> = ({

// Run Mode
context.ready.then(async () => {
let runArgs = await handleRunDialog();
let runCommand = runArgs["runCommand"];
let config = runArgs["config"];

const current_path = context.path;
const model_path = current_path.split(".xircuits")[0] + ".py";

let code = startRunOutputStr()

if (runType == 'remote-run') {
// Run subprocess when run type is Remote Run
code += doRemoteRun(model_path, config['command'], config['msg'], config['url']);
} else {
code += "%run " + model_path + runCommand
let code = startRunOutputStr();

let result;

if (runType == 'run') {
result = await handleLocalRunDialog();
if (result.status === 'ok') {
code += "%run " + model_path + result.args;
}
} else if (runType == 'remote-run') {
result = await handleRemoteRunDialog();
if (result.status === 'ok') {
code += buildRemoteRunCommand(model_path, result.args);
}
}
if (runArgs) {
if (result.status === 'ok') {
commands.execute(commandIDs.executeToOutputPanel, { code });
} else if (result.status === 'cancelled') {
console.log("Run operation cancelled by user.");
}
})
}
Expand All @@ -628,7 +636,10 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
if (shell.currentWidget?.id !== widgetId) {
return;
}
saveAndCompileAndRun();
if(runType == 'remote-run'){
await getRemoteRunTypeFromConfig();
}
await saveAndCompileAndRun();
}

const handleLockClick = () => {
Expand Down Expand Up @@ -692,7 +703,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
}
}

const getRunTypeFromConfig = async () => {
const getRemoteRunTypeFromConfig = async () => {
const configuration = await getRunTypesFromConfig("RUN_TYPES");
const error_msg = configuration["err_msg"];
if (error_msg) {
Expand All @@ -704,27 +715,36 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
buttons: [Dialog.warnButton({ label: 'OK' })]
});
}
setRunTypesCfg(configuration["run_types"])
setRunConfigs(configuration["run_types_config"]);
}

// Compare new configuration with previous
if (JSON.stringify(configuration) !== JSON.stringify(prevRemoteConfiguration)) {
// Configuration has changed, reset lastConfig
setLastConfigs("");
setPrevRemoteConfiguration(configuration);
}

setRemoteRunTypesCfg(configuration["run_types"]);
setRemoteRunConfigs(configuration["run_types_config"]);
};

// fetch remote run config when toggling to remote run
useEffect(() => {
// Get run configuration when in 'Remote Run' mode only
if (runType == 'remote-run') {
getRunTypeFromConfig();
} else {
setRunConfigs("")
getRemoteRunTypeFromConfig();
}, [runType]);

useEffect(() => {

const setterByType = {
'string': setStringNodes,
'int': setIntNodes,
'float': setFloatNodes,
'boolean': setBoolNodes,
'any': setAnyNodes
}

context.ready.then(() => {
const setterByType = {
'string': setStringNodes,
'int': setIntNodes,
'float': setFloatNodes,
'boolean': setBoolNodes,
'any': setAnyNodes
}
Object.values(setterByType).forEach(set => set([]));

context.ready.then(() => {

if (initialize) {
let allNodes = xircuitsApp.getDiagramEngine().getModel().getNodes();
Expand All @@ -740,21 +760,16 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
}
}
}
else {
Object.values(setterByType).forEach(set => set([]));
}
})
}, [initialize, runType]);

const handleRunDialog = async () => {
let title = 'Run';
}, [initialize]);

const handleLocalRunDialog = async () => {
let title = 'Execute Workflow';
const dialogOptions: Partial<Dialog.IOptions<any>> = {
title,
body: formDialogWidget(
<RunDialog
runTypes={runTypesCfg}
runConfigs={runConfigs}
lastConfig={lastConfig}
<LocalRunDialog
childStringNodes={stringNodes}
childBoolNodes={boolNodes}
childIntNodes={intNodes}
Expand All @@ -766,23 +781,10 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
focusNodeSelector: '#name'
};
const dialogResult = await showFormDialog(dialogOptions);

if (dialogResult["button"]["label"] == 'Cancel') {
if (dialogResult.button.label === 'Cancel') {
// When Cancel is clicked on the dialog, just return
return false;
}

// Remember the last config chose and set the chosen config to output
let config;
let runType = dialogResult["value"]['runType'] ?? "";
let runConfig = dialogResult["value"]['runConfig'] ?? "";
if (runConfigs.length != 0) {
runConfigs.map(cfg => {
if (cfg.run_type == runType && cfg.run_config_name == runConfig) {
config = cfg;
setLastConfigs(cfg);
}
})
return { status: 'cancelled' };
}

const date = new Date();
Expand All @@ -797,12 +799,53 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
.reduce((cmd, param) => {
xircuitLogger.info(param + ": " + dialogResult.value[param]);
let filteredParam = param.replace(/\s+/g, "_");
filteredParam = filteredParam.toLowerCase();
return `${cmd} --${filteredParam} ${dialogResult.value[param]}`;
}, s);
}, "");

return { runCommand, config };
return { status: 'ok', args: runCommand };
};

const handleRemoteRunDialog = async () => {
let title = 'Execute Workflow';
const dialogOptions: Partial<Dialog.IOptions<any>> = {
title,
body: formDialogWidget(
<RemoteRunDialog
remoteRunTypes={remoteRunTypesCfg}
remoteRunConfigs={remoteRunConfigs}
lastConfig={lastConfig}
childStringNodes={stringNodes}
childBoolNodes={boolNodes}
childIntNodes={intNodes}
childFloatNodes={floatNodes}
/>
),
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: ('Start') })],
defaultButton: 1,
focusNodeSelector: '#name'
};
const dialogResult = await showFormDialog(dialogOptions);

if (dialogResult.button.label === 'Cancel') {
// When Cancel is clicked on the dialog, just return
return { status: 'cancelled' };
}

// Remember the last config chose and set the chosen config to output
let config;
let remoteRunType = dialogResult["value"]['remoteRunType'] ?? "";
let runConfig = dialogResult["value"]['remoteRunConfig'] ?? "";
if (remoteRunConfigs.length != 0) {
remoteRunConfigs.map(cfg => {
if (cfg.run_type == remoteRunType && cfg.run_config_name == runConfig) {
config = { ...cfg, ...dialogResult["value"] };
setLastConfigs(config);
}
})
}

return { status: 'ok', args: config };
};

const connectSignal = ([signal, handler]) => {
Expand All @@ -818,6 +861,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
[saveXircuitSignal, handleSaveClick],
[compileXircuitSignal, handleCompileClick],
[runXircuitSignal, handleRunClick],
[fetchRemoteRunConfigSignal, getRemoteRunTypeFromConfig],
[lockNodeSignal, handleLockClick],
[triggerLoadingAnimationSignal, triggerLoadingAnimation],
[reloadAllNodesSignal, handleReloadAll],
Expand Down Expand Up @@ -1052,7 +1096,6 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
}

// note: can not use the same port name in the same node,or the same name port can not link to other ports
// you can use shift + click and then use delete to delete link
if (node != null) {
let point = xircuitsApp.getDiagramEngine().getRelativeMousePoint(event);
node.setPosition(point);
Expand Down
Loading
Loading