@boomerang-io/carbon-addons-boomerang-react
Version:
Carbon Addons for Boomerang apps
114 lines (111 loc) • 10.8 kB
JavaScript
import React from 'react';
import { QueryClientProvider } from '@tanstack/react-query';
import { Email, Document, HelpDesk, CatalogPublish, Policy, Forum, ChatLaunch, Cognitive, Book } 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 { SignOutMenuItem } from '../SignOut/SignOut.js';
import { queryClient } from '../../config/servicesConfig.js';
import { USER_PLATFORM_ROLE } from '../../constants/UserType.js';
/*
IBM Confidential
694970X, 69497O0
© Copyright IBM Corp. 2022, 2024
*/
function UIShell({ analyticsHelpers, baseEnvUrl, carbonTheme = "g10", config, createJoinTeamTrigger, enableTeamSwitcher = true, history, isLaunchpad = false, isLoadingTeamSwitcher, isSuccessTeamSwitcher, setIsSuccessTeamSwitcher, leftPanel, platformName, productName, profileMenuItems = [], supportMenuItems = [], renderPrivacyRedirect = true, renderPrivacyStatement = true, rightPanel, handleShowTutorial, refetchUser, refetchUserTeams, refetchNavigation, skipToContentProps, templateMeteringEvent, trackEvent, triggerEvent, tutorialScreenToShow, user, userTeams, userTeamsAssets, enableIcaMacs, }) {
// Support base header .e.g for an error state
if (!config) {
return (React.createElement(QueryClientProvider, { client: queryClient },
React.createElement(Header, { baseEnvUrl: baseEnvUrl ?? "", baseServicesUrl: "", carbonTheme: carbonTheme, enableAppSwitcher: false, enableNotifications: false, enableNotificationsCount: false, enableTeamSwitcher: enableTeamSwitcher, productName: productName || platformName || "", user: user })));
}
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 sendBluePointsAwardUrl = platform?.sendBluePointsAwardUrl;
const partnerEmailId = "ica-support@ibm.com";
/**
* Check feature enablement via explicit feature flags
*/
const isAppSwitcherEnabled = Boolean(features?.["appSwitcher.enabled"]);
const instanceSwitcherEnabled = Boolean(platform?.["instanceSwitcherEnabled"]);
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);
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, { analyticsHelpers: analyticsHelpers, baseEnvUrl: platform.baseEnvUrl, baseServicesUrl: platform.baseServicesUrl, carbonTheme: carbonTheme, createJoinTeamTrigger: createJoinTeamTrigger, enableAppSwitcher: isAppSwitcherEnabled, instanceSwitcherEnabled: instanceSwitcherEnabled, enableNotifications: isNotificationsEnabled, enableNotificationsCount: isNotificationsCountEnabled, enableTeamSwitcher: enableTeamSwitcher, leftPanel: leftPanel, navLinks: navigation, platform: platform, 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, refetchUser: refetchUser, refetchUserTeams: refetchUserTeams, refetchNavigation: refetchNavigation })),
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: [
!isPartnerUser && (React.createElement(HeaderMenuItem, { key: "docs", href: platform?.docs?.url, icon: React.createElement(Document, null), "data-testid": "docs", kind: "external", text: "Docs", type: "link" })),
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" }))),
React.createElement(HeaderMenuItem, { key: "release-notes", href: platform?.releaseNotesUrl, icon: React.createElement(CatalogPublish, null), "data-testid": "release-notes", kind: "app", text: "Release Notes", type: "link" }),
React.createElement(HeaderMenuItem, { key: "legal-terms", href: platform?.legalTermsUrl, icon: React.createElement(Policy, null), "data-testid": "legal-terms", kind: "app", text: "Legal Terms", type: "link" }),
React.createElement("span", { style: { borderBottom: "1px solid #b8c1c1" } }),
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, sendBluePointsAwardUrl: sendBluePointsAwardUrl })),
!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,
!isPartnerUser && enableIcaMacs && (React.createElement(HeaderMenuItem, { key: "launch-ideation-agent", href: `${platform.baseEnvUrl}/launchpad/macs`, icon: React.createElement(Cognitive, null), "data-testid": "launch-ideation-agent", kind: "app", text: "AI Proposal Feedback Tool", type: "link" })),
isAboutPlatformEnabled && (React.createElement(AboutPlatformMenuItem, { key: "about-platform", name: platform.name, baseServicesUrl: platform.baseServicesUrl })),
tutorialScreenToShow && handleShowTutorial && (React.createElement(HeaderMenuItem, { key: "launch-tutorial", onClick: handleShowTutorial, icon: React.createElement(Book, null), "data-testid": "launch-tutorial", text: "Launch Tutorial", type: "button" })),
...supportMenuItems,
].filter(Boolean), history: history, isLaunchpad: isLaunchpad, isLoadingTeamSwitcher: isLoadingTeamSwitcher, isSuccessTeamSwitcher: isSuccessTeamSwitcher, refetchUser: refetchUser, refetchNavigation: refetchNavigation, setIsSuccessTeamSwitcher: setIsSuccessTeamSwitcher, trackEvent: trackEvent, user: user, userTeams: userTeams, userTeamsAssets: userTeamsAssets }),
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 };