From b2e6c16565cfc592865b1f2c301a0f17ab147bdd Mon Sep 17 00:00:00 2001 From: Michelle Bergquist <11967646+michellescripts@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:36:51 -0600 Subject: [PATCH] conditionally show assist popover (#32267) --- web/packages/teleport/src/Main/Main.tsx | 5 +- .../teleport/src/TopBar/TopBar.test.tsx | 112 ++++++++++++++++++ web/packages/teleport/src/TopBar/TopBar.tsx | 14 ++- web/packages/teleport/src/teleportContext.tsx | 58 ++++----- 4 files changed, 155 insertions(+), 34 deletions(-) create mode 100644 web/packages/teleport/src/TopBar/TopBar.test.tsx diff --git a/web/packages/teleport/src/Main/Main.tsx b/web/packages/teleport/src/Main/Main.tsx index 2bf94804c0ea..1b6b1f69ea8a 100644 --- a/web/packages/teleport/src/Main/Main.tsx +++ b/web/packages/teleport/src/Main/Main.tsx @@ -161,6 +161,7 @@ export function Main(props: MainProps) { const onboard = localStorage.getOnboardDiscover(); const requiresOnboarding = onboard && !onboard.hasResource && !onboard.notified; + const displayOnboardDiscover = requiresOnboarding && showOnboardDiscover; return ( @@ -175,14 +176,14 @@ export function Main(props: MainProps) { - + - {requiresOnboarding && showOnboardDiscover && ( + {displayOnboardDiscover && ( )} {showOnboardSurvey && ( diff --git a/web/packages/teleport/src/TopBar/TopBar.test.tsx b/web/packages/teleport/src/TopBar/TopBar.test.tsx new file mode 100644 index 000000000000..41a145f506ff --- /dev/null +++ b/web/packages/teleport/src/TopBar/TopBar.test.tsx @@ -0,0 +1,112 @@ +/** + * Copyright 2023 Gravitational, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render, screen } from 'design/utils/testing'; + +import { Router } from 'react-router'; +import { createMemoryHistory } from 'history'; + +import { LayoutContextProvider } from 'teleport/Main/LayoutContext'; +import TeleportContextProvider from 'teleport/TeleportContextProvider'; +import { FeaturesContextProvider } from 'teleport/FeaturesContext'; +import { getOSSFeatures } from 'teleport/features'; +import TeleportContext, { + disabledFeatureFlags, +} from 'teleport/teleportContext'; + +import { makeUserContext } from 'teleport/services/user'; + +import { mockUserContextProviderWith } from 'teleport/User/testHelpers/mockUserContextWith'; +import { makeTestUserContext } from 'teleport/User/testHelpers/makeTestUserContext'; + +import { clusters } from 'teleport/Clusters/fixtures'; + +import { TopBar } from './TopBar'; + +let ctx; + +function setup(): void { + ctx = new TeleportContext(); + jest + .spyOn(ctx, 'getFeatureFlags') + .mockReturnValue({ ...disabledFeatureFlags, assist: true }); + ctx.clusterService.fetchClusters = () => Promise.resolve(clusters); + + ctx.assistEnabled = true; + ctx.storeUser.state = makeUserContext({ + userName: 'admin', + cluster: { + name: 'test-cluster', + lastConnected: Date.now(), + }, + }); + mockUserContextProviderWith(makeTestUserContext()); +} + +test('does not show assist popup if hidePopup is true', () => { + setup(); + + render( + + + + + + + + + + ); + + expect(screen.queryByTestId('assistPopup')).not.toBeInTheDocument(); +}); + +test('shows assist popup if hidePopup is absent', () => { + setup(); + + render( + + + + + + + + + + ); + + expect(screen.getByTestId('assistPopup')).toBeInTheDocument(); +}); + +test('shows assist popup if hidePopup is false', () => { + setup(); + + render( + + + + + + + + + + ); + + expect(screen.getByTestId('assistPopup')).toBeInTheDocument(); +}); diff --git a/web/packages/teleport/src/TopBar/TopBar.tsx b/web/packages/teleport/src/TopBar/TopBar.tsx index 27512c5b971c..edd0d3a9288b 100644 --- a/web/packages/teleport/src/TopBar/TopBar.tsx +++ b/web/packages/teleport/src/TopBar/TopBar.tsx @@ -79,7 +79,14 @@ const Background = styled.div` background: rgba(0, 0, 0, 0.6); `; -export function TopBar() { +type TopBarProps = { + // hidePopup indicates if the popup should be hidden based on parent component states. + // if true, another modal is present; and we do not want to display the assist popup. + // if false or absent, display as pre normal logical rules. + hidePopup?: boolean; +}; + +export function TopBar({ hidePopup = false }: TopBarProps) { const theme = useTheme(); const ctx = useTeleport(); @@ -185,11 +192,10 @@ export function TopBar() { setShowAssist(true)}> - - {showAssistPopup && ( + {showAssistPopup && !hidePopup && ( <> - + New! {' '} diff --git a/web/packages/teleport/src/teleportContext.tsx b/web/packages/teleport/src/teleportContext.tsx index f46507faf7c5..e7bcf83c836f 100644 --- a/web/packages/teleport/src/teleportContext.tsx +++ b/web/packages/teleport/src/teleportContext.tsx @@ -96,34 +96,7 @@ class TeleportContext implements types.Context { const userContext = this.storeUser; if (!this.storeUser.state) { - return { - activeSessions: false, - applications: false, - audit: false, - authConnector: false, - billing: false, - databases: false, - desktops: false, - kubernetes: false, - nodes: false, - recordings: false, - roles: false, - trustedClusters: false, - users: false, - newAccessRequest: false, - accessRequests: false, - downloadCenter: false, - discover: false, - plugins: false, - integrations: false, - deviceTrust: false, - enrollIntegrationsOrPlugins: false, - enrollIntegrations: false, - locks: false, - newLocks: false, - assist: false, - managementSection: false, - }; + return disabledFeatureFlags; } // If feature hiding is enabled in the license, this returns true if the user has no list access to any feature within the management section. @@ -195,4 +168,33 @@ class TeleportContext implements types.Context { } } +export const disabledFeatureFlags: types.FeatureFlags = { + activeSessions: false, + applications: false, + audit: false, + authConnector: false, + billing: false, + databases: false, + desktops: false, + kubernetes: false, + nodes: false, + recordings: false, + roles: false, + trustedClusters: false, + users: false, + newAccessRequest: false, + accessRequests: false, + downloadCenter: false, + discover: false, + plugins: false, + integrations: false, + deviceTrust: false, + enrollIntegrationsOrPlugins: false, + enrollIntegrations: false, + locks: false, + newLocks: false, + assist: false, + managementSection: false, +}; + export default TeleportContext;