Browse Source

ref(onboarding): Update silent project deletion logic - (#45415)

Priscila Oliveira 2 years ago
parent
commit
7251b5ac40

+ 3 - 0
static/app/views/onboarding/components/footer.spec.tsx

@@ -27,6 +27,7 @@ describe('Onboarding Footer', function () {
           location={router.location}
           route={route}
           router={router}
+          newOrg
         />
       </PersistedStoreProvider>,
       {
@@ -76,6 +77,7 @@ describe('Onboarding Footer', function () {
           location={router.location}
           route={route}
           router={router}
+          newOrg
         />
       </PersistedStoreProvider>,
       {
@@ -119,6 +121,7 @@ describe('Onboarding Footer', function () {
           location={router.location}
           route={route}
           router={router}
+          newOrg
         />
       </PersistedStoreProvider>,
       {

+ 18 - 3
static/app/views/onboarding/components/footer.tsx

@@ -17,6 +17,7 @@ import {Group, Project} from 'sentry/types';
 import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {useQuery} from 'sentry/utils/queryClient';
 import useOrganization from 'sentry/utils/useOrganization';
+import useProjects from 'sentry/utils/useProjects';
 import {useSessionStorage} from 'sentry/utils/useSessionStorage';
 
 import {usePersistedOnboardingState} from '../utils';
@@ -73,6 +74,7 @@ export function Footer({projectSlug, router, newOrg}: Props) {
   const [firstError, setFirstError] = useState<string | null>(null);
   const [firstIssue, setFirstIssue] = useState<Group | undefined>(undefined);
   const [clientState, setClientState] = usePersistedOnboardingState();
+  const {projects} = useProjects();
 
   const onboarding_sessionStorage_key = `onboarding-${projectSlug}`;
 
@@ -140,16 +142,29 @@ export function Footer({projectSlug, router, newOrg}: Props) {
       source: 'targeted_onboarding_first_event_footer',
     });
 
+    const selectedProjectId = projects.find(project => project.slug === projectSlug)?.id;
+
     openChangeRouteModal({
       router,
       nextLocation: {
         ...router.location,
-        pathname: `/organizations/${organization.slug}/issues/?referrer=onboarding-first-event-footer-skip`,
+        pathname:
+          `/organizations/${organization.slug}/issues/?` +
+          (selectedProjectId ? `project=${selectedProjectId}&` : '') +
+          `referrer=onboarding-first-event-footer-skip`,
       },
       setClientState,
       clientState,
     });
-  }, [router, organization, sessionStorage.status, setClientState, clientState]);
+  }, [
+    router,
+    organization,
+    sessionStorage.status,
+    setClientState,
+    clientState,
+    projects,
+    projectSlug,
+  ]);
 
   useEffect(() => {
     if (!firstError) {
@@ -202,7 +217,7 @@ export function Footer({projectSlug, router, newOrg}: Props) {
   return (
     <Wrapper newOrg={!!newOrg} sidebarCollapsed={!!preferences.collapsed}>
       <Column>
-        {sessionStorage.status === OnboardingStatus.WAITING && (
+        {sessionStorage.status === OnboardingStatus.WAITING && newOrg && (
           <Button onClick={handleSkipOnboarding} priority="link">
             {t('Skip Onboarding')}
           </Button>

+ 25 - 2
static/app/views/onboarding/index.tsx

@@ -10,11 +10,13 @@ import Hook from 'sentry/components/hook';
 import Link from 'sentry/components/links/link';
 import LogoSentry from 'sentry/components/logoSentry';
 import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
+import {PlatformKey} from 'sentry/data/platformCategories';
 import {IconArrow} from 'sentry/icons';
 import {t} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import {Organization, Project} from 'sentry/types';
 import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
+import handleXhrErrorResponse from 'sentry/utils/handleXhrErrorResponse';
 import Redirect from 'sentry/utils/redirect';
 import testableTransition from 'sentry/utils/testableTransition';
 import useApi from 'sentry/utils/useApi';
@@ -149,7 +151,7 @@ function Onboarding(props: Props) {
     browserHistory.push(normalizeUrl(`/onboarding/${organization.slug}/${nextStep.id}/`));
   };
 
-  const handleGoBack = () => {
+  const handleGoBack = async () => {
     if (!stepObj) {
       return;
     }
@@ -170,7 +172,28 @@ function Onboarding(props: Props) {
         .map(platform => platformToProjectIdMap[platform])
         .filter((slug): slug is string => slug !== undefined);
 
-      removeProject(api, organization.slug, selectedProjectSlugs[0]);
+      try {
+        await removeProject(api, organization.slug, selectedProjectSlugs[0]);
+        if (clientState) {
+          setClientState({
+            url: 'setup-docs/',
+            state: 'projects_selected',
+            selectedPlatforms: [selectedProjectSlugs[0] as PlatformKey],
+            platformToProjectIdMap: Object.keys(platformToProjectIdMap).reduce(
+              (acc, value) => {
+                if (value !== selectedProjectSlugs[0] && !acc[value]) {
+                  acc[value] = value;
+                }
+                return acc;
+              },
+              {}
+            ),
+          });
+        }
+      } catch (error) {
+        handleXhrErrorResponse(t('Unable to delete project'))(error);
+        // we don't give the user any feedback regarding this error as this shall be silent
+      }
     }
 
     if (stepObj.cornerVariant !== previousStep.cornerVariant) {