Skip to content

Commit 61c6926

Browse files
authored
Merge pull request #4165 from ProjectMirador/pluginTarget
Allow pluginTarget to be passed as a prop to WindowTopBarPluginMenu
2 parents 86a7c0e + 787ffe6 commit 61c6926

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

__tests__/src/components/WindowTopBarPluginMenu.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ describe('WindowTopBarPluginMenu', () => {
6262
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
6363
});
6464
});
65+
66+
describe('pluginTarget prop', () => {
67+
it('passes the pluginTarget to usePlugins', () => {
68+
const spy = vi.mocked(usePlugins);
69+
spy.mockReturnValue({ PluginComponents: [mockComponentA] });
70+
71+
render(<Subject pluginTarget="CustomPluginTarget" />);
72+
73+
expect(spy).toHaveBeenCalledWith('CustomPluginTarget');
74+
});
75+
76+
it('defaults pluginTarget to WindowTopBarPluginMenu if not provided', () => {
77+
const spy = vi.mocked(usePlugins);
78+
spy.mockReturnValue({ PluginComponents: [mockComponentA] });
79+
80+
render(<Subject />);
81+
82+
expect(spy).toHaveBeenCalledWith('WindowTopBarPluginMenu');
83+
});
84+
});
6585
});

src/components/WindowTopBarPluginMenu.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ import MiradorMenuButton from '../containers/MiradorMenuButton';
77
import { PluginHook } from './PluginHook';
88
import WorkspaceContext from '../contexts/WorkspaceContext';
99
import { usePlugins } from '../extend/usePlugins';
10-
1110
/**
1211
*
1312
*/
1413
export function WindowTopBarPluginMenu({
15-
windowId, menuIcon = <MoreVertIcon />,
14+
windowId, menuIcon = <MoreVertIcon />, pluginTarget = 'WindowTopBarPluginMenu',
1615
}) {
1716
const { t } = useTranslation();
1817
const container = useContext(WorkspaceContext);
1918
const pluginProps = arguments[0]; // eslint-disable-line prefer-rest-params
2019
const [anchorEl, setAnchorEl] = useState(null);
2120
const [open, setOpen] = useState(false);
2221
const windowPluginMenuId = useId();
23-
const { PluginComponents } = usePlugins('WindowTopBarPluginMenu');
22+
const { PluginComponents } = usePlugins(pluginTarget);
2423

2524
/** */
2625
const handleMenuClick = (event) => {
@@ -63,7 +62,7 @@ export function WindowTopBarPluginMenu({
6362
open={open}
6463
onClose={handleMenuClose}
6564
>
66-
<PluginHook targetName="WindowTopBarPluginMenu" handleClose={handleMenuClose} {...pluginProps} />
65+
<PluginHook targetName={pluginTarget} handleClose={handleMenuClose} {...pluginProps} />
6766
</Menu>
6867
</>
6968
);
@@ -74,5 +73,6 @@ WindowTopBarPluginMenu.propTypes = {
7473
container: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
7574
menuIcon: PropTypes.element,
7675
open: PropTypes.bool,
76+
pluginTarget: PropTypes.string,
7777
windowId: PropTypes.string.isRequired,
7878
};

0 commit comments

Comments
 (0)