From df25033a6d52504527f9a7da5410395429f07ed8 Mon Sep 17 00:00:00 2001 From: "Laurie T. Malau" Date: Tue, 7 Dec 2021 10:49:11 +0000 Subject: [PATCH] Plug in experiment --- components/dashboard/src/Login.tsx | 42 +++++++++++++++---------- components/dashboard/src/experiments.ts | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/components/dashboard/src/Login.tsx b/components/dashboard/src/Login.tsx index 7f8a45501c1a7e..339015dea54b3e 100644 --- a/components/dashboard/src/Login.tsx +++ b/components/dashboard/src/Login.tsx @@ -11,6 +11,7 @@ import { UserContext } from "./user-context"; import { TeamsContext } from "./teams/teams-context"; import { getGitpodService } from "./service/service"; import { iconForAuthProvider, openAuthorizeWindow, simplifyProviderName, getSafeURLRedirect } from "./provider-utils"; +import { Experiment } from './experiments'; import gitpod from './images/gitpod.svg'; import gitpodDark from './images/gitpod-dark.svg'; import gitpodIcon from './icons/gitpod.svg'; @@ -47,9 +48,12 @@ export function hasVisitedMarketingWebsiteBefore() { export function Login() { const { setUser } = useContext(UserContext); const { setTeams } = useContext(TeamsContext); + const experiment = "login-from-context-6826"; + const urlHash = getURLHash(); let hostFromContext: string | undefined; let repoPathname: string | undefined; + try { if (urlHash.length > 0) { const url = new URL(urlHash); @@ -63,7 +67,11 @@ export function Login() { const [authProviders, setAuthProviders] = useState([]); const [errorMessage, setErrorMessage] = useState(undefined); const [providerFromContext, setProviderFromContext] = useState(); - const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore() && !urlHash.startsWith("https://"); + + const showWelcome = Experiment.has(experiment) ? + (!hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore() && !urlHash.startsWith("https://")) + : (!hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore()) + ; useEffect(() => { (async () => { @@ -71,12 +79,14 @@ export function Login() { })(); }, []) - useEffect(() => { - if (hostFromContext && authProviders) { - const providerFromContext = authProviders.find(provider => provider.host === hostFromContext); - setProviderFromContext(providerFromContext); - } - }, [authProviders]) + if (Experiment.has(experiment)) { + useEffect(() => { + if (hostFromContext && authProviders) { + const providerFromContext = authProviders.find(provider => provider.host === hostFromContext); + setProviderFromContext(providerFromContext); + } + }, [authProviders]) + } const authorizeSuccessful = async (payload?: string) => { updateUser().catch(console.error); @@ -178,16 +188,16 @@ export function Login() {
{providerFromContext ? - + : - authProviders.map(ap => - ) + authProviders.map(ap => + ) }
diff --git a/components/dashboard/src/experiments.ts b/components/dashboard/src/experiments.ts index 101c022e4a5fea..aad146f86eb64a 100644 --- a/components/dashboard/src/experiments.ts +++ b/components/dashboard/src/experiments.ts @@ -28,6 +28,7 @@ const Experiments = { * Experiment "example" will be activate on login for 10% of all clients. */ // "example": 0.1, + "login-from-context-6826": 0.5, }; const ExperimentsSet = new Set(Object.keys(Experiments)) as Set; export type Experiment = keyof (typeof Experiments);