{propertyInfo.displayName as string}
{
this.context.updateObject(userPropertyValues, {
values: Object.assign(
{},
values,
propertyValues
)
});
}}
readOnly={false}
/>
));
}
}
);
////////////////////////////////////////////////////////////////////////////////
export const userPropertiesProperty: PropertyInfo = {
name: "userProperties",
type: PropertyType.Array,
typeClass: UserProperty,
partOfNavigation: false,
enumerable: false,
defaultValue: [],
propertyGridGroup: specificGroup,
disabled: (object: EezObject) => {
return (
!ProjectEditor.getProject(object).projectTypeTraits
.hasFlowSupport ||
(object instanceof ProjectEditor.PageClass &&
!object.isUsedAsUserWidget)
);
}
};
////////////////////////////////////////////////////////////////////////////////
export class UserPropertyValues extends EezObject {
values: {
[id: string]: string;
};
static classInfo: ClassInfo = {
label: () => "User Properties",
properties: [
{
name: "values",
type: PropertyType.Any,
visitProperty: (userPropertyValues: UserPropertyValues) => {
const valueObjects: EezValueObject[] = [];
let flow = getReferencedFlow(userPropertyValues);
if (!flow) {
return valueObjects;
}
flow.userProperties.forEach(userProperty => {
if (
userPropertyValues.values.hasOwnProperty(
userProperty.id
)
) {
valueObjects.push(
makeValueObjectForUserProperty(
userPropertyValues,
userProperty
)
);
}
});
return valueObjects;
}
}
],
defaultValue: {
values: {}
},
beforeLoadHook: (object: IEezObject, jsObject: any) => {
if (jsObject.values == undefined) {
jsObject.values = {};
}
},
check: (
userPropertyValues: UserPropertyValues,
messages: IMessage[]
) => {
let flow = getReferencedFlow(userPropertyValues);
if (!flow) {
return;
}
const component = getAncestorOfType(
userPropertyValues,
ProjectEditor.ComponentClass.classInfo
) as Component;
flow.userProperties.forEach(userProperty => {
const value = userPropertyValues.values[userProperty.id];
if (value) {
if (userProperty.assignable) {
try {
checkAssignableExpression(component, value);
} catch (err) {
messages.push(
new Message(
MessageType.ERROR,
`${
userProperty.displayName ||
userProperty.name
}: invalid assignable expression (${err})`,
makeValueObjectForUserProperty(
userPropertyValues,
userProperty
)
)
);
}
} else {
try {
checkExpression(component, value);
} catch (err) {
messages.push(
new Message(
MessageType.ERROR,
`${
userProperty.displayName ||
userProperty.name
}: invalid expression (${err})`,
makeValueObjectForUserProperty(
userPropertyValues,
userProperty
)
)
);
}
}
} else {
messages.push(
new Message(
MessageType.ERROR,
`${
userProperty.displayName || userProperty.name
}: not set`,
makeValueObjectForUserProperty(
userPropertyValues,
userProperty
)
)
);
}
});
},
getPropertyDisplayName: (
userPropertyValues: UserPropertyValues,
propertyKey: string
) => {
if (propertyKey.startsWith("values.")) {
let flow = getReferencedFlow(userPropertyValues);
if (flow) {
let userProperty = flow.userProperties.find(
userProperty =>
userProperty.id ==
propertyKey.slice("values.".length)
);
if (userProperty) {
return userProperty.displayName || userProperty.name;
}
}
}
return undefined;
}
};
override makeEditable() {
super.makeEditable();
// setTimeout(() => this.removeUnusedPropertyValues());
makeObservable(this, {
values: observable
});
}
removeUnusedPropertyValues() {
let flow = getReferencedFlow(this);
if (flow) {
let usedPropertyIds = flow.userProperties.map(
userProperty => userProperty.id
);
for (let key of Object.keys(this.values)) {
if (!usedPropertyIds.includes(key)) {
delete this.values[key];
}
}
}
}
}
export const userPropertyValuesProperty: PropertyInfo = {
name: "userPropertyValues",
type: PropertyType.Object,
typeClass: UserPropertyValues,
propertyGridGroup: specificGroup,
propertyGridFullRowComponent: UserPropertyValuesProperty,
enumerable: false,
disabled: (object: EezObject) => {
return !ProjectEditor.getProject(object).projectTypeTraits
.hasFlowSupport;
}
};