Skip to content

[teams] make Gitpod icon team-aware #5854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ function App() {
setUser(user);

const teams = await teamsPromise;

{
// if a team was selected previously and we call the root URL (e.g. "gitpod.io"),
// let's continue with the team page
const hash = getURLHash();
const isRoot = window.location.pathname === '/' && hash === '';
if (isRoot) {
try {
const teamSlug = localStorage.getItem('team-selection');
if (teams.some(t => t.slug === teamSlug)) {
history.push(`/t/${teamSlug}`);
}
} catch {
}
}
}
setTeams(teams);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -260,7 +276,7 @@ function App() {
<Route exact path="/teams/new" component={NewTeam} />
<Route exact path="/teams/join" component={JoinTeam} />
</Route>
{(teams || []).map(team => <Route path={`/t/${team.slug}`}>
{(teams || []).map(team => <Route key={`route-for-team-${team.slug}`} path={`/t/${team.slug}`}>
<Route exact path={`/t/${team.slug}`}>
<Redirect to={`/t/${team.slug}/projects`} />
</Route>
Expand Down
19 changes: 17 additions & 2 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export default function Menu() {
const showTeamsUI = user?.rolesOrPermissions?.includes('teams-and-projects');
const team = getCurrentTeam(location, teams);

if (team) {
// updating last team selection
try {
localStorage.setItem('team-selection', team.slug);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how can you revert back to User is selected by default? Current code reads like if you select a team once, you'll forever have a team selected by default, never your own user.

Also, I find restoring this selection on page load quite dangerous, and would personally prefer we rely on URLs for correct team selection (i.e. no local storage + restore on root).

} catch {
}
}

// Hide most of the top menu when in a full-page form.
const isMinimalUI = ['/new', '/teams/new'].includes(location.pathname);

Expand Down Expand Up @@ -208,11 +216,18 @@ export default function Menu() {
)
}

const gitpodIconUrl = () => {
if (team) {
return `/t/${team.slug}`;
}
return "/"
}

return <>
<header className={`lg:px-28 px-10 flex flex-col pt-4 space-y-4 ${isMinimalUI || !!prebuildId ? 'pb-4' : ''}`} data-analytics='{"button_type":"menu"}'>
<div className="flex h-10">
<div className="flex justify-between items-center pr-3">
<Link to="/">
<Link to={gitpodIconUrl()}>
<img src={gitpodIcon} className="h-6" />
</Link>
{!isMinimalUI && <div className="ml-2 text-base">
Expand Down Expand Up @@ -261,7 +276,7 @@ export default function Menu() {
</div>
</div>
{!isMinimalUI && showTeamsUI && !prebuildId && <div className="flex">
{leftMenu.map((entry: Entry) => <TabMenuItem name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
{leftMenu.map((entry: Entry) => <TabMenuItem key={entry.title} name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
</div>}
</header>
{showTeamsUI && <Separator />}
Expand Down
25 changes: 21 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4356,6 +4356,11 @@
jest-diff "^26.0.0"
pretty-format "^26.0.0"

"@types/js-cookie@^2.2.7":
version "2.2.7"
resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-2.2.7.tgz#226a9e31680835a6188e887f3988e60c04d3f6a3"
integrity sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==

"@types/js-yaml@^3.10.1":
version "3.11.2"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.11.2.tgz#699ad86054cc20043c30d66a6fcde30bbf5d3d5e"
Expand Down Expand Up @@ -4665,7 +4670,7 @@
"@types/history" "*"
"@types/react" "*"

"@types/react@*", "@types/react@^17.0.0":
"@types/react@*", "@types/react@17.0.0", "@types/react@^17.0.0":
version "17.0.0"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8"
integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw==
Expand Down Expand Up @@ -13374,6 +13379,11 @@ js-base64@^2.1.9:
version "2.4.9"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.9.tgz#748911fb04f48a60c4771b375cac45a80df11c03"

js-cookie@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.1.tgz#9e39b4c6c2f56563708d7d31f6f5f21873a92414"
integrity sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw==

"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down Expand Up @@ -14859,7 +14869,7 @@ mz@^2.4.0:
object-assign "^4.0.1"
thenify-all "^1.0.0"

nan@^2.12.1, nan@^2.13.2, nan@^2.9.2:
nan@2.14.1, nan@^2.12.1, nan@^2.13.2, nan@^2.14.0, nan@^2.9.2:
version "2.14.1"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
Expand Down Expand Up @@ -15406,6 +15416,13 @@ onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"

[email protected]:
version "7.2.1"
resolved "https://registry.yarnpkg.com/oniguruma/-/oniguruma-7.2.1.tgz#51775834f7819b6e31aa878706aa7f65ad16b07f"
integrity sha512-WPS/e1uzhswPtJSe+Zls/kAj27+lEqZjCmRSjnYk/Z4L2Mu+lJC2JWtkZhPJe4kZeTQfz7ClcLyXlI4J68MG2w==
dependencies:
nan "^2.14.0"

open@^7.0.2:
version "7.4.2"
resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321"
Expand Down Expand Up @@ -17540,7 +17557,7 @@ react-dev-utils@^11.0.3:
strip-ansi "6.0.0"
text-table "0.2.0"

react-dom@^17.0.1:
react-dom@17.0.1, react-dom@^17.0.1:
version "17.0.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6"
integrity sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk/lx/Ug==
Expand Down Expand Up @@ -17669,7 +17686,7 @@ react-scripts@^4.0.3:
optionalDependencies:
fsevents "^2.1.3"

react@^17.0.1:
react@17.0.1, react@^17.0.1:
version "17.0.1"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127"
integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w==
Expand Down