Browse Source

ref(onboarding): Convert platform aspnet to new structure (#58221)

- relates to https://github.com/getsentry/sentry/issues/56549
ArthurKnaus 1 year ago
parent
commit
67bef4696b

+ 6 - 6
static/app/gettingStartedDocs/android/android.tsx

@@ -11,6 +11,7 @@ import {
   OnboardingConfig,
 } from 'sentry/components/onboarding/gettingStartedDoc/types';
 import {t, tct} from 'sentry/locale';
+import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
 
 export enum InstallationMode {
   AUTO = 'auto',
@@ -46,12 +47,11 @@ const isAutoInstall = (params: Params) =>
 const getManualInstallSnippet = (params: Params) => `
 plugins {
   id "com.android.application" // should be in the same module
-  id "io.sentry.android.gradle" version "${
-    params.sourcePackageRegistries?.isLoading
-      ? t('\u2026loading')
-      : params.sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']
-          ?.version ?? '3.12.0'
-  }"
+  id "io.sentry.android.gradle" version "${getPackageVersion(
+    params,
+    'sentry.java.android.gradle-plugin',
+    '3.12.0'
+  )}"
 }`;
 
 const getConfigurationSnippet = (params: Params) => `

+ 24 - 12
static/app/gettingStartedDocs/dotnet/aspnet.spec.tsx

@@ -1,18 +1,30 @@
-import {render, screen} from 'sentry-test/reactTestingLibrary';
+import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
+import {screen} from 'sentry-test/reactTestingLibrary';
+import {textWithMarkupMatcher} from 'sentry-test/utils';
 
-import {StepTitle} from 'sentry/components/onboarding/gettingStartedDoc/step';
+import docs from './aspnet';
 
-import {GettingStartedWithAspnet, steps} from './aspnet';
+describe('aspnet onboarding docs', function () {
+  it('renders gradle docs correctly', async function () {
+    renderWithOnboardingLayout(docs, {
+      releaseRegistry: {
+        'sentry.dotnet.aspnet': {
+          version: '1.99.9',
+        },
+      },
+    });
 
-describe('GettingStartedWithAspnet', function () {
-  it('renders doc correctly', function () {
-    render(<GettingStartedWithAspnet dsn="test-dsn" projectSlug="test-project" />);
+    // Renders main headings
+    expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
+    expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
+    expect(screen.getByRole('heading', {name: 'Documentation'})).toBeInTheDocument();
+    expect(screen.getByRole('heading', {name: 'Samples'})).toBeInTheDocument();
 
-    // Steps
-    for (const step of steps()) {
-      expect(
-        screen.getByRole('heading', {name: step.title ?? StepTitle[step.type]})
-      ).toBeInTheDocument();
-    }
+    // Renders SDK version from registry
+    expect(
+      await screen.findByText(
+        textWithMarkupMatcher(/Install-Package Sentry.AspNet -Version 1\.99\.9/)
+      )
+    ).toBeInTheDocument();
   });
 });

+ 123 - 125
static/app/gettingStartedDocs/dotnet/aspnet.tsx

@@ -5,75 +5,32 @@ import {Alert} from 'sentry/components/alert';
 import ExternalLink from 'sentry/components/links/externalLink';
 import List from 'sentry/components/list';
 import ListItem from 'sentry/components/list/listItem';
-import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
-import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
 import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
+import {
+  Docs,
+  DocsParams,
+  OnboardingConfig,
+} from 'sentry/components/onboarding/gettingStartedDoc/types';
 import {t, tct} from 'sentry/locale';
+import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
 
-// Configuration Start
-export const steps = ({
-  dsn,
-  sourcePackageRegistries,
-}: Partial<
-  Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
-> = {}): LayoutProps['steps'] => [
-  {
-    type: StepType.INSTALL,
-    description: (
-      <p>
-        {tct('Install the [strong:NuGet] package:', {
-          strong: <strong />,
-        })}
-      </p>
-    ),
-    configurations: [
-      {
-        language: 'shell',
-        partialLoading: sourcePackageRegistries?.isLoading,
-        description: t('Package Manager:'),
-        code: `Install-Package Sentry.AspNet -Version ${
-          sourcePackageRegistries?.isLoading
-            ? t('\u2026loading')
-            : sourcePackageRegistries?.data?.['sentry.dotnet.aspnet']?.version ?? '3.34.0'
-        }`,
-      },
-      {
-        language: 'shell',
-        partialLoading: sourcePackageRegistries?.isLoading,
-        description: t('Using Entity Framework 6?'),
-        code: `Install-Package Sentry.EntityFramework -Version ${
-          sourcePackageRegistries?.isLoading
-            ? t('\u2026loading')
-            : sourcePackageRegistries?.data?.['sentry.dotnet.ef']?.version ?? '3.34.0'
-        }`,
-      },
-    ],
-    additionalInfo: (
-      <AlertWithoutMarginBottom type="info">
-        {tct(
-          '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
-          {strong: <strong />}
-        )}
-      </AlertWithoutMarginBottom>
-    ),
-  },
-  {
-    type: StepType.CONFIGURE,
-    description: (
-      <p>
-        {tct(
-          'You should [initCode:init] the Sentry SDK as soon as possible during your application load by adding Sentry to [globalCode:Global.asax.cs]:',
-          {
-            initCode: <code />,
-            globalCode: <code />,
-          }
-        )}
-      </p>
-    ),
-    configurations: [
-      {
-        language: 'csharp',
-        code: `
+type Params = DocsParams;
+
+const getInstallSnippetPackageManager = (params: Params) => `
+Install-Package Sentry.AspNet -Version ${getPackageVersion(
+  params,
+  'sentry.dotnet.aspnet',
+  '3.34.0'
+)}`;
+
+const getInstallSnippetEntityFramework = (params: Params) => `
+Install-Package Sentry.EntityFramework -Version ${getPackageVersion(
+  params,
+  'sentry.dotnet.aspnet',
+  '3.34.0'
+)}`;
+
+const getConfigureSnippet = (params: Params) => `
 using System;
 using System.Configuration;
 using System.Web.Mvc;
@@ -92,7 +49,7 @@ public class MvcApplication : HttpApplication
         _sentry = SentrySdk.Init(o =>
         {
             o.AddAspNet();
-            o.Dsn = "${dsn}";
+            o.Dsn = "${params.dsn}";
             // When configuring for the first time, to see what the SDK is doing:
             o.Debug = true;
             // Set TracesSampleRate to 1.0 to capture 100%
@@ -123,67 +80,108 @@ public class MvcApplication : HttpApplication
         _sentry?.Dispose();
     }
 }
-        `,
-      },
-    ],
-  },
-  {
-    title: t('Documentation'),
-    description: (
-      <p>
-        {tct(
-          "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete ASP.NET docs].",
-          {
-            link: (
-              <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnet/" />
-            ),
-          }
-        )}
-      </p>
-    ),
-  },
-  {
-    title: t('Samples'),
-    description: (
-      <Fragment>
-        {t(
-          'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
-        )}
-        <List symbol="bullet">
-          <ListItem>
-            {tct(
-              '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
-              {
-                link: (
-                  <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
-                ),
-                code: <code />,
+        `;
+
+const onboarding: OnboardingConfig = {
+  install: params => [
+    {
+      type: StepType.INSTALL,
+      description: tct('Install the [strong:NuGet] package:', {
+        strong: <strong />,
+      }),
+      configurations: [
+        {
+          language: 'shell',
+          partialLoading: params.sourcePackageRegistries.isLoading,
+          description: t('Package Manager:'),
+          code: getInstallSnippetPackageManager(params),
+        },
+        {
+          language: 'shell',
+          partialLoading: params.sourcePackageRegistries.isLoading,
+          description: t('Using Entity Framework 6?'),
+          code: getInstallSnippetEntityFramework(params),
+        },
+      ],
+      additionalInfo: (
+        <AlertWithoutMarginBottom type="info">
+          {tct(
+            '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
+            {strong: <strong />}
+          )}
+        </AlertWithoutMarginBottom>
+      ),
+    },
+  ],
+  configure: params => [
+    {
+      type: StepType.CONFIGURE,
+      description: tct(
+        'You should [initCode:init] the Sentry SDK as soon as possible during your application load by adding Sentry to [globalCode:Global.asax.cs]:',
+        {
+          initCode: <code />,
+          globalCode: <code />,
+        }
+      ),
+      configurations: [
+        {
+          language: 'csharp',
+          code: getConfigureSnippet(params),
+        },
+      ],
+    },
+  ],
+  // TODO: Add proper verify step
+  verify: () => [
+    {
+      title: t('Documentation'),
+      description: tct(
+        "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete ASP.NET docs].",
+        {
+          link: (
+            <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnet/" />
+          ),
+        }
+      ),
+    },
+    {
+      title: t('Samples'),
+      description: (
+        <Fragment>
+          {t(
+            'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
+          )}
+          <List symbol="bullet">
+            <ListItem>
+              {tct(
+                '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
+                {
+                  link: (
+                    <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
+                  ),
+                  code: <code />,
+                  strong: <strong />,
+                }
+              )}
+            </ListItem>
+            <ListItem>
+              {tct('[link:Basic F# sample] [strong:(F#)]', {
+                link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
                 strong: <strong />,
-              }
-            )}
-          </ListItem>
-          <ListItem>
-            {tct('[link:Basic F# sample] [strong:(F#)]', {
-              link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
-              strong: <strong />,
-            })}
-          </ListItem>
-        </List>
-      </Fragment>
-    ),
-  },
-];
-// Configuration End
+              })}
+            </ListItem>
+          </List>
+        </Fragment>
+      ),
+    },
+  ],
+};
 
-export function GettingStartedWithAspnet({
-  dsn,
-  sourcePackageRegistries,
-  ...props
-}: ModuleProps) {
-  return <Layout steps={steps({dsn, sourcePackageRegistries})} {...props} />;
-}
+const docs: Docs = {
+  onboarding,
+};
 
-export default GettingStartedWithAspnet;
+export default docs;
 
 const AlertWithoutMarginBottom = styled(Alert)`
   margin-bottom: 0;

+ 3 - 10
static/app/gettingStartedDocs/dotnet/dotnet.tsx

@@ -10,22 +10,15 @@ import {
   OnboardingConfig,
 } from 'sentry/components/onboarding/gettingStartedDoc/types';
 import {t, tct} from 'sentry/locale';
+import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
 
 type Params = DocsParams;
 
 const installSnippetPackageManager = (params: Params) => `
-Install-Package Sentry -Version ${
-  params.sourcePackageRegistries.isLoading
-    ? t('\u2026loading')
-    : params.sourcePackageRegistries.data?.['sentry.dotnet']?.version ?? '3.34.0'
-}`;
+Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
 
 const installSnippetCoreCli = (params: Params) => `
-dotnet add package Sentry -v ${
-  params.sourcePackageRegistries.isLoading
-    ? t('\u2026loading')
-    : params.sourcePackageRegistries.data?.['sentry.dotnet']?.version ?? '3.34.0'
-}`;
+dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
 
 const getConfigureSnippet = (params: Params) => `
 using Sentry;

+ 12 - 18
static/app/gettingStartedDocs/java/spring-boot.tsx

@@ -10,6 +10,7 @@ import {
   OnboardingConfig,
 } from 'sentry/components/onboarding/gettingStartedDoc/types';
 import {t, tct} from 'sentry/locale';
+import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
 
 export enum SpringBootVersion {
   V2 = 'v2',
@@ -61,12 +62,11 @@ buildscript {
 }
 
 plugins {
-  id "io.sentry.jvm.gradle" version "${
-    params.sourcePackageRegistries.isLoading
-      ? t('\u2026loading')
-      : params.sourcePackageRegistries.data?.['sentry.java.android.gradle-plugin']
-          ?.version ?? '3.12.0'
-  }"
+  id "io.sentry.jvm.gradle" version "${getPackageVersion(
+    params,
+    'sentry.java.android.gradle-plugin',
+    '3.12.0'
+  )}"
 }
 
 sentry {
@@ -86,12 +86,11 @@ const getMavenInstallSnippet = (params: Params) =>
 <dependency>
   <groupId>io.sentry</groupId>
   <artifactId>sentry-spring-boot-starter-jakarta</artifactId>
-  <version>${
-    params.sourcePackageRegistries?.isLoading
-      ? t('\u2026loading')
-      : params.sourcePackageRegistries?.data?.['sentry.java.spring-boot.jakarta']
-          ?.version ?? '6.28.0'
-  }</version>
+  <version>${getPackageVersion(
+    params,
+    'sentry.java.spring-boot.jakarta',
+    '6.28.0'
+  )}</version>
 </dependency>`
     : `
 <dependency>
@@ -109,12 +108,7 @@ const getLogbackInstallSnippet = (params: Params) => `
 <dependency>
     <groupId>io.sentry</groupId>
     <artifactId>sentry-logback</artifactId>
-    <version>${
-      params.sourcePackageRegistries?.isLoading
-        ? t('\u2026loading')
-        : params.sourcePackageRegistries?.data?.['sentry.java.logback']?.version ??
-          '6.28.0'
-    }</version>
+    <version>${getPackageVersion(params, 'sentry.java.logback', '6.28.0')}</version>
 </dependency>`;
 
 const getMavenPluginSnippet = (params: Params) => `

+ 8 - 0
static/app/utils/gettingStartedDocs/getPackageVersion.ts

@@ -0,0 +1,8 @@
+import {DocsParams} from 'sentry/components/onboarding/gettingStartedDoc/types';
+import {t} from 'sentry/locale';
+
+export function getPackageVersion(params: DocsParams, name: string, fallback: string) {
+  return params.sourcePackageRegistries.isLoading
+    ? t('loading\u2026')
+    : params.sourcePackageRegistries.data?.[name]?.version ?? fallback;
+}