Path: blob/main/components/dashboard/src/dedicated-setup/use-needs-setup.ts
2506 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useQuery } from "@tanstack/react-query";7import { noPersistence } from "../data/setup";8import { installationClient } from "../service/public-api";9import { GetOnboardingStateRequest } from "@gitpod/public-api/lib/gitpod/v1/installation_pb";10import { useInstallationConfiguration } from "../data/installation/installation-config-query";1112/**13* @description Returns a flag stating if the current installation still needs setup before it can be used. Also returns an isLoading indicator as the check is async14*/15export const useNeedsSetup = () => {16const { data: onboardingState, isLoading } = useOnboardingState();17const { data: installationConfig } = useInstallationConfiguration();18const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation;1920// This needs to only be true if we've loaded the onboarding state21let needsSetup = !isLoading && onboardingState && onboardingState.completed !== true;2223if (isCurrentHostExcludedFromSetup()) {24needsSetup = false;25}2627return {28needsSetup: isDedicatedInstallation && needsSetup,29// disabled queries stay in `isLoading` state, so checking feature flag here too30isLoading: isDedicatedInstallation && isLoading,31};32};3334export const useOnboardingState = () => {35const { data: installationConfig } = useInstallationConfiguration();3637return useQuery(38noPersistence(["onboarding-state"]),39async () => {40const response = await installationClient.getOnboardingState(new GetOnboardingStateRequest());41return response.onboardingState!;42},43{44// Only query if feature flag is enabled45enabled: !!installationConfig?.isDedicatedInstallation,46},47);48};4950// TODO: This is a temporary safety-guard against this flow showing up on gitpod.io51// We can remove this once we've ensured we're distinguishing different installation types for this52export const isCurrentHostExcludedFromSetup = () => {53// Purposely not using isGitpodIo() check here to avoid disabling on preview environments too.54return ["gitpod.io", "gitpod-staging.com"].includes(window.location.hostname);55};565758