Skip to content

Commit 9369738

Browse files
authored
feat(dashboard): improve repositories loading (#6928)
* update getRepositoriesByTeam query * wip: get single repo * handle navigating back from single repo using breadcrumbs
1 parent 9849d6c commit 9369738

File tree

4 files changed

+106
-10
lines changed

4 files changed

+106
-10
lines changed

packages/app/src/app/graphql/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,6 +3209,7 @@ export type ContributionBranchesQuery = { __typename?: 'RootQueryType' } & {
32093209

32103210
export type RepositoriesByTeamQueryVariables = Exact<{
32113211
teamId: Scalars['UUID4'];
3212+
syncData: Maybe<Scalars['Boolean']>;
32123213
}>;
32133214

32143215
export type RepositoriesByTeamQuery = { __typename?: 'RootQueryType' } & {
@@ -3223,6 +3224,15 @@ export type RepositoriesByTeamQuery = { __typename?: 'RootQueryType' } & {
32233224
>;
32243225
};
32253226

3227+
export type RepositoryByDetailsQueryVariables = Exact<{
3228+
owner: Scalars['String'];
3229+
name: Scalars['String'];
3230+
}>;
3231+
3232+
export type RepositoryByDetailsQuery = { __typename?: 'RootQueryType' } & {
3233+
project: Maybe<{ __typename?: 'Project' } & ProjectFragment>;
3234+
};
3235+
32263236
export type RecentNotificationFragment = { __typename?: 'Notification' } & Pick<
32273237
Notification,
32283238
'id' | 'type' | 'data' | 'insertedAt' | 'read'

packages/app/src/app/overmind/effects/gql/dashboard/queries.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import {
5151
ContributionBranchesQueryVariables,
5252
RepositoriesByTeamQuery,
5353
RepositoriesByTeamQueryVariables,
54+
RepositoryByDetailsQuery,
55+
RepositoryByDetailsQueryVariables,
5456
} from 'app/graphql/types';
5557
import { gql, Query } from 'overmind-graphql';
5658

@@ -490,12 +492,12 @@ export const getRepositoriesByTeam: Query<
490492
RepositoriesByTeamQuery,
491493
RepositoriesByTeamQueryVariables
492494
> = gql`
493-
query RepositoriesByTeam($teamId: UUID4!) {
495+
query RepositoriesByTeam($teamId: UUID4!, $syncData: Boolean) {
494496
me {
495497
team(id: $teamId) {
496498
id
497499
name
498-
projects {
500+
projects(syncData: $syncData) {
499501
...project
500502
}
501503
}
@@ -504,3 +506,16 @@ export const getRepositoriesByTeam: Query<
504506
${projectFragment}
505507
${branchFragment}
506508
`;
509+
510+
export const getRepositoryByDetails: Query<
511+
RepositoryByDetailsQuery,
512+
RepositoryByDetailsQueryVariables
513+
> = gql`
514+
query RepositoryByDetails($owner: String!, $name: String!) {
515+
project(gitProvider: GITHUB, owner: $owner, repo: $name) {
516+
...project
517+
}
518+
}
519+
${projectFragment}
520+
${branchFragment}
521+
`;

packages/app/src/app/overmind/namespaces/dashboard/actions.ts

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,18 +1972,65 @@ export const getRepositoriesByTeam = async ({ state, effects }: Context) => {
19721972
try {
19731973
dashboard.repositories = null;
19741974

1975-
const repositoriesData = await effects.gql.queries.getRepositoriesByTeam({
1976-
teamId: activeTeam,
1975+
// First fetch data without syncing with GitHub
1976+
// to decrease waiting time.
1977+
const unsyncedRepositoriesData = await effects.gql.queries.getRepositoriesByTeam(
1978+
{
1979+
teamId: activeTeam,
1980+
syncData: false,
1981+
}
1982+
);
1983+
const unsyncedRepositories = unsyncedRepositoriesData?.me?.team?.projects;
1984+
if (!unsyncedRepositories?.length) {
1985+
return;
1986+
}
1987+
1988+
dashboard.repositories = unsyncedRepositories;
1989+
1990+
// Then fetch data synced with GitHub to make sure
1991+
// what we show is up-to-date.
1992+
const syncedRepositoriesData = await effects.gql.queries.getRepositoriesByTeam(
1993+
{
1994+
teamId: activeTeam,
1995+
syncData: true,
1996+
}
1997+
);
1998+
const syncedRepositories = syncedRepositoriesData?.me?.team?.projects;
1999+
if (!syncedRepositories?.length) {
2000+
return;
2001+
}
2002+
2003+
dashboard.repositories = syncedRepositories;
2004+
} catch (error) {
2005+
effects.notificationToast.error(
2006+
'There was a problem getting your repositories'
2007+
);
2008+
}
2009+
};
2010+
2011+
// If the repository page is accessed directly, we can use this
2012+
// to avoid fetching all repos.
2013+
export const getRepositoryByDetails = async (
2014+
{ state, effects }: Context,
2015+
{ owner, name }: { owner: string; name: string }
2016+
) => {
2017+
const { dashboard } = state;
2018+
try {
2019+
dashboard.repositories = null;
2020+
2021+
const repositoryData = await effects.gql.queries.getRepositoryByDetails({
2022+
owner,
2023+
name,
19772024
});
1978-
const v2Repositories = repositoriesData?.me?.team?.projects;
1979-
if (!v2Repositories?.length) {
2025+
const repository = repositoryData?.project;
2026+
if (!repository) {
19802027
return;
19812028
}
19822029

1983-
dashboard.repositories = v2Repositories;
2030+
dashboard.repositories = [repository];
19842031
} catch (error) {
19852032
effects.notificationToast.error(
1986-
'There was a problem getting your open repositories'
2033+
`There was a problem getting repository ${name} from ${owner}`
19872034
);
19882035
}
19892036
};

packages/app/src/app/pages/Dashboard/Content/routes/Repositories/index.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,34 @@ export const RepositoriesPage = () => {
1515
activeTeam,
1616
dashboard: { repositories },
1717
} = useAppState();
18+
const pathRef = React.useRef<string>(null);
1819

1920
React.useEffect(() => {
20-
actions.dashboard.getRepositoriesByTeam();
21-
}, [activeTeam, actions.dashboard]);
21+
// If no repositories were fetched yet and the user tries
22+
// to directly access a repository, we should fetch said
23+
// repository only.
24+
if (repositories === null) {
25+
if (path) {
26+
const [, owner, name] = path.split('/');
27+
actions.dashboard.getRepositoryByDetails({ owner, name });
28+
} else {
29+
actions.dashboard.getRepositoriesByTeam();
30+
}
31+
}
32+
33+
// If the current view is the list of the repositories
34+
// and the previous view was a repo and only that repo
35+
// was fetched, get all repositories of that team.
36+
if (
37+
path === '' &&
38+
pathRef.current?.startsWith('github') &&
39+
repositories.length === 1
40+
) {
41+
actions.dashboard.getRepositoriesByTeam();
42+
}
43+
44+
pathRef.current = path;
45+
}, [path]);
2246

2347
const pageType: PageTypes = 'repositories';
2448

0 commit comments

Comments
 (0)