UNPKG

@boomerang-io/carbon-addons-boomerang-react

Version:
107 lines (104 loc) 8.39 kB
import React from 'react'; import { QueryClientProvider } from 'react-query'; import { Email, HelpDesk, Forum, ChatLaunch } from '@carbon/react/icons'; import Header from '../Header/Header.js'; import HeaderMenuItem from '../Header/HeaderMenuItem.js'; import PrivacyRedirect from '../PrivacyRedirect/PrivacyRedirect.js'; import { AboutPlatformMenuItem } from '../AboutPlatform/AboutPlatform.js'; import { FeedbackMenuItem } from '../Feedback/Feedback.js'; import { SupportCenterMenuItem } from '../SupportCenter/SupportCenter.js'; import { PrivacyStatementMenuItem } from '../PrivacyStatement/PrivacyStatement.js'; import { ProfileSettingsMenuItem } from '../ProfileSettings/ProfileSettings.js'; import { queryClient } from '../../config/servicesConfig.js'; import { SignOutMenuItem } from '../SignOut/SignOut.js'; import { USER_PLATFORM_ROLE } from '../../constants/UserType.js'; /* IBM Confidential 694970X, 69497O0 © Copyright IBM Corp. 2022, 2024 */ function UIShell({ carbonTheme = "g10", config, leftPanel, platformName, productName, profileMenuItems = [], supportMenuItems = [], renderPrivacyRedirect = true, renderPrivacyStatement = true, rightPanel, skipToContentProps, templateMeteringEvent, triggerEvent, user, userTeams, }) { // Support base header .e.g for an error state if (!config) { return (React.createElement(Header, { baseEnvUrl: "", baseServicesUrl: "", carbonTheme: carbonTheme, enableAppSwitcher: false, enableNotifications: false, enableNotificationsCount: false, productName: productName || platformName || "" })); } const { features, navigation, platform, platformMessage } = config; const names = getProductAndPlatformNames({ productName, platformName, platform }); const sendIdeasUrl = platform?.feedbackUrl || "https://ideas.ibm.com"; const supportLink = platform?.supportUrl; const partnerEmailId = "ica-support@ibm.com"; /** * Check feature enablement via explicit feature flags */ const isAppSwitcherEnabled = Boolean(features?.["appSwitcher.enabled"]); const isFeedbackEnabled = Boolean(features?.["feedback.enabled"]); const isNotificationsEnabled = Boolean(features?.["notifications.enabled"]); const isNotificationsCountEnabled = Boolean(features?.["notificationsCount.enabled"]); const isSupportEnabled = Boolean(features?.["support.enabled"]); /** * Check feature enablement via value truthiness */ const isAboutPlatformEnabled = Boolean(platform.name && platform.version); const isCommunityEnabled = Boolean(platform?.communityUrl); const isSendMailEnabled = Boolean(platform.sendMail); const isSignOutEnabled = Boolean(platform?.signOutUrl); const isUserEnabled = Boolean(user?.id); const isPartnerUser = Boolean(user?.type === USER_PLATFORM_ROLE.Partner); const supportFlagCheck = user?.showSupport; const askICAEnabled = Boolean(platform?.askICAEnabled); /** * Checking for conditions when we explicitly set "renderPrivacyRedirect" to false (it defaults to true) OR * it's disabled overall for the platform. This lets us toggle the UIShell consent redirect per app as needed * e.g. disabled in Launchpad, but have it enabled for rest of the platform AND also support * having it disabled in a "standalone" mode via the consent.enable feature flag, i.e. data driven via the service */ const isPrivacyRedirectDisabled = renderPrivacyRedirect === false || features?.["consent.enabled"] === false; const isPrivacyModalRendered = isPrivacyRedirectDisabled === false && user?.hasConsented === false; /** * Also enable/disable privacy statement via the consent.enabled feature flag */ const isPrivacyStatementDisabled = renderPrivacyStatement === false || features?.["consent.enabled"] === false; return (React.createElement(QueryClientProvider, { client: queryClient }, React.createElement(Header, { baseEnvUrl: platform.baseEnvUrl, baseServicesUrl: platform.baseServicesUrl, carbonTheme: carbonTheme, enableAppSwitcher: isAppSwitcherEnabled, enableNotifications: isNotificationsEnabled, enableNotificationsCount: isNotificationsCountEnabled, leftPanel: leftPanel, navLinks: navigation, platformMessage: platformMessage, prefixName: names.platformName, productName: names.productName, rightPanel: rightPanel, requestSummary: user?.requestSummary, skipToContentProps: skipToContentProps, templateMeteringEvent: templateMeteringEvent, triggerEvent: triggerEvent, profileMenuItems: [ isUserEnabled && (React.createElement(ProfileSettingsMenuItem, { key: "profile-settings", baseServicesUrl: platform.baseServicesUrl, src: `${platform.baseServicesUrl}/users/image/${user?.email}`, userName: user?.displayName ?? user?.name })), isSendMailEnabled && (React.createElement(HeaderMenuItem, { key: "email-preferences", href: `${platform.baseEnvUrl}/launchpad/email-preferences`, icon: React.createElement(Email, null), kind: "internal", text: "Email Preferences", type: "link" })), !isPrivacyStatementDisabled && (React.createElement(PrivacyStatementMenuItem, { key: "privacy-statement", baseServicesUrl: platform.baseServicesUrl, platformEmail: platform?.platformEmail })), ...profileMenuItems, isSignOutEnabled && React.createElement(SignOutMenuItem, { key: "Sign Out", signOutLink: platform.signOutUrl }), ].filter(Boolean), supportMenuItems: [ isSupportEnabled && ((supportFlagCheck || isPartnerUser) ? React.createElement(SupportCenterMenuItem, { key: "support-center", platformName: platform?.platformName, platformOrganization: platform?.platformOrganization, supportLink: supportLink, partnerEmailId: partnerEmailId, enablePartner: isPartnerUser, baseServicesUrl: platform.baseServicesUrl }) : React.createElement(HeaderMenuItem, { key: "support-center", href: platform?.supportUrl, icon: React.createElement(HelpDesk, null), kind: "external", text: "Support Center", type: "link" })), isCommunityEnabled && (React.createElement(HeaderMenuItem, { key: "community", href: platform?.communityUrl, icon: React.createElement(Forum, null), kind: "external", text: "Community", type: "link" })), isFeedbackEnabled && (React.createElement(FeedbackMenuItem, { key: "feedback", platformName: platform?.platformName, platformOrganization: platform?.platformOrganization, sendIdeasUrl: sendIdeasUrl })), ((!isPartnerUser && askICAEnabled) ? (React.createElement(HeaderMenuItem, { key: "chat-launch", href: platform?.askICAUrl, icon: React.createElement(ChatLaunch, null), "data-testid": "askICA-chatlaunch", kind: "external", text: "AskICA", type: "link" })) : null), isAboutPlatformEnabled && (React.createElement(AboutPlatformMenuItem, { key: "about-platform", name: platform.name, version: platform.version, assistantVersion: platform.assistantVersion, agentsVersion: platform.agentsVersion, scribeFlowVersion: platform.scribeFlowVersion })), ...supportMenuItems, ].filter(Boolean), userTeams: userTeams }), isPrivacyModalRendered ? (React.createElement(PrivacyRedirect, { isOpen: true, baseEnvUrl: platform.baseEnvUrl, platformName: platform?.name, user: user })) : null)); } /** * Determine how to render the name and prefix in the Header based * on what is passed in. If we only have the plaform or product name, then * we want it to be bolded. If we have both, then make the platform the prefix */ function getProductAndPlatformNames(args) { const { productName, platformName, platform } = args; const resolvedPlatformName = platform.platformName ?? platformName; let finalProductName = ""; let finalPlatformName = ""; if (productName && resolvedPlatformName) { finalProductName = productName; finalPlatformName = resolvedPlatformName; } else if (productName && !resolvedPlatformName) { finalProductName = productName; } else if (!productName && resolvedPlatformName) { finalProductName = resolvedPlatformName; } else ; return { productName: finalProductName, platformName: finalPlatformName }; } export { UIShell as default };