Entity specialization #11
Replies: 4 comments 4 replies
-
Hey @c-falardeau, Why not simply hide the editor component for any attribute that shouldn't be modifiable by the user? function TextFieldAttributes() {
return (
<div>
<LabelAttribute />
<PlaceholderAttribute />
{/* <WhateverAttribute /> Just omit it from the UI. */}
</div>
);
} Then you can manually populate the attribute value when instantiating an entity: builderStore.addEntity({
type: "textField",
attributes: { whatever: someValue },
}); Or am I misunderstanding your question? Could you share more about your use case? |
Beta Was this translation helpful? Give feedback.
-
@c-falardeau If you just want to pass some custom props to your entity component, you can create the component inside a hook like this: function useTextField(customProps: { someProp: string }) {
return useMemo(
() =>
createEntityComponent(textFieldEntity, (props) => {
return <div>{customProps.someProp}</div>;
}),
[customProps.someProp]
);
} Then use the hook like this: function MyApp() {
const TextField = useTextField({ someProp: "someValue" });
return (
<BuilderEntities
builderStore={builderStore}
components={{ textField: TextField }}
/>
);
} But I'm still not sure I fully understand your question. Could you elaborate in case I'm missing the point? |
Beta Was this translation helpful? Give feedback.
-
@c-falardeau If you want to make some custom data/configuration available to multiple components across different entity types, you can simply wrap them in a custom React context: const SomeContext = createContext({
someProp: "someDefaultValue",
});
const TextFieldEntity = createEntityComponent(
textFieldEntity,
(props) => {
const { someProp } = useContext(SomeContext);
return <div>{/* ... */}</div>;
}
);
function MyApp() {
return (
<SomeContext.Provider value={{ someProp: "someCustomValue" }}>
<BuilderEntities
builderStore={builderStore}
components={{ textField: TextField }}
/>
</SomeContext.Provider>
);
} |
Beta Was this translation helpful? Give feedback.
-
I was able to do it but inelegantly (since the current work I had to do is a POC).
So I can do this
instance of this
So each time we add a new entity type, we do not have to update the condition, just make to attach the correct flowDirection value when creating the entity type (definition) I need this information out of context of the entity component, like in the component that calls BuilderEntities, so I cannot get the custom props passed to the children. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello :), I don't know if there is a way currently, but it would be nice to be able to extend the Entity type to add custom props that are not modifiable like attributes and not intended to be editable by user. These props would help me generalize some behaviours without apply condition on specific report types
Beta Was this translation helpful? Give feedback.
All reactions