Skip to content

Commit a094d78

Browse files
authored
BACKLOG-20903 Add possibility to determine visibility (#232)
* BACKLOG-20903 Add possibility to determine action visibility * BACKLOG-20903 Revert unnecessary change
1 parent c61239d commit a094d78

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/ui-extender/src/actions/menuAction/menuAction.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const reducer = (state, action) => {
216216
};
217217

218218
const MenuActionComponent = props => {
219-
const {rootMenuContext, parentMenuContext, isMenuPreload, render: Render, loading: Loading} = props;
219+
const {rootMenuContext, parentMenuContext, isMenuPreload, render: Render, loading: Loading, visibilityPredicate} = props;
220220
const id = 'actionComponent-' + props.id;
221221

222222
const elRef = useRef(document.getElementById('menuHolder'));
@@ -268,6 +268,12 @@ const MenuActionComponent = props => {
268268
}
269269
}, [id, menuState, menuContext]);
270270

271+
let isVisible = !isMenuPreload || menuState.loadedItems.length > 0;
272+
273+
if (visibilityPredicate) {
274+
isVisible = visibilityPredicate(menuState);
275+
}
276+
271277
return (
272278
<>
273279
{menuState.isOpen && menuState.loadingItems.length > 0 && Loading ? (
@@ -276,7 +282,7 @@ const MenuActionComponent = props => {
276282
<Render {...props}
277283
menuContext={menuContext}
278284
menuState={menuState}
279-
isVisible={!isMenuPreload || menuState.loadedItems.length > 0}
285+
isVisible={isVisible}
280286
onClick={(eventProps, event) => {
281287
// Handle click to open menu only if not in a submenu (already handled on mouse over)
282288
if (!parentMenuContext) {
@@ -378,7 +384,11 @@ MenuActionComponent.propTypes = {
378384
/**
379385
* Render for the action button
380386
*/
381-
loading: PropTypes.func
387+
loading: PropTypes.func,
388+
/**
389+
* Helps determine if action is visible
390+
*/
391+
visibilityPredicate: PropTypes.func
382392
};
383393

384394
/**

0 commit comments

Comments
 (0)