import React from "react"; import { observable, runInAction, makeObservable } from "mobx"; import { observer } from "mobx-react"; import classNames from "classnames"; import { humanize } from "eez-studio-shared/string"; import { Icon } from "eez-studio-ui/icon"; import { PropertyProps } from "project-editor/core/object"; import { ProjectContext } from "project-editor/project/context"; import type { IVariable } from "project-editor/flow/flow-interfaces"; import { getObjectVariableTypeFromType, IObjectVariableValue, getObjectType, isObjectType } from "project-editor/features/variable/value-type"; import type { Variable } from "project-editor/features/variable/variable"; import { Loader } from "eez-studio-ui/loader"; import { Button } from "eez-studio-ui/button"; import { CodeEditor } from "eez-studio-ui/code-editor"; //////////////////////////////////////////////////////////////////////////////// export const RenderVariableStatusPropertyUI = observer( class RenderVariableStatusPropertyUI extends React.Component { static contextType = ProjectContext; declare context: React.ContextType; objectVariableValue: IObjectVariableValue | undefined; constructor(props: PropertyProps) { super(props); makeObservable(this, { objectVariableValue: observable }); } async updateObjectVariableValue() { const variable = this.props.objects[0] as Variable; const value = this.context.runtimeSettings.getVariableValue(variable); runInAction(() => (this.objectVariableValue = value)); } componentDidMount() { this.updateObjectVariableValue(); } componentDidUpdate(prevProps: PropertyProps) { if (this.props.objects[0] != prevProps.objects[0]) { this.updateObjectVariableValue(); } } render() { const variable = this.props.objects[0] as Variable; if (isObjectType(variable.type)) { const objectVariableType = getObjectVariableTypeFromType( this.context, variable.type ); if (!objectVariableType) { return null; } const objectVariableValue = this.objectVariableValue; return ( { const constructorParams = await objectVariableType.editConstructorParams!( variable, objectVariableValue?.constructorParams, false ); if (constructorParams !== undefined) { this.context.runtimeSettings.setVariableValue( variable, constructorParams ); this.updateObjectVariableValue(); } }} onClear={async () => { this.context.runtimeSettings.setVariableValue( variable, undefined ); this.updateObjectVariableValue(); }} /> ); } else { const value = this.context.runtimeSettings.getVariableValue(variable); return value != undefined ? (
Stored value:
{}} minLines={2} maxLines={20} readOnly={true} style={{ marginTop: 5, marginBottom: 10, border: "1px solid #aaa" }} >
) : null; } } } ); //////////////////////////////////////////////////////////////////////////////// export const RenderVariableStatus = observer( ({ variable, value, onClick, onClear }: { variable: IVariable; value?: IObjectVariableValue; onClick: () => void; onClear?: () => void; }) => { const image = value?.status?.image; const color = value?.status?.color; const error = value?.status?.error != undefined; const title = value?.status?.error; let label; let hint; if (onClear) { if (value?.constructorParams != null) { label = value.status.label; } else { hint = `Select ${getObjectType(variable.type)}`; } } else { label = value?.status.label || variable.description || humanize(variable.fullName); } const clickable = !onClear && variable.persistent; const element = (
{image && (typeof image == "string" ? ( ) : ( image ))} {color && (color == "loader" ? ( ) : ( ))} {label} {hint} {error && ( )}
); if (!onClear) { return element; } return (
{element}
); } );