Skip to content

feat: show version on login page #13033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into version-on-login
  • Loading branch information
aslilac committed Apr 23, 2024
commit f4f9358996029e63d2c93456ea71a8ddd3a31b52
9 changes: 4 additions & 5 deletions site/src/api/queries/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const initialAppearanceData = getMetadataAsJSON<AppearanceConfig>("appearance");
const appearanceConfigKey = ["appearance"] as const;

export const appearance = (): UseQueryOptions<AppearanceConfig> => {
return {
// We either have our initial data or should immediately
// fetch and never again!
...cachedQuery(initialAppearanceData),
// We either have our initial data or should immediately fetch and never again!
return cachedQuery({
initialData: initialAppearanceData,
queryKey: ["appearance"],
queryFn: () => API.getAppearance(),
};
});
};

export const updateAppearance = (queryClient: QueryClient) => {
Expand Down
15 changes: 4 additions & 11 deletions site/src/api/queries/buildInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ const initialBuildInfoData = getMetadataAsJSON<BuildInfoResponse>("build-info");
const buildInfoKey = ["buildInfo"] as const;

export const buildInfo = (): UseQueryOptions<BuildInfoResponse> => {
return {
// We either have our initial data or should immediately
// fetch and never again!
...cachedQuery(initialBuildInfoData),
// The version of the app can't change without reloading the page.
return cachedQuery({
initialData: initialBuildInfoData,
queryKey: buildInfoKey,
queryFn: () => API.getBuildInfo(),
// The version of the app can't change without reloading the page.
cacheTime: Infinity,
staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
};
});
};
6 changes: 3 additions & 3 deletions site/src/api/queries/entitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const initialEntitlementsData = getMetadataAsJSON<Entitlements>("entitlements");
const entitlementsQueryKey = ["entitlements"] as const;

export const entitlements = (): UseQueryOptions<Entitlements> => {
return {
...cachedQuery(initialEntitlementsData),
return cachedQuery({
initialData: initialEntitlementsData,
queryKey: entitlementsQueryKey,
queryFn: () => API.getEntitlements(),
};
});
};

export const refreshEntitlements = (queryClient: QueryClient) => {
Expand Down
6 changes: 3 additions & 3 deletions site/src/api/queries/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const initialExperimentsData = getMetadataAsJSON<Experiments>("experiments");
const experimentsKey = ["experiments"] as const;

export const experiments = (): UseQueryOptions<Experiments> => {
return {
...cachedQuery(initialExperimentsData),
return cachedQuery({
initialData: initialExperimentsData,
queryKey: experimentsKey,
queryFn: () => API.getExperiments(),
} satisfies UseQueryOptions<Experiments>;
});
};

export const availableExperiments = () => {
Expand Down
12 changes: 6 additions & 6 deletions site/src/api/queries/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ const meKey = ["me"];
export const me = (): UseQueryOptions<User> & {
queryKey: QueryKey;
} => {
return {
...cachedQuery(initialUserData),
return cachedQuery({
initialData: initialUserData,
queryKey: meKey,
queryFn: API.getAuthenticatedUser,
};
});
};

export function apiKey(): UseQueryOptions<GenerateAPIKeyResponse> {
Expand All @@ -144,12 +144,12 @@ export function apiKey(): UseQueryOptions<GenerateAPIKeyResponse> {
}

export const hasFirstUser = (): UseQueryOptions<boolean> => {
return {
return cachedQuery({
// This cannot be false otherwise it will not fetch!
...cachedQuery(typeof initialUserData !== "undefined" ? true : undefined),
initialData: Boolean(initialUserData) || undefined,
queryKey: ["hasFirstUser"],
queryFn: API.hasFirstUser,
};
});
};

export const login = (
Expand Down
48 changes: 26 additions & 22 deletions site/src/api/queries/util.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import type { UseQueryOptions } from "react-query";
import { UseQueryOptions } from "react-query";

Check failure on line 1 in site/src/api/queries/util.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

Check failure on line 1 in site/src/api/queries/util.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

// cachedQuery allows the caller to only make a request
// a single time, and use `initialData` if it is provided.
//
// This is particularly helpful for passing values injected
// via metadata. We do this for the initial user fetch, buildinfo,
// and a few others to reduce page load time.
export const cachedQuery = <T>(initialData?: T): Partial<UseQueryOptions<T>> =>
// Only do this if there is initial data,
// otherwise it can conflict with tests.
initialData
? {
cacheTime: Infinity,
staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
initialData,
}
: {
initialData,
};
/**
* cachedQuery allows the caller to only make a request a single time, and use
* `initialData` if it is provided. This is particularly helpful for passing
* values injected via metadata. We do this for the initial user fetch,
* buildinfo, and a few others to reduce page load time.
*/
export const cachedQuery = <
TQueryOptions extends UseQueryOptions<TData>,
TData,
>(
options: TQueryOptions,
): TQueryOptions =>
// Only do this if there is initial data, otherwise it can conflict with tests.
({
...(options.initialData
? {
cacheTime: Infinity,
staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
}
: {}),
...options,
});
12 changes: 7 additions & 5 deletions site/src/contexts/ProxyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
useEffect,
useState,
} from "react";
import { type UseQueryOptions, useQuery } from "react-query";

Check failure on line 10 in site/src/contexts/ProxyContext.tsx

View workflow job for this annotation

GitHub Actions / fmt

'UseQueryOptions' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in site/src/contexts/ProxyContext.tsx

View workflow job for this annotation

GitHub Actions / lint

'UseQueryOptions' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 10 in site/src/contexts/ProxyContext.tsx

View workflow job for this annotation

GitHub Actions / lint

'UseQueryOptions' is defined but never used. Allowed unused vars must match /^_/u
import { getWorkspaceProxies, getWorkspaceProxyRegions } from "api/api";
import { cachedQuery } from "api/queries/util";
import type { Region, WorkspaceProxy } from "api/typesGenerated";
Expand Down Expand Up @@ -131,11 +131,13 @@
error: proxiesError,
isLoading: proxiesLoading,
isFetched: proxiesFetched,
} = useQuery({
...cachedQuery(initialData),
queryKey,
queryFn: query,
} as UseQueryOptions<readonly Region[]>);
} = useQuery(
cachedQuery({
initialData,
queryKey,
queryFn: query,
}),
);

// Every time we get a new proxiesResponse, update the latency check
// to each workspace proxy.
Expand Down
3 changes: 2 additions & 1 deletion site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { Navigate, useLocation, useNavigate } from "react-router-dom";
import { buildInfo } from "api/queries/buildInfo";
import { authMethods } from "api/queries/users";
import { useAuthContext } from "contexts/auth/AuthProvider";
import { getApplicationName } from "utils/appearance";
import { retrieveRedirect } from "utils/redirect";
Expand Down Expand Up @@ -65,7 +66,7 @@ export const LoginPage: FC = () => {
<LoginPageView
authMethods={authMethodsQuery.data}
error={signInError}
isLoading={isLoading}
isLoading={isLoading || authMethodsQuery.isLoading}
buildInfo={buildInfoQuery.data}
isSigningIn={isSigningIn}
onSignIn={async ({ email, password }) => {
Expand Down
4 changes: 2 additions & 2 deletions site/src/utils/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export const getApplicationName = (): string => {
.querySelector(`meta[name=application-name]`)
?.getAttribute("content");
// Fallback to "Coder" if the application name is not available for some reason.
// We need to check if the content does not look like {{ .ApplicationName}}
// as it means that Coder is running in development mode (port :8080).
// We need to check if the content does not look like `{{ .ApplicationName }}`
// as it means that Coder is running in development mode.
return c && !c.startsWith("{{ .") ? c : "Coder";
};

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.