-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Setup data loading for repos list #18935
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC } from "react"; | ||
|
||
type Props = { | ||
className?: string; | ||
children: string; | ||
}; | ||
export const RepositoryURL: FC<Props> = ({ className, children }) => { | ||
const cleanURL = children.endsWith(".git") ? children.slice(0, -4) : children; | ||
|
||
return <span className={className}>{cleanURL}</span>; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import classNames, { Argument } from "classnames"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
// Helper type to add a className prop to a component | ||
export type PropsWithClassName<Props = {}> = { | ||
className?: string; | ||
} & Props; | ||
|
||
// Helper fn to merge tailwind classes with a className prop | ||
export function cn(...inputs: Argument[]) { | ||
return twMerge(classNames(inputs)); | ||
} |
14 changes: 14 additions & 0 deletions
14
components/dashboard/src/components/podkit/typography/Text.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC, PropsWithChildren } from "react"; | ||
import { PropsWithClassName, cn } from "@podkit/lib/cn"; | ||
|
||
type TextProps = PropsWithChildren<PropsWithClassName>; | ||
|
||
export const Text: FC<TextProps> = ({ className, children }) => { | ||
return <span className={cn("text-black dark:text-white", className)}>{children}</span>; | ||
}; |
14 changes: 14 additions & 0 deletions
14
components/dashboard/src/components/podkit/typography/TextMuted.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC, PropsWithChildren } from "react"; | ||
import { PropsWithClassName, cn } from "@podkit/lib/cn"; | ||
|
||
type TextMutedProps = PropsWithChildren<PropsWithClassName>; | ||
|
||
export const TextMuted: FC<TextMutedProps> = ({ className, children }) => { | ||
return <span className={cn("text-gray-500 dark:text-gray-400", className)}>{children}</span>; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
components/dashboard/src/data/projects/list-all-projects-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { Project } from "@gitpod/gitpod-protocol"; | ||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import { useCallback } from "react"; | ||
import { listAllProjects } from "../../service/public-api"; | ||
import { useCurrentOrg } from "../organizations/orgs-query"; | ||
|
||
export type ListAllProjectsQueryResults = { | ||
projects: Project[]; | ||
}; | ||
|
||
export const useListAllProjectsQuery = () => { | ||
const org = useCurrentOrg().data; | ||
const orgId = org?.id; | ||
return useQuery<ListAllProjectsQueryResults>({ | ||
enabled: !!orgId, | ||
queryKey: getListAllProjectsQueryKey(orgId || ""), | ||
cacheTime: 1000 * 60 * 60 * 1, // 1 hour | ||
queryFn: async () => { | ||
if (!orgId) { | ||
return { | ||
projects: [], | ||
latestPrebuilds: new Map(), | ||
}; | ||
} | ||
|
||
const projects = await listAllProjects({ orgId }); | ||
return { | ||
projects, | ||
}; | ||
}, | ||
}); | ||
}; | ||
|
||
// helper to force a refresh of the list projects query | ||
export const useRefreshAllProjects = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useCallback( | ||
async (orgId: string) => { | ||
// Don't refetch if no org is provided | ||
if (!orgId) { | ||
return; | ||
} | ||
|
||
return await queryClient.refetchQueries({ | ||
queryKey: getListAllProjectsQueryKey(orgId), | ||
}); | ||
}, | ||
[queryClient], | ||
); | ||
}; | ||
|
||
export const getListAllProjectsQueryKey = (orgId: string) => { | ||
return ["projects", "list-all", { orgId }]; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
export const usePrettyRepoURL = (url: string) => { | ||
return url.endsWith(".git") ? url.slice(0, -4) : url; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
components/dashboard/src/repositories/list/RepoListItem.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC } from "react"; | ||
import { usePrettyRepoURL } from "../../hooks/use-pretty-repo-url"; | ||
import { TextMuted } from "@podkit/typography/TextMuted"; | ||
import { Text } from "@podkit/typography/Text"; | ||
import { Link } from "react-router-dom"; | ||
import { Button } from "../../components/Button"; | ||
import { Project } from "@gitpod/public-api/lib/gitpod/experimental/v1/projects_pb"; | ||
|
||
type Props = { | ||
project: Project; | ||
}; | ||
export const RepositoryListItem: FC<Props> = ({ project }) => { | ||
const url = usePrettyRepoURL(project.cloneUrl); | ||
|
||
return ( | ||
<li key={project.id} className="flex flex-row w-full space-between items-center"> | ||
<div className="flex flex-col flex-grow gap-1"> | ||
<Text className="font-semibold">{project.name}</Text> | ||
<TextMuted className="text-sm">{url}</TextMuted> | ||
</div> | ||
|
||
<div> | ||
<Link to={`/repositories/${project.id}`}> | ||
<Button type="secondary">View</Button> | ||
</Link> | ||
</div> | ||
</li> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could potentially change this to omit the scheme in the future, as I don't think it makes much of a difference with all of them being http/https.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'll def do that in a followup, mostly an oversight 😄