Skip to content

Commit

Permalink
Merge branch 'main' into spalmurray/amplitude-context-flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov authored Jan 29, 2025
2 parents 63460ce + 173686a commit c303abd
Show file tree
Hide file tree
Showing 70 changed files with 1,256 additions and 3,973 deletions.
1 change: 0 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const user = {
student: false,
studentCreatedAt: null,
studentUpdatedAt: null,
customerIntent: 'PERSONAL',
},
trackingMetadata: {
service: 'github',
Expand Down
Binary file added src/assets/onboarding/org_list_install_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaultConfig = {
SENTRY_ERROR_SAMPLE_RATE: 1.0,
GH_APP: DEFAULT_GH_APP,
GH_APP_AI: 'codecov-ai',
SUNBURST_ENABLED: true,
}

export function removeReactAppPrefix(obj) {
Expand All @@ -33,6 +34,10 @@ export function removeReactAppPrefix(obj) {
keys['HIDE_ACCESS_TAB'] = keys['HIDE_ACCESS_TAB'].toLowerCase() === 'true'
}

if ('SUNBURST_ENABLED' in keys) {
keys['SUNBURST_ENABLED'] = keys['SUNBURST_ENABLED'].toLowerCase() === 'true'
}

if ('SENTRY_TRACING_SAMPLE_RATE' in keys) {
keys['SENTRY_TRACING_SAMPLE_RATE'] = parseFloat(
keys['SENTRY_TRACING_SAMPLE_RATE']
Expand Down
20 changes: 11 additions & 9 deletions src/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import { removeReactAppPrefix } from 'config'
describe('config', () => {
describe('removeReactAppPrefix', () => {
it('removes REACT_APP prefix', () => {
const obj = {
REACT_APP_TEST_ENV: 'test env',
}
const obj = { REACT_APP_TEST_ENV: 'test env' }

expect(removeReactAppPrefix(obj)).toEqual({ TEST_ENV: 'test env' })
})

describe('sets IS_SELF_HOSTED to boolean', () => {
it('sets to true', () => {
const obj = {
ENV: 'enterprise',
}
const obj = { ENV: 'enterprise' }

expect(removeReactAppPrefix(obj)).toEqual({
ENV: 'enterprise',
Expand All @@ -23,9 +19,7 @@ describe('config', () => {
})

it('sets to false', () => {
const obj = {
ENV: 'production',
}
const obj = { ENV: 'production' }

expect(removeReactAppPrefix(obj)).toEqual({
ENV: 'production',
Expand Down Expand Up @@ -68,6 +62,14 @@ describe('config', () => {
})
})

describe('sets SUNBURST_ENABLED to boolean', () => {
it('sets to true', () => {
const obj = { SUNBURST_ENABLED: 'true' }

expect(removeReactAppPrefix(obj)).toEqual({ SUNBURST_ENABLED: true })
})
})

describe('sets IS_DEDICATED_NAMESPACE to boolean', () => {
it('sets to true', () => {
const obj = {
Expand Down
81 changes: 5 additions & 76 deletions src/layouts/BaseLayout/BaseLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ const mockedUseImpersonate = useImpersonate as Mock
vi.mock('shared/GlobalTopBanners', () => ({
default: () => 'GlobalTopBanners',
}))
vi.mock('./InstallationHelpBanner', () => ({
default: () => 'InstallationHelpBanner',
}))
vi.mock('pages/TermsOfService', () => ({ default: () => 'TermsOfService' }))
vi.mock('pages/DefaultOrgSelector', () => ({
default: () => 'DefaultOrgSelector',
}))
vi.mock('layouts/Header', () => ({ default: () => 'Header' }))
vi.mock('layouts/Footer', () => ({ default: () => 'Footer' }))

Expand All @@ -53,7 +47,6 @@ const mockUser = {
student: false,
studentCreatedAt: null,
studentUpdatedAt: null,
customerIntent: 'BUSINESS',
externalId: 'asdf',
owners: [
{
Expand Down Expand Up @@ -330,9 +323,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand All @@ -352,9 +342,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand Down Expand Up @@ -385,68 +372,19 @@ describe('BaseLayout', () => {
const header = screen.queryByText(/Header/)
expect(header).not.toBeInTheDocument()
})

it('renders help banner', async () => {
setup({
currentUser: userNoTermsAgreement,
internalUser: mockUserNoTermsAgreement,
})

render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })
const helpBanner = await screen.findByText(/InstallationHelpBanner/)
expect(helpBanner).toBeInTheDocument()
})
})

describe('when no default org selected', () => {
it('renders the default org selector', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const defaultOrgSelector = await screen.findByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).toBeInTheDocument()
})

it('does not render the header', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const defaultOrgSelector = await screen.findByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).toBeInTheDocument()

const header = screen.queryByText(/Header/)
expect(header).not.toBeInTheDocument()
})

it('renders help banner', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})

render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })
const helpBanner = await screen.findByText(/InstallationHelpBanner/)
expect(helpBanner).toBeInTheDocument()
})
})

describe('when agreed to TOS and default org selected', () => {
describe('when agreed to TOS', () => {
it('renders children', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const children = await screen.findByText(/hello/)
expect(children).toBeInTheDocument()
})

it('renders header', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const header = await screen.findByText(/Header/)
Expand Down Expand Up @@ -488,9 +426,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand All @@ -510,9 +445,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand Down Expand Up @@ -550,23 +482,20 @@ describe('BaseLayout', () => {

const header = await screen.findByText(/Header/)
expect(header).toBeInTheDocument()

const defaultOrgSelector = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).not.toBeInTheDocument()
})
})

describe('when agreed to TOS and default org selected', () => {
it('renders children', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const children = await screen.findByText(/hello/)
expect(children).toBeInTheDocument()
})

it('renders header', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const header = await screen.findByText(/Header/)
Expand Down
106 changes: 44 additions & 62 deletions src/layouts/BaseLayout/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EmptyErrorComponent } from 'layouts/shared/ErrorBoundary/ErrorBoundary'
import NetworkErrorBoundary from 'layouts/shared/NetworkErrorBoundary'
import SilentNetworkErrorWrapper from 'layouts/shared/SilentNetworkErrorWrapper'
import ToastNotifications from 'layouts/ToastNotifications'
import { OnboardingContainerProvider } from 'pages/OwnerPage/OnboardingContainerContext/context'
import { RepoBreadcrumbProvider } from 'pages/RepoPage/context'
import { useEventContext } from 'services/events/hooks'
import { useImpersonate } from 'services/impersonate'
Expand All @@ -20,8 +21,6 @@ import LoadingLogo from 'ui/LoadingLogo'
import { NavigatorDataQueryOpts } from './hooks/NavigatorDataQueryOpts'
import { useUserAccessGate } from './hooks/useUserAccessGate'

const DefaultOrgSelector = lazy(() => import('pages/DefaultOrgSelector'))
const InstallationHelpBanner = lazy(() => import('./InstallationHelpBanner'))
const TermsOfService = lazy(() => import('pages/TermsOfService'))

const FullPageLoader = () => (
Expand All @@ -31,20 +30,16 @@ const FullPageLoader = () => (
)

interface OnboardingOrChildrenProps extends React.PropsWithChildren {
isImpersonating: boolean
isFullExperience: boolean
showAgreeToTerms: boolean
redirectToSyncPage: boolean
showDefaultOrgSelector: boolean
}

function OnboardingOrChildren({
children,
isImpersonating,
isFullExperience,
showAgreeToTerms,
redirectToSyncPage,
showDefaultOrgSelector,
}: OnboardingOrChildrenProps) {
if (showAgreeToTerms && !isFullExperience) {
return (
Expand All @@ -58,14 +53,6 @@ function OnboardingOrChildren({
return <Redirect to="/sync" />
}

if (showDefaultOrgSelector && !isFullExperience && !isImpersonating) {
return (
<Suspense fallback={null}>
<DefaultOrgSelector />
</Suspense>
)
}

return <>{children}</>
}

Expand All @@ -83,7 +70,6 @@ function BaseLayout({ children }: React.PropsWithChildren) {
const {
isFullExperience,
showAgreeToTerms,
showDefaultOrgSelector,
redirectToSyncPage,
isLoading: isUserAccessGateLoading,
} = useUserAccessGate()
Expand All @@ -109,53 +95,49 @@ function BaseLayout({ children }: React.PropsWithChildren) {

return (
<>
<RepoBreadcrumbProvider>
{/* Header */}
<Suspense>
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
<SilentNetworkErrorWrapper>
{isFullExperience || isImpersonating ? (
<>
<GlobalTopBanners />
<Header hasRepoAccess={data?.hasRepoAccess} />
</>
) : (
<>
{showDefaultOrgSelector ? <InstallationHelpBanner /> : null}
</>
)}
</SilentNetworkErrorWrapper>
</ErrorBoundary>
</Suspense>

{/* Main Page Contents */}
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary sentryScopes={[['layout', 'base']]}>
<NetworkErrorBoundary>
<main className="container mb-8 flex grow flex-col gap-2 md:p-0">
<GlobalBanners />
<OnboardingOrChildren
isFullExperience={isFullExperience}
showAgreeToTerms={showAgreeToTerms}
showDefaultOrgSelector={showDefaultOrgSelector}
redirectToSyncPage={redirectToSyncPage}
isImpersonating={isImpersonating}
>
{children}
</OnboardingOrChildren>
</main>
</NetworkErrorBoundary>
</ErrorBoundary>
</Suspense>

{/* Footer */}
{isFullExperience && (
<>
<Footer />
<ToastNotifications />
</>
)}
</RepoBreadcrumbProvider>
<OnboardingContainerProvider>
<RepoBreadcrumbProvider>
{/* Header */}
<Suspense>
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
<SilentNetworkErrorWrapper>
{isFullExperience || isImpersonating ? (
<>
<GlobalTopBanners />
<Header hasRepoAccess={data?.hasRepoAccess} />
</>
) : null}
</SilentNetworkErrorWrapper>
</ErrorBoundary>
</Suspense>

{/* Main Page Contents */}
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary sentryScopes={[['layout', 'base']]}>
<NetworkErrorBoundary>
<main className="container mb-8 flex grow flex-col gap-2 md:p-0">
<GlobalBanners />
<OnboardingOrChildren
isFullExperience={isFullExperience}
showAgreeToTerms={showAgreeToTerms}
redirectToSyncPage={redirectToSyncPage}
>
{children}
</OnboardingOrChildren>
</main>
</NetworkErrorBoundary>
</ErrorBoundary>
</Suspense>

{/* Footer */}
{isFullExperience ? (
<>
<Footer />
<ToastNotifications />
</>
) : null}
</RepoBreadcrumbProvider>
</OnboardingContainerProvider>
</>
)
}
Expand Down
Loading

0 comments on commit c303abd

Please sign in to comment.