Skip to content

Commit

Permalink
Editors menus (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
luorlandini authored Jul 14, 2021
1 parent cb875bf commit f104f6a
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const DropdownList = ({

const dropdownItems = items
.map((itm, idx) => {

if (itm.type === 'plugin' && itm.Component) {
return (<li><itm.Component variant="default" /></li>);
}
if (itm.type === 'divider') {
return <Dropdown.Divider key={idx} />;
}
Expand Down Expand Up @@ -122,7 +126,6 @@ const DropdownList = ({
toogleIcon ? <FaIcon name={toogleIcon} />
: undefined
}

{labelId && <Message msgId={labelId} /> || label}
{isValidBadgeValue(badgeValue) && <Badge>{badgeValue}</Badge>}
</Dropdown.Toggle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const MenuItem = ({ item, menuItemsProps, containerNode, tabIndex, draggable, cl

const { formatHref, query } = menuItemsProps;
const { id, type, label, labelId = '', items = [], href, style, badge = '', image, Component, target } = item;

const badgeValue = badge;
if (type === 'dropdown') {
return (<DropdownList
Expand All @@ -64,7 +63,7 @@ const MenuItem = ({ item, menuItemsProps, containerNode, tabIndex, draggable, cl
/>);
}

if (type === 'custom' && Component) {
if ((type === 'custom' || type === 'plugin') && Component) {
return <Component />;
}

Expand Down
30 changes: 13 additions & 17 deletions geonode_mapstore_client/client/js/plugins/ActionNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,47 @@ function checkResourcePerms(menuItem, resourcePerms) {
}
return true;
}

function ActionNavbarPlugin({
items,
leftMenuItems,
rightMenuItems,
resourcePerms
}, context) {


const { loadedPlugins } = context;
const configuredItems = usePluginItems({ items, loadedPlugins });
const leftMenuConfiguredItems = configuredItems
.filter(({ target }) => target === 'leftMenuItem')
.map(({ Component }) => ({ type: 'custom', labelId: "gnviewer.edit", Component }));

const rightMenuConfiguredItems = configuredItems
.filter(({ target }) => target === 'rightMenuItem')
.map(({ Component }) => ({ type: 'custom', Component }));
const leftMenuItemsPlugins = reduceArrayRecursive(leftMenuItems, (item) => {
configuredItems.find(plugin => {
if ( item.type === 'plugin' && plugin.name === item.name ) {
item.Component = plugin?.Component;
}
});
return (item);
});

const leftItems = reduceArrayRecursive(
[...leftMenuConfiguredItems, ...leftMenuItems],
menuItem => checkResourcePerms(menuItem, resourcePerms)
);
const rightItems = reduceArrayRecursive(
[...rightMenuConfiguredItems, ...rightMenuItems],
leftMenuItemsPlugins,
menuItem => checkResourcePerms(menuItem, resourcePerms)
);

return (

<ActionNavbar
leftItems={leftItems}
rightItems={rightItems}
/>
);
}

ActionNavbarPlugin.propTypes = {
items: PropTypes.array,
leftMenuItems: PropTypes.array,
rightMenuItems: PropTypes.array
leftMenuItems: PropTypes.array
};

ActionNavbarPlugin.defaultProps = {
items: [],
leftMenuItems: [],
rightMenuItems: []
leftMenuItems: []
};

const ConnectedActionNavbarPlugin = connect(
Expand Down
1 change: 0 additions & 1 deletion geonode_mapstore_client/client/js/plugins/DetailViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export default createPlugin('DetailViewer', {
},
ActionNavbar: {
name: 'ButtonViewer',
target: 'leftMenuItem',
Component: ConnectedButton,
priority: 1
}
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/plugins/Save.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ const SavePlugin = connect(

function SaveButton({
enabled,
onClick
onClick,
variant
}) {
return enabled
? <Button
variant="primary"
variant={variant || "primary"}
onClick={() => onClick()}
>
<Message msgId="save"/>
Expand Down Expand Up @@ -123,7 +124,6 @@ export default createPlugin('Save', {
},
ActionNavbar: {
name: 'Save',
target: 'leftMenuItem',
Component: ConnectedSaveButton
}
},
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ const SaveAsPlugin = connect(

function SaveAsButton({
enabled,
onClick
onClick,
variant
}) {
return enabled
? <Button
variant="primary"
variant={variant || "primary"}
onClick={() => onClick()}
>
<Message msgId="saveAs"/>
Expand Down Expand Up @@ -135,7 +136,6 @@ export default createPlugin('SaveAs', {
},
ActionNavbar: {
name: 'SaveAs',
target: 'leftMenuItem',
Component: ConnectedSaveAsButton
}
},
Expand Down
4 changes: 2 additions & 2 deletions geonode_mapstore_client/client/js/plugins/Share.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ const SharePlugin = connect(

function ShareButton({
enabled,
variant,
onClick
}) {
return enabled
? <Button
variant="primary"
variant={variant || "primary"}
onClick={() => onClick()}
>
<Message msgId="share.title"/>
Expand Down Expand Up @@ -148,7 +149,6 @@ export default createPlugin('Share', {
},
ActionNavbar: {
name: 'Share',
target: 'leftMenuItem',
Component: ConnectedShareButton
}
},
Expand Down
4 changes: 0 additions & 4 deletions geonode_mapstore_client/client/js/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export const plugins = {
containers: {
ActionNavbar: {
name: 'LayerDownload',
target: 'leftMenuItem',
Component: LayerDownloadActionButton
}
}
Expand Down Expand Up @@ -118,7 +117,6 @@ export const plugins = {
containers: {
ActionNavbar: {
name: 'Catalog',
target: 'leftMenuItem',
Component: CatalogActionButton,
priority: 1
},
Expand Down Expand Up @@ -166,7 +164,6 @@ export const plugins = {
containers: {
ActionNavbar: {
name: 'Measure',
target: 'leftMenuItem',
Component: MeasureActionButton
}
}
Expand Down Expand Up @@ -275,7 +272,6 @@ export const plugins = {
containers: {
ActionNavbar: {
name: 'Print',
target: 'leftMenuItem',
Component: PrintActionButton,
priority: 5,
doNotHide: true
Expand Down
Loading

0 comments on commit f104f6a

Please sign in to comment.