import React, { useCallback } from 'react'; import kebabCase from 'lodash/kebabCase'; import { cx } from '@leafygreen-ui/emotion'; import { useDarkMode } from '@leafygreen-ui/leafygreen-provider'; import Tooltip from '@leafygreen-ui/tooltip'; import { useMongoNavContext } from '../../MongoNavContext'; import { useOnElementClick } from '../../on-element-click-provider'; import { CurrentProjectInterface, Environment, NavElement, PlanType, Product, ProductName, URLS, } from '../../types'; import { ProjectNavProps } from '../ProjectNav.types'; import { AtlasBlob, ChartsBlob, CloudManagerBlob, RealmBlob, } from './ProductBlobs'; import { blobClassName, blobStyle, productTabBaseStyle, productTabsWrapperStyle, productTabThemeStyle, tabActiveBaseStyle, tabActiveThemeStyle, tabContentClassName, tabDisabledFocusThemeStyle, tabDisabledThemeStyle, tabFocusBaseStyle, tabFocusThemeStyle, tabNameStyle, } from './styles'; const { ProjectNavCloud, ProjectNavRealm, ProjectNavCharts } = NavElement; const BlobMap: Record> = { 'Cloud Manager': CloudManagerBlob, 'App Services': RealmBlob, 'Data Services': AtlasBlob, Realm: RealmBlob, Charts: ChartsBlob, }; interface ProductTabProps { id: Product; name: ProductName; href: string; NavElement: NavElement; current?: CurrentProjectInterface; activeProduct?: Product; } function ProductTab({ id, name, href: hrefProp, current, NavElement, activeProduct, }: ProductTabProps) { const { theme } = useDarkMode(); const onElementClick = useOnElementClick(); const Blob = BlobMap[name]; const productKebab = kebabCase(name); const useCNRegionsOnly = current?.useCNRegionsOnly === true && current?.planType === PlanType.Atlas; const isCNRegionsOnly = useCallback( (product: Product) => { const disabledProducts: Array = [Product.Realm, Product.Charts]; return useCNRegionsOnly && disabledProducts.includes(product); }, [useCNRegionsOnly], ); const disabled = isCNRegionsOnly(id) || !current; const href = id === 'cloud' || !disabled ? hrefProp : undefined; const Tab = ( {name} ); return ( This product is not available for AWS China regions-only projects ); } interface ProductTabsProps { environment?: ProjectNavProps['environment']; hosts: ProjectNavProps['hosts']; urls: URLS['projectNav']; } export const ProductTabs = ({ environment, hosts, urls }: ProductTabsProps) => { const { useAppServicesBranding, activeProduct, currentProject } = useMongoNavContext(); const isCloudManager = currentProject?.planType === PlanType.Cloud; const isGovernment = environment === Environment.Government; const cloudHref = currentProject ? `${hosts.cloud}/v2/${currentProject?.projectId}#` : hosts.cloud; return (
{!isGovernment && !isCloudManager && ( <> )}
); };