An open-source, faster Devin alternative
TypeScript
Board and item: keep what is loaded when a poll fails, with a quiet couldn't refresh
Igor Zalutski via Computerd9f783c4b614
diff --git a/web/src/managed-agents/work/Board.tsx b/web/src/managed-agents/work/Board.tsxindex eeedc647..bf1ed5c0 100644--- a/web/src/managed-agents/work/Board.tsx+++ b/web/src/managed-agents/work/Board.tsx@@ -78,7 +78,7 @@ export function Board() {const open = useOpenItems()const repository = open.data?.page.repository ?? null// Before a repository is chosen: is GitHub connected at all?- const noRepository = open.isSuccess && !repository+ const noRepository = open.data !== undefined && !repositoryconst installations = useGrantingInstallations(noRepository)const closed = useInfiniteQuery({queryKey: workKeys.closed(org),@@ -95,7 +95,9 @@ export function Board() {</div>)}- if (open.isError) {+ // A failed poll keeps the board it has (IndexStatus says it could not+ // refresh); the error screen is for when there is nothing to show.+ if (!open.data) {const missing = open.error instanceof ApiError && open.error.status === 404return (<BoardFrame>@@ -155,6 +157,7 @@ export function Board() {problem={repositoryProblem(page.repository)}building={page.building}asOf={page.asOf}+ refreshFailed={open.isError}/>)// Nothing to show yet: no tabs or filter, the lanes drawn as placeholders.@@ -425,11 +428,13 @@ function IndexStatus({problem,building,asOf,+ refreshFailed,}: {repository: stringproblem: string | nullbuilding: booleanasOf: string | null+ refreshFailed: boolean}) {return (<p className="text-muted-foreground flex flex-wrap items-center gap-x-1.5 text-xs">@@ -460,6 +465,7 @@ function IndexStatus({) : null}</>)}+ {refreshFailed ? <span>· Couldn't refresh</span> : null}</p>)}diff --git a/web/src/managed-agents/work/Item.tsx b/web/src/managed-agents/work/Item.tsxindex 601c1170..e52a2c08 100644--- a/web/src/managed-agents/work/Item.tsx+++ b/web/src/managed-agents/work/Item.tsx@@ -80,15 +80,18 @@ export function ItemView() {!(error instanceof ApiError && error.status === 404) && count < 2,})- if (!valid || item.isError) {- const status = item.error instanceof ApiError ? item.error.status : null- // The server's 404 for a number it does not track; any other 404 means- // the routes are not there yet, as on the board.- const noItem =- !valid ||- (status === 404 &&- item.error instanceof ApiError &&- item.error.type === 'item_not_found')+ const status = item.error instanceof ApiError ? item.error.status : null+ // The server's 404 for a number it does not track; any other 404 means+ // the routes are not there yet, as on the board.+ const noItem =+ !valid ||+ (status === 404 &&+ item.error instanceof ApiError &&+ item.error.type === 'item_not_found')+ // A failed poll keeps the item it has, with a quiet word that it could not+ // refresh; the error screen is for when there is nothing to show, or the+ // item is gone.+ if (noItem || (item.isError && !item.data)) {const { title, description } = noItem? {title: valid ? `No item ${number}` : 'No such item',@@ -125,7 +128,7 @@ export function ItemView() {</div>)}- if (item.isPending) {+ if (!item.data) {return (<div role="status" className="flex min-h-64 items-center justify-center"><Loader2 className="text-muted-foreground size-5 animate-spin" />@@ -136,7 +139,7 @@ export function ItemView() {const it = item.data.itemreturn (<div>- <Breadcrumb number={it.number} />+ <Breadcrumb number={it.number} refreshFailed={item.isError} /><ItemHeader item={it} /><div className="mt-8 grid gap-10 lg:grid-cols-[minmax(0,1fr)_20rem] lg:gap-0"><article className="min-w-0 lg:pr-12">@@ -192,19 +195,28 @@ export function ItemView() {)}-function Breadcrumb({ number }: { number: number | null }) {+function Breadcrumb({+ number,+ refreshFailed = false,+}: {+ number: number | null+ refreshFailed?: boolean+}) {return (- <nav aria-label="Breadcrumb" className="text-muted-foreground mb-3 text-xs">- <Link to="/computer/work" className="hover:text-foreground">- Board- </Link>- {number !== null ? (- <>- <span className="mx-1.5">/</span>- <span className="tabular-nums">{number}</span>- </>- ) : null}- </nav>+ <div className="text-muted-foreground mb-3 flex items-center gap-3 text-xs">+ <nav aria-label="Breadcrumb">+ <Link to="/computer/work" className="hover:text-foreground">+ Board+ </Link>+ {number !== null ? (+ <>+ <span className="mx-1.5">/</span>+ <span className="tabular-nums">{number}</span>+ </>+ ) : null}+ </nav>+ {refreshFailed ? <span>Couldn't refresh</span> : null}+ </div>)}diff --git a/web/src/managed-agents/work/screens.test.tsx b/web/src/managed-agents/work/screens.test.tsxindex eacb9ad8..a0f173ce 100644--- a/web/src/managed-agents/work/screens.test.tsx+++ b/web/src/managed-agents/work/screens.test.tsx@@ -108,6 +108,15 @@ async function render(url: string) {)})await settle()+ return client+}++// A poll that fails after the screen has loaded.+async function failRefetch(client: QueryClient) {+ await act(async () => {+ await client.refetchQueries({ queryKey: ['work'] })+ })+ await settle()}// Flushes until nothing is loading (the repository setting loads in two@@ -319,6 +328,20 @@ describe('board', () => {).toBe('acme/knowledge')})+ it('keeps the board when a poll fails, and says it could not refresh', async () => {+ workApi.getOpenItems.mockResolvedValue(openPage(items))+ const client = await render('/computer/work')+ expect(container.textContent).not.toContain("Couldn't refresh")+ workApi.getOpenItems.mockRejectedValue(new ApiError('Down', 500))+ await failRefetch(client)+ expect(titles(column('In progress'))).toContain('Mine, needs me')+ expect(container.textContent).toContain("Couldn't refresh")+ expect(container.textContent).not.toContain('Could not load the board')+ workApi.getOpenItems.mockResolvedValue(openPage(items))+ await failRefetch(client)+ expect(container.textContent).not.toContain("Couldn't refresh")+ })+it('reads a 404 as not available yet', async () => {workApi.getOpenItems.mockRejectedValue(new ApiError('Not found', 404))await render('/computer/work')@@ -613,6 +636,26 @@ describe('item page', () => {).toContain('abcdef1')})+ it('keeps the item when a poll fails, and says it could not refresh', async () => {+ workApi.getItem.mockResolvedValue({ item, body: '# Usage billing' })+ const client = await render('/computer/work/12')+ workApi.getItem.mockRejectedValue(new ApiError('Down', 500))+ await failRefetch(client)+ expect(container.querySelector('h1')?.textContent).toBe('12Usage billing')+ expect(container.textContent).toContain("Couldn't refresh")+ expect(container.textContent).not.toContain('Could not load this item')+ })++ it('says the item is gone when a poll finds it removed', async () => {+ workApi.getItem.mockResolvedValue({ item, body: '# Usage billing' })+ const client = await render('/computer/work/12')+ workApi.getItem.mockRejectedValue(+ new ApiError('No such item.', 404, 'item_not_found'),+ )+ await failRefetch(client)+ expect(container.textContent).toContain('No item 12')+ })+it('says when there is no such item, with a way back', async () => {workApi.getItem.mockRejectedValue(new ApiError('No such item.', 404, 'item_not_found'),