mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
fix(cloud): D4 section says the clone line once; rows show owner and visibility; Show more repositories
This commit is contained in:
@@ -159,6 +159,7 @@ export function NewWorkspaceComposerProjectSection({
|
||||
cloudRepoValue={cloudOnly?.picked?.fullName ?? null}
|
||||
onCloudRepoSelected={cloudOnly?.pick}
|
||||
onMoreCloudAccess={cloudOnly?.moreAccess}
|
||||
onShowMoreCloudRepos={cloudOnly?.showMore ?? null}
|
||||
placeholder={
|
||||
projectPlaceholder ??
|
||||
t('auto.components.NewWorkspaceComposerCard.dccd26d4e4', 'Choose project')
|
||||
|
||||
@@ -19,6 +19,7 @@ import type { OrcaCloudGitHubRepository } from '@/lib/orca-cloud/use-orca-cloud-
|
||||
import {
|
||||
CLOUD_REPO_KEY_PREFIX,
|
||||
CLOUD_REPO_MORE_KEY,
|
||||
CLOUD_REPO_SHOW_MORE_KEY,
|
||||
cloudRepoKey,
|
||||
filterCloudRepos,
|
||||
ProjectComboboxCloudSection
|
||||
@@ -40,6 +41,8 @@ type ProjectComboboxProps = {
|
||||
cloudRepoValue?: string | null
|
||||
onCloudRepoSelected?: (fullName: string) => void
|
||||
onMoreCloudAccess?: () => void
|
||||
/** Present while GitHub has more repositories than are listed. */
|
||||
onShowMoreCloudRepos?: (() => void) | null
|
||||
}
|
||||
|
||||
const ADD_PROJECT_KEY = 'add-project'
|
||||
@@ -59,7 +62,8 @@ export default function ProjectCombobox({
|
||||
cloudRepos = null,
|
||||
cloudRepoValue = null,
|
||||
onCloudRepoSelected,
|
||||
onMoreCloudAccess
|
||||
onMoreCloudAccess,
|
||||
onShowMoreCloudRepos = null
|
||||
}: ProjectComboboxProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const [tooltipOpen, setTooltipOpen] = useState(false)
|
||||
@@ -76,10 +80,11 @@ export default function ProjectCombobox({
|
||||
...(cloudRepos
|
||||
? filterCloudRepos(cloudRepos, query).map((repo) => cloudRepoKey(repo.fullName))
|
||||
: []),
|
||||
...(cloudRepos && onShowMoreCloudRepos ? [CLOUD_REPO_SHOW_MORE_KEY] : []),
|
||||
...(cloudRepos && onMoreCloudAccess ? [CLOUD_REPO_MORE_KEY] : []),
|
||||
...(onAddProject ? [ADD_PROJECT_KEY] : [])
|
||||
],
|
||||
[cloudRepos, onAddProject, onMoreCloudAccess, options, recentIds]
|
||||
[cloudRepos, onAddProject, onMoreCloudAccess, onShowMoreCloudRepos, options, recentIds]
|
||||
)
|
||||
const {
|
||||
query,
|
||||
@@ -123,6 +128,11 @@ export default function ProjectCombobox({
|
||||
if (key === null) {
|
||||
return
|
||||
}
|
||||
if (key === CLOUD_REPO_SHOW_MORE_KEY) {
|
||||
// Keep the list open: the next page appends in place.
|
||||
onShowMoreCloudRepos?.()
|
||||
return
|
||||
}
|
||||
close()
|
||||
if (key === ADD_PROJECT_KEY) {
|
||||
onAddProject?.()
|
||||
@@ -139,7 +149,15 @@ export default function ProjectCombobox({
|
||||
onValueChange(key)
|
||||
onValueSelected?.(key)
|
||||
},
|
||||
[close, onAddProject, onCloudRepoSelected, onMoreCloudAccess, onValueChange, onValueSelected]
|
||||
[
|
||||
close,
|
||||
onAddProject,
|
||||
onCloudRepoSelected,
|
||||
onMoreCloudAccess,
|
||||
onShowMoreCloudRepos,
|
||||
onValueChange,
|
||||
onValueSelected
|
||||
]
|
||||
)
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
@@ -358,6 +376,7 @@ export default function ProjectCombobox({
|
||||
onArm={arm}
|
||||
onCommit={commit}
|
||||
showMoreAccess={Boolean(onMoreCloudAccess)}
|
||||
showMoreRepos={Boolean(onShowMoreCloudRepos)}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
// Cloud can reach with no clone on this computer, plus a way to give it access to more. Shown only
|
||||
// while Orca Cloud is the Run on target.
|
||||
import React from 'react'
|
||||
import { Check, Github, Plus } from 'lucide-react'
|
||||
import { Check, ChevronDown, Github, Plus } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import type { OrcaCloudGitHubRepository } from '@/lib/orca-cloud/use-orca-cloud-github-repositories'
|
||||
|
||||
export const CLOUD_REPO_KEY_PREFIX = 'github:'
|
||||
export const CLOUD_REPO_MORE_KEY = 'github-more-access'
|
||||
export const CLOUD_REPO_SHOW_MORE_KEY = 'github-show-more'
|
||||
|
||||
export function cloudRepoKey(fullName: string): string {
|
||||
return `${CLOUD_REPO_KEY_PREFIX}${fullName}`
|
||||
@@ -30,7 +31,8 @@ export function ProjectComboboxCloudSection({
|
||||
armedId,
|
||||
onArm,
|
||||
onCommit,
|
||||
showMoreAccess
|
||||
showMoreAccess,
|
||||
showMoreRepos = false
|
||||
}: {
|
||||
repos: readonly OrcaCloudGitHubRepository[]
|
||||
value: string | null
|
||||
@@ -39,6 +41,8 @@ export function ProjectComboboxCloudSection({
|
||||
onArm: (key: string) => void
|
||||
onCommit: (key: string) => void
|
||||
showMoreAccess: boolean
|
||||
/** GitHub has more pages than are listed. */
|
||||
showMoreRepos?: boolean
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
if (repos.length === 0 && !showMoreAccess) {
|
||||
@@ -65,11 +69,17 @@ export function ProjectComboboxCloudSection({
|
||||
)
|
||||
return (
|
||||
<div role="group" aria-label={heading}>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="px-2 pt-2.5 pb-1 text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase"
|
||||
>
|
||||
{heading}
|
||||
<div aria-hidden="true" className="px-2 pt-2.5 pb-1">
|
||||
<div className="text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase">
|
||||
{heading}
|
||||
</div>
|
||||
{/* Said once for the section; rows carry what tells them apart. */}
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{t(
|
||||
'components.newWorkspace.cloudOnly.detail',
|
||||
'Orca Cloud clones it. No copy on this computer needed.'
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{repos.map((repo) => {
|
||||
const key = cloudRepoKey(repo.fullName)
|
||||
@@ -85,10 +95,13 @@ export function ProjectComboboxCloudSection({
|
||||
{repo.fullName}
|
||||
</span>
|
||||
<span className="min-w-0 truncate text-xs text-muted-foreground">
|
||||
{t(
|
||||
'components.newWorkspace.cloudOnly.detail',
|
||||
'Orca Cloud clones it. No copy on this computer needed.'
|
||||
)}
|
||||
{repo.private
|
||||
? t('components.newWorkspace.cloudOnly.private', '{{owner}} · Private', {
|
||||
owner: repo.fullName.split('/')[0] ?? repo.fullName
|
||||
})
|
||||
: t('components.newWorkspace.cloudOnly.public', '{{owner}} · Public', {
|
||||
owner: repo.fullName.split('/')[0] ?? repo.fullName
|
||||
})}
|
||||
</span>
|
||||
</span>
|
||||
{current ? (
|
||||
@@ -102,6 +115,19 @@ export function ProjectComboboxCloudSection({
|
||||
</>
|
||||
)
|
||||
})}
|
||||
{showMoreRepos
|
||||
? row(
|
||||
CLOUD_REPO_SHOW_MORE_KEY,
|
||||
<>
|
||||
<span className="flex h-5 w-4 shrink-0 items-center justify-center">
|
||||
<ChevronDown aria-hidden className="size-3.5 text-muted-foreground" />
|
||||
</span>
|
||||
<span className="min-w-0 truncate text-muted-foreground">
|
||||
{t('components.newWorkspace.cloudOnly.showMore', 'Show more repositories…')}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
: null}
|
||||
{showMoreAccess
|
||||
? row(
|
||||
CLOUD_REPO_MORE_KEY,
|
||||
|
||||
@@ -219,7 +219,8 @@ export const d3NotOnGitHub = defineFixture({
|
||||
})
|
||||
const cloudRepos = [
|
||||
{ fullName: 'acme/billing', url: 'https://github.com/acme/billing', private: true },
|
||||
{ fullName: 'acme/infra', url: 'https://github.com/acme/infra', private: true }
|
||||
{ fullName: 'acme/infra', url: 'https://github.com/acme/infra', private: true },
|
||||
{ fullName: 'acme/docs', url: 'https://github.com/acme/docs', private: false }
|
||||
]
|
||||
/** D4: Orca Cloud picked; the Project picker adds GitHub repositories with no clone here. */
|
||||
export const d4GitHubProjects = defineFixture({
|
||||
|
||||
@@ -102,6 +102,7 @@ export function ComposerPreview({
|
||||
? {
|
||||
cloudOnly: {
|
||||
repos: cloudRepos,
|
||||
showMore: () => {},
|
||||
picked: cloudRepos.find((repo) => repo.fullName === picked) ?? null,
|
||||
githubStep: null,
|
||||
pick: setPicked,
|
||||
|
||||
@@ -14,6 +14,8 @@ import type { CloudSetupStep } from './cloud-start-model'
|
||||
|
||||
export type CloudOnlyRepo = {
|
||||
repos: readonly OrcaCloudGitHubRepository[] | null
|
||||
/** Fetches GitHub's next pages; null when everything is listed. */
|
||||
showMore: (() => void) | null
|
||||
picked: OrcaCloudGitHubRepository | null
|
||||
/** The GitHub row is done for a repository listed from the team's installations. */
|
||||
githubStep: CloudSetupStep | null
|
||||
@@ -32,7 +34,7 @@ export function useCloudOnlyRepo({
|
||||
/** The list needs an account; signed out, setup comes first. */
|
||||
signedIn: boolean
|
||||
}): CloudOnlyRepo {
|
||||
const repos = useOrcaCloudGitHubRepositories(enabled && signedIn)
|
||||
const { repos, showMore } = useOrcaCloudGitHubRepositories(enabled && signedIn)
|
||||
const [pickedName, setPickedName] = useState<string | null>(null)
|
||||
const picked = useMemo(
|
||||
() => (enabled ? (repos?.find((repo) => repo.fullName === pickedName) ?? null) : null),
|
||||
@@ -66,7 +68,7 @@ export function useCloudOnlyRepo({
|
||||
: Promise.resolve(false),
|
||||
[picked]
|
||||
)
|
||||
return { repos, picked, githubStep, pick: setPickedName, clear, moreAccess, start }
|
||||
return { repos, showMore, picked, githubStep, pick: setPickedName, clear, moreAccess, start }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23137,7 +23137,10 @@
|
||||
"notOnThisComputer": "Not on this computer · Orca Cloud only",
|
||||
"startFailed": "Couldn’t start the cloud workspace. Nothing was created, and you weren’t charged.",
|
||||
"starting": "Starting {{repo}} in Orca Cloud…",
|
||||
"openLater": "Your cloud workspace started, but this computer couldn’t open it yet. Open it from Cloud workspaces."
|
||||
"openLater": "Your cloud workspace started, but this computer couldn’t open it yet. Open it from Cloud workspaces.",
|
||||
"private": "{{owner}} · Private",
|
||||
"public": "{{owner}} · Public",
|
||||
"showMore": "Show more repositories…"
|
||||
}
|
||||
},
|
||||
"JiraIssueWorkspace": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Repositories Orca Cloud can reach on GitHub that have no clone on this computer (cloud-start D4,
|
||||
// N12): the Project picker lists them under "On GitHub · Orca Cloud only" while Orca Cloud is
|
||||
// picked, because a sandbox clones from GitHub anyway.
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useAppStore } from '@/store'
|
||||
import type { HostedGithubRepositoriesResponse } from '../../../../shared/hosted-sandbox/hosted-github-wire'
|
||||
import { orcaCloudGitHubRepoUrl } from './use-orca-cloud-repo-access'
|
||||
@@ -13,39 +13,53 @@ export type OrcaCloudGitHubRepository = {
|
||||
private: boolean
|
||||
}
|
||||
|
||||
/** Two pages cover nearly every team; the rest is a search away on GitHub's own page. */
|
||||
const MAX_PAGES = 2
|
||||
/** Two pages at a time cover nearly every team; "Show more repositories…" fetches the next two. */
|
||||
const PAGES_PER_LOAD = 2
|
||||
const CACHE_MS = 5 * 60_000
|
||||
|
||||
let cache: { at: number; value: Promise<OrcaCloudGitHubRepository[]> } | null = null
|
||||
type Listing = { repos: OrcaCloudGitHubRepository[]; nextCursor: string | null }
|
||||
|
||||
async function fetchAll(): Promise<OrcaCloudGitHubRepository[]> {
|
||||
const out: OrcaCloudGitHubRepository[] = []
|
||||
let cursor: string | null = null
|
||||
for (let page = 0; page < MAX_PAGES; page += 1) {
|
||||
let cache: { at: number; value: Promise<Listing> } | null = null
|
||||
|
||||
async function fetchPages(after: Listing): Promise<Listing> {
|
||||
const repos = [...after.repos]
|
||||
let cursor = after.nextCursor
|
||||
for (let page = 0; page < PAGES_PER_LOAD; page += 1) {
|
||||
const result = await window.api.orcaCloudWorkspace.listGitHubRepositories({ cursor })
|
||||
if (!result.ok) {
|
||||
break
|
||||
}
|
||||
const value: HostedGithubRepositoriesResponse = result.value
|
||||
for (const repo of value.repositories) {
|
||||
out.push({ fullName: repo.fullName, url: repo.url, private: repo.private })
|
||||
repos.push({ fullName: repo.fullName, url: repo.url, private: repo.private })
|
||||
}
|
||||
cursor = value.nextCursor
|
||||
if (!cursor) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return out
|
||||
return { repos, nextCursor: cursor }
|
||||
}
|
||||
|
||||
function loadRepositories(): Promise<OrcaCloudGitHubRepository[]> {
|
||||
function loadRepositories(more = false): Promise<Listing> {
|
||||
const now = Date.now()
|
||||
if (!cache || now - cache.at >= CACHE_MS) {
|
||||
const entry = { at: now, value: fetchAll().catch(() => []) }
|
||||
cache = entry
|
||||
cache = { at: now, value: fetchPages({ repos: [], nextCursor: null }) }
|
||||
} else if (more) {
|
||||
const previous = cache.value
|
||||
cache = {
|
||||
at: cache.at,
|
||||
value: previous.then((listing) => (listing.nextCursor ? fetchPages(listing) : listing))
|
||||
}
|
||||
}
|
||||
return cache.value
|
||||
const entry = cache
|
||||
// A failed read isn't cached: the next open asks again.
|
||||
return entry.value.catch(() => {
|
||||
if (cache === entry) {
|
||||
cache = null
|
||||
}
|
||||
return { repos: [], nextCursor: null }
|
||||
})
|
||||
}
|
||||
|
||||
/** Forget the list after the user gives Orca Cloud access to more repositories. */
|
||||
@@ -75,33 +89,38 @@ export function selectCloudOnlyRepositories(
|
||||
.sort((a, b) => a.fullName.localeCompare(b.fullName))
|
||||
}
|
||||
|
||||
export function useOrcaCloudGitHubRepositories(
|
||||
enabled: boolean
|
||||
): OrcaCloudGitHubRepository[] | null {
|
||||
export function useOrcaCloudGitHubRepositories(enabled: boolean): {
|
||||
repos: OrcaCloudGitHubRepository[] | null
|
||||
/** Present while GitHub has more pages than are listed. */
|
||||
showMore: (() => void) | null
|
||||
} {
|
||||
const repos = useAppStore((s) => s.repos)
|
||||
const [reachable, setReachable] = useState<OrcaCloudGitHubRepository[] | null>(null)
|
||||
const [listing, setListing] = useState<Listing | null>(null)
|
||||
const [moreRequests, setMoreRequests] = useState(0)
|
||||
useEffect(() => {
|
||||
if (!enabled) {
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
void loadRepositories().then((value) => {
|
||||
void loadRepositories(moreRequests > 0).then((value) => {
|
||||
if (!cancelled) {
|
||||
setReachable(value)
|
||||
setListing(value)
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [enabled])
|
||||
return useMemo(
|
||||
}, [enabled, moreRequests])
|
||||
const visible = useMemo(
|
||||
() =>
|
||||
enabled && reachable
|
||||
enabled && listing
|
||||
? selectCloudOnlyRepositories(
|
||||
reachable,
|
||||
listing.repos,
|
||||
repos.map((repo) => orcaCloudGitHubRepoUrl(repo))
|
||||
)
|
||||
: null,
|
||||
[enabled, reachable, repos]
|
||||
[enabled, listing, repos]
|
||||
)
|
||||
const showMore = useCallback(() => setMoreRequests((n) => n + 1), [])
|
||||
return { repos: visible, showMore: enabled && listing?.nextCursor ? showMore : null }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user