Skip to content

Commit 5cf2cb8

Browse files
svenefftingeroboquat
authored andcommitted
[dashboard] keep team selection
1 parent 41d484f commit 5cf2cb8

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

components/dashboard/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Redirect, Route, Switch } from "react-router";
1010

1111
import { Login } from "./Login";
1212
import { UserContext } from "./user-context";
13-
import { TeamsContext } from "./teams/teams-context";
13+
import { getSelectedTeamSlug, TeamsContext } from "./teams/teams-context";
1414
import { ThemeContext } from "./theme-context";
1515
import { getGitpodService } from "./service/service";
1616
import { shouldSeeWhatsNew, WhatsNew } from "./whatsnew/WhatsNew";
@@ -179,7 +179,7 @@ function App() {
179179
const isRoot = window.location.pathname === "/" && hash === "";
180180
if (isRoot) {
181181
try {
182-
const teamSlug = localStorage.getItem("team-selection");
182+
const teamSlug = getSelectedTeamSlug();
183183
if (teams.some((t) => t.slug === teamSlug)) {
184184
history.push(`/t/${teamSlug}`);
185185
}

components/dashboard/src/Menu.tsx

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { countries } from "countries-list";
1313
import gitpodIcon from "./icons/gitpod.svg";
1414
import { getGitpodService, gitpodHostUrl } from "./service/service";
1515
import { UserContext } from "./user-context";
16-
import { TeamsContext, getCurrentTeam } from "./teams/teams-context";
16+
import { TeamsContext, getCurrentTeam, getSelectedTeamSlug } from "./teams/teams-context";
1717
import getSettingsMenu from "./settings/settings-menu";
1818
import { getAdminMenu } from "./admin/admin-menu";
1919
import ContextMenu from "./components/ContextMenu";
@@ -92,13 +92,6 @@ export default function Menu() {
9292

9393
const userFullName = user?.fullName || user?.name || "...";
9494

95-
{
96-
// updating last team selection
97-
try {
98-
localStorage.setItem("team-selection", team ? team.slug : "");
99-
} catch {}
100-
}
101-
10295
// Hide most of the top menu when in a full-page form.
10396
const isMinimalUI = inResource(location.pathname, ["new", "teams/new", "open"]);
10497
const isWorkspacesUI = inResource(location.pathname, ["workspaces"]);
@@ -260,33 +253,23 @@ export default function Menu() {
260253
const onFeedbackFormClose = () => {
261254
setFeedbackFormVisible(false);
262255
};
256+
const isTeamLevelActive = !projectSlug && !isWorkspacesUI && !isAdminUI && teamOrUserSlug;
263257
const renderTeamMenu = () => {
264258
const classes =
265259
"flex h-full text-base py-0 " +
266-
(!projectSlug && !isWorkspacesUI && !isAdminUI && teamOrUserSlug
267-
? "text-gray-50 bg-gray-800 dark:text-gray-900 dark:bg-gray-50 border-gray-700"
268-
: "text-gray-500 bg-gray-50 dark:bg-gray-800 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 dark:border-gray-700");
260+
(isTeamLevelActive
261+
? "text-gray-50 bg-gray-800 dark:bg-gray-50 dark:text-gray-900 border-gray-700 dark:border-gray-200"
262+
: "text-gray-500 bg-gray-50 dark:bg-gray-800 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 dark:border-gray-700");
269263
return (
270264
<div className="flex p-1 pl-3">
271-
{projectSlug && (
272-
<Link to={team ? `/t/${team.slug}/projects` : `/projects`}>
273-
<span
274-
className={`${classes} rounded-tl-2xl rounded-bl-2xl dark:border-gray-700 border-r pl-3 pr-2 py-1 bg-gray-50 font-semibold`}
275-
>
276-
{team?.name || userFullName}
277-
</span>
278-
</Link>
279-
)}
280-
{!projectSlug && (
281-
<Link to={team ? `/t/${team.slug}/projects` : `/projects`}>
282-
<span
283-
className={`${classes} rounded-tl-2xl rounded-bl-2xl dark:border-gray-200 border-r pl-3 pr-2 py-1 bg-gray-50 font-semibold`}
284-
>
285-
{team?.name || userFullName}
286-
</span>
287-
</Link>
288-
)}
289-
<div className={`${classes} rounded-tr-2xl rounded-br-2xl dark:border-gray-700 px-1 bg-gray-50`}>
265+
<Link to={getSelectedTeamSlug() ? `/t/${getSelectedTeamSlug()}/projects` : `/projects`}>
266+
<span
267+
className={`${classes} rounded-tl-2xl rounded-bl-2xl border-r pl-3 pr-2 py-1 bg-gray-50 font-semibold`}
268+
>
269+
{teams?.find((t) => t.slug === getSelectedTeamSlug())?.name || userFullName}
270+
</span>
271+
</Link>
272+
<div className={`${classes} rounded-tr-2xl rounded-br-2xl px-1`}>
290273
<ContextMenu
291274
customClasses="w-64 left-0"
292275
menuEntries={[
@@ -300,7 +283,7 @@ export default function Menu() {
300283
<span className="">Personal Account</span>
301284
</div>
302285
),
303-
active: !team,
286+
active: getSelectedTeamSlug() === "",
304287
separator: true,
305288
link: "/projects",
306289
},
@@ -321,7 +304,7 @@ export default function Menu() {
321304
</span>
322305
</div>
323306
),
324-
active: team && team.id === t.id,
307+
active: getSelectedTeamSlug() === t.slug,
325308
separator: true,
326309
link: `/t/${t.slug}`,
327310
}))

components/dashboard/src/teams/teams-context.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ export const TeamsContextProvider: React.FC = ({ children }) => {
2121
};
2222

2323
export function getCurrentTeam(location: Location<any>, teams?: Team[]): Team | undefined {
24-
const slug = location.pathname.startsWith("/t/") ? location.pathname.split("/")[2] : undefined;
25-
if (!slug || !teams) {
24+
if (!teams) {
2625
return;
2726
}
28-
return teams.find((t) => t.slug === slug);
27+
const slug = location.pathname.startsWith("/t/") ? location.pathname.split("/")[2] : undefined;
28+
if (slug === undefined && ["projects", "usage", "settings"].indexOf(location.pathname.split("/")[1]) === -1) {
29+
return undefined;
30+
}
31+
const team = teams.find((t) => t.slug === slug);
32+
localStorage.setItem("team-selection", team?.slug || "");
33+
return team;
34+
}
35+
36+
export function getSelectedTeamSlug(): string {
37+
return localStorage.getItem("team-selection") || "";
2938
}

0 commit comments

Comments
 (0)