Skip to content

Commit d28d433

Browse files
AlexTugarevroboquat
authored andcommitted
[team] memorize team selection and reload on root
1 parent ba939e5 commit d28d433

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

components/dashboard/src/App.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ function App() {
8484
setUser(user);
8585

8686
const teams = await teamsPromise;
87+
88+
{
89+
// if a team was selected previously and we call the root URL (e.g. "gitpod.io"),
90+
// let's continue with the team page
91+
const hash = getURLHash();
92+
const isRoot = window.location.pathname === '/' && hash === '';
93+
if (isRoot) {
94+
try {
95+
const teamSlug = localStorage.getItem('team-selection');
96+
if (teams.some(t => t.slug === teamSlug)) {
97+
history.push(`/t/${teamSlug}`);
98+
}
99+
} catch {
100+
}
101+
}
102+
}
87103
setTeams(teams);
88104
} catch (error) {
89105
console.error(error);
@@ -260,7 +276,7 @@ function App() {
260276
<Route exact path="/teams/new" component={NewTeam} />
261277
<Route exact path="/teams/join" component={JoinTeam} />
262278
</Route>
263-
{(teams || []).map(team => <Route path={`/t/${team.slug}`}>
279+
{(teams || []).map(team => <Route key={`route-for-team-${team.slug}`} path={`/t/${team.slug}`}>
264280
<Route exact path={`/t/${team.slug}`}>
265281
<Redirect to={`/t/${team.slug}/projects`} />
266282
</Route>

components/dashboard/src/Menu.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ export default function Menu() {
5858
const showTeamsUI = user?.rolesOrPermissions?.includes('teams-and-projects');
5959
const team = getCurrentTeam(location, teams);
6060

61+
if (team) {
62+
// updating last team selection
63+
try {
64+
localStorage.setItem('team-selection', team.slug);
65+
} catch {
66+
}
67+
}
68+
6169
// Hide most of the top menu when in a full-page form.
6270
const isMinimalUI = ['/new', '/teams/new'].includes(location.pathname);
6371

@@ -268,7 +276,7 @@ export default function Menu() {
268276
</div>
269277
</div>
270278
{!isMinimalUI && showTeamsUI && !prebuildId && <div className="flex">
271-
{leftMenu.map((entry: Entry) => <TabMenuItem name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
279+
{leftMenu.map((entry: Entry) => <TabMenuItem key={entry.title} name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
272280
</div>}
273281
</header>
274282
{showTeamsUI && <Separator />}

yarn.lock

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,6 +4356,11 @@
43564356
jest-diff "^26.0.0"
43574357
pretty-format "^26.0.0"
43584358

4359+
"@types/js-cookie@^2.2.7":
4360+
version "2.2.7"
4361+
resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-2.2.7.tgz#226a9e31680835a6188e887f3988e60c04d3f6a3"
4362+
integrity sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==
4363+
43594364
"@types/js-yaml@^3.10.1":
43604365
version "3.11.2"
43614366
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.11.2.tgz#699ad86054cc20043c30d66a6fcde30bbf5d3d5e"
@@ -4665,7 +4670,7 @@
46654670
"@types/history" "*"
46664671
"@types/react" "*"
46674672

4668-
"@types/react@*", "@types/react@^17.0.0":
4673+
"@types/react@*", "@types/react@17.0.0", "@types/react@^17.0.0":
46694674
version "17.0.0"
46704675
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8"
46714676
integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw==
@@ -13374,6 +13379,11 @@ js-base64@^2.1.9:
1337413379
version "2.4.9"
1337513380
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.9.tgz#748911fb04f48a60c4771b375cac45a80df11c03"
1337613381

13382+
js-cookie@^3.0.1:
13383+
version "3.0.1"
13384+
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.1.tgz#9e39b4c6c2f56563708d7d31f6f5f21873a92414"
13385+
integrity sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw==
13386+
1337713387
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
1337813388
version "4.0.0"
1337913389
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -14859,7 +14869,7 @@ mz@^2.4.0:
1485914869
object-assign "^4.0.1"
1486014870
thenify-all "^1.0.0"
1486114871

14862-
nan@^2.12.1, nan@^2.13.2, nan@^2.9.2:
14872+
nan@2.14.1, nan@^2.12.1, nan@^2.13.2, nan@^2.14.0, nan@^2.9.2:
1486314873
version "2.14.1"
1486414874
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
1486514875
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
@@ -15406,6 +15416,13 @@ onetime@^5.1.2:
1540615416
dependencies:
1540715417
mimic-fn "^2.1.0"
1540815418

15419+
15420+
version "7.2.1"
15421+
resolved "https://registry.yarnpkg.com/oniguruma/-/oniguruma-7.2.1.tgz#51775834f7819b6e31aa878706aa7f65ad16b07f"
15422+
integrity sha512-WPS/e1uzhswPtJSe+Zls/kAj27+lEqZjCmRSjnYk/Z4L2Mu+lJC2JWtkZhPJe4kZeTQfz7ClcLyXlI4J68MG2w==
15423+
dependencies:
15424+
nan "^2.14.0"
15425+
1540915426
open@^7.0.2:
1541015427
version "7.4.2"
1541115428
resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321"
@@ -17540,7 +17557,7 @@ react-dev-utils@^11.0.3:
1754017557
strip-ansi "6.0.0"
1754117558
text-table "0.2.0"
1754217559

17543-
react-dom@^17.0.1:
17560+
react-dom@17.0.1, react-dom@^17.0.1:
1754417561
version "17.0.1"
1754517562
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6"
1754617563
integrity sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk/lx/Ug==
@@ -17669,7 +17686,7 @@ react-scripts@^4.0.3:
1766917686
optionalDependencies:
1767017687
fsevents "^2.1.3"
1767117688

17672-
react@^17.0.1:
17689+
react@17.0.1, react@^17.0.1:
1767317690
version "17.0.1"
1767417691
resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127"
1767517692
integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w==

0 commit comments

Comments
 (0)