-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add links to the minimap (#246)
Co-authored-by: jared-dickman <[email protected]> Co-authored-by: mparticle-automation <[email protected]>
- Loading branch information
1 parent
5319ce4
commit 80bd00c
Showing
13 changed files
with
646 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 55 additions & 31 deletions
86
src/components/navigation/GlobalNavigation/HomeButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,73 @@ | ||
import React from 'react' | ||
import { Center, Icon, Popover, Tooltip } from 'src/components' | ||
import MiniMap from 'src/components/navigation/MiniMap/MiniMap' | ||
import { IMiniMapOptions } from 'src/components/navigation/GlobalNavigation/GlobalNavigationItems' | ||
|
||
interface MpHomeButtonProps { | ||
onClick: () => void | ||
} | ||
|
||
interface MinimapWithPopoverProps { | ||
overviewHref: string | ||
onClick: () => void | ||
interface MinimapWithPopoverProps extends IMiniMapOptions { | ||
onPopoverClick: () => void | ||
} | ||
|
||
interface TooltipWithButtonProps { | ||
onClick: () => void | ||
onTooltipClick: () => void | ||
} | ||
|
||
interface HomeButtonProps { | ||
minimapOptions: { | ||
overviewHref?: string | ||
show?: boolean | ||
} | ||
minimapOptions?: IMiniMapOptions | ||
onMpHomeClick: () => void | ||
} | ||
const MpHomeButton: React.FC<MpHomeButtonProps> = ({ onClick }) => ( | ||
<Center className="globalNavigation__mpHome" onClick={onClick}> | ||
<Icon name="mpLogo" size="lg" color="white" /> | ||
</Center> | ||
) | ||
|
||
const MinimapWithPopover: React.FC<MinimapWithPopoverProps> = ({ overviewHref, onClick }) => ( | ||
<Popover content={() => <MiniMap overviewHref={overviewHref} />} placement="rightBottom" arrow={false}> | ||
<MpHomeButton onClick={onClick} /> | ||
</Popover> | ||
) | ||
|
||
const TooltipWithButton: React.FC<TooltipWithButtonProps> = ({ onClick }) => ( | ||
<Tooltip title="mParticle Overview" placement="right"> | ||
<MpHomeButton onClick={onClick} /> | ||
</Tooltip> | ||
) | ||
|
||
export const HomeButton: React.FC<HomeButtonProps> = props => { | ||
return props.minimapOptions?.show ? ( | ||
<MinimapWithPopover overviewHref={props.minimapOptions?.overviewHref ?? '/'} onClick={props.onMpHomeClick} /> | ||
) : ( | ||
<TooltipWithButton onClick={props.onMpHomeClick} /> | ||
|
||
function MpHomeButton(props: MpHomeButtonProps) { | ||
return ( | ||
<Center className="globalNavigation__mpHome" onClick={props.onClick}> | ||
<Icon name="mpLogo" size="lg" color="white" /> | ||
</Center> | ||
) | ||
} | ||
|
||
function MinimapWithPopover(props: MinimapWithPopoverProps) { | ||
return ( | ||
<Popover | ||
content={() => ( | ||
<MiniMap | ||
overviewHref={props.overviewHref} | ||
onUnAuthorizedClick={props.onUnAuthorizedClick} | ||
links={props.links} | ||
onLinkClick={props.onLinkClick} | ||
unauthorizedLinks={props.unauthorizedLinks} | ||
/> | ||
)} | ||
placement="rightBottom" | ||
arrow={false}> | ||
<MpHomeButton onClick={props.onPopoverClick} /> | ||
</Popover> | ||
) | ||
} | ||
|
||
function TooltipWithButton(props: TooltipWithButtonProps) { | ||
return ( | ||
<Tooltip title="mParticle Overview" placement="right"> | ||
<MpHomeButton onClick={props.onTooltipClick} /> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export function HomeButton(props: HomeButtonProps) { | ||
if (!props.minimapOptions) { | ||
return <TooltipWithButton onTooltipClick={props.onMpHomeClick} /> | ||
} | ||
|
||
return ( | ||
<MinimapWithPopover | ||
onUnAuthorizedClick={props.minimapOptions.onUnAuthorizedClick} | ||
overviewHref={props.minimapOptions.overviewHref} | ||
links={props.minimapOptions.links} | ||
onLinkClick={props.minimapOptions.onLinkClick} | ||
unauthorizedLinks={props.minimapOptions.unauthorizedLinks} | ||
onPopoverClick={props.onMpHomeClick} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { Children, ReactElement } from 'react' | ||
import './miniMap.css' | ||
|
||
export interface ISvgLink { | ||
elementId: string | ||
href: string | ||
variant?: 'regular' | 'black' | 'drop-shadow' | ||
isUnauthorized?: boolean | ||
} | ||
|
||
interface ISvgLinkerProps { | ||
links: ISvgLink[] | ||
children: React.ReactNode | ||
onLinkClick: (link: ISvgLink) => void | ||
} | ||
|
||
export const SvgLinker = (props: ISvgLinkerProps) => { | ||
const handleContainerClick = (e: React.MouseEvent) => { | ||
e.preventDefault() | ||
const target = e.target as HTMLElement | ||
const href = target.closest('a')?.getAttribute('href') | ||
const link = props.links.find(b => b.href === href) | ||
|
||
if (link) props.onLinkClick(link) | ||
} | ||
|
||
return <div onClick={handleContainerClick}>{wrapButtonsIntoLinks(props.children)}</div> | ||
|
||
function wrapButtonsIntoLinks(parent: React.ReactNode): React.ReactNode { | ||
const wrapElement = (element: ReactElement): ReactElement => { | ||
const { id, children } = element.props | ||
const link = props.links.find(b => b.elementId === id) | ||
|
||
if (link) { | ||
const className = `svg-linker-root__button svg-linker-root__button--${link.variant}${ | ||
link.isUnauthorized ? ' svg-linker-root__button--disabled' : '' | ||
}` | ||
|
||
return ( | ||
<a key={id} href={link.href} className={className}> | ||
{element} | ||
</a> | ||
) | ||
} | ||
|
||
const wrappedChildren = wrapButtonsIntoLinks(children) | ||
|
||
return React.createElement(element.type, { ...element.props, children: wrappedChildren }) | ||
} | ||
|
||
return Children.map(parent, child => (React.isValidElement(child) ? wrapElement(child as ReactElement) : child)) | ||
} | ||
} | ||
|
||
export default SvgLinker |
Oops, something went wrong.