frontend: default to use case onboarding on console

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9253
Co-authored-by: Rishichandra Wawhal <27274869+wawhal@users.noreply.github.com>
GitOrigin-RevId: 08a7905acfc17d84ffcbb0f84867a5d44a999805
This commit is contained in:
Varun Dey 2023-05-26 16:27:38 +05:30 committed by hasura-bot
parent 81636e0a48
commit ea3c640943
5 changed files with 40 additions and 37 deletions

View File

@ -54,5 +54,6 @@ export const WithoutSurvey: StoryObj = {
onboardingDataEmptyActivity, onboardingDataEmptyActivity,
fetchAnsweredSurveysHandler, fetchAnsweredSurveysHandler,
], ],
chromatic: { disableSnapshot: true },
}, },
}; };

View File

@ -93,11 +93,15 @@ describe('Check different configurations of Onboarding wizard depending on onboa
); );
}); });
it('should show wizard as user activity is empty', async () => { it('should not show wizard', async () => {
server.use(onboardingDataEmptyActivity); server.use(onboardingDataEmptyActivity);
render(<Root />, { wrapper }); render(<Root />, { wrapper });
await screen.findByText('Welcome to your new Hasura project!'); await waitFor(() =>
expect(
screen.queryByText('Welcome to your new Hasura project!')
).not.toBeInTheDocument()
);
}); });
it('should hide wizard as onboarding skipped by user', async () => { it('should hide wizard as onboarding skipped by user', async () => {

View File

@ -1,6 +1,5 @@
import React, { useEffect, useState, useMemo } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
import { Button } from '../../../../../new-components/Button'; import { Button } from '../../../../../new-components/Button';
import { LS_KEYS, removeLSItem } from '../../../../../utils/localStorage';
import { emitOnboardingEvent } from '../../utils'; import { emitOnboardingEvent } from '../../utils';
import { import {
getUseCaseExperimentOnboardingVariables, getUseCaseExperimentOnboardingVariables,
@ -10,10 +9,7 @@ import { Analytics, trackCustomEvent } from '../../../../Analytics';
import { Dispatch } from '../../../../../types'; import { Dispatch } from '../../../../../types';
import _push from '../../../../../components/Services/Data/push'; import _push from '../../../../../components/Services/Data/push';
type UseCaseScreenProps = { type UseCaseScreenProps = { dismiss: () => void; dispatch: Dispatch };
dismiss: () => void;
dispatch: Dispatch;
};
export type UseCases = export type UseCases =
| 'data-api' | 'data-api'
@ -78,15 +74,16 @@ export const UseCaseScreen = (props: UseCaseScreenProps) => {
return useCasesAssets.sort(() => Math.random() - 0.5); return useCasesAssets.sort(() => Math.random() - 0.5);
}, [useCasesAssets]); }, [useCasesAssets]);
const onSubmit = () => { const useCase = useCasesAssets.find(
const useCase = useCasesAssets.filter(
useCase => useCase.id === selectedUseCase useCase => useCase.id === selectedUseCase
)[0]; );
removeLSItem(LS_KEYS.useCaseExperimentOnboarding); const onSubmit = () => {
if (useCase) {
props.dispatch(_push(useCase.consoleUrl)); props.dispatch(_push(useCase.consoleUrl));
window.open(useCase.docsUrl, '_blank', 'noreferrer,noopener');
emitOnboardingEvent(getUseCaseExperimentOnboardingVariables(useCase.id)); emitOnboardingEvent(getUseCaseExperimentOnboardingVariables(useCase.id));
props.dismiss();
}
}; };
return ( return (
@ -117,7 +114,7 @@ export const UseCaseScreen = (props: UseCaseScreenProps) => {
</div> </div>
<div className="use-cases flex flex-wrap justify-around gap-y-15 gap-y-8"> <div className="use-cases flex flex-wrap justify-around gap-y-15 gap-y-8">
{randomUseCaseAssets.map((item, index) => ( {randomUseCaseAssets.map((item, index) => (
<div className="flex relative h-[250px]"> <div className="flex relative h-[250px]" key={index}>
<label <label
key={index} key={index}
htmlFor={item.id} htmlFor={item.id}
@ -155,28 +152,33 @@ export const UseCaseScreen = (props: UseCaseScreenProps) => {
className="ml-xs mr-4 text-secondary flex items-center cursor-pointer" className="ml-xs mr-4 text-secondary flex items-center cursor-pointer"
onClick={() => { onClick={() => {
props.dismiss(); props.dismiss();
removeLSItem(LS_KEYS.useCaseExperimentOnboarding);
emitOnboardingEvent(skippedUseCaseExperimentOnboarding); emitOnboardingEvent(skippedUseCaseExperimentOnboarding);
}} }}
> >
Skip Skip
</div> </div>
</Analytics> </Analytics>
{useCase ? (
<Analytics name={`use-case-onboarding-${selectedUseCase}`}>
<a
href={useCase.docsUrl}
target="_blank"
rel="noopener noreferrer"
onClick={onSubmit}
>
<Button mode="primary">Continue</Button>
</a>
</Analytics>
) : (
<Analytics <Analytics
name={`use-case-onboarding-${selectedUseCase}`} name={`use-case-onboarding-unselected`}
passHtmlAttributesToChildren passHtmlAttributesToChildren
> >
<Button <Button mode="primary" disabled>
mode="primary"
disabled={selectedUseCase === null}
onClick={() => {
props.dismiss();
onSubmit();
}}
>
Continue Continue
</Button> </Button>
</Analytics> </Analytics>
)}
</div> </div>
</div> </div>
); );

View File

@ -90,11 +90,8 @@ export function getWizardState(
// transform the onboarding data if present, to a consumable format // transform the onboarding data if present, to a consumable format
const transformedOnboardingData = onboardingDataTransformFn(onboardingData); const transformedOnboardingData = onboardingDataTransformFn(onboardingData);
if (shouldShowOnboarding(transformedOnboardingData)) { if (shouldShowOnboarding(transformedOnboardingData)) {
if (getLSItem(LS_KEYS.useCaseExperimentOnboarding)) {
return 'use-case-onboarding';
}
if (showFamiliaritySurvey) return 'familiarity-survey'; if (showFamiliaritySurvey) return 'familiarity-survey';
return 'landing-page'; return 'use-case-onboarding';
} }
return 'hidden'; return 'hidden';
} }

View File

@ -125,7 +125,6 @@ export const LS_KEYS = {
notificationsLastSeen: 'notifications:lastSeen', notificationsLastSeen: 'notifications:lastSeen',
authState: 'AUTH_STATE', authState: 'AUTH_STATE',
skipOnboarding: 'SKIP_CLOUD_ONBOARDING', skipOnboarding: 'SKIP_CLOUD_ONBOARDING',
useCaseExperimentOnboarding: 'onboarding:useCaseExperiment',
showUseCaseOverviewPopup: 'onboarding:showUseCaseOverviewPopup', showUseCaseOverviewPopup: 'onboarding:showUseCaseOverviewPopup',
}; };