diff --git a/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx b/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx index 45e502bf5..a5da8bcf0 100644 --- a/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx +++ b/frontend/app/components/shared/ProjectDropdown/ProjectDropdown.tsx @@ -1,19 +1,23 @@ +import { + CaretDownOutlined, + FolderAddOutlined, +} from '@ant-design/icons'; +import { Button, Divider, Dropdown, Space, Typography } from 'antd'; +import cn from 'classnames'; import React from 'react'; import { connect } from 'react-redux'; -import { Button, Divider, Dropdown, Menu, Space, Typography } from 'antd'; -import { CaretDownOutlined, FolderAddOutlined, FolderOutlined } from '@ant-design/icons'; -import { withRouter, RouteComponentProps } from 'react-router-dom'; -import { hasSiteId, siteChangeAvailable } from 'App/routes'; -import { setSiteId } from 'Duck/site'; -import { fetchListActive as fetchMetadata } from 'Duck/customField'; -import { clearSearch } from 'Duck/search'; -import { clearSearch as clearSearchLive } from 'Duck/liveSearch'; -import { useModal } from 'Components/Modal'; -import { init as initProject } from 'Duck/site'; -import NewSiteForm from 'Components/Client/Sites/NewSiteForm'; +import { RouteComponentProps, withRouter } from 'react-router-dom'; + import { withStore } from 'App/mstore'; -import { Icon } from 'UI' -import cn from 'classnames' +import { hasSiteId, siteChangeAvailable } from 'App/routes'; +import NewSiteForm from 'Components/Client/Sites/NewSiteForm'; +import { useModal } from 'Components/Modal'; +import { fetchListActive as fetchMetadata } from 'Duck/customField'; +import { clearSearch as clearSearchLive } from 'Duck/liveSearch'; +import { clearSearch } from 'Duck/search'; +import { setSiteId } from 'Duck/site'; +import { init as initProject } from 'Duck/site'; +import { Icon } from 'UI'; const { Text } = Typography; @@ -39,7 +43,8 @@ function ProjectDropdown(props: Props) { const { sites, siteId, location, account } = props; const isAdmin = account.admin || account.superAdmin; const activeSite = sites.find((s) => s.id === siteId); - const showCurrent = hasSiteId(location.pathname) || siteChangeAvailable(location.pathname); + const showCurrent = + hasSiteId(location.pathname) || siteChangeAvailable(location.pathname); const { showModal, hideModal } = useModal(); const handleSiteChange = (newSiteId: string) => { @@ -56,40 +61,81 @@ function ProjectDropdown(props: Props) { showModal(, { right: true }); }; - const menu = ( - - {isAdmin && ( - <> - } key='all-projects' onClick={addProjectClickHandler}> - Add Project - - - - )} - - {sites.map((site) => ( - } - key={site.id} - onClick={() => handleSiteChange(site.id)} - className={cn('!py-2', activeSite?.host === site.host ? 'bg-active-blue' : '')} + // @ts-ignore immutable + const menuItems = sites.toJS().map((site) => ({ + key: site.id, + label: ( +
handleSiteChange(site.id)} + className={'!py-1 flex items-center gap-2'} + > + + - {site.host} - - ))} -
- ); + {site.host} + + + ), + })); + if (isAdmin) { + menuItems.unshift({ + key: 'add-proj', + label: ( + <> +
+ + Add Project +
+ + + ), + }); + } return ( - + @@ -100,7 +146,7 @@ function ProjectDropdown(props: Props) { const mapStateToProps = (state: any) => ({ sites: state.getIn(['site', 'list']), siteId: state.getIn(['site', 'siteId']), - account: state.getIn(['user', 'account']) + account: state.getIn(['user', 'account']), }); export default withRouter( @@ -109,6 +155,6 @@ export default withRouter( fetchMetadata, clearSearch, clearSearchLive, - initProject + initProject, })(withStore(ProjectDropdown)) );