Skip to content

Commit fdc44f4

Browse files
CuriousCorrelationroboquat
authored andcommitted
fix(dashboard): Tab menu visible for urls trailing '/'
1 parent 04b9a64 commit fdc44f4

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

components/dashboard/src/Menu.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { getProjectSettingsMenu } from "./projects/ProjectSettings";
2525
import { ProjectContext } from "./projects/project-context";
2626
import { PaymentContext } from "./payment-context";
2727
import FeedbackFormModal from "./feedback-form/FeedbackModal";
28-
import { isGitpodIo } from "./utils";
28+
import { inResource, isGitpodIo } from "./utils";
2929
import { getExperimentsClient } from "./experiments/client";
3030

3131
interface Entry {
@@ -105,9 +105,9 @@ export default function Menu() {
105105
}
106106

107107
// Hide most of the top menu when in a full-page form.
108-
const isMinimalUI = ["/new", "/teams/new", "/open"].includes(location.pathname);
109-
const isWorkspacesUI = ["/workspaces"].includes(location.pathname);
110-
const isAdminUI = window.location.pathname.startsWith("/admin");
108+
const isMinimalUI = inResource(location.pathname, ["new", "teams/new", "open"]);
109+
const isWorkspacesUI = inResource(location.pathname, ["workspaces"]);
110+
const isAdminUI = inResource(window.location.pathname, ["admin"]);
111111

112112
const [teamMembers, setTeamMembers] = useState<Record<string, TeamMemberInfo[]>>({});
113113
useEffect(() => {

components/dashboard/src/utils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ export function isGitpodIo() {
5757
window.location.hostname.endsWith("gitpod-io-dev.com")
5858
);
5959
}
60+
61+
function trimResource(resource: string): string {
62+
return resource.split('/').filter(Boolean).join('/');
63+
}
64+
65+
// Returns 'true' if a 'pathname' is a part of 'resources' provided.
66+
// `inResource("/app/testing/", ["new", "app", "teams"])` will return true
67+
// because '/app/testing' is a part of root 'app'
68+
//
69+
// 'pathname' arg can be provided via `location.pathname`.
70+
export function inResource(pathname: string, resources: string[]): boolean {
71+
// Removes leading and trailing '/'
72+
const trimmedResource = trimResource(pathname)
73+
74+
// Checks if a path is part of a resource.
75+
// E.g. "api/userspace/resource" path is a part of resource "api/userspace"
76+
return resources.map(res => trimmedResource.startsWith(trimResource(res))).some(Boolean)
77+
}

0 commit comments

Comments
 (0)