mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 00:40:01 +02:00
updates AsyncMethodComponent to work with backend
This commit is contained in:
parent
74fc5d9aab
commit
26689d8578
@ -7,7 +7,7 @@ import { LevelName } from './NotificationsComponent';
|
|||||||
type AsyncMethodProps = {
|
type AsyncMethodProps = {
|
||||||
name: string;
|
name: string;
|
||||||
parentPath: string;
|
parentPath: string;
|
||||||
value: Record<string, string>;
|
value: 'RUNNING' | null;
|
||||||
docString?: string;
|
docString?: string;
|
||||||
hideOutput?: boolean;
|
hideOutput?: boolean;
|
||||||
addNotification: (message: string, levelname?: LevelName) => void;
|
addNotification: (message: string, levelname?: LevelName) => void;
|
||||||
@ -38,33 +38,12 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
renderCount.current++;
|
renderCount.current++;
|
||||||
|
|
||||||
// updates the value of each form control that has a matching name in the
|
|
||||||
// runningTask object
|
|
||||||
if (runningTask) {
|
|
||||||
const formElement = formRef.current;
|
|
||||||
if (formElement) {
|
|
||||||
Object.entries(runningTask).forEach(([name, value]) => {
|
|
||||||
const inputElement = formElement.elements.namedItem(name);
|
|
||||||
if (inputElement) {
|
|
||||||
inputElement.value = value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [runningTask]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let message: string;
|
let message: string;
|
||||||
|
|
||||||
if (runningTask === null) {
|
if (runningTask === null) {
|
||||||
message = `${fullAccessPath} task was stopped.`;
|
message = `${fullAccessPath} task was stopped.`;
|
||||||
} else {
|
} else {
|
||||||
const runningTaskEntries = Object.entries(runningTask)
|
message = `${fullAccessPath} was started.`;
|
||||||
.map(([key, value]) => `${key}: "${value}"`)
|
|
||||||
.join(', ');
|
|
||||||
|
|
||||||
message = `${fullAccessPath} was started with parameters { ${runningTaskEntries} }.`;
|
|
||||||
}
|
}
|
||||||
addNotification(message);
|
addNotification(message);
|
||||||
}, [props.value]);
|
}, [props.value]);
|
||||||
@ -94,7 +73,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
<DocStringComponent docString={docString} />
|
<DocStringComponent docString={docString} />
|
||||||
</InputGroup.Text>
|
</InputGroup.Text>
|
||||||
<Button id={`button-${id}`} type="submit">
|
<Button id={`button-${id}`} type="submit">
|
||||||
{runningTask ? 'Stop ' : 'Start '}
|
{runningTask === 'RUNNING' ? 'Stop ' : 'Start '}
|
||||||
</Button>
|
</Button>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</Form>
|
</Form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user