|
| 1 | +import * as React from 'react'; |
| 2 | +import { useIntl } from 'react-intl'; |
| 3 | +import noop from 'lodash/noop'; |
| 4 | +import { BoxAiLogo } from '@box/blueprint-web-assets/icons/Logo'; |
| 5 | +import { Size6 } from '@box/blueprint-web-assets/tokens/tokens'; |
| 6 | +import AdditionalTabs from './additional-tabs'; |
| 7 | +import DocGenIcon from '../../icon/fill/DocGenIcon'; |
| 8 | +import IconChatRound from '../../icons/general/IconChatRound'; |
| 9 | +import IconDocInfo from '../../icons/general/IconDocInfo'; |
| 10 | +import IconMagicWand from '../../icons/general/IconMagicWand'; |
| 11 | +import IconMetadataThick from '../../icons/general/IconMetadataThick'; |
| 12 | +import SidebarNavButton from './SidebarNavButton'; |
| 13 | +import SidebarNavSign from './SidebarNavSign'; |
| 14 | +import SidebarNavTablist from './SidebarNavTablist'; |
| 15 | +import SidebarToggle from './SidebarToggle'; |
| 16 | +import messages from '../common/messages'; |
| 17 | +import { SIDEBAR_NAV_TARGETS } from '../common/interactionTargets'; |
| 18 | +import { |
| 19 | + SIDEBAR_VIEW_ACTIVITY, |
| 20 | + SIDEBAR_VIEW_BOXAI, |
| 21 | + SIDEBAR_VIEW_DETAILS, |
| 22 | + SIDEBAR_VIEW_DOCGEN, |
| 23 | + SIDEBAR_VIEW_METADATA, |
| 24 | + SIDEBAR_VIEW_SKILLS, |
| 25 | +} from '../../constants'; |
| 26 | +import { useFeatureConfig } from '../common/feature-checking'; |
| 27 | +import type { NavigateOptions, AdditionalSidebarTab } from './flowTypes'; |
| 28 | +import './SidebarNav.scss'; |
| 29 | + |
| 30 | +interface Props { |
| 31 | + additionalTabs?: AdditionalSidebarTab[]; |
| 32 | + elementId: string; |
| 33 | + fileId: string; |
| 34 | + hasActivity: boolean; |
| 35 | + hasAdditionalTabs: boolean; |
| 36 | + hasBoxAI: boolean; |
| 37 | + hasDetails: boolean; |
| 38 | + hasDocGen?: boolean; |
| 39 | + hasMetadata: boolean; |
| 40 | + hasSkills: boolean; |
| 41 | + isOpen?: boolean; |
| 42 | + onNavigate?: (event: React.SyntheticEvent<HTMLElement>, options: NavigateOptions) => void; |
| 43 | + onPanelChange?: (name: string, isInitialState: boolean) => void; |
| 44 | +} |
| 45 | + |
| 46 | +const SidebarNav = ({ |
| 47 | + additionalTabs, |
| 48 | + elementId, |
| 49 | + fileId, |
| 50 | + hasActivity, |
| 51 | + hasAdditionalTabs, |
| 52 | + hasBoxAI, |
| 53 | + hasDetails, |
| 54 | + hasMetadata, |
| 55 | + hasSkills, |
| 56 | + hasDocGen = false, |
| 57 | + isOpen, |
| 58 | + onNavigate, |
| 59 | + onPanelChange = noop, |
| 60 | +}: Props): React.ReactElement => { |
| 61 | + const { formatMessage } = useIntl(); |
| 62 | + const { enabled: hasBoxSign } = useFeatureConfig('boxSign'); |
| 63 | + const { disabledTooltip: boxAIDisabledTooltip, showOnlyNavButton: showOnlyBoxAINavButton } = |
| 64 | + useFeatureConfig('boxai.sidebar'); |
| 65 | + |
| 66 | + const handleSidebarNavButtonClick = (sidebarview: string): void => { |
| 67 | + onPanelChange(sidebarview, false); |
| 68 | + }; |
| 69 | + |
| 70 | + return ( |
| 71 | + <nav className="bcs-SidebarNav" aria-label={formatMessage(messages.sidebarNavLabel)} data-testid="sidebar-nav"> |
| 72 | + <div className="bcs-SidebarNav-tabs" data-testid="sidebar-nav-tabs"> |
| 73 | + <SidebarNavTablist elementId={elementId} isOpen={isOpen} onNavigate={onNavigate}> |
| 74 | + {hasBoxAI && ( |
| 75 | + <SidebarNavButton |
| 76 | + data-resin-target={SIDEBAR_NAV_TARGETS.BOXAI} |
| 77 | + data-target-id="SidebarNavButton-boxAI" |
| 78 | + data-testid="sidebarboxai" |
| 79 | + isDisabled={showOnlyBoxAINavButton} |
| 80 | + onClick={handleSidebarNavButtonClick} |
| 81 | + sidebarView={SIDEBAR_VIEW_BOXAI} |
| 82 | + tooltip={ |
| 83 | + showOnlyBoxAINavButton |
| 84 | + ? boxAIDisabledTooltip |
| 85 | + : formatMessage(messages.sidebarBoxAITitle) |
| 86 | + } |
| 87 | + > |
| 88 | + <BoxAiLogo height={Size6} width={Size6} /> |
| 89 | + </SidebarNavButton> |
| 90 | + )} |
| 91 | + {hasActivity && ( |
| 92 | + <SidebarNavButton |
| 93 | + data-resin-target={SIDEBAR_NAV_TARGETS.ACTIVITY} |
| 94 | + data-target-id="SidebarNavButton-activity" |
| 95 | + data-testid="sidebaractivity" |
| 96 | + onClick={handleSidebarNavButtonClick} |
| 97 | + sidebarView={SIDEBAR_VIEW_ACTIVITY} |
| 98 | + tooltip={formatMessage(messages.sidebarActivityTitle)} |
| 99 | + > |
| 100 | + <IconChatRound className="bcs-SidebarNav-icon" /> |
| 101 | + </SidebarNavButton> |
| 102 | + )} |
| 103 | + {hasDetails && ( |
| 104 | + <SidebarNavButton |
| 105 | + data-resin-target={SIDEBAR_NAV_TARGETS.DETAILS} |
| 106 | + data-target-id="SidebarNavButton-details" |
| 107 | + data-testid="sidebardetails" |
| 108 | + onClick={handleSidebarNavButtonClick} |
| 109 | + sidebarView={SIDEBAR_VIEW_DETAILS} |
| 110 | + tooltip={formatMessage(messages.sidebarDetailsTitle)} |
| 111 | + > |
| 112 | + <IconDocInfo className="bcs-SidebarNav-icon" /> |
| 113 | + </SidebarNavButton> |
| 114 | + )} |
| 115 | + {hasSkills && ( |
| 116 | + <SidebarNavButton |
| 117 | + data-resin-target={SIDEBAR_NAV_TARGETS.SKILLS} |
| 118 | + data-target-id="SidebarNavButton-skills" |
| 119 | + data-testid="sidebarskills" |
| 120 | + onClick={handleSidebarNavButtonClick} |
| 121 | + sidebarView={SIDEBAR_VIEW_SKILLS} |
| 122 | + tooltip={formatMessage(messages.sidebarSkillsTitle)} |
| 123 | + > |
| 124 | + <IconMagicWand className="bcs-SidebarNav-icon" /> |
| 125 | + </SidebarNavButton> |
| 126 | + )} |
| 127 | + {hasMetadata && ( |
| 128 | + <SidebarNavButton |
| 129 | + data-resin-target={SIDEBAR_NAV_TARGETS.METADATA} |
| 130 | + data-target-id="SidebarNavButton-metadata" |
| 131 | + data-testid="sidebarmetadata" |
| 132 | + onClick={handleSidebarNavButtonClick} |
| 133 | + sidebarView={SIDEBAR_VIEW_METADATA} |
| 134 | + tooltip={formatMessage(messages.sidebarMetadataTitle)} |
| 135 | + > |
| 136 | + <IconMetadataThick className="bcs-SidebarNav-icon" /> |
| 137 | + </SidebarNavButton> |
| 138 | + )} |
| 139 | + {hasDocGen && ( |
| 140 | + <SidebarNavButton |
| 141 | + data-resin-target={SIDEBAR_NAV_TARGETS.DOCGEN} |
| 142 | + data-target-id="SidebarNavButton-docGen" |
| 143 | + onClick={handleSidebarNavButtonClick} |
| 144 | + sidebarView={SIDEBAR_VIEW_DOCGEN} |
| 145 | + tooltip={formatMessage(messages.sidebarDocGenTooltip)} |
| 146 | + > |
| 147 | + <DocGenIcon className="bcs-SidebarNav-icon" /> |
| 148 | + </SidebarNavButton> |
| 149 | + )} |
| 150 | + </SidebarNavTablist> |
| 151 | + |
| 152 | + {hasBoxSign && ( |
| 153 | + <div className="bcs-SidebarNav-secondary"> |
| 154 | + <SidebarNavSign /> |
| 155 | + </div> |
| 156 | + )} |
| 157 | + |
| 158 | + {hasAdditionalTabs && ( |
| 159 | + <div className="bcs-SidebarNav-overflow"> |
| 160 | + <AdditionalTabs key={fileId} tabs={additionalTabs} /> |
| 161 | + </div> |
| 162 | + )} |
| 163 | + </div> |
| 164 | + <div className="bcs-SidebarNav-footer"> |
| 165 | + <SidebarToggle isOpen={isOpen} /> |
| 166 | + </div> |
| 167 | + </nav> |
| 168 | + ); |
| 169 | +}; |
| 170 | + |
| 171 | +export default SidebarNav; |
0 commit comments