Skip to content
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

Ability to navigate to the user's accounts from the main page #545

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions src/AllRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import GitHubIcon from '@mui/icons-material/GitHub';
import GCPStatus from './components/status/GCPStatus';
import GitHubStatus from './components/status/GitHubStatus';
import * as Sentry from '@sentry/react';
import AccountsSwitch from './components/common/AccountSwitch';

const AsyncViewerProfile = React.lazy(() => import('./scenes/Profile/ViewerProfile'));

Expand Down Expand Up @@ -228,6 +229,11 @@ function AllRoutes() {
Cirrus CI
</Typography>
</Link>
<Suspense fallback={<div />}>
<div className={classes.titleShift}>
<AccountsSwitch></AccountsSwitch>
</div>
</Suspense>
<div className={classes.flex} />
<Suspense fallback={<div />}>
<GCPStatus />
Expand Down
33 changes: 16 additions & 17 deletions src/components/common/AccountSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { useFragment } from 'react-relay';
import { useLazyLoadQuery } from 'react-relay';
import { graphql } from 'babel-plugin-relay/macro';

import Menu from '@mui/material/Menu';
Expand All @@ -10,25 +10,11 @@ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';

import { navigateHelper } from '../../utils/navigateHelper';

import { AccountSwitch_viewer$key } from './__generated__/AccountSwitch_viewer.graphql';
import { AccountSwitchQuery } from './__generated__/AccountSwitchQuery.graphql';

interface AccountSwitchProps {
viewer?: AccountSwitch_viewer$key;
}
interface AccountSwitchProps {}

export default function AccountsSwitch(props: AccountSwitchProps) {
let viewer = useFragment(
graphql`
fragment AccountSwitch_viewer on User {
relatedOwners {
platform
name
}
}
`,
props.viewer,
);

const navigate = useNavigate();

const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(null);
Expand All @@ -46,6 +32,19 @@ export default function AccountsSwitch(props: AccountSwitchProps) {
navigateHelper(navigate, e, '/github/' + name);
};

const viewer = useLazyLoadQuery<AccountSwitchQuery>(
graphql`
query AccountSwitchQuery {
viewer {
relatedOwners {
platform
name
}
}
}
`,
{},
).viewer;
if (!viewer) return null;
if (viewer.relatedOwners && viewer.relatedOwners.length <= 1) return null;

Expand Down
12 changes: 0 additions & 12 deletions src/components/common/AppBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import BookmarkBorderIcon from '@mui/icons-material/BookmarkBorder';

import { absoluteLink } from '../../utils/link';
import RepositoryIcon from './RepositoryIcon';
import AccountSwitch from './AccountSwitch';

import { AppBreadcrumbs_build$key } from './__generated__/AppBreadcrumbs_build.graphql';
import { AppBreadcrumbs_repository$key } from './__generated__/AppBreadcrumbs_repository.graphql';
import { AppBreadcrumbs_task$key } from './__generated__/AppBreadcrumbs_task.graphql';
import { AppBreadcrumbs_info$key } from './__generated__/AppBreadcrumbs_info.graphql';
import { AppBreadcrumbs_viewer$key } from './__generated__/AppBreadcrumbs_viewer.graphql';

const useStyles = makeStyles(theme => {
return {
Expand Down Expand Up @@ -61,7 +59,6 @@ interface Props {
href?: string;
Icon: typeof SvgIcon | React.ElementType;
}>;
viewer?: AppBreadcrumbs_viewer$key;
}

export default function AppBreadcrumbs(props: Props) {
Expand Down Expand Up @@ -121,14 +118,6 @@ export default function AppBreadcrumbs(props: Props) {
`,
props.task,
);
let viewer = useFragment(
graphql`
fragment AppBreadcrumbs_viewer on User {
...AccountSwitch_viewer
}
`,
props.viewer,
);

let { branch, extraCrumbs } = props;
let classes = useStyles();
Expand Down Expand Up @@ -177,7 +166,6 @@ export default function AppBreadcrumbs(props: Props) {

return (
<Stack className={classes.root} direction="row" spacing={1}>
<AccountSwitch viewer={viewer} />
<Breadcrumbs
className={classes.breadcrumbs}
separator={<NavigateNextIcon fontSize="small" />}
Expand Down
5 changes: 1 addition & 4 deletions src/scenes/Build/BuildById.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default function BuildById(): JSX.Element {
...BuildDetails_build
...AppBreadcrumbs_build
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ buildId },
Expand All @@ -32,7 +29,7 @@ export default function BuildById(): JSX.Element {
}
return (
<>
<AppBreadcrumbs build={response.build} viewer={response.viewer} />
<AppBreadcrumbs build={response.build} />
<BuildDetails build={response.build} />
</>
);
Expand Down
5 changes: 1 addition & 4 deletions src/scenes/Build/BuildBySHA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default function BuildBySHA() {
...BuildDetails_build
...AppBreadcrumbs_build
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ owner, name, SHA },
Expand All @@ -40,7 +37,7 @@ export default function BuildBySHA() {
}
return (
<>
<AppBreadcrumbs build={response.searchBuilds[0]} viewer={response.viewer} />
<AppBreadcrumbs build={response.searchBuilds[0]} />
<BuildDetails build={response.searchBuilds[0]} />
</>
);
Expand Down
5 changes: 1 addition & 4 deletions src/scenes/Owner/Owner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default function Owner(): JSX.Element {
...OwnerRepositoryList_info
...AppBreadcrumbs_info
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ platform, owner },
Expand All @@ -32,7 +29,7 @@ export default function Owner(): JSX.Element {
}
return (
<>
<AppBreadcrumbs info={response.ownerInfoByName} viewer={response.viewer} />
<AppBreadcrumbs info={response.ownerInfoByName} />
<OwnerRepositoryList info={response.ownerInfoByName} />
</>
);
Expand Down
4 changes: 0 additions & 4 deletions src/scenes/Owner/OwnerSettingsRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default function OwnerSettingsRenderer(): JSX.Element {
...OwnerSettings_info
...AppBreadcrumbs_info
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ platform, name },
Expand All @@ -31,7 +28,6 @@ export default function OwnerSettingsRenderer(): JSX.Element {
<>
<AppBreadcrumbs
info={response.ownerInfoByName}
viewer={response.viewer}
extraCrumbs={[
{
name: 'Account Settings',
Expand Down
5 changes: 1 addition & 4 deletions src/scenes/Repository/OwnerRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default function OwnerRepository(): JSX.Element {
...AppBreadcrumbs_repository
...RepositoryBuildList_repository @arguments(branch: $branch)
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ platform, owner, name, branch },
Expand All @@ -42,7 +39,7 @@ export default function OwnerRepository(): JSX.Element {
}
return (
<>
<AppBreadcrumbs repository={response.ownerRepository} viewer={response.viewer} branch={branch} />
<AppBreadcrumbs repository={response.ownerRepository} branch={branch} />
<RepositoryBuildList repository={response.ownerRepository} branch={branch} />
</>
);
Expand Down
4 changes: 0 additions & 4 deletions src/scenes/RepositoryMetrics/RepositoryMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export default function RepositoryMetrics(parentProps): JSX.Element {
...AppBreadcrumbs_repository
...RepositoryMetricsPage_repository
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ platform, owner, name },
Expand All @@ -35,7 +32,6 @@ export default function RepositoryMetrics(parentProps): JSX.Element {
<>
<AppBreadcrumbs
repository={response.ownerRepository}
viewer={response.viewer}
extraCrumbs={[
{
name: 'Metrics',
Expand Down
4 changes: 0 additions & 4 deletions src/scenes/RepositorySettings/RepositorySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export default function RepositorySettings(): JSX.Element {
...AppBreadcrumbs_repository
...RepositorySettingsPage_repository
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ repositoryId },
Expand All @@ -35,7 +32,6 @@ export default function RepositorySettings(): JSX.Element {
<>
<AppBreadcrumbs
repository={response.repository}
viewer={response.viewer}
extraCrumbs={[
{
name: 'Repository Settings',
Expand Down
5 changes: 1 addition & 4 deletions src/scenes/Task/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default function Task(): JSX.Element {
...TaskDetails_task
...AppBreadcrumbs_task
}
viewer {
...AppBreadcrumbs_viewer
}
}
`,
{ taskId },
Expand All @@ -32,7 +29,7 @@ export default function Task(): JSX.Element {
}
return (
<>
<AppBreadcrumbs task={response.task} viewer={response.viewer} />
<AppBreadcrumbs task={response.task} />
<TaskDetails task={response.task} />
</>
);
Expand Down