-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5bdde5
commit 5651a98
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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,54 @@ | ||
import React, { useEffect, useMemo } from "react"; | ||
import { useRepoTree } from "./use-octokit"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select"; | ||
|
||
function ProjectSelection({ | ||
repo, | ||
branch, | ||
onSelect, | ||
}: { | ||
repo?: string; | ||
branch?: string; | ||
onSelect?: (val: string[]) => void; | ||
}) { | ||
const { data: repoData, isLoading } = useRepoTree(repo, branch); | ||
|
||
const data = useMemo(() => { | ||
if (!!repoData) { | ||
return repoData.filter( | ||
(i) => i.path?.endsWith(".csproj") && !i.path.endsWith(".Tests.csproj") | ||
); | ||
} | ||
|
||
return undefined; | ||
}, [repoData]); | ||
|
||
const _onSelect = (val: string) => { | ||
const parentFolder = val.split("/").slice(0, -2).join("/"); | ||
|
||
if (!repoData) return; | ||
|
||
onSelect?.(repoData.filter(i => parentFolder ? i.path?.startsWith(parentFolder + "/") : true).map(i => i.path!)); | ||
} | ||
|
||
if (isLoading || !data) return <div>Loading...</div>; | ||
|
||
return ( | ||
<Select onValueChange={e => _onSelect(e)}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select project" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{data.map(i => <SelectItem key={i.path} value={i.path || ''}>{i.path}</SelectItem>)} | ||
</SelectContent> | ||
</Select> | ||
); | ||
} | ||
|
||
export default ProjectSelection; |
This file contains 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 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