Skip to content

Commit

Permalink
fix user property bugs: not opening expression builder and auto updat…
Browse files Browse the repository at this point in the history
…e after rename
  • Loading branch information
mvladic committed Oct 6, 2024
1 parent b6480d9 commit cfd0318
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/project-editor/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,10 @@ export function* searchForReference(
let identifierType: IdentifierType | undefined;
let structType: ValueType | undefined;
let enumType: ValueType | undefined;
if (object instanceof ProjectEditor.VariableClass) {
if (
object instanceof ProjectEditor.VariableClass ||
object instanceof ProjectEditor.UserPropertyClass
) {
let flow = getAncestorOfType(object, ProjectEditor.FlowClass.classInfo);
if (flow) {
identifierType = "local-variable";
Expand Down
38 changes: 32 additions & 6 deletions packages/project-editor/flow/user-property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getParent,
IEezObject,
IMessage,
IOnSelectParams,
MessageType,
PropertyInfo,
PropertyProps,
Expand Down Expand Up @@ -251,8 +252,11 @@ function getReferencedFlow(object: IEezObject): Flow | undefined {
return undefined;
}

function getPropertyInfoForUserProperty(userProperty: UserProperty) {
return userProperty.assignable
function getPropertyInfoForUserProperty(
userProperty: UserProperty,
parent: IEezObject
) {
const propertyInfo = userProperty.assignable
? makeAssignableExpressionProperty(
{
name: userProperty.id,
Expand All @@ -273,12 +277,31 @@ function getPropertyInfoForUserProperty(userProperty: UserProperty) {
},
userProperty.type
);

const onSelect = propertyInfo.onSelect!;

propertyInfo.onSelect = async (
object: IEezObject,
propertyInfo: PropertyInfo,
params?: IOnSelectParams
) => {
(object as any)._eez_parent = parent;

await onSelect(object, propertyInfo, params);

delete (object as any)._eez_parent;
};

return propertyInfo;
}

function getUserPropertiesAsPropertyInfos(
userProperties: UserProperty[]
userProperties: UserProperty[],
parent: IEezObject
): PropertyInfo[] {
return userProperties.map(getPropertyInfoForUserProperty);
return userProperties.map(userProperty =>
getPropertyInfoForUserProperty(userProperty, parent)
);
}

function makeValueObjectForUserProperty(
Expand All @@ -287,7 +310,7 @@ function makeValueObjectForUserProperty(
) {
const valueObject = EezValueObject.create(
userPropertyValues,
getPropertyInfoForUserProperty(userProperty),
getPropertyInfoForUserProperty(userProperty, userPropertyValues),
userPropertyValues.values[userProperty.id]
);

Expand Down Expand Up @@ -394,7 +417,10 @@ export const UserPropertyValuesProperty = observer(
return [];
}

return getUserPropertiesAsPropertyInfos(flow.userProperties);
return getUserPropertiesAsPropertyInfos(
flow.userProperties,
object
);
}

render() {
Expand Down
2 changes: 2 additions & 0 deletions packages/project-editor/project-editor-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import { evalProperty } from "project-editor/flow/helper";
import { migrateLvglVersion } from "./lvgl/migrate";
import { FlowTabState } from "project-editor/flow/flow-tab-state";
import { Color } from "project-editor/features/style/theme";
import { UserProperty } from "./flow/user-property";

export const conditionalStyleConditionProperty = makeExpressionProperty(
{
Expand Down Expand Up @@ -186,6 +187,7 @@ export async function createProjectEditor(
OutputActionComponentClass: OutputActionComponent,
CallActionActionComponentClass: CallActionActionComponent,
VariableClass: Variable,
UserPropertyClass: UserProperty,
GlyphClass: Glyph,
ScpiCommandClass: ScpiCommand,
ScpiSubsystemClass: ScpiSubsystem,
Expand Down
2 changes: 2 additions & 0 deletions packages/project-editor/project-editor-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import type { PropertyInfo } from "project-editor/core/object";
import type { migrateLvglVersion } from "project-editor/lvgl/migrate";
import type { FlowTabState } from "project-editor/flow/flow-tab-state";
import type { Color } from "project-editor/features/style/theme";
import type { UserProperty } from "./flow/user-property";

export interface IProjectEditor {
homeTabs?: Tabs;
Expand Down Expand Up @@ -135,6 +136,7 @@ export interface IProjectEditor {
OutputActionComponentClass: typeof OutputActionComponent;
CallActionActionComponentClass: typeof CallActionActionComponent;
VariableClass: typeof Variable;
UserPropertyClass: typeof UserProperty;
GlyphClass: typeof Glyph;
ScpiCommandClass: typeof ScpiCommand;
ScpiSubsystemClass: typeof ScpiSubsystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ export const Property = observer(
if (newValue != oldValue) {
this.context.undoManager.setCombineCommands(true);

console.log("Change unique value", oldValue, newValue);

runInAction(() => {
replaceObjectReference(
this.props.objects[0],
Expand Down

0 comments on commit cfd0318

Please sign in to comment.