File tree 2 files changed +22
-4
lines changed
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import { getProjectSettingsMenu } from "./projects/ProjectSettings";
25
25
import { ProjectContext } from "./projects/project-context" ;
26
26
import { PaymentContext } from "./payment-context" ;
27
27
import FeedbackFormModal from "./feedback-form/FeedbackModal" ;
28
- import { isGitpodIo } from "./utils" ;
28
+ import { inResource , isGitpodIo } from "./utils" ;
29
29
import { getExperimentsClient } from "./experiments/client" ;
30
30
31
31
interface Entry {
@@ -105,9 +105,9 @@ export default function Menu() {
105
105
}
106
106
107
107
// 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"] ) ;
111
111
112
112
const [ teamMembers , setTeamMembers ] = useState < Record < string , TeamMemberInfo [ ] > > ( { } ) ;
113
113
useEffect ( ( ) => {
Original file line number Diff line number Diff line change @@ -57,3 +57,21 @@ export function isGitpodIo() {
57
57
window . location . hostname . endsWith ( "gitpod-io-dev.com" )
58
58
) ;
59
59
}
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
+ }
You can’t perform that action at this time.
0 commit comments