Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/dedicated-setup/use-needs-setup.ts
2506 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useQuery } from "@tanstack/react-query";
8
import { noPersistence } from "../data/setup";
9
import { installationClient } from "../service/public-api";
10
import { GetOnboardingStateRequest } from "@gitpod/public-api/lib/gitpod/v1/installation_pb";
11
import { useInstallationConfiguration } from "../data/installation/installation-config-query";
12
13
/**
14
* @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 async
15
*/
16
export const useNeedsSetup = () => {
17
const { data: onboardingState, isLoading } = useOnboardingState();
18
const { data: installationConfig } = useInstallationConfiguration();
19
const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation;
20
21
// This needs to only be true if we've loaded the onboarding state
22
let needsSetup = !isLoading && onboardingState && onboardingState.completed !== true;
23
24
if (isCurrentHostExcludedFromSetup()) {
25
needsSetup = false;
26
}
27
28
return {
29
needsSetup: isDedicatedInstallation && needsSetup,
30
// disabled queries stay in `isLoading` state, so checking feature flag here too
31
isLoading: isDedicatedInstallation && isLoading,
32
};
33
};
34
35
export const useOnboardingState = () => {
36
const { data: installationConfig } = useInstallationConfiguration();
37
38
return useQuery(
39
noPersistence(["onboarding-state"]),
40
async () => {
41
const response = await installationClient.getOnboardingState(new GetOnboardingStateRequest());
42
return response.onboardingState!;
43
},
44
{
45
// Only query if feature flag is enabled
46
enabled: !!installationConfig?.isDedicatedInstallation,
47
},
48
);
49
};
50
51
// TODO: This is a temporary safety-guard against this flow showing up on gitpod.io
52
// We can remove this once we've ensured we're distinguishing different installation types for this
53
export const isCurrentHostExcludedFromSetup = () => {
54
// Purposely not using isGitpodIo() check here to avoid disabling on preview environments too.
55
return ["gitpod.io", "gitpod-staging.com"].includes(window.location.hostname);
56
};
57
58