fix(forge): remove saved comment cards from the changes view (#8653)
* fix(forge): remove saved comment cards from the changes view A comment added to the main input left a card beside its code that the reader could not remove, also after its code changed or its file left the diff. The card's menu now offers Remove for a reference and for a publication receipt; the notice that follows offers Undo, which puts the card back at its place. Removing a card changes neither the main input nor the code host. The three browser-kept cards share the thread card's geometry and its header menu. A browser draft's Edit and Delete move into the menu, its deletion asks first, and its move into the pending review is named Start review while the user has none, as the comment form names it. The card title "Your comment" is gone: the header shows the lines and the state. * fix(forge): keep a draft's Delete while it is edited and let the view name each notice's tone A browser draft being edited hid its menu, so a draft whose text the reader emptied could be neither finished nor deleted. The menu now stays during editing and offers Delete, which asks first as before. The changes view passed its notices to a per-mount function that chose the tone from a list of keys and forwarded the undo action. A second mount with its own copy of that function would show a removal as a failure without Undo. The view now passes the tone and the undo action with each notice, and the mount hands them to the notice store as given.
This commit is contained in:
1 parent
8a96cba995
commit
afca6e729a
16 files changed
+463
-123
No files matched your search
@@ -1142,6 +1142,14 @@ it.skipIf(MODE === 'record')('shows the local changes of the Session by scope an
|
||||
await captureStableAria(page, '[data-composer-input]', scaffold.workspaceCwd), MODE)
|
||||
expect((await readPersistedEvents(scaffold, sessionId)).some(event => event.type === 'user/message'
|
||||
&& event.data.content.some(block => block.type === 'text' && block.text.includes('## User Comment')))).toBe(false)
|
||||
// Removing a reference card leaves its quote in the composer, and the notice's Undo puts the card back at its line.
|
||||
const extra = local.locator('[data-forge-diff-file="src/extra.ts"]')
|
||||
await extra.getByRole('button', { name: '评论 R1 的操作', exact: true }).click()
|
||||
await page.getByRole('menuitem', { name: '移除', exact: true }).click()
|
||||
await expect.poll(() => extra.locator('[data-forge-review-thread]').count()).toBe(0)
|
||||
expect(await page.locator('[data-composer-input]').first().innerText()).toContain('请检查这项修改')
|
||||
await page.getByRole('alert').filter({ hasText: '已移除' }).getByRole('button', { name: '撤销', exact: true }).click()
|
||||
await extra.locator('[data-forge-review-thread="agent"]').getByText('请检查这项修改', { exact: true }).waitFor()
|
||||
const reviewed = scaffold.whenTurnSettled()
|
||||
await page.locator('[data-composer-input]').first().press('Enter')
|
||||
await reviewed
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 2f8a621b991260a1
|
||||
/deepseek-ai-dsh-experimental-client-ui-forge/use-this-package:
|
||||
en: 2c853cfbae8b7cfd
|
||||
zh: 82148507cefd6d17
|
||||
en: c2b46d13622b98ab
|
||||
zh: f8b61ca06bc89bc0
|
||||
/deepseek-ai-dsh-experimental-client-ui-forge/understand-the-implementation:
|
||||
en: 4778e1dca2c6ff47
|
||||
zh: a8589b3e950a8ca1
|
||||
|
||||
@@ -51,7 +51,7 @@ The diff follows the file tree’s depth-first order: directories before files,
|
||||
|
||||
`gitCommand`, `gitTimeoutMs`, `graceMs`, `maxOutputBytes`, `readinessTimeoutMs`, `maxBranches`, `worktreePrefix`, `maxDiffBytes`, `maxUntrackedFiles`, `maxCachedDiffBytes`, `maxCachedReviewBytes`, `reviewRefreshMs`, `maxCommits`, `testPaths`, `interfacePaths`, `lensTimeoutMs`, `maxLensReadBytes`, `maxCachedLensBytes`, and `maxAnnotationsPerFile` are listed in the [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-experimental-client-ui-forge).
|
||||
|
||||
All files opens a searchable directory tree with the selected file scrolled to its middle. Single-child directories share a row, and renamed files also match their old path. A wide changes pane shows the same tree beside the diff; its File tree toolbar button cycles through left, right, and hidden, starting on the left. Its accessible name describes the next action, and focus stays on the button when it moves or hides the tree. The search, folds, selection, and width survive moving or hiding the tree and switching tabs or Sessions. Drag the divider or use its arrow keys to resize the tree, which stays at least as wide as the lens above it needs to show the layer names whole. Files and folders reserve the same disclosure column so each child is indented from its parent. The tree already shows each directory, so only a renamed file names both paths, in a tooltip after 500ms of hover; a name its row clips crawls into view while the pointer rests on the row. Local changes and each PR retain separate tabs. Select code text or use line numbers to select a range within one displayed hunk and side; text selection and copying stay on the starting side. The plus button opens the plain-text comment editor. With a mouse, hovering a line also shows a plus beside its line number, which stays clickable, on the hovered side in two columns and on the line's own side in one column; pressing it selects that line, dragging extends the range on that side, and releasing opens the editor. Several editors can stay open at once, and choosing the range of an open one focuses it again. In two columns, each comment sits under its own side of the row, so a left and a right comment share that row side by side, each continuing its line’s background. It accepts newlines and IME composition; only its action buttons submit the comment. Drag its lower edge to adjust the height. Add to input inserts a removable quote into the main composer that shows the file name, side and lines, and comment, and on hover the file path; multiple quotes are sent together only when the user sends that composer. Once the review threads are read and the user may review, the split button adds the comment to the user's pending review on the code host, starting one when there is none; the comment then shows as a thread tagged Pending, which only the user sees until the review is submitted. Its menu publishes a single comment immediately and is absent while the user has a pending review. Agent references and published comments remain beside their code. Request changes requires a review summary; the dialog explains this beside the summary field and announces the requirement when the decision changes. Submit review in the PR title bar opens a centered dialog showing only the pending count, summary, and Comment, Approve, or Request changes. With a pending review, it submits that review, keeping a submission whose outcome is unknown blocked until the user checks GitHub, as a direct submission is, and Discard review deletes the review and its comments after a confirmation; without one, it publishes the summary as one review. Decisions the code host does not let the user record are unavailable, such as Approve and Request changes on the user's own pull request on GitHub; when only Comment remains, the dialog says so. The view's copy names the code host and its word for a change request, such as GitHub and PR, after the change request's provider. Added and deleted files show only their populated line-number column. The summary, decision, and records of Agent references and published comments are stored in this browser per Session and tab, including the original PR head commit. Switching Sessions or hiding the pane retains them; closing the tab clears them, and reopening starts an empty summary. The pending review, published GitHub comments, and references already added to the main composer are unaffected. Comment drafts an earlier version kept in this browser stay beside their code tagged Browser draft and can be edited, deleted, or added to the pending review; they keep Submit review disabled while a pending review exists, and without one Submit review publishes them with the summary. Records whose code changed remain visible below their file, or after the diff when the file is absent. A changed head requires fresh line selections. While the tab remains open, an uncertain write stays blocked across reloads until the user checks GitHub and explicitly permits another submission.
|
||||
All files opens a searchable directory tree with the selected file scrolled to its middle. Single-child directories share a row, and renamed files also match their old path. A wide changes pane shows the same tree beside the diff; its File tree toolbar button cycles through left, right, and hidden, starting on the left. Its accessible name describes the next action, and focus stays on the button when it moves or hides the tree. The search, folds, selection, and width survive moving or hiding the tree and switching tabs or Sessions. Drag the divider or use its arrow keys to resize the tree, which stays at least as wide as the lens above it needs to show the layer names whole. Files and folders reserve the same disclosure column so each child is indented from its parent. The tree already shows each directory, so only a renamed file names both paths, in a tooltip after 500ms of hover; a name its row clips crawls into view while the pointer rests on the row. Local changes and each PR retain separate tabs. Select code text or use line numbers to select a range within one displayed hunk and side; text selection and copying stay on the starting side. The plus button opens the plain-text comment editor. With a mouse, hovering a line also shows a plus beside its line number, which stays clickable, on the hovered side in two columns and on the line's own side in one column; pressing it selects that line, dragging extends the range on that side, and releasing opens the editor. Several editors can stay open at once, and choosing the range of an open one focuses it again. In two columns, each comment sits under its own side of the row, so a left and a right comment share that row side by side, each continuing its line’s background. It accepts newlines and IME composition; only its action buttons submit the comment. Drag its lower edge to adjust the height. Add to input inserts a removable quote into the main composer that shows the file name, side and lines, and comment, and on hover the file path; multiple quotes are sent together only when the user sends that composer. Once the review threads are read and the user may review, the split button adds the comment to the user's pending review on the code host, starting one when there is none; the comment then shows as a thread tagged Pending, which only the user sees until the review is submitted. Its menu publishes a single comment immediately and is absent while the user has a pending review. Agent references and published comments remain beside their code as cards that name their lines and state; Remove in a card's menu takes the card out of the view, leaves the main composer and the code host unchanged, and shows a notice that offers Undo. Request changes requires a review summary; the dialog explains this beside the summary field and announces the requirement when the decision changes. Submit review in the PR title bar opens a centered dialog showing only the pending count, summary, and Comment, Approve, or Request changes. With a pending review, it submits that review, keeping a submission whose outcome is unknown blocked until the user checks GitHub, as a direct submission is, and Discard review deletes the review and its comments after a confirmation; without one, it publishes the summary as one review. Decisions the code host does not let the user record are unavailable, such as Approve and Request changes on the user's own pull request on GitHub; when only Comment remains, the dialog says so. The view's copy names the code host and its word for a change request, such as GitHub and PR, after the change request's provider. Added and deleted files show only their populated line-number column. The summary, decision, and records of Agent references and published comments are stored in this browser per Session and tab, including the original PR head commit. Switching Sessions or hiding the pane retains them; closing the tab clears them, and reopening starts an empty summary. The pending review, published GitHub comments, and references already added to the main composer are unaffected. Comment drafts an earlier version kept in this browser stay beside their code tagged Browser draft and can be edited, deleted after a confirmation, or added to the pending review; they keep Submit review disabled while a pending review exists, and without one Submit review publishes them with the summary. Records whose code changed remain visible below their file, or after the diff when the file is absent. A changed head requires fresh line selections. While the tab remains open, an uncertain write stays blocked across reloads until the user checks GitHub and explicitly permits another submission.
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ diff 按文件树的深度优先顺序排列:同层目录在前、文件在后
|
||||
|
||||
`gitCommand`、`gitTimeoutMs`、`graceMs`、`maxOutputBytes`、`readinessTimeoutMs`、`maxBranches`、`worktreePrefix`、`maxDiffBytes`、`maxUntrackedFiles`、`maxCachedDiffBytes`、`maxCachedReviewBytes`、`reviewRefreshMs`、`maxCommits`、`testPaths`、`interfacePaths`、`lensTimeoutMs`、`maxLensReadBytes`、`maxCachedLensBytes` 与 `maxAnnotationsPerFile` 列在[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-experimental-client-ui-forge)中。
|
||||
|
||||
“全部文件”打开可搜索的目录树,并把选中文件滚动到中间;只有一个子目录的路径会合并显示,重命名文件也可以按旧路径搜索。较宽的变更面板会在 diff 旁显示同一棵树,工具栏的“文件树”按钮按“左侧 → 右侧 → 隐藏”循环切换,默认显示在左侧。按钮的无障碍名称说明下一步操作,移动或隐藏文件树时焦点仍留在按钮上。移动或隐藏文件树,以及切换标签页与 Session 时保留搜索、折叠状态、选中文件和宽度。拖动分隔线,或聚焦分隔线后使用方向键,可以调整文件树宽度;文件树至少保持上方透镜完整显示各层名称所需的宽度。文件与文件夹预留相同的展开箭头列,子项相对父目录向内缩进。树已经表示了目录,所以只有重命名的文件会在悬停 500ms 后用提示显示新旧两条路径;文件名放不下时,指针停在这一行上会滚动显示全文。本地变更与每个 PR 保留独立标签页。划选代码文字或通过行号选择同一已显示 hunk、同一侧的连续行,文字划选与复制都限定在起始侧。点击“+”打开纯文本评论框。使用鼠标时,悬停在某一行上也会在其行号旁显示“+”,行号仍可点击:两栏时显示在悬停的一侧,单栏时显示在该行所属的一侧;按下即选中这一行,拖动可在同一侧扩展范围,松开即打开评论框。可以同时打开多个评论框,再次选中已打开评论框的范围会回到该评论框。两栏时每条评论位于该行自己一侧的下方,左右两侧的评论并排处在同一行,各自延续所在行的底色。评论框支持换行和输入法组合输入,只有点击操作按钮才提交。可拖动底边调整高度。“添加到输入框”将评论作为可移除的引用加入主输入框,引用显示文件名、侧与行号以及评论,悬停时显示文件路径;多条引用只会在用户发送主输入框时一起发送。读到评审讨论且用户可以评审时,分段按钮会把这条评论加入用户在代码托管平台上的待提交评审,没有时先开始一个;评论随后显示为带“待提交”标签的讨论,提交评审之前只有用户自己能看到。下拉菜单可以立即发布单条评论;用户有待提交评审时没有该菜单。Agent 引用和已发布的评论保留在对应代码旁。“请求更改”需要填写评审总结,弹窗在总结输入框旁说明此要求,并在切换评审决定时播报。PR 标题栏中的“提交评审”打开居中弹窗,只显示待提交数量、总结以及“评论”“批准”“请求更改”选项。有待提交评审时提交该评审,结果不明的提交与直接提交一样,在用户到 GitHub 核对之前阻止再次提交;“丢弃评审”在确认后删除该评审及其中的评论;没有待提交评审时,把总结作为一次评审发布。代码托管平台不允许用户记录的结论不可用,例如在 GitHub 上用户自己的 PR 里,“批准”和“请求更改”不可用;只剩“评论”时,对话框会说明。视图中的文案按变更请求的提供方称呼代码托管平台及其对变更请求的叫法,例如 GitHub 和 PR。新建和删除文件只显示有内容的一侧行号。总结、评审决定,以及 Agent 引用与已发布评论的记录按 Session 和页签保存在当前浏览器,包括最初评审的 head。切换 Session 或隐藏面板时保留;关闭页签会清空它们,重新打开从空总结开始。待提交评审、已发布到 GitHub 的评论与已加入主输入框的引用不受影响。早期版本保存在此浏览器中的评论草稿保留在对应代码旁,带“浏览器草稿”标签,可以编辑、删除或加入待提交评审;存在待提交评审时,它们会让“提交评审”保持不可用;没有待提交评审时,“提交评审”把它们连同总结一起发布。head 变化后需要重新选择评论行。代码变化后的记录保留在文件末尾;文件已不在 diff 中时,记录显示在 diff 之后。页签保持打开时,结果不明的提交在重新加载后仍会阻止重复发送,直到用户检查 GitHub 并明确允许再次提交。
|
||||
“全部文件”打开可搜索的目录树,并把选中文件滚动到中间;只有一个子目录的路径会合并显示,重命名文件也可以按旧路径搜索。较宽的变更面板会在 diff 旁显示同一棵树,工具栏的“文件树”按钮按“左侧 → 右侧 → 隐藏”循环切换,默认显示在左侧。按钮的无障碍名称说明下一步操作,移动或隐藏文件树时焦点仍留在按钮上。移动或隐藏文件树,以及切换标签页与 Session 时保留搜索、折叠状态、选中文件和宽度。拖动分隔线,或聚焦分隔线后使用方向键,可以调整文件树宽度;文件树至少保持上方透镜完整显示各层名称所需的宽度。文件与文件夹预留相同的展开箭头列,子项相对父目录向内缩进。树已经表示了目录,所以只有重命名的文件会在悬停 500ms 后用提示显示新旧两条路径;文件名放不下时,指针停在这一行上会滚动显示全文。本地变更与每个 PR 保留独立标签页。划选代码文字或通过行号选择同一已显示 hunk、同一侧的连续行,文字划选与复制都限定在起始侧。点击“+”打开纯文本评论框。使用鼠标时,悬停在某一行上也会在其行号旁显示“+”,行号仍可点击:两栏时显示在悬停的一侧,单栏时显示在该行所属的一侧;按下即选中这一行,拖动可在同一侧扩展范围,松开即打开评论框。可以同时打开多个评论框,再次选中已打开评论框的范围会回到该评论框。两栏时每条评论位于该行自己一侧的下方,左右两侧的评论并排处在同一行,各自延续所在行的底色。评论框支持换行和输入法组合输入,只有点击操作按钮才提交。可拖动底边调整高度。“添加到输入框”将评论作为可移除的引用加入主输入框,引用显示文件名、侧与行号以及评论,悬停时显示文件路径;多条引用只会在用户发送主输入框时一起发送。读到评审讨论且用户可以评审时,分段按钮会把这条评论加入用户在代码托管平台上的待提交评审,没有时先开始一个;评论随后显示为带“待提交”标签的讨论,提交评审之前只有用户自己能看到。下拉菜单可以立即发布单条评论;用户有待提交评审时没有该菜单。Agent 引用和已发布的评论以卡片保留在对应代码旁,卡片标出行范围和状态;卡片菜单里的“移除”把卡片从视图中去掉,不改动主输入框和代码托管平台,随后的提示提供“撤销”。“请求更改”需要填写评审总结,弹窗在总结输入框旁说明此要求,并在切换评审决定时播报。PR 标题栏中的“提交评审”打开居中弹窗,只显示待提交数量、总结以及“评论”“批准”“请求更改”选项。有待提交评审时提交该评审,结果不明的提交与直接提交一样,在用户到 GitHub 核对之前阻止再次提交;“丢弃评审”在确认后删除该评审及其中的评论;没有待提交评审时,把总结作为一次评审发布。代码托管平台不允许用户记录的结论不可用,例如在 GitHub 上用户自己的 PR 里,“批准”和“请求更改”不可用;只剩“评论”时,对话框会说明。视图中的文案按变更请求的提供方称呼代码托管平台及其对变更请求的叫法,例如 GitHub 和 PR。新建和删除文件只显示有内容的一侧行号。总结、评审决定,以及 Agent 引用与已发布评论的记录按 Session 和页签保存在当前浏览器,包括最初评审的 head。切换 Session 或隐藏面板时保留;关闭页签会清空它们,重新打开从空总结开始。待提交评审、已发布到 GitHub 的评论与已加入主输入框的引用不受影响。早期版本保存在此浏览器中的评论草稿保留在对应代码旁,带“浏览器草稿”标签,可以编辑、确认后删除或加入待提交评审;存在待提交评审时,它们会让“提交评审”保持不可用;没有待提交评审时,“提交评审”把它们连同总结一起发布。head 变化后需要重新选择评论行。代码变化后的记录保留在文件末尾;文件已不在 diff 中时,记录显示在 diff 之后。页签保持打开时,结果不明的提交在重新加载后仍会阻止重复发送,直到用户检查 GitHub 并明确允许再次提交。
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import type {
|
||||
ForgeCommitList, ForgeReviewData, ForgeReviewRequest, ForgeReviewResult, ForgeReviewThread, ForgeReviewWrite, ForgeReviewWriteResult,
|
||||
ForgeThreadId, ForgeViewedFiles, ForgeViewedRequest,
|
||||
} from '@deepseek-ai/dsh-experimental-forge/types'
|
||||
import { sameReviewSource, type ReviewQueue } from './review-queue.ts'
|
||||
import { sameReviewSource, type RemovedRecord, type ReviewQueue } from './review-queue.ts'
|
||||
import { ReviewThread, useFileReview } from './ReviewThread.tsx'
|
||||
import type { ReviewActions } from './ReviewComposer.tsx'
|
||||
import { SubmitReview } from './SubmitReview.tsx'
|
||||
@@ -70,7 +70,7 @@ import type { FileThreads, ThreadActions, ThreadFocus, ThreadWrite } from './Rev
|
||||
import { inFileOrder, type ThreadFilter } from './review-threads.ts'
|
||||
import { usePlacedThreads, useThreadRead, type PlacedThread } from './thread-state.ts'
|
||||
import { ThreadList } from './ThreadList.tsx'
|
||||
import type { HostStream, PanelSnapshot, StreamSnapshot } from './source.ts'
|
||||
import type { HostStream, NoticeOptions, PanelSnapshot, StreamSnapshot } from './source.ts'
|
||||
import { numberOf, openChangeRequestOf, TONE_LABEL, toneOf } from './status.ts'
|
||||
import css from './ChangesTab.module.css'
|
||||
|
||||
@@ -149,8 +149,8 @@ export interface ChangesTabInjected {
|
||||
readonly copyPath: (path: string) => void
|
||||
/** Ask the Session's Agent to create a change request for its changes, reporting the outcome. */
|
||||
readonly createChangeRequest: () => void
|
||||
/** Show a failure notice. */
|
||||
readonly report: (key: ForgePanelKey, params?: Readonly<Record<string, string>>) => void
|
||||
/** Show a notice: a failure unless the options name another tone, with the undo action they carry. */
|
||||
readonly report: (key: ForgePanelKey, options?: NoticeOptions) => void
|
||||
}
|
||||
|
||||
/** Full props of the changes tab body. */
|
||||
@@ -562,8 +562,8 @@ export function ChangesTab({
|
||||
return message
|
||||
}
|
||||
if (!complete(result.url)) return t('review.unknown')
|
||||
if (request.kind === 'review') report('review.submitted')
|
||||
else report('review.published', hostCopy)
|
||||
if (request.kind === 'review') report('review.submitted', { tone: 'success' })
|
||||
else report('review.published', { tone: 'success', params: hostCopy })
|
||||
if (request.kind === 'review') setReviewOpen(false)
|
||||
return undefined
|
||||
} catch (_error) {
|
||||
@@ -768,7 +768,7 @@ export function ChangesTab({
|
||||
useEffect(() => {
|
||||
if (withdrawn === null) return
|
||||
actions.filtered(tab.id, null)
|
||||
report('filterLens.removed', { lens: live.current.lensTitle(withdrawn) })
|
||||
report('filterLens.removed', { params: { lens: live.current.lensTitle(withdrawn) } })
|
||||
}, [withdrawn, actions, tab.id, report])
|
||||
const chooseLens = (next: string | null): void => { actions.filtered(tab.id, next) }
|
||||
// The hunks each kept file folds stay folded until the reader shows them for that file; a new result folds again.
|
||||
@@ -796,9 +796,9 @@ export function ChangesTab({
|
||||
const hostOwner = useMemo(() => data?.kind === 'change' && data.viewed !== null
|
||||
? { url: data.url, headSha: data.headSha, files: data.files, viewed: data.viewed } : null, [data])
|
||||
const host = useHostViewed(hostOwner, setFileViewed, (failure) => {
|
||||
if (failure.kind === 'stale') report('viewed.syncStale', hostCopy)
|
||||
else if (failure.kind === 'unknown') report('viewed.syncUnknown', { message: failure.message })
|
||||
else report('viewed.syncFailed', { ...hostCopy, message: failure.message })
|
||||
if (failure.kind === 'stale') report('viewed.syncStale', { params: hostCopy })
|
||||
else if (failure.kind === 'unknown') report('viewed.syncUnknown', { params: { message: failure.message } })
|
||||
else report('viewed.syncFailed', { params: { ...hostCopy, message: failure.message } })
|
||||
})
|
||||
const marks = host?.marks ?? localMarks
|
||||
// Files marked viewed at their current change, which the file tree draws subdued.
|
||||
@@ -900,7 +900,7 @@ export function ChangesTab({
|
||||
return
|
||||
}
|
||||
if (result.ok) report('toast.expandStale')
|
||||
else report('toast.expandFailed', { message: result.error.message })
|
||||
else report('toast.expandFailed', { params: { message: result.error.message } })
|
||||
update((value) => {
|
||||
const { [path]: _text, ...texts } = value.texts
|
||||
const { [path]: _open, ...open } = value.open
|
||||
@@ -954,7 +954,7 @@ export function ChangesTab({
|
||||
setReviewError(failure)
|
||||
return
|
||||
}
|
||||
report(done)
|
||||
report(done, { tone: 'success' })
|
||||
setReviewOpen(false)
|
||||
} finally {
|
||||
reviewRunning.current = false
|
||||
@@ -1000,11 +1000,15 @@ export function ChangesTab({
|
||||
return writeReview(selection.source.url, { kind: 'add-pending', headSha: selection.source.headSha, comment: { path, side, startLine, endLine, body } })
|
||||
}
|
||||
|
||||
/** Report a reference or receipt removed from the view and offer to put it back where it was. */
|
||||
const reportRemoved = (removed: RemovedRecord): void => {
|
||||
report('review.recordRemoved', { tone: 'success', undo: () => { if (!queue.restoreRecord(removed)) report('toast.undoFailed') } })
|
||||
}
|
||||
const recordActions: ReviewActions = {
|
||||
source: shownSource ?? (source.kind === 'local'
|
||||
? { kind: 'local', scope, base: null, baseRef: baseRefOf(localScope), commits: commitsOf(localScope) }
|
||||
: { kind: 'change', url: source.url, headSha: '', commits: changeCommits }),
|
||||
records: queue, addToInput: addReviewToInput, openLink,
|
||||
records: queue, addToInput: addReviewToInput, openLink, onRemoved: reportRemoved,
|
||||
}
|
||||
const absentPaths = [...new Set([...reviewState.comments, ...reviewState.records.map(item => item.selection)]
|
||||
.filter(item => sameReviewSource(item.source, recordActions.source)).map(item => item.comment.path))]
|
||||
@@ -1141,7 +1145,7 @@ export function ChangesTab({
|
||||
// props and state, which the retried render assigns again.
|
||||
const callbacks = {
|
||||
data, expandedByDefault, expand, readContext, markViewed, fileActions, publishReview, writeReview, addPending, report, nextThread,
|
||||
lensTitle, renderSlot, kept, t,
|
||||
lensTitle, renderSlot, kept, reportRemoved, t,
|
||||
}
|
||||
const live = useRef(callbacks)
|
||||
live.current = callbacks
|
||||
@@ -1199,6 +1203,7 @@ export function ChangesTab({
|
||||
renderActions: owner => live.current.renderSlot('forge.diff.comment.actions', { target, ...owner }),
|
||||
records: queue, openLink, reviewStarted,
|
||||
onQuoted: (selection) => { if (!queue.recordAgent(selection)) live.current.report('review.saveFailed') },
|
||||
onRemoved: (removed) => { live.current.reportRemoved(removed) },
|
||||
publishingBlocked,
|
||||
...queueable ? { queue: (selection: ReviewSelection) => live.current.addPending(selection) } : {},
|
||||
...single ? {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* Inline review forms use the same field, action, and badge treatments as settings and conversation controls. */
|
||||
.root, .thread { box-sizing: border-box; width: calc(100% - 20px); max-width: 680px; margin: 10px; padding: 12px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: var(--dsw-font-xs-13); font-family: Inter, var(--dsw-font-family); white-space: normal; }
|
||||
.root { background: var(--dsw-alias-bg-layer-2); border-radius: var(--dsw-radius-lg); }
|
||||
.root { box-sizing: border-box; width: calc(100% - 20px); max-width: 680px; margin: 10px; padding: 12px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-lg); background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); font: var(--dsw-font-xs-13); font-family: Inter, var(--dsw-font-family); white-space: normal; }
|
||||
.root:focus-within { border-color: var(--dsw-alias-border-l4); }
|
||||
/* Side by side, a comment fills its side's cell under the code instead of the row's width. */
|
||||
[data-forge-comments] > .root, [data-forge-comments] > .thread { width: auto; max-width: none; margin: 0; }
|
||||
[data-forge-comments] > .root { width: auto; max-width: none; margin: 0; }
|
||||
.title { margin-bottom: 12px; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
||||
/* Fixed-size textarea layout stays local during typing; native resizing can still change its outer height. */
|
||||
.input { display: block; box-sizing: border-box; width: 100%; height: 88px; min-height: 88px; contain: strict; padding: 10px 12px; resize: vertical; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md); outline: none; background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font: inherit; }
|
||||
@@ -16,11 +15,6 @@
|
||||
.gitAction { display: inline-flex; flex: none; align-items: stretch; }
|
||||
.gitMain { border-start-end-radius: 0; border-end-end-radius: 0; }
|
||||
.gitArrow { width: 30px; padding: 0; border-start-start-radius: 0; border-end-start-radius: 0; border-inline-start: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary-foreground) 25%, transparent); }
|
||||
.threadHeader { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
|
||||
.author { font-weight: 500; }
|
||||
.range { color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
||||
.commentBody { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.threadActions { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px -8px -4px; }
|
||||
.gutter { position: relative; }
|
||||
.line { display: block; width: 100%; height: 100%; padding: 0; color: inherit; text-align: inherit; cursor: pointer; border: 0; border-radius: 0; background: transparent; font: inherit; user-select: none; touch-action: pan-y; }
|
||||
.selected { background: var(--dsw-alias-interactive-bg-hover); outline: 1px solid var(--dsw-alias-border-l2); outline-offset: -1px; }
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { Button, IconChevronDownOutlineRegular, Menu, MenuItemButton } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { ReviewQueue } from './review-queue.ts'
|
||||
import type { RemovedRecord, ReviewQueue } from './review-queue.ts'
|
||||
import { reviewRange, type ReviewSelection, type ReviewSource } from './review.ts'
|
||||
import type { NS } from './locales.ts'
|
||||
import type { ForgeCommentActionsProps } from './slots.ts'
|
||||
@@ -26,6 +26,8 @@ export interface ReviewActions {
|
||||
readonly addToInput: (selection: ReviewSelection) => boolean
|
||||
/** Retain a new comment after its quote was accepted. */
|
||||
readonly onQuoted?: (selection: ReviewSelection) => void
|
||||
/** Report a reference or publication receipt the reader removed from the view, so the report can offer to put it back. */
|
||||
readonly onRemoved?: (removed: RemovedRecord) => void
|
||||
/** Publish one comment; an error string preserves the editor. */
|
||||
readonly publish?: (selection: ReviewSelection) => Promise<string | undefined>
|
||||
/** Add one comment to the pending review on the code host, starting one when needed; an error string preserves the editor. */
|
||||
|
||||
@@ -4,10 +4,12 @@ import { useCallback, useState, useSyncExternalStore, type ReactNode } from 'rea
|
||||
import { Button, Tag } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { ReviewActions } from './ReviewComposer.tsx'
|
||||
import { CardMenu, DeleteConfirm } from './ReviewThreads.tsx'
|
||||
import { EMPTY_FILE_REVIEW, type FileReviewState, type ReviewThread as Thread } from './review-queue.ts'
|
||||
import { reviewRange } from './review.ts'
|
||||
import type { NS } from './locales.ts'
|
||||
import css from './ReviewComposer.module.css'
|
||||
import css from './ReviewThreads.module.css'
|
||||
import composerCss from './ReviewComposer.module.css'
|
||||
|
||||
const noSubscription = (): (() => void) => () => {}
|
||||
|
||||
@@ -24,7 +26,9 @@ export function useFileReview(actions: ReviewActions | undefined, path: string):
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a saved comment at its line. A comment draft kept in the browser can be edited, deleted, or moved into the
|
||||
* Render a saved comment at its line: its lines and state, the menu of its less frequent actions, its text, and Add to
|
||||
* input. A reference or a publication receipt can be removed from the view, which leaves the main input and the code
|
||||
* host as they are. A comment draft kept in the browser can be edited, deleted after a confirmation, or moved into the
|
||||
* pending review on the code host.
|
||||
* @param props - record, edit availability, source actions, and localized copy.
|
||||
* @returns one compact inline comment card.
|
||||
@@ -35,16 +39,20 @@ export function ReviewThread({ thread, actions, locked, outdated, t }: PropsLoca
|
||||
readonly locked: boolean
|
||||
readonly outdated: boolean
|
||||
}): ReactNode {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [mode, setMode] = useState<'view' | 'edit' | 'delete'>('view')
|
||||
const [body, setBody] = useState(thread.selection.comment.body)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [moving, setMoving] = useState(false)
|
||||
const comment = thread.selection.comment
|
||||
const quoted = editing && thread.kind === 'pending' ? { ...thread.selection, comment: { ...comment, body } } : thread.selection
|
||||
// A draft published while its form is open becomes a receipt, which has neither form.
|
||||
const editing = mode === 'edit' && thread.kind === 'pending'
|
||||
const confirming = mode === 'delete' && thread.kind === 'pending'
|
||||
const quoted = editing ? { ...thread.selection, comment: { ...comment, body } } : thread.selection
|
||||
const range = reviewRange(comment)
|
||||
const status = thread.kind === 'pending' ? 'review.browserDraft' : thread.kind === 'published' ? 'review.published' : 'review.quoted'
|
||||
const save = (): boolean => actions.records?.editThread(thread.key, body) === true
|
||||
const queue = actions.queue
|
||||
const waiting = locked || moving
|
||||
/** Add the draft to the pending review on the code host, then delete it from the browser. */
|
||||
const move = async (add: NonNullable<ReviewActions['queue']>): Promise<void> => {
|
||||
setMoving(true)
|
||||
@@ -59,37 +67,53 @@ export function ReviewThread({ thread, actions, locked, outdated, t }: PropsLoca
|
||||
setMoving(false)
|
||||
}
|
||||
}
|
||||
return <section className={css.thread} data-forge-review-thread={thread.kind} data-side={comment.side} aria-label={t('review.range', { range })}>
|
||||
<div className={css.threadHeader}>
|
||||
<span className={css.author}>{t('review.yourComment')}</span>
|
||||
<span className={css.range}>{range}</span>
|
||||
<Tag tone="neutral">{t(outdated ? 'review.outdated' : status)}</Tag>
|
||||
const select = (id: string): void => {
|
||||
if (id === 'edit') {
|
||||
setBody(comment.body)
|
||||
setMode('edit')
|
||||
} else if (id === 'delete') setMode('delete')
|
||||
else {
|
||||
const removed = actions.records?.removeRecord(thread.key) ?? null
|
||||
if (removed === null) setError(t('review.saveFailed'))
|
||||
else actions.onRemoved?.(removed)
|
||||
}
|
||||
}
|
||||
return <section className={css.card} data-forge-review-thread={thread.kind} data-side={comment.side} aria-label={t('review.range', { range })}>
|
||||
<div className={css.recordHeader}>
|
||||
<div className={css.recordInfo}>
|
||||
<span className={css.place}>{range}</span>
|
||||
<Tag tone="neutral">{t(status)}</Tag>
|
||||
{outdated && <Tag tone="neutral">{t('review.outdated')}</Tag>}
|
||||
</div>
|
||||
{!confirming && <CardMenu label={t('review.recordActions', { range })} disabled={thread.kind === 'pending' && waiting}
|
||||
select={select} items={thread.kind === 'pending'
|
||||
// A draft being edited keeps Delete, the way out of a draft whose text the reader emptied.
|
||||
? [...editing ? [] : [{ id: 'edit', label: t('review.edit') }], { id: 'delete', label: t('review.remove') }]
|
||||
: [{ id: 'remove', label: t('review.removeRecord') }]} />}
|
||||
</div>
|
||||
{editing && thread.kind === 'pending'
|
||||
? <textarea autoFocus className={css.input} rows={3} value={body} disabled={locked} aria-label={t('review.comment')}
|
||||
{editing
|
||||
? <textarea autoFocus className={composerCss.input} rows={3} value={body} disabled={locked} aria-label={t('review.comment')}
|
||||
onChange={(event) => {
|
||||
setBody(event.target.value)
|
||||
if (actions.records?.editThread(thread.key, event.target.value) === true) setError(null)
|
||||
else setError(t('review.saveFailed'))
|
||||
}} />
|
||||
: <div className={css.commentBody}>{comment.body}</div>}
|
||||
{error !== null && <div className={css.error} role="alert">{error}</div>}
|
||||
<div className={css.threadActions}>
|
||||
: <div className={css.plain}>{comment.body}</div>}
|
||||
{confirming && <DeleteConfirm question={t('thread.deleteConfirm')} confirmLabel={t('review.remove')} disabled={waiting} error={error}
|
||||
cancel={() => { setError(null); setMode('view') }}
|
||||
confirm={() => { if (actions.records?.editThread(thread.key, null) !== true) setError(t('review.saveFailed')) }} t={t} />}
|
||||
{error !== null && !confirming && <div className={composerCss.error} role="alert">{error}</div>}
|
||||
<div className={css.actions}>
|
||||
<Button size="sm" disabled={quoted.comment.body.trim() === ''} onClick={() => {
|
||||
if (!actions.addToInput(quoted)) setError(t('review.inputFailed'))
|
||||
}}>{t('review.addToInput')}</Button>
|
||||
{thread.kind === 'pending' && <>
|
||||
{editing
|
||||
? <Button size="sm" disabled={locked || moving || body.trim() === ''} onClick={() => {
|
||||
if (save()) { setEditing(false); setError(null) } else setError(t('review.saveFailed'))
|
||||
}}>{t('review.done')}</Button>
|
||||
: <Button size="sm" disabled={locked || moving} onClick={() => { setBody(comment.body); setEditing(true) }}>{t('review.edit')}</Button>}
|
||||
<Button size="sm" disabled={locked || moving} onClick={() => {
|
||||
if (actions.records?.editThread(thread.key, null) !== true) setError(t('review.saveFailed'))
|
||||
}}>{t('review.remove')}</Button>
|
||||
{queue !== undefined && !editing && !outdated && <Button size="sm" disabled={locked || moving}
|
||||
onClick={() => { void move(queue) }}>{t(moving ? 'review.publishing' : 'review.queue')}</Button>}
|
||||
</>}
|
||||
{editing && <Button size="sm" disabled={waiting || body.trim() === ''} onClick={() => {
|
||||
if (save()) { setMode('view'); setError(null) } else setError(t('review.saveFailed'))
|
||||
}}>{t('review.done')}</Button>}
|
||||
{thread.kind === 'pending' && queue !== undefined && mode === 'view' && !outdated && <Button size="sm" disabled={waiting}
|
||||
onClick={() => { void move(queue) }}>
|
||||
{t(moving ? 'review.publishing' : actions.reviewStarted === true ? 'review.queue' : 'review.startReview')}
|
||||
</Button>}
|
||||
{thread.kind === 'published' && actions.openLink !== undefined && <Button size="sm" onClick={() => { actions.openLink?.(thread.url) }}>{t('review.recheck')}</Button>}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -73,6 +73,30 @@
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
/* A saved comment's header keeps its menu at the top end while the lines and tags wrap beside it. */
|
||||
.recordHeader {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.recordInfo {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
min-height: 20px;
|
||||
}
|
||||
|
||||
/* A saved comment is plain text, drawn with its line breaks. */
|
||||
.plain {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.spacer { flex: 1; }
|
||||
|
||||
/* Text actions inside a card: no fill, accent ink, the same height as the tags beside them. */
|
||||
|
||||
@@ -167,6 +167,47 @@ function TextForm({ label, initial, busy, error, cancel, children }: {
|
||||
</div>
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the button that ends a card's header row and the menu of the card's less frequent actions.
|
||||
* @param props - the menu's accessible name, its items, the handler of a chosen item, and availability.
|
||||
* @returns the button and, while open, its menu.
|
||||
*/
|
||||
export function CardMenu({ label, items, select, disabled = false }: {
|
||||
readonly label: string
|
||||
readonly items: readonly { readonly id: string; readonly label: string }[]
|
||||
readonly select: (id: string) => void
|
||||
readonly disabled?: boolean
|
||||
}): ReactNode {
|
||||
const [open, setOpen] = useState(false)
|
||||
return <Menu open={open && !disabled} portal dense align="end" autoFocus onClose={() => { setOpen(false) }} items={items}
|
||||
onSelect={(id) => { setOpen(false); select(id) }}
|
||||
anchor={<span className={css.menuAnchor}><Tooltip label={label} side="bottom" delayMs={500}>
|
||||
<button type="button" className={css.icon} disabled={disabled} aria-label={label} aria-haspopup="menu" aria-expanded={open && !disabled}
|
||||
onClick={() => { setOpen(value => !value) }}><IconEllipsisOutlineRegular size={14} /></button>
|
||||
</Tooltip></span>} />
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask before a deletion under the content it deletes, which stays readable above the question.
|
||||
* @param props - the question, the deleting answer's label, whether both answers wait, the failure, the answers, and copy.
|
||||
* @returns the question with Cancel and the deleting answer.
|
||||
*/
|
||||
export function DeleteConfirm({ question, confirmLabel, disabled, error, cancel, confirm, t }: PropsLocale<typeof NS> & {
|
||||
readonly question: string
|
||||
readonly confirmLabel: string
|
||||
readonly disabled: boolean
|
||||
readonly error: string | null
|
||||
readonly cancel: () => void
|
||||
readonly confirm: () => void
|
||||
}): ReactNode {
|
||||
return <div className={css.confirm} role="group" aria-label={question}>
|
||||
<span className={css.confirmText}>{question}</span>
|
||||
<Button size="sm" disabled={disabled} onClick={cancel}>{t('review.cancel')}</Button>
|
||||
<Button size="sm" variant="primary" disabled={disabled} onClick={confirm}>{confirmLabel}</Button>
|
||||
{error !== null && <div className={clsx(composerCss.error, css.confirmError)} role="alert">{error}</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
/** Tells the card which of its forms hold text the reader is writing, so it does not fold them away. */
|
||||
type Drafting = (form: string, active: boolean) => void
|
||||
|
||||
@@ -185,7 +226,6 @@ function Comment({ comment, last, actions, labels, now, drafting, t }: {
|
||||
drafting(comment.id, mode === 'edit')
|
||||
return () => { drafting(comment.id, false) }
|
||||
}, [drafting, comment.id, mode])
|
||||
const [menu, setMenu] = useState(false)
|
||||
const writing = useWriting(t)
|
||||
const writes = actions.writes
|
||||
const login = comment.author?.login ?? null
|
||||
@@ -208,13 +248,8 @@ function Comment({ comment, last, actions, labels, now, drafting, t }: {
|
||||
{comment.pending && <Tag tone="warning">{t('review.pending')}</Tag>}
|
||||
{(editable || deletable) && mode === 'view' && <>
|
||||
<span className={css.spacer} />
|
||||
<Menu open={menu} portal dense align="end" autoFocus onClose={() => { setMenu(false) }}
|
||||
items={[...editable ? [{ id: 'edit', label: t('review.edit') }] : [], ...deletable ? [{ id: 'delete', label: t('review.remove') }] : []]}
|
||||
onSelect={(id) => { setMenu(false); setMode(id === 'edit' ? 'edit' : 'delete') }}
|
||||
anchor={<span className={css.menuAnchor}><Tooltip label={menuLabel} side="bottom" delayMs={500}>
|
||||
<button type="button" className={css.icon} aria-label={menuLabel} aria-haspopup="menu" aria-expanded={menu}
|
||||
onClick={() => { setMenu(value => !value) }}><IconEllipsisOutlineRegular size={14} /></button>
|
||||
</Tooltip></span>} />
|
||||
<CardMenu label={menuLabel} select={(id) => { setMode(id === 'edit' ? 'edit' : 'delete') }}
|
||||
items={[...editable ? [{ id: 'edit', label: t('review.edit') }] : [], ...deletable ? [{ id: 'delete', label: t('review.remove') }] : []]} />
|
||||
</>}
|
||||
</div>
|
||||
{mode === 'edit'
|
||||
@@ -227,14 +262,9 @@ function Comment({ comment, last, actions, labels, now, drafting, t }: {
|
||||
</TextForm>
|
||||
// Raw HTML renders nothing, as GitHub hides comments and unknown tags, and never enters the DOM.
|
||||
: <div className={css.body}><MarkdownText text={comment.body} labels={labels} variant="body" omitHtml /></div>}
|
||||
{mode === 'delete' && <div className={css.confirm} role="group" aria-label={t(last ? 'thread.deleteLast' : 'thread.deleteConfirm')}>
|
||||
<span className={css.confirmText}>{t(last ? 'thread.deleteLast' : 'thread.deleteConfirm')}</span>
|
||||
<Button size="sm" disabled={writing.busy} onClick={() => { setMode('view') }}>{t('review.cancel')}</Button>
|
||||
<Button size="sm" variant="primary" disabled={writing.busy} onClick={() => { void send({ kind: 'delete-comment', comment: comment.id }) }}>
|
||||
{t(writing.busy ? 'thread.deleting' : 'review.remove')}
|
||||
</Button>
|
||||
{writing.error !== null && <div className={clsx(composerCss.error, css.confirmError)} role="alert">{writing.error}</div>}
|
||||
</div>}
|
||||
{mode === 'delete' && <DeleteConfirm question={t(last ? 'thread.deleteLast' : 'thread.deleteConfirm')}
|
||||
confirmLabel={t(writing.busy ? 'thread.deleting' : 'review.remove')} disabled={writing.busy} error={writing.error}
|
||||
cancel={() => { setMode('view') }} confirm={() => { void send({ kind: 'delete-comment', comment: comment.id }) }} t={t} />}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ export const zh = {
|
||||
'review.close': '关闭',
|
||||
'review.pending': '待提交',
|
||||
'review.quoted': '已添加到输入框',
|
||||
'review.yourComment': '你的评论',
|
||||
'review.removeRecord': '移除',
|
||||
'review.recordActions': '评论 {range} 的操作',
|
||||
'review.recordRemoved': '已移除',
|
||||
'review.outdated': '代码已更新',
|
||||
'review.done': '完成',
|
||||
'review.addComment': '添加评论',
|
||||
@@ -512,7 +514,9 @@ export const en: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Close',
|
||||
'review.pending': 'Pending',
|
||||
'review.quoted': 'Added to input',
|
||||
'review.yourComment': 'Your comment',
|
||||
'review.removeRecord': 'Remove',
|
||||
'review.recordActions': 'Actions for the comment on {range}',
|
||||
'review.recordRemoved': 'Removed',
|
||||
'review.outdated': 'Code updated',
|
||||
'review.done': 'Done',
|
||||
'review.addComment': 'Add comment',
|
||||
@@ -1007,7 +1011,9 @@ export const ja: Record<ForgePanelKey, string> = {
|
||||
'review.close': '閉じる',
|
||||
'review.pending': '保留中',
|
||||
'review.quoted': '入力欄に追加済み',
|
||||
'review.yourComment': '自分のコメント',
|
||||
'review.removeRecord': 'この表示から削除',
|
||||
'review.recordActions': '{range} のコメントの操作',
|
||||
'review.recordRemoved': 'この表示から削除しました',
|
||||
'review.outdated': 'コード更新済み',
|
||||
'review.done': '完了',
|
||||
'review.addComment': 'コメントを追加',
|
||||
@@ -1495,7 +1501,9 @@ export const es: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Cerrar',
|
||||
'review.pending': 'Pendiente',
|
||||
'review.quoted': 'Añadido al campo de entrada',
|
||||
'review.yourComment': 'Tu comentario',
|
||||
'review.removeRecord': 'Quitar',
|
||||
'review.recordActions': 'Acciones del comentario en {range}',
|
||||
'review.recordRemoved': 'Se quitó',
|
||||
'review.outdated': 'Código actualizado',
|
||||
'review.done': 'Listo',
|
||||
'review.addComment': 'Añadir comentario',
|
||||
@@ -1983,7 +1991,9 @@ export const fr: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Fermer',
|
||||
'review.pending': 'En attente',
|
||||
'review.quoted': 'Ajouté au champ de saisie',
|
||||
'review.yourComment': 'Votre commentaire',
|
||||
'review.removeRecord': 'Retirer',
|
||||
'review.recordActions': 'Actions du commentaire sur {range}',
|
||||
'review.recordRemoved': 'Retiré',
|
||||
'review.outdated': 'Code mis à jour',
|
||||
'review.done': 'Terminé',
|
||||
'review.addComment': 'Ajouter un commentaire',
|
||||
@@ -2471,7 +2481,9 @@ export const de: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Schließen',
|
||||
'review.pending': 'Ausstehend',
|
||||
'review.quoted': 'Zum Eingabefeld hinzugefügt',
|
||||
'review.yourComment': 'Dein Kommentar',
|
||||
'review.removeRecord': 'Entfernen',
|
||||
'review.recordActions': 'Aktionen für den Kommentar zu {range}',
|
||||
'review.recordRemoved': 'Entfernt',
|
||||
'review.outdated': 'Code aktualisiert',
|
||||
'review.done': 'Fertig',
|
||||
'review.addComment': 'Kommentar hinzufügen',
|
||||
@@ -2959,7 +2971,9 @@ export const ru: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Закрыть',
|
||||
'review.pending': 'Ожидает отправки',
|
||||
'review.quoted': 'Добавлено в поле ввода',
|
||||
'review.yourComment': 'Ваш комментарий',
|
||||
'review.removeRecord': 'Убрать',
|
||||
'review.recordActions': 'Действия с комментарием к {range}',
|
||||
'review.recordRemoved': 'Убрано',
|
||||
'review.outdated': 'Код обновлён',
|
||||
'review.done': 'Готово',
|
||||
'review.addComment': 'Добавить комментарий',
|
||||
@@ -3447,7 +3461,9 @@ export const pt: Record<ForgePanelKey, string> = {
|
||||
'review.close': 'Fechar',
|
||||
'review.pending': 'Pendente',
|
||||
'review.quoted': 'Adicionado ao campo de entrada',
|
||||
'review.yourComment': 'Seu comentário',
|
||||
'review.removeRecord': 'Remover',
|
||||
'review.recordActions': 'Ações do comentário em {range}',
|
||||
'review.recordRemoved': 'Removido',
|
||||
'review.outdated': 'Código atualizado',
|
||||
'review.done': 'Concluído',
|
||||
'review.addComment': 'Adicionar comentário',
|
||||
|
||||
@@ -383,10 +383,7 @@ function registerUi(ctx: Context): void {
|
||||
openLink,
|
||||
copyPath,
|
||||
createChangeRequest: () => { createChangeRequest(sessionId) },
|
||||
report: (key, params) => {
|
||||
notices.report(key, { tone: key === 'review.published' || key === 'review.submitted' || key === 'review.discarded' ? 'success' : 'failure',
|
||||
...params === undefined ? {} : { params } })
|
||||
},
|
||||
report: notices.report,
|
||||
}
|
||||
}
|
||||
/** Request a worktree; a refused branch name goes back to the naming dialog, any other failure to a toast. */
|
||||
|
||||
@@ -37,6 +37,13 @@ export type ReviewRecord =
|
||||
/** One inline record; its numeric key belongs only to the retained browser store. */
|
||||
export type ReviewThread = { readonly key: number } & (ReviewRecord | { readonly kind: 'pending'; readonly selection: ReviewSelection })
|
||||
|
||||
/** A record taken out of the store, with the position that puts it back. */
|
||||
export interface RemovedRecord {
|
||||
readonly record: ReviewRecord
|
||||
/** Position among the stored records before the removal. */
|
||||
readonly index: number
|
||||
}
|
||||
|
||||
/** File-scoped snapshot that does not change while unrelated comments or the summary are edited. */
|
||||
export interface FileReviewState {
|
||||
readonly threads: readonly ReviewThread[]
|
||||
@@ -147,6 +154,29 @@ export class ReviewQueue {
|
||||
return this.save({ ...this.state, uncertain: null, records: [...this.state.records, { kind: 'published', selection, url }] })
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the reference or publication receipt behind an inline record. A comment draft is deleted through `editThread`;
|
||||
* a published comment stays on the code host.
|
||||
* @param key - browser-store identity from fileComments.
|
||||
* @returns the removed record and its position, or null when no record has the key or the removal was not saved.
|
||||
*/
|
||||
removeRecord(key: number): RemovedRecord | null {
|
||||
const index = this.state.records.findIndex(item => this.keyOf(item.selection) === key)
|
||||
const record = this.state.records[index]
|
||||
if (record === undefined) return null
|
||||
return this.save({ ...this.state, records: this.state.records.filter(item => item !== record) }) ? { record, index } : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a removed record back at its earlier position, or after the remaining records when fewer are left.
|
||||
* @param removed - result of removeRecord.
|
||||
* @returns whether the record was saved.
|
||||
*/
|
||||
restoreRecord(removed: RemovedRecord): boolean {
|
||||
const records = this.state.records
|
||||
return this.save({ ...this.state, records: [...records.slice(0, removed.index), removed.record, ...records.slice(removed.index)] })
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe queue edits and storage failures.
|
||||
* @param listener - snapshot invalidation.
|
||||
|
||||
@@ -1292,7 +1292,7 @@ describe('ChangesTab unchanged lines', () => {
|
||||
const app = m.section('src/app.ts')
|
||||
fireEvent.click(within(app).getByRole('button', { name: '2 unchanged lines' }))
|
||||
await settle()
|
||||
expect(m.faces.report).toHaveBeenLastCalledWith('toast.expandFailed', { message: 'gone' })
|
||||
expect(m.faces.report).toHaveBeenLastCalledWith('toast.expandFailed', { params: { message: 'gone' } })
|
||||
const gap = within(app).getByRole('button', { name: '2 unchanged lines' })
|
||||
expect(gap.hasAttribute('disabled')).toBe(false)
|
||||
|
||||
@@ -1598,7 +1598,7 @@ describe('line review actions', () => {
|
||||
m.publish()
|
||||
await settle()
|
||||
expect(m.sectionQueries.queryByRole('textbox')).toBeNull()
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.published', { forge: 'GitHub', noun: 'PR' })
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.published', { tone: 'success', params: { forge: 'GitHub', noun: 'PR' } })
|
||||
expect(m.section('src/app.ts').querySelector('[data-forge-review-thread="published"]')).not.toBeNull()
|
||||
})
|
||||
it.each(['rejected', 'remote-error', 'receipt-storage'] as const)('holds an uncertain %s result for explicit reconciliation', async (kind) => {
|
||||
@@ -1741,7 +1741,7 @@ describe('line review actions', () => {
|
||||
await settle()
|
||||
expect(m.faces.changeRequestReviewWrite).toHaveBeenLastCalledWith(URL7,
|
||||
{ kind: 'submit-pending', headSha: HEAD, review: 'review-1', event: 'request-changes', body: 'Needs a fix' })
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.submitted')
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.submitted', { tone: 'success' })
|
||||
expect(m.view.queryByRole('dialog')).toBeNull()
|
||||
expect(m.faces.reviewQueue({ id: TAB, signal: m.aborter.signal }).getSnapshot()).toMatchObject({ body: '', event: 'comment' })
|
||||
expect(m.view.getByRole('button', { name: 'Submit review' })).toBeTruthy()
|
||||
@@ -1766,7 +1766,7 @@ describe('line review actions', () => {
|
||||
expect(m.faces.report).not.toHaveBeenCalled()
|
||||
fireEvent.click(within(dialog.getByRole('group', { name: 'Discard review' })).getByRole('button', { name: 'Discard review' }))
|
||||
await settle()
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.discarded')
|
||||
expect(m.faces.report).toHaveBeenCalledWith('review.discarded', { tone: 'success' })
|
||||
expect(m.view.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
it('submits a pending review once when two activations arrive in the same render batch', async () => {
|
||||
@@ -1863,7 +1863,7 @@ describe('line review actions', () => {
|
||||
} })
|
||||
await settle()
|
||||
const drafts = [...m.section('src/app.ts').querySelectorAll<HTMLElement>('[data-forge-review-thread="pending"]')]
|
||||
for (const draft of drafts) fireEvent.click(within(draft).getByRole('button', { name: 'Add to review' }))
|
||||
for (const draft of drafts) fireEvent.click(within(draft).getByRole('button', { name: 'Start review' }))
|
||||
await settle()
|
||||
expect(m.faces.changeRequestReviewWrite).toHaveBeenCalledTimes(1)
|
||||
first.settle(ok({ ok: false, code: 'failed', message: 'Busy' }))
|
||||
@@ -1929,7 +1929,7 @@ describe('line review actions', () => {
|
||||
const draft = within(m.section('src/app.ts').querySelector('[data-forge-review-thread="pending"]')!)
|
||||
expect(draft.getByText(en['review.browserDraft'])).toBeTruthy()
|
||||
expect(m.view.getByRole('button', { name: 'Submit review (1)' })).toBeTruthy()
|
||||
fireEvent.click(draft.getByRole('button', { name: 'Add to review' }))
|
||||
fireEvent.click(draft.getByRole('button', { name: 'Start review' }))
|
||||
await settle()
|
||||
expect(m.faces.changeRequestReviewWrite).toHaveBeenCalledWith(URL7, { kind: 'add-pending', headSha: HEAD,
|
||||
comment: { path: 'src/app.ts', side: 'R', startLine: 4, endLine: 4, body: 'Kept from before' } })
|
||||
@@ -1955,9 +1955,56 @@ describe('line review actions', () => {
|
||||
await settle()
|
||||
const record = within(m.view.container.querySelector('[data-forge-review-file="src/app.ts"]')!)
|
||||
expect(record.getByText('Keep this draft')).toBeTruthy()
|
||||
fireEvent.click(record.getByRole('button', { name: 'Delete' }))
|
||||
fireEvent.click(record.getByRole('button', { name: 'Actions for the comment on R4' }))
|
||||
fireEvent.click(m.view.getByRole('menuitem', { name: 'Delete' }))
|
||||
fireEvent.click(within(record.getByRole('group', { name: en['thread.deleteConfirm'] })).getByRole('button', { name: 'Delete' }))
|
||||
expect(m.faces.reviewQueue({ id: TAB, signal: m.aborter.signal }).getSnapshot().comments).toHaveLength(0)
|
||||
})
|
||||
it('removes a reference from the view, offers to undo it, and puts it back at its line', async () => {
|
||||
const m = mount()
|
||||
await settle()
|
||||
const section = within(m.section('src/app.ts'))
|
||||
for (const [line, body] of [['R4', 'First'], ['R5', 'Second']] as const) {
|
||||
fireEvent.click(section.getByRole('button', { name: `Select line ${line}` }))
|
||||
fireEvent.click(section.getByRole('button', { name: 'Add comment' }))
|
||||
fireEvent.change(section.getByRole('textbox'), { target: { value: body } })
|
||||
fireEvent.click(within(m.section('src/app.ts').querySelector('[data-forge-comment]')!).getByRole('button', { name: 'Add to input' }))
|
||||
}
|
||||
const bodies = (): (string | null)[] => [...m.section('src/app.ts').querySelectorAll('[data-forge-review-thread="agent"]')]
|
||||
.map(card => within(card as HTMLElement).getByText(/First|Second/).textContent)
|
||||
expect(bodies()).toEqual(['First', 'Second'])
|
||||
fireEvent.click(section.getByRole('button', { name: 'Actions for the comment on R4' }))
|
||||
fireEvent.click(m.view.getByRole('menuitem', { name: 'Remove' }))
|
||||
expect(bodies()).toEqual(['Second'])
|
||||
expect(m.faces.addReviewToInput).toHaveBeenCalledTimes(2)
|
||||
expect(m.faces.report.mock.lastCall).toMatchObject(['review.recordRemoved', { tone: 'success' }])
|
||||
const undo = m.faces.report.mock.lastCall![1]!.undo!
|
||||
act(() => { undo() })
|
||||
expect(bodies()).toEqual(['First', 'Second'])
|
||||
expect(m.faces.report).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
it('removes the reference of a file that left the diff with its section and says when undoing came too late', async () => {
|
||||
const m = mount()
|
||||
await settle()
|
||||
const section = within(m.section('src/app.ts'))
|
||||
fireEvent.click(section.getByRole('button', { name: 'Select line R4' }))
|
||||
fireEvent.click(section.getByRole('button', { name: 'Add comment' }))
|
||||
fireEvent.change(section.getByRole('textbox'), { target: { value: 'Left behind' } })
|
||||
fireEvent.click(within(m.section('src/app.ts').querySelector('[data-forge-comment]')!).getByRole('button', { name: 'Add to input' }))
|
||||
m.faces.localDiff.mockResolvedValue(ok({ ...LOCAL, files: [] }))
|
||||
fireEvent.click(m.view.getByRole('button', { name: 'Refresh changes' }))
|
||||
await settle()
|
||||
const orphan = within(m.view.container.querySelector('[data-forge-review-file="src/app.ts"]')!)
|
||||
expect(orphan.getByText('Left behind')).toBeTruthy()
|
||||
fireEvent.click(orphan.getByRole('button', { name: 'Actions for the comment on R4' }))
|
||||
fireEvent.click(m.view.getByRole('menuitem', { name: 'Remove' }))
|
||||
expect(m.view.container.querySelector('[data-forge-review-file]')).toBeNull()
|
||||
const undo = m.faces.report.mock.lastCall![1]!.undo!
|
||||
m.faces.reviewQueue({ id: TAB, signal: m.aborter.signal }).close()
|
||||
act(() => { undo() })
|
||||
expect(m.faces.report).toHaveBeenLastCalledWith('toast.undoFailed')
|
||||
expect(m.view.container.querySelector('[data-forge-review-file]')).toBeNull()
|
||||
})
|
||||
it('retains an uncertain write across tab remount and requires explicit reconciliation', async () => {
|
||||
const m = mount({ source: { kind: 'change', url: URL7 }, state: ready({ changeRequests: [entry(7, snapshot(7))] }),
|
||||
setup: (faces) => {
|
||||
@@ -2102,8 +2149,8 @@ describe('ChangesTab viewed marks the host keeps', () => {
|
||||
})
|
||||
|
||||
it.each([
|
||||
['refused', { ok: false, error: new RemoteError('forgePanel/action-failed', 'Resource not accessible', {}) }, ['viewed.syncFailed', { forge: 'GitHub', noun: 'PR', message: 'Resource not accessible' }]],
|
||||
['stale', REFUSED.staleHead, ['viewed.syncStale', { forge: 'GitHub', noun: 'PR' }]],
|
||||
['refused', { ok: false, error: new RemoteError('forgePanel/action-failed', 'Resource not accessible', {}) }, ['viewed.syncFailed', { params: { forge: 'GitHub', noun: 'PR', message: 'Resource not accessible' } }]],
|
||||
['stale', REFUSED.staleHead, ['viewed.syncStale', { params: { forge: 'GitHub', noun: 'PR' } }]],
|
||||
] as const)('returns a %s mark to what the host keeps and says why', async (_label, result, report) => {
|
||||
const m = mount({ source, setup: (faces) => {
|
||||
faces.changeRequestViewed.mockResolvedValue(hosted({ 'src/app.ts': 'viewed' }))
|
||||
@@ -2218,7 +2265,7 @@ describe('ChangesTab viewed marks the host keeps', () => {
|
||||
expect(marks(m).map(row => row[1])).toEqual(['viewed', 'viewed', 'unviewed'])
|
||||
expect(box(m, 'src/app.ts', 'app.ts').disabled).toBe(false)
|
||||
expect(box(m, 'docs/gone.txt', 'gone.txt').disabled).toBe(true)
|
||||
expect(m.faces.report).toHaveBeenCalledWith('viewed.syncFailed', { forge: 'GitHub', noun: 'PR', message: 'late' })
|
||||
expect(m.faces.report).toHaveBeenCalledWith('viewed.syncFailed', { params: { forge: 'GitHub', noun: 'PR', message: 'late' } })
|
||||
await act(async () => { next.resolve(ok(undefined)); await Promise.resolve() })
|
||||
expect(box(m, 'docs/gone.txt', 'gone.txt').disabled).toBe(false)
|
||||
})
|
||||
@@ -2282,7 +2329,7 @@ describe('ChangesTab viewed marks the host keeps', () => {
|
||||
await settle()
|
||||
expect(marks(m)[2]?.[1]).toBe('viewed')
|
||||
expect(box(m, 'src/app.ts', 'app.ts').disabled).toBe(false)
|
||||
expect(m.faces.report).toHaveBeenCalledWith('viewed.syncUnknown', { message: 'Something went wrong' })
|
||||
expect(m.faces.report).toHaveBeenCalledWith('viewed.syncUnknown', { params: { message: 'Something went wrong' } })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2876,7 +2923,7 @@ describe('ChangesTab extensions', () => {
|
||||
act(() => { m.extensions.set({ state: { ...hosted, lenses: [UNUSED] }, disconnected: false }) })
|
||||
expect(m.paths()).toHaveLength(6)
|
||||
expect(m.store.getSnapshot().byTab[TAB]?.filterLens).toBeNull()
|
||||
expect(m.faces.report).toHaveBeenCalledWith('filterLens.removed', { lens: 'Exports' })
|
||||
expect(m.faces.report).toHaveBeenCalledWith('filterLens.removed', { params: { lens: 'Exports' } })
|
||||
})
|
||||
|
||||
it('asks again for a lens registered at another version and for equal files of another scope', async () => {
|
||||
|
||||
@@ -1073,15 +1073,12 @@ describe('mountForgePanel changes view', () => {
|
||||
expect(open).toHaveBeenCalledWith('https://github.com/octo/demo/blob/main/a.ts', '_blank', 'noopener,noreferrer')
|
||||
f.changes(S1).report('toast.expandStale')
|
||||
expect(f.notice()).toMatchObject({ key: 'toast.expandStale', tone: 'failure', params: {} })
|
||||
f.changes(S1).report('toast.expandFailed', { message: 'gone' })
|
||||
expect(f.notice()).toMatchObject({ key: 'toast.expandFailed', tone: 'failure', params: { message: 'gone' } })
|
||||
|
||||
f.changes(S1).report('review.submitted')
|
||||
expect(f.notice()).toMatchObject({ key: 'review.submitted', tone: 'success' })
|
||||
f.changes(S1).report('review.published')
|
||||
expect(f.notice()).toMatchObject({ key: 'review.published', tone: 'success' })
|
||||
f.changes(S1).report('review.discarded')
|
||||
expect(f.notice()).toMatchObject({ key: 'review.discarded', tone: 'success' })
|
||||
f.changes(S1).report('toast.expandFailed', { params: { message: 'gone' } })
|
||||
expect(f.notice()).toMatchObject({ key: 'toast.expandFailed', tone: 'failure', params: { message: 'gone' }, undo: undefined })
|
||||
// The view names the tone and the undo action of each notice; the notice store shows them as given.
|
||||
const undo = vi.fn()
|
||||
f.changes(S1).report('review.recordRemoved', { tone: 'success', undo })
|
||||
expect(f.notice()).toMatchObject({ key: 'review.recordRemoved', tone: 'success', params: {}, undo })
|
||||
|
||||
const writeText = vi.fn(async (_text: string) => {})
|
||||
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } })
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/** Frozen line references, durable pending reviews, and plain-text destination actions. */
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { Profiler } from 'react'
|
||||
import { act, cleanup, fireEvent, render, within } from '@testing-library/react'
|
||||
import { act, cleanup, fireEvent, render, within, type RenderResult } from '@testing-library/react'
|
||||
import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import type { ForgeReviewId } from '@deepseek-ai/dsh-experimental-forge/types'
|
||||
import type { ForgeDiffFile } from '../src/types.ts'
|
||||
@@ -35,6 +35,18 @@ function drafted(...drafts: ReviewSelection[]): ReviewQueue {
|
||||
|
||||
const PENDING = { id: 'review-1' as ForgeReviewId, comments: 2 }
|
||||
|
||||
/** Open the menu of the saved comment on the fixture's lines and read the actions it offers. */
|
||||
function openMenu(view: RenderResult): (string | null)[] {
|
||||
fireEvent.click(view.getByRole('button', { name: 'Actions for the comment on R3–4' }))
|
||||
return within(view.getByRole('menu')).getAllByRole('menuitem').map(item => item.textContent)
|
||||
}
|
||||
|
||||
/** Choose an action from the menu of the saved comment on the fixture's lines. */
|
||||
function choose(view: RenderResult, action: string): void {
|
||||
openMenu(view)
|
||||
fireEvent.click(view.getByRole('menuitem', { name: action }))
|
||||
}
|
||||
|
||||
describe('review references', () => {
|
||||
it('anchors added and deleted files and detects changed source or hunk content', () => {
|
||||
const added = { ...file, hunks: [{ oldStart: 1, oldLines: 0, newStart: 1, newLines: 1, lines: ['+new'] }] }
|
||||
@@ -297,6 +309,41 @@ describe('pending reviews', () => {
|
||||
expect(queue.fileComments('a.ts', { ...source, ...left }).threads).toHaveLength(1)
|
||||
expect(queue.fileComments('a.ts', { ...source, ...right }).threads).toHaveLength(0)
|
||||
})
|
||||
it('removes a reference or a receipt by its inline identity and puts it back where it was', () => {
|
||||
const queue = drafted(selection)
|
||||
const second = { ...selection, comment: { ...selection.comment, body: 'Second' } }
|
||||
queue.recordAgent(selection)
|
||||
queue.published(second, 'https://github.com/octo/demo/pull/7#comment-1')
|
||||
const [reference, receipt, draft] = queue.fileComments('a.ts', selection.source).threads
|
||||
const removed = queue.removeRecord(reference!.key)
|
||||
expect(removed).toEqual({ record: { kind: 'agent', selection }, index: 0 })
|
||||
expect(queue.fileComments('a.ts', selection.source).threads.map(item => item.kind)).toEqual(['published', 'pending'])
|
||||
expect(new ReviewQueue('review-test').getSnapshot().records.map(item => item.kind)).toEqual(['published'])
|
||||
expect(queue.removeRecord(reference!.key)).toBeNull()
|
||||
expect(queue.removeRecord(draft!.key)).toBeNull()
|
||||
expect(queue.getSnapshot().comments).toHaveLength(1)
|
||||
expect(queue.restoreRecord(removed!)).toBe(true)
|
||||
expect(queue.fileComments('a.ts', selection.source).threads.map(item => [item.kind, item.key]))
|
||||
.toEqual([['agent', reference!.key], ['published', receipt!.key], ['pending', draft!.key]])
|
||||
const last = queue.removeRecord(receipt!.key)
|
||||
expect(last?.index).toBe(1)
|
||||
queue.removeRecord(reference!.key)
|
||||
expect(queue.restoreRecord(last!)).toBe(true)
|
||||
expect(new ReviewQueue('review-test').getSnapshot().records.map(item => item.kind)).toEqual(['published'])
|
||||
})
|
||||
it('keeps a record whose removal the browser did not save and refuses a restoration after the tab closed', () => {
|
||||
const queue = new ReviewQueue('review-test')
|
||||
queue.recordAgent(selection)
|
||||
const key = queue.fileComments('a.ts', selection.source).threads[0]!.key
|
||||
const setter = vi.spyOn(Storage.prototype, 'setItem').mockImplementationOnce(() => { throw new DOMException('quota', 'QuotaExceededError') })
|
||||
expect(queue.removeRecord(key)).toBeNull()
|
||||
expect(queue.getSnapshot()).toMatchObject({ error: 'save', records: [{ kind: 'agent' }] })
|
||||
setter.mockRestore()
|
||||
const removed = queue.removeRecord(key)
|
||||
expect(removed).not.toBeNull()
|
||||
queue.close()
|
||||
expect(queue.restoreRecord(removed!)).toBe(false)
|
||||
})
|
||||
it('keeps the previous queue on quota failure and allows retry after recovery', () => {
|
||||
const queue = new ReviewQueue('review-test')
|
||||
const setter = vi.spyOn(Storage.prototype, 'setItem').mockImplementationOnce(() => { throw new DOMException('quota', 'QuotaExceededError') })
|
||||
@@ -317,7 +364,7 @@ describe('inline records', () => {
|
||||
const view = render(<ReviewThread thread={thread} actions={actions} locked={false} outdated={false} t={t} />)
|
||||
fireEvent.click(view.getByRole('button', { name: 'Add to input' }))
|
||||
expect(view.getByRole('alert')).toHaveProperty('textContent', en['review.inputFailed'])
|
||||
fireEvent.click(view.getByRole('button', { name: 'Edit' }))
|
||||
choose(view, 'Edit')
|
||||
fireEvent.change(view.getByRole('textbox'), { target: { value: 'Edited' } })
|
||||
expect(view.queryByRole('alert')).toBeNull()
|
||||
addToInput.mockReturnValue(true)
|
||||
@@ -325,22 +372,74 @@ describe('inline records', () => {
|
||||
expect(addToInput).toHaveBeenLastCalledWith({ ...selection, comment: { ...selection.comment, body: 'Edited' } })
|
||||
fireEvent.click(view.getByRole('button', { name: 'Done' }))
|
||||
expect(view.queryByRole('textbox')).toBeNull()
|
||||
fireEvent.click(view.getByRole('button', { name: 'Delete' }))
|
||||
})
|
||||
it('asks before deleting a browser draft and keeps it when the reader cancels', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
expect(openMenu(view)).toEqual(['Edit', 'Delete'])
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Delete' }))
|
||||
const question = within(view.getByRole('group', { name: en['thread.deleteConfirm'] }))
|
||||
expect(view.queryByRole('button', { name: 'Actions for the comment on R3–4' })).toBeNull()
|
||||
fireEvent.click(question.getByRole('button', { name: 'Cancel' }))
|
||||
expect(view.queryByRole('group')).toBeNull()
|
||||
expect(records.getSnapshot().comments).toHaveLength(1)
|
||||
choose(view, 'Delete')
|
||||
fireEvent.click(within(view.getByRole('group')).getByRole('button', { name: 'Delete' }))
|
||||
expect(records.getSnapshot().comments).toEqual([])
|
||||
})
|
||||
it('deletes a draft whose text the reader emptied while editing it, after the same confirmation', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
choose(view, 'Edit')
|
||||
fireEvent.change(view.getByRole('textbox'), { target: { value: '' } })
|
||||
expect(records.getSnapshot().comments[0]?.comment.body).toBe('')
|
||||
expect(view.getByRole('button', { name: 'Done' })).toHaveProperty('disabled', true)
|
||||
expect(openMenu(view)).toEqual(['Delete'])
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Delete' }))
|
||||
expect(view.queryByRole('textbox')).toBeNull()
|
||||
fireEvent.click(within(view.getByRole('group', { name: en['thread.deleteConfirm'] })).getByRole('button', { name: 'Delete' }))
|
||||
expect(records.getSnapshot().comments).toEqual([])
|
||||
})
|
||||
it('preserves unsaved edits and reports failed editing, finishing, and deletion', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records }}
|
||||
locked={false} outdated t={t} />)
|
||||
fireEvent.click(view.getByRole('button', { name: 'Edit' }))
|
||||
const actions = { source: selection.source, addToInput: () => true, records }
|
||||
const view = render(<ReviewThread thread={thread} actions={actions} locked={false} outdated t={t} />)
|
||||
choose(view, 'Edit')
|
||||
records.close()
|
||||
fireEvent.change(view.getByRole('textbox'), { target: { value: 'Not saved' } })
|
||||
expect(view.getByRole('alert')).toHaveProperty('textContent', en['review.saveFailed'])
|
||||
fireEvent.click(view.getByRole('button', { name: 'Done' }))
|
||||
expect(view.getByRole('textbox')).toHaveProperty('value', 'Not saved')
|
||||
fireEvent.click(view.getByRole('button', { name: 'Delete' }))
|
||||
expect(view.getByRole('alert')).toBeTruthy()
|
||||
view.unmount()
|
||||
const closed = render(<ReviewThread thread={thread} actions={actions} locked={false} outdated t={t} />)
|
||||
choose(closed, 'Delete')
|
||||
const question = within(closed.getByRole('group'))
|
||||
fireEvent.click(question.getByRole('button', { name: 'Delete' }))
|
||||
expect(question.getByRole('alert')).toHaveProperty('textContent', en['review.saveFailed'])
|
||||
fireEvent.click(question.getByRole('button', { name: 'Cancel' }))
|
||||
expect(closed.queryByRole('alert')).toBeNull()
|
||||
})
|
||||
it('keeps a browser draft as it is while a write is unsettled', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const queue = vi.fn<NonNullable<ReviewActions['queue']>>()
|
||||
const actions = { source: selection.source, addToInput: () => true, records, queue }
|
||||
const view = render(<ReviewThread thread={thread} actions={actions} locked={false} outdated={false} t={t} />)
|
||||
choose(view, 'Delete')
|
||||
view.rerender(<ReviewThread thread={thread} actions={actions} locked outdated={false} t={t} />)
|
||||
for (const button of within(view.getByRole('group')).getAllByRole('button')) expect(button).toHaveProperty('disabled', true)
|
||||
view.unmount()
|
||||
const locked = render(<ReviewThread thread={thread} actions={actions} locked outdated={false} t={t} />)
|
||||
const menu = locked.getByRole('button', { name: 'Actions for the comment on R3–4' })
|
||||
expect(menu).toHaveProperty('disabled', true)
|
||||
fireEvent.click(menu)
|
||||
expect(locked.queryByRole('menu')).toBeNull()
|
||||
expect(locked.getByRole('button', { name: 'Start review' })).toHaveProperty('disabled', true)
|
||||
})
|
||||
it('labels a browser draft and moves it into the pending review, deleting it from the browser only once the host took it', async () => {
|
||||
const records = drafted(selection)
|
||||
@@ -349,46 +448,113 @@ describe('inline records', () => {
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records, queue }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
expect(view.getByText(en['review.browserDraft'])).toBeTruthy()
|
||||
fireEvent.click(view.getByRole('button', { name: 'Add to review' }))
|
||||
fireEvent.click(view.getByRole('button', { name: 'Start review' }))
|
||||
expect(view.getByRole('button', { name: en['review.publishing'] })).toHaveProperty('disabled', true)
|
||||
expect(view.getByRole('button', { name: 'Actions for the comment on R3–4' })).toHaveProperty('disabled', true)
|
||||
expect(await view.findByRole('alert')).toHaveProperty('textContent', 'GitHub refused')
|
||||
expect(records.getSnapshot().comments).toHaveLength(1)
|
||||
queue.mockRejectedValueOnce(new Error('transport lost'))
|
||||
fireEvent.click(view.getByRole('button', { name: 'Add to review' }))
|
||||
fireEvent.click(view.getByRole('button', { name: 'Start review' }))
|
||||
await vi.waitFor(() => { expect(view.getByRole('alert').textContent).toBe(hostCopy('review.unknown')) })
|
||||
queue.mockResolvedValueOnce(undefined)
|
||||
vi.spyOn(records, 'editThread').mockReturnValueOnce(false)
|
||||
fireEvent.click(view.getByRole('button', { name: 'Add to review' }))
|
||||
fireEvent.click(view.getByRole('button', { name: 'Start review' }))
|
||||
await vi.waitFor(() => { expect(view.getByRole('alert').textContent).toBe(en['review.saveFailed']) })
|
||||
queue.mockResolvedValueOnce(undefined)
|
||||
fireEvent.click(view.getByRole('button', { name: 'Add to review' }))
|
||||
fireEvent.click(view.getByRole('button', { name: 'Start review' }))
|
||||
await vi.waitFor(() => { expect(records.getSnapshot().comments).toEqual([]) })
|
||||
expect(queue).toHaveBeenCalledWith(selection)
|
||||
})
|
||||
it('offers no move for an outdated browser draft, one being edited, or without a pending review destination', () => {
|
||||
it('names the move after whether the user already has a pending review, as the comment form does', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const queue = vi.fn<NonNullable<ReviewActions['queue']>>()
|
||||
const actions = { source: selection.source, addToInput: () => true, records, queue, reviewStarted: true }
|
||||
const view = render(<ReviewThread thread={thread} actions={actions} locked={false} outdated={false} t={t} />)
|
||||
expect(view.getByRole('button', { name: 'Add to review' })).toBeTruthy()
|
||||
expect(view.queryByRole('button', { name: 'Start review' })).toBeNull()
|
||||
})
|
||||
it('offers no move for an outdated browser draft, one being edited or deleted, or without a pending review destination', () => {
|
||||
const records = drafted(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const queue = vi.fn<NonNullable<ReviewActions['queue']>>()
|
||||
const outdated = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records, queue }}
|
||||
locked={false} outdated t={t} />)
|
||||
expect(outdated.queryByRole('button', { name: 'Add to review' })).toBeNull()
|
||||
expect(outdated.queryByRole('button', { name: 'Start review' })).toBeNull()
|
||||
expect(outdated.getByText(en['review.browserDraft'])).toBeTruthy()
|
||||
expect(outdated.getByText(en['review.outdated'])).toBeTruthy()
|
||||
outdated.unmount()
|
||||
const current = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records, queue }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
fireEvent.click(current.getByRole('button', { name: 'Edit' }))
|
||||
expect(current.queryByRole('button', { name: 'Add to review' })).toBeNull()
|
||||
choose(current, 'Edit')
|
||||
expect(current.queryByRole('button', { name: 'Start review' })).toBeNull()
|
||||
fireEvent.click(current.getByRole('button', { name: 'Done' }))
|
||||
choose(current, 'Delete')
|
||||
expect(current.queryByRole('button', { name: 'Start review' })).toBeNull()
|
||||
current.unmount()
|
||||
const without = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
expect(without.queryByRole('button', { name: 'Add to review' })).toBeNull()
|
||||
expect(without.queryByRole('button', { name: 'Start review' })).toBeNull()
|
||||
})
|
||||
it('opens a published receipt and omits editing on immutable records', () => {
|
||||
it('removes a reference from the view without asking and reports it so the removal can be undone', () => {
|
||||
const records = new ReviewQueue('review-test')
|
||||
records.recordAgent(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const onRemoved = vi.fn<NonNullable<ReviewActions['onRemoved']>>()
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records, onRemoved }}
|
||||
locked outdated={false} t={t} />)
|
||||
expect(view.getByText(en['review.quoted'])).toBeTruthy()
|
||||
expect(view.queryByText(en['review.outdated'])).toBeNull()
|
||||
expect(view.getByRole('button', { name: 'Add to input' })).toBeTruthy()
|
||||
expect(openMenu(view)).toEqual(['Remove'])
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Remove' }))
|
||||
expect(view.queryByRole('group')).toBeNull()
|
||||
expect(records.getSnapshot().records).toEqual([])
|
||||
expect(onRemoved).toHaveBeenCalledWith({ record: { kind: 'agent', selection }, index: 0 })
|
||||
})
|
||||
it('keeps a record and says so when its removal was not saved', () => {
|
||||
const records = new ReviewQueue('review-test')
|
||||
records.recordAgent(selection)
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const onRemoved = vi.fn<NonNullable<ReviewActions['onRemoved']>>()
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, records, onRemoved }}
|
||||
locked={false} outdated t={t} />)
|
||||
vi.spyOn(Storage.prototype, 'setItem').mockImplementationOnce(() => { throw new DOMException('quota', 'QuotaExceededError') })
|
||||
choose(view, 'Remove')
|
||||
expect(view.getByRole('alert')).toHaveProperty('textContent', en['review.saveFailed'])
|
||||
expect(onRemoved).not.toHaveBeenCalled()
|
||||
expect(records.getSnapshot().records).toHaveLength(1)
|
||||
})
|
||||
it('opens a published receipt, removes it from the view, and omits editing on immutable records', () => {
|
||||
const openLink = vi.fn()
|
||||
const view = render(<ReviewThread thread={{ key: 1, kind: 'published', selection, url: 'https://github.com/review' }}
|
||||
actions={{ source: selection.source, addToInput: () => true, openLink }} locked={false} outdated={false} t={t} />)
|
||||
const records = new ReviewQueue('review-test')
|
||||
records.published(selection, 'https://github.com/review')
|
||||
const thread = records.fileComments('a.ts', selection.source).threads[0]!
|
||||
const view = render(<ReviewThread thread={thread} actions={{ source: selection.source, addToInput: () => true, openLink, records }}
|
||||
locked={false} outdated={false} t={t} />)
|
||||
fireEvent.click(view.getByRole('button', { name: hostCopy('review.recheck') }))
|
||||
expect(openLink).toHaveBeenCalledWith('https://github.com/review')
|
||||
expect(view.queryByRole('button', { name: 'Edit' })).toBeNull()
|
||||
expect(openMenu(view)).toEqual(['Remove'])
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Remove' }))
|
||||
expect(records.getSnapshot().records).toEqual([])
|
||||
view.unmount()
|
||||
const unowned = render(<ReviewThread thread={{ key: 1, kind: 'published', selection, url: 'https://github.com/review' }}
|
||||
actions={{ source: selection.source, addToInput: () => true }} locked={false} outdated={false} t={t} />)
|
||||
expect(unowned.queryByRole('button', { name: hostCopy('review.recheck') })).toBeNull()
|
||||
choose(unowned, 'Remove')
|
||||
expect(unowned.getByRole('alert')).toHaveProperty('textContent', en['review.saveFailed'])
|
||||
})
|
||||
it('turns a draft published while its form is open into a receipt without the form', () => {
|
||||
const records = drafted(selection)
|
||||
const drafts = (): ReturnType<ReviewQueue['fileComments']>['threads'] => records.fileComments('a.ts', selection.source).threads
|
||||
const actions = { source: selection.source, addToInput: () => true, records }
|
||||
const view = render(<ReviewThread thread={drafts()[0]!} actions={actions} locked={false} outdated={false} t={t} />)
|
||||
choose(view, 'Edit')
|
||||
records.finish(true, 'https://github.com/octo/demo/pull/7#review-1')
|
||||
view.rerender(<ReviewThread thread={drafts()[0]!} actions={actions} locked={false} outdated={false} t={t} />)
|
||||
expect(view.queryByRole('textbox')).toBeNull()
|
||||
expect(view.queryByRole('button', { name: 'Done' })).toBeNull()
|
||||
expect(openMenu(view)).toEqual(['Remove'])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user