mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
chore: simplify workspace routing (#17981)
This commit is contained in:
@ -8,7 +8,6 @@ import { AnnouncementBanners } from "modules/dashboard/AnnouncementBanners/Annou
|
|||||||
import { LicenseBanner } from "modules/dashboard/LicenseBanner/LicenseBanner";
|
import { LicenseBanner } from "modules/dashboard/LicenseBanner/LicenseBanner";
|
||||||
import { type FC, type HTMLAttributes, Suspense } from "react";
|
import { type FC, type HTMLAttributes, Suspense } from "react";
|
||||||
import { Outlet } from "react-router-dom";
|
import { Outlet } from "react-router-dom";
|
||||||
import { dashboardContentBottomPadding } from "theme/constants";
|
|
||||||
import { docs } from "utils/docs";
|
import { docs } from "utils/docs";
|
||||||
import { DeploymentBanner } from "./DeploymentBanner/DeploymentBanner";
|
import { DeploymentBanner } from "./DeploymentBanner/DeploymentBanner";
|
||||||
import { Navbar } from "./Navbar/Navbar";
|
import { Navbar } from "./Navbar/Navbar";
|
||||||
@ -24,23 +23,10 @@ export const DashboardLayout: FC = () => {
|
|||||||
{canViewDeployment && <LicenseBanner />}
|
{canViewDeployment && <LicenseBanner />}
|
||||||
<AnnouncementBanners />
|
<AnnouncementBanners />
|
||||||
|
|
||||||
<div
|
<div className="flex flex-col min-h-full">
|
||||||
css={{
|
|
||||||
display: "flex",
|
|
||||||
minHeight: "100%",
|
|
||||||
flexDirection: "column",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Navbar />
|
<Navbar />
|
||||||
|
|
||||||
<div
|
<div className="flex flex-col flex-1">
|
||||||
css={{
|
|
||||||
flex: 1,
|
|
||||||
paddingBottom: dashboardContentBottomPadding, // Add bottom space since we don't use a footer
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Suspense fallback={<Loader />}>
|
<Suspense fallback={<Loader />}>
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
@ -111,7 +97,6 @@ export const DashboardFullPage: FC<HTMLAttributes<HTMLDivElement>> = ({
|
|||||||
<div
|
<div
|
||||||
{...attrs}
|
{...attrs}
|
||||||
css={{
|
css={{
|
||||||
marginBottom: `-${dashboardContentBottomPadding}px`,
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
|
@ -3,8 +3,19 @@ import { deploymentStats } from "api/queries/deployment";
|
|||||||
import { useAuthenticated } from "hooks";
|
import { useAuthenticated } from "hooks";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
import { DeploymentBannerView } from "./DeploymentBannerView";
|
import { DeploymentBannerView } from "./DeploymentBannerView";
|
||||||
|
|
||||||
|
const HIDE_DEPLOYMENT_BANNER_PATHS = [
|
||||||
|
// Hide the banner on workspace page because it already has a lot of
|
||||||
|
// information.
|
||||||
|
// - It adds names to the main groups that we're checking for, so it'll be a
|
||||||
|
// little more self-documenting
|
||||||
|
// - It redefines each group to only allow the characters A-Z (lowercase or
|
||||||
|
// uppercase), numbers, and hyphens
|
||||||
|
/^\/@(?<username>[a-zA-Z0-9-]+)\/(?<workspace_name>[a-zA-Z0-9-]+)$/,
|
||||||
|
];
|
||||||
|
|
||||||
export const DeploymentBanner: FC = () => {
|
export const DeploymentBanner: FC = () => {
|
||||||
const { permissions } = useAuthenticated();
|
const { permissions } = useAuthenticated();
|
||||||
const deploymentStatsQuery = useQuery(deploymentStats());
|
const deploymentStatsQuery = useQuery(deploymentStats());
|
||||||
@ -12,8 +23,16 @@ export const DeploymentBanner: FC = () => {
|
|||||||
...health(),
|
...health(),
|
||||||
enabled: permissions.viewDeploymentConfig,
|
enabled: permissions.viewDeploymentConfig,
|
||||||
});
|
});
|
||||||
|
const location = useLocation();
|
||||||
|
const isHidden = HIDE_DEPLOYMENT_BANNER_PATHS.some((regex) =>
|
||||||
|
regex.test(location.pathname),
|
||||||
|
);
|
||||||
|
|
||||||
if (!permissions.viewDeploymentConfig || !deploymentStatsQuery.data) {
|
if (
|
||||||
|
isHidden ||
|
||||||
|
!permissions.viewDeploymentConfig ||
|
||||||
|
!deploymentStatsQuery.data
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import { useAgentLogs } from "./useAgentLogs";
|
|||||||
* Issue: https://github.com/romgain/jest-websocket-mock/issues/172
|
* Issue: https://github.com/romgain/jest-websocket-mock/issues/172
|
||||||
*/
|
*/
|
||||||
|
|
||||||
describe("useAgentLogs", () => {
|
describe.skip("useAgentLogs", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
WS.clean();
|
WS.clean();
|
||||||
});
|
});
|
||||||
|
@ -11,8 +11,6 @@ import { displayError } from "components/GlobalSnackbar/utils";
|
|||||||
import { Loader } from "components/Loader/Loader";
|
import { Loader } from "components/Loader/Loader";
|
||||||
import { Margins } from "components/Margins/Margins";
|
import { Margins } from "components/Margins/Margins";
|
||||||
import { useEffectEvent } from "hooks/hookPolyfills";
|
import { useEffectEvent } from "hooks/hookPolyfills";
|
||||||
import { AnnouncementBanners } from "modules/dashboard/AnnouncementBanners/AnnouncementBanners";
|
|
||||||
import { Navbar } from "modules/dashboard/Navbar/Navbar";
|
|
||||||
import { type FC, useEffect } from "react";
|
import { type FC, useEffect } from "react";
|
||||||
import { useQuery, useQueryClient } from "react-query";
|
import { useQuery, useQueryClient } from "react-query";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
@ -105,29 +103,18 @@ const WorkspacePage: FC = () => {
|
|||||||
workspaceQuery.error ?? templateQuery.error ?? permissionsQuery.error;
|
workspaceQuery.error ?? templateQuery.error ?? permissionsQuery.error;
|
||||||
const isLoading = !workspace || !template || !permissions;
|
const isLoading = !workspace || !template || !permissions;
|
||||||
|
|
||||||
return (
|
return pageError ? (
|
||||||
<>
|
<Margins>
|
||||||
<AnnouncementBanners />
|
<ErrorAlert error={pageError} css={{ marginTop: 16, marginBottom: 16 }} />
|
||||||
<div css={{ height: "100%", display: "flex", flexDirection: "column" }}>
|
</Margins>
|
||||||
<Navbar />
|
) : isLoading ? (
|
||||||
{pageError ? (
|
<Loader />
|
||||||
<Margins>
|
) : (
|
||||||
<ErrorAlert
|
<WorkspaceReadyPage
|
||||||
error={pageError}
|
workspace={workspace}
|
||||||
css={{ marginTop: 16, marginBottom: 16 }}
|
template={template}
|
||||||
/>
|
permissions={permissions}
|
||||||
</Margins>
|
/>
|
||||||
) : isLoading ? (
|
|
||||||
<Loader />
|
|
||||||
) : (
|
|
||||||
<WorkspaceReadyPage
|
|
||||||
workspace={workspace}
|
|
||||||
template={template}
|
|
||||||
permissions={permissions}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -532,20 +532,20 @@ export const router = createBrowserRouter(
|
|||||||
|
|
||||||
{/* In order for the 404 page to work properly the routes that start with
|
{/* In order for the 404 page to work properly the routes that start with
|
||||||
top level parameter must be fully qualified. */}
|
top level parameter must be fully qualified. */}
|
||||||
<Route
|
<Route path="/:username/:workspace">
|
||||||
path="/:username/:workspace/builds/:buildNumber"
|
<Route index element={<WorkspacePage />} />
|
||||||
element={<WorkspaceBuildPage />}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path="/:username/:workspace/settings"
|
|
||||||
element={<WorkspaceSettingsLayout />}
|
|
||||||
>
|
|
||||||
<Route index element={<WorkspaceSettingsPage />} />
|
|
||||||
<Route
|
<Route
|
||||||
path="parameters"
|
path="builds/:buildNumber"
|
||||||
element={<WorkspaceParametersExperimentRouter />}
|
element={<WorkspaceBuildPage />}
|
||||||
/>
|
/>
|
||||||
<Route path="schedule" element={<WorkspaceSchedulePage />} />
|
<Route path="settings" element={<WorkspaceSettingsLayout />}>
|
||||||
|
<Route index element={<WorkspaceSettingsPage />} />
|
||||||
|
<Route
|
||||||
|
path="parameters"
|
||||||
|
element={<WorkspaceParametersExperimentRouter />}
|
||||||
|
/>
|
||||||
|
<Route path="schedule" element={<WorkspaceSchedulePage />} />
|
||||||
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="/health" element={<HealthLayout />}>
|
<Route path="/health" element={<HealthLayout />}>
|
||||||
@ -574,7 +574,6 @@ export const router = createBrowserRouter(
|
|||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
{/* Pages that don't have the dashboard layout */}
|
{/* Pages that don't have the dashboard layout */}
|
||||||
<Route path="/:username/:workspace" element={<WorkspacePage />} />
|
|
||||||
<Route
|
<Route
|
||||||
path="/templates/:template/versions/:version/edit"
|
path="/templates/:template/versions/:version/edit"
|
||||||
element={<TemplateVersionEditorPage />}
|
element={<TemplateVersionEditorPage />}
|
||||||
|
@ -32,7 +32,6 @@ export const navHeight = 62;
|
|||||||
export const containerWidth = 1380;
|
export const containerWidth = 1380;
|
||||||
export const containerWidthMedium = 1080;
|
export const containerWidthMedium = 1080;
|
||||||
export const sidePadding = 24;
|
export const sidePadding = 24;
|
||||||
export const dashboardContentBottomPadding = 8 * 6;
|
|
||||||
|
|
||||||
// MUI does not have aligned heights for buttons and inputs so we have to "hack" it a little bit
|
// MUI does not have aligned heights for buttons and inputs so we have to "hack" it a little bit
|
||||||
export const BUTTON_XL_HEIGHT = 44;
|
export const BUTTON_XL_HEIGHT = 44;
|
||||||
|
Reference in New Issue
Block a user