|
1 |
| -import{FC,lazy,Suspense}from"react" |
| 1 | +import{useSelector}from"@xstate/react" |
| 2 | +import{FC,lazy,Suspense,useContext}from"react" |
2 | 3 | import{Navigate,Route,Routes}from"react-router-dom"
|
| 4 | +import{selectPermissions}from"xServices/auth/authSelectors" |
| 5 | +import{XServiceContext}from"xServices/StateContext" |
3 | 6 | import{AuthAndFrame}from"./components/AuthAndFrame/AuthAndFrame"
|
4 | 7 | import{RequireAuth}from"./components/RequireAuth/RequireAuth"
|
5 | 8 | import{SettingsLayout}from"./components/SettingsLayout/SettingsLayout"
|
@@ -27,167 +30,172 @@ const WorkspacesPage = lazy(() => import("./pages/WorkspacesPage/WorkspacesPage"
|
27 | 30 | constCreateWorkspacePage=lazy(()=>import("./pages/CreateWorkspacePage/CreateWorkspacePage"))
|
28 | 31 | constAuditPage=lazy(()=>import("./pages/AuditPage/AuditPage"))
|
29 | 32 |
|
30 |
| -exportconstAppRouter:FC=()=>( |
31 |
| -<Suspensefallback={<></>}> |
32 |
| -<Routes> |
33 |
| -<Route |
34 |
| -index |
35 |
| -element={ |
36 |
| -<RequireAuth> |
37 |
| -<IndexPage/> |
38 |
| -</RequireAuth> |
39 |
| -} |
40 |
| -/> |
| 33 | +exportconstAppRouter:FC=()=>{ |
| 34 | +constxServices=useContext(XServiceContext) |
| 35 | +constpermissions=useSelector(xServices.authXService,selectPermissions) |
41 | 36 |
|
42 |
| -<Routepath="login"element={<LoginPage/>}/> |
43 |
| -<Routepath="healthz"element={<HealthzPage/>}/> |
44 |
| -<Route |
45 |
| -path="cli-auth" |
46 |
| -element={ |
47 |
| -<RequireAuth> |
48 |
| -<CliAuthenticationPage/> |
49 |
| -</RequireAuth> |
50 |
| -} |
51 |
| -/> |
52 |
| - |
53 |
| -<Routepath="workspaces"> |
| 37 | +return( |
| 38 | +<Suspensefallback={<></>}> |
| 39 | +<Routes> |
54 | 40 | <Route
|
55 | 41 | index
|
56 | 42 | element={
|
57 |
| -<AuthAndFrame> |
58 |
| -<WorkspacesPage/> |
59 |
| -</AuthAndFrame> |
| 43 | +<RequireAuth> |
| 44 | +<IndexPage/> |
| 45 | +</RequireAuth> |
60 | 46 | }
|
61 | 47 | />
|
62 |
| -</Route> |
63 | 48 |
|
64 |
| -<Routepath="templates"> |
| 49 | +<Routepath="login"element={<LoginPage/>}/> |
| 50 | +<Routepath="healthz"element={<HealthzPage/>}/> |
65 | 51 | <Route
|
66 |
| -index |
| 52 | +path="cli-auth" |
67 | 53 | element={
|
68 |
| -<AuthAndFrame> |
69 |
| -<TemplatesPage/> |
70 |
| -</AuthAndFrame> |
| 54 | +<RequireAuth> |
| 55 | +<CliAuthenticationPage/> |
| 56 | +</RequireAuth> |
71 | 57 | }
|
72 | 58 | />
|
73 | 59 |
|
74 |
| -<Routepath=":template"> |
| 60 | +<Routepath="workspaces"> |
75 | 61 | <Route
|
76 | 62 | index
|
77 | 63 | element={
|
78 | 64 | <AuthAndFrame>
|
79 |
| -<TemplatePage/> |
| 65 | +<WorkspacesPage/> |
80 | 66 | </AuthAndFrame>
|
81 | 67 | }
|
82 | 68 | />
|
83 |
| -<Route |
84 |
| -path="workspace" |
85 |
| -element={ |
86 |
| -<RequireAuth> |
87 |
| -<CreateWorkspacePage/> |
88 |
| -</RequireAuth> |
89 |
| -} |
90 |
| -/> |
91 | 69 | </Route>
|
92 |
| -</Route> |
93 |
| - |
94 |
| -<Routepath="users"> |
95 |
| -<Route |
96 |
| -index |
97 |
| -element={ |
98 |
| -<AuthAndFrame> |
99 |
| -<UsersPage/> |
100 |
| -</AuthAndFrame> |
101 |
| -} |
102 |
| -/> |
103 |
| -<Route |
104 |
| -path="create" |
105 |
| -element={ |
106 |
| -<RequireAuth> |
107 |
| -<CreateUserPage/> |
108 |
| -</RequireAuth> |
109 |
| -} |
110 |
| -/> |
111 |
| -</Route> |
112 | 70 |
|
113 |
| -{/* REMARK: Route under construction |
114 |
| - Eventually, we should gate this page |
115 |
| - with permissions and licensing */} |
116 |
| -<Routepath="/audit"> |
117 |
| -<Route |
118 |
| -index |
119 |
| -element={ |
120 |
| -process.env.NODE_ENV==="production" ?( |
121 |
| -<Navigateto="/workspaces"/> |
122 |
| -) :( |
| 71 | +<Routepath="templates"> |
| 72 | +<Route |
| 73 | +index |
| 74 | +element={ |
123 | 75 | <AuthAndFrame>
|
124 |
| -<AuditPage/> |
| 76 | +<TemplatesPage/> |
125 | 77 | </AuthAndFrame>
|
126 |
| -) |
127 |
| -} |
128 |
| -></Route> |
129 |
| -</Route> |
| 78 | +} |
| 79 | +/> |
130 | 80 |
|
131 |
| -<Routepath="settings"element={<SettingsLayout/>}> |
132 |
| -<Routepath="account"element={<AccountPage/>}/> |
133 |
| -<Routepath="security"element={<SecurityPage/>}/> |
134 |
| -<Routepath="ssh-keys"element={<SSHKeysPage/>}/> |
135 |
| -</Route> |
| 81 | +<Routepath=":template"> |
| 82 | +<Route |
| 83 | +index |
| 84 | +element={ |
| 85 | +<AuthAndFrame> |
| 86 | +<TemplatePage/> |
| 87 | +</AuthAndFrame> |
| 88 | +} |
| 89 | +/> |
| 90 | +<Route |
| 91 | +path="workspace" |
| 92 | +element={ |
| 93 | +<RequireAuth> |
| 94 | +<CreateWorkspacePage/> |
| 95 | +</RequireAuth> |
| 96 | +} |
| 97 | +/> |
| 98 | +</Route> |
| 99 | +</Route> |
136 | 100 |
|
137 |
| -<Routepath="/@:username"> |
138 |
| -<Routepath=":workspace"> |
| 101 | +<Routepath="users"> |
139 | 102 | <Route
|
140 | 103 | index
|
141 | 104 | element={
|
142 | 105 | <AuthAndFrame>
|
143 |
| -<WorkspacePage/> |
| 106 | +<UsersPage/> |
144 | 107 | </AuthAndFrame>
|
145 | 108 | }
|
146 | 109 | />
|
147 | 110 | <Route
|
148 |
| -path="schedule" |
| 111 | +path="create" |
149 | 112 | element={
|
150 | 113 | <RequireAuth>
|
151 |
| -<WorkspaceSchedulePage/> |
| 114 | +<CreateUserPage/> |
152 | 115 | </RequireAuth>
|
153 | 116 | }
|
154 | 117 | />
|
| 118 | +</Route> |
155 | 119 |
|
| 120 | +{/* REMARK: Route under construction |
| 121 | + Eventually, we should gate this page |
| 122 | + with permissions and licensing */} |
| 123 | +<Routepath="/audit"> |
156 | 124 | <Route
|
157 |
| -path="terminal" |
| 125 | +index |
158 | 126 | element={
|
159 |
| -<RequireAuth> |
160 |
| -<TerminalPage/> |
161 |
| -</RequireAuth> |
| 127 | +process.env.NODE_ENV==="production"||!permissions?.viewAuditLog ?( |
| 128 | +<Navigateto="/workspaces"/> |
| 129 | +) :( |
| 130 | +<AuthAndFrame> |
| 131 | +<AuditPage/> |
| 132 | +</AuthAndFrame> |
| 133 | +) |
162 | 134 | }
|
163 |
| -/> |
| 135 | +></Route> |
| 136 | +</Route> |
| 137 | + |
| 138 | +<Routepath="settings"element={<SettingsLayout/>}> |
| 139 | +<Routepath="account"element={<AccountPage/>}/> |
| 140 | +<Routepath="security"element={<SecurityPage/>}/> |
| 141 | +<Routepath="ssh-keys"element={<SSHKeysPage/>}/> |
| 142 | +</Route> |
164 | 143 |
|
165 |
| -<Routepath="apps"> |
| 144 | +<Routepath="/@:username"> |
| 145 | +<Routepath=":workspace"> |
166 | 146 | <Route
|
167 |
| -path=":app/*" |
| 147 | +index |
168 | 148 | element={
|
169 | 149 | <AuthAndFrame>
|
170 |
| -<WorkspaceAppErrorPage/> |
| 150 | +<WorkspacePage/> |
171 | 151 | </AuthAndFrame>
|
172 | 152 | }
|
173 | 153 | />
|
174 |
| -</Route> |
| 154 | +<Route |
| 155 | +path="schedule" |
| 156 | +element={ |
| 157 | +<RequireAuth> |
| 158 | +<WorkspaceSchedulePage/> |
| 159 | +</RequireAuth> |
| 160 | +} |
| 161 | +/> |
175 | 162 |
|
176 |
| -<Route |
177 |
| -path="builds/:buildNumber" |
178 |
| -element={ |
179 |
| -<AuthAndFrame> |
180 |
| -<WorkspaceBuildPage/> |
181 |
| -</AuthAndFrame> |
182 |
| -} |
183 |
| -/> |
| 163 | +<Route |
| 164 | +path="terminal" |
| 165 | +element={ |
| 166 | +<RequireAuth> |
| 167 | +<TerminalPage/> |
| 168 | +</RequireAuth> |
| 169 | +} |
| 170 | +/> |
| 171 | + |
| 172 | +<Routepath="apps"> |
| 173 | +<Route |
| 174 | +path=":app/*" |
| 175 | +element={ |
| 176 | +<AuthAndFrame> |
| 177 | +<WorkspaceAppErrorPage/> |
| 178 | +</AuthAndFrame> |
| 179 | +} |
| 180 | +/> |
| 181 | +</Route> |
| 182 | + |
| 183 | +<Route |
| 184 | +path="builds/:buildNumber" |
| 185 | +element={ |
| 186 | +<AuthAndFrame> |
| 187 | +<WorkspaceBuildPage/> |
| 188 | +</AuthAndFrame> |
| 189 | +} |
| 190 | +/> |
| 191 | +</Route> |
184 | 192 | </Route>
|
185 |
| -</Route> |
186 | 193 |
|
187 |
| -{/* Using path="*"" means "match anything", so this route |
| 194 | +{/* Using path="*"" means "match anything", so this route |
188 | 195 | acts like a catch-all for URLs that we don't have explicit
|
189 | 196 | routes for. */}
|
190 |
| -<Routepath="*"element={<NotFoundPage/>}/> |
191 |
| -</Routes> |
192 |
| -</Suspense> |
193 |
| -) |
| 197 | +<Routepath="*"element={<NotFoundPage/>}/> |
| 198 | +</Routes> |
| 199 | +</Suspense> |
| 200 | +) |
| 201 | +} |