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

View File

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