Skip to content

Commit

Permalink
ref(onboarding-docs): Convert java-spring-boot to new docs structure (#…
Browse files Browse the repository at this point in the history
…57771)

* Add types and forking logic for new structure
* Add test helpers for testing docs that follow the new structure
* Convert `java-spring-boot`
* Allow `React.ReactNode[]` for text content to enable using `tct()`
without wrapping it with a tag.

Closes #57447
  • Loading branch information
ArthurKnaus committed Oct 11, 2023
1 parent 004e94a commit 6c8c3c2
Show file tree
Hide file tree
Showing 22 changed files with 753 additions and 415 deletions.
32 changes: 17 additions & 15 deletions static/app/components/onboarding/gettingStartedDoc/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import List from 'sentry/components/list';
import ListItem from 'sentry/components/list/listItem';
import {AuthTokenGeneratorProvider} from 'sentry/components/onboarding/gettingStartedDoc/authTokenGenerator';
import {Step, StepProps} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {NextStep} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {PlatformOptionsControl} from 'sentry/components/onboarding/platformOptionsControl';
import {ProductSelection} from 'sentry/components/onboarding/productSelection';
import {t} from 'sentry/locale';
Expand All @@ -19,12 +20,6 @@ const ProductSelectionAvailabilityHook = HookOrDefault({
defaultComponent: ProductSelection,
});

type NextStep = {
description: string;
link: string;
name: string;
};

export type LayoutProps = {
projectSlug: string;
steps: StepProps[];
Expand Down Expand Up @@ -52,14 +47,16 @@ export function Layout({
return (
<AuthTokenGeneratorProvider projectSlug={projectSlug}>
<Wrapper>
{introduction && <Introduction>{introduction}</Introduction>}
<ProductSelectionAvailabilityHook
organization={organization}
platform={platformKey}
/>
{platformOptions ? (
<PlatformOptionsControl platformOptions={platformOptions} />
) : null}
<Header>
{introduction && <Introduction>{introduction}</Introduction>}
<ProductSelectionAvailabilityHook
organization={organization}
platform={platformKey}
/>
{platformOptions ? (
<PlatformOptionsControl platformOptions={platformOptions} />
) : null}
</Header>
<Divider withBottomMargin={newOrg} />
<Steps>
{steps.map(step => (
Expand All @@ -86,6 +83,12 @@ export function Layout({
);
}

const Header = styled('div')`
display: flex;
flex-direction: column;
gap: ${space(2)};
`;

const Divider = styled('hr')<{withBottomMargin?: boolean}>`
height: 1px;
width: 100%;
Expand All @@ -104,7 +107,6 @@ const Introduction = styled('div')`
display: flex;
flex-direction: column;
gap: ${space(1)};
padding-bottom: ${space(2)};
`;

const Wrapper = styled('div')`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import {Fragment, useMemo} from 'react';
import styled from '@emotion/styled';

import HookOrDefault from 'sentry/components/hookOrDefault';
import ExternalLink from 'sentry/components/links/externalLink';
import List from 'sentry/components/list';
import ListItem from 'sentry/components/list/listItem';
import {AuthTokenGeneratorProvider} from 'sentry/components/onboarding/gettingStartedDoc/authTokenGenerator';
import {Step} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {Docs, DocsParams} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {useSourcePackageRegistries} from 'sentry/components/onboarding/gettingStartedDoc/useSourcePackageRegistries';
import {
PlatformOptionsControl,
useUrlPlatformOptions,
} from 'sentry/components/onboarding/platformOptionsControl';
import {
ProductSelection,
ProductSolution,
} from 'sentry/components/onboarding/productSelection';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {PlatformKey, Project} from 'sentry/types';
import useOrganization from 'sentry/utils/useOrganization';

const ProductSelectionAvailabilityHook = HookOrDefault({
hookName: 'component:product-selection-availability',
defaultComponent: ProductSelection,
});

export type OnboardingLayoutProps = {
docsConfig: Docs<any>;
dsn: string;
platformKey: PlatformKey;
projectId: Project['id'];
projectSlug: Project['slug'];
activeProductSelection?: ProductSolution[];
newOrg?: boolean;
};

const EMPTY_ARRAY: never[] = [];

export function OnboardingLayout({
docsConfig,
dsn,
platformKey,
projectId,
projectSlug,
activeProductSelection = EMPTY_ARRAY,
newOrg,
}: OnboardingLayoutProps) {
const organization = useOrganization();
const {isLoading: isLoadingRegistry, data: registryData} =
useSourcePackageRegistries(organization);
const selectedOptions = useUrlPlatformOptions(docsConfig.platformOptions);

const {platformOptions} = docsConfig;

const {introduction, steps, nextSteps} = useMemo(() => {
const {onboarding} = docsConfig;

const docParams: DocsParams<any> = {
dsn,
organization,
platformKey,
projectId,
projectSlug,
isPerformanceSelected: activeProductSelection.includes(
ProductSolution.PERFORMANCE_MONITORING
),
isProfilingSelected: activeProductSelection.includes(ProductSolution.PROFILING),
isReplaySelected: activeProductSelection.includes(ProductSolution.SESSION_REPLAY),
sourcePackageRegistries: {
isLoading: isLoadingRegistry,
data: registryData,
},
platformOptions: selectedOptions,
newOrg,
};

return {
introduction: onboarding.introduction?.(docParams),
steps: [
...onboarding.install(docParams),
...onboarding.configure(docParams),
...onboarding.verify(docParams),
],
nextSteps: onboarding.nextSteps?.(docParams) || [],
};
}, [
activeProductSelection,
docsConfig,
dsn,
isLoadingRegistry,
newOrg,
organization,
platformKey,
projectId,
projectSlug,
registryData,
selectedOptions,
]);

return (
<AuthTokenGeneratorProvider projectSlug={projectSlug}>
<Wrapper>
<Header>
{introduction && <div>{introduction}</div>}
<ProductSelectionAvailabilityHook
organization={organization}
platform={platformKey}
/>
{platformOptions ? (
<PlatformOptionsControl platformOptions={platformOptions} />
) : null}
</Header>
<Divider withBottomMargin />
<Steps>
{steps.map(step => (
<Step key={step.title ?? step.type} {...step} />
))}
</Steps>
{nextSteps.length > 0 && (
<Fragment>
<Divider />
<h4>{t('Next Steps')}</h4>
<List symbol="bullet">
{nextSteps.map(step => (
<ListItem key={step.name}>
<ExternalLink href={step.link}>{step.name}</ExternalLink>
{': '}
{step.description}
</ListItem>
))}
</List>
</Fragment>
)}
</Wrapper>
</AuthTokenGeneratorProvider>
);
}

const Header = styled('div')`
display: flex;
flex-direction: column;
gap: ${space(2)};
`;

const Divider = styled('hr')<{withBottomMargin?: boolean}>`
height: 1px;
width: 100%;
background: ${p => p.theme.border};
border: none;
${p => p.withBottomMargin && `margin-bottom: ${space(3)}`}
`;

const Steps = styled('div')`
display: flex;
flex-direction: column;
gap: 1.5rem;
`;

const Wrapper = styled('div')`
h4 {
margin-bottom: 0.5em;
}
&& {
p {
margin-bottom: 0;
}
h5 {
margin-bottom: 0;
}
}
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {useEffect, useState} from 'react';

import LoadingIndicator from 'sentry/components/loadingIndicator';
import {OnboardingLayout} from 'sentry/components/onboarding/gettingStartedDoc/onboardingLayout';
import {Docs} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {useSourcePackageRegistries} from 'sentry/components/onboarding/gettingStartedDoc/useSourcePackageRegistries';
import {ProductSolution} from 'sentry/components/onboarding/productSelection';
import type {
Expand All @@ -15,10 +17,10 @@ import {useApiQuery} from 'sentry/utils/queryClient';
type SdkDocumentationProps = {
activeProductSelection: ProductSolution[];
organization: Organization;
platform: PlatformIntegration | null;
platform: PlatformIntegration;
projectId: Project['id'];
projectSlug: Project['slug'];
newOrg?: boolean;
projectId?: Project['id'];
};

export type ModuleProps = {
Expand All @@ -32,6 +34,11 @@ export type ModuleProps = {
sourcePackageRegistries?: ReturnType<typeof useSourcePackageRegistries>;
};

function isFunctionalComponent(obj: any): obj is React.ComponentType<ModuleProps> {
// As we only use function components in the docs this should suffice
return typeof obj === 'function';
}

// Loads the component containing the documentation for the specified platform
export function SdkDocumentation({
platform,
Expand All @@ -44,7 +51,7 @@ export function SdkDocumentation({
const sourcePackageRegistries = useSourcePackageRegistries(organization);

const [module, setModule] = useState<null | {
default: React.ComponentType<ModuleProps>;
default: Docs<any> | React.ComponentType<ModuleProps>;
}>(null);

// TODO: This will be removed once we no longer rely on sentry-docs to load platform icons
Expand Down Expand Up @@ -89,7 +96,7 @@ export function SdkDocumentation({
if (projectKeysIsError || projectKeysIsLoading) {
return;
}

setModule(null);
async function getGettingStartedDoc() {
const mod = await import(
/* webpackExclude: /.spec/ */
Expand All @@ -104,18 +111,33 @@ export function SdkDocumentation({
return <LoadingIndicator />;
}

const {default: GettingStartedDoc} = module;
const {default: docs} = module;

if (isFunctionalComponent(docs)) {
const GettingStartedDoc = docs;
return (
<GettingStartedDoc
dsn={projectKeys[0].dsn.public}
activeProductSelection={activeProductSelection}
newOrg={newOrg}
platformKey={platform.id}
organization={organization}
projectId={projectId}
projectSlug={projectSlug}
sourcePackageRegistries={sourcePackageRegistries}
/>
);
}

return (
<GettingStartedDoc
<OnboardingLayout
docsConfig={docs}
dsn={projectKeys[0].dsn.public}
activeProductSelection={activeProductSelection}
newOrg={newOrg}
platformKey={platform?.id}
organization={organization}
platformKey={platform.id}
projectId={projectId}
projectSlug={projectSlug}
sourcePackageRegistries={sourcePackageRegistries}
/>
);
}
5 changes: 3 additions & 2 deletions static/app/components/onboarding/gettingStartedDoc/step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type ConfigurationType = {
partialLoading?: boolean;
};

// TODO(aknaus): move to types
interface BaseStepProps {
/**
* Additional information to be displayed below the configurations
Expand All @@ -121,7 +122,7 @@ interface BaseStepProps {
/**
* A brief description of the step
*/
description?: React.ReactNode;
description?: React.ReactNode | React.ReactNode[];
}
interface StepPropsWithTitle extends BaseStepProps {
title: string;
Expand Down Expand Up @@ -227,7 +228,7 @@ const Configurations = styled(Configuration)`
margin-top: ${space(2)};
`;

const Description = styled(Configuration)`
const Description = styled('div')`
code {
color: ${p => p.theme.pink400};
}
Expand Down
Loading

0 comments on commit 6c8c3c2

Please sign in to comment.