fix: option funcs for trait pane

This commit is contained in:
cha0s 2020-06-25 10:49:30 -05:00
parent 1c2103441c
commit 6a0c4461ed
3 changed files with 8 additions and 6 deletions

View File

@ -30,7 +30,7 @@ const EntityComponent = (props) => {
<div className="entity">
<div className="document-pane" />
<div className="settings-pane">
<Traits context={entity.context} target={json.uuid} traits={traits} />
<Traits context={entity.context} entity={entity} target={json.uuid} traits={traits} />
</div>
</div>
);

View File

@ -19,7 +19,7 @@ const ensureTraitComponents = () => {
}
};
const makeTraitPaneRenderer = (context, dispatch, target, traitType) => (trait) => {
const makeTraitPaneRenderer = (context, dispatch, entity, target, traitType) => (trait) => {
ensureTraitComponents();
const {params, state} = trait;
const {[traitType]: TraitComponent} = TraitComponents;
@ -50,7 +50,7 @@ const makeTraitPaneRenderer = (context, dispatch, target, traitType) => (trait)
<Value.Component
context={context}
onChange={(value) => dispatch(setTraitProperty({...payload, value}))}
options={options}
options={'function' === typeof options ? options(entity) : options}
type={type}
value={values[key]}
/>
@ -69,6 +69,7 @@ const makeTraitPaneRenderer = (context, dispatch, target, traitType) => (trait)
const TraitPane = (props) => {
const {
context,
entity,
target,
trait,
type,
@ -76,8 +77,8 @@ const TraitPane = (props) => {
const dispatch = useDispatch();
// TODO: dependency on context is too noisy
const renderTraitPane = useMemo(
() => makeTraitPaneRenderer(context, dispatch, target, type),
[context, dispatch, target, type],
() => makeTraitPaneRenderer(context, dispatch, entity, target, type),
[context, dispatch, entity, target, type],
);
return useMemo(
() => renderTraitPane(trait),

View File

@ -30,7 +30,7 @@ const decorate = compose(
// );
const Traits = (props) => {
const {context, target, traits} = props;
const {context, entity, target, traits} = props;
const [tabIndex, setTabIndex] = useState(0);
let listRef;
const entries = Object.entries(traits);
@ -62,6 +62,7 @@ const Traits = (props) => {
<TabPanel key={type}>
<TraitPane
context={context}
entity={entity}
key={type}
target={target}
trait={trait}