Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions site/src/pages/AgentsPage/AgentChatPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,13 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
const isArchived = chat.archived;
const liveChatStatus =
useChatSelector(store, selectChatStatus) ?? chat.status;
const parsedPrNumber = Number(
parsePullRequestUrl(chat.diff_status?.url)?.number,
);
const prNumber = chat.diff_status?.pr_number ?? (parsedPrNumber || undefined);
const diffStatus = chat.diff_status;
const parsedPrNumber = Number(parsePullRequestUrl(diffStatus?.url)?.number);
const prNumber = diffStatus?.pr_number ?? (parsedPrNumber || undefined);
const prTab =
diffStatus && prNumber
? { prNumber, chatId: agentId, diffStatus }
: undefined;

const canSubmitChatTurn = !isInputDisabled && !isSubmissionPending;

Expand Down Expand Up @@ -674,9 +677,7 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
case "git":
return (
<GitPanel
prTab={
prNumber && agentId ? { prNumber, chatId: agentId } : undefined
}
prTab={prTab}
repositories={gitWatcher.repositories}
everDirty={gitWatcher.everDirty}
isGitStatusLoading={
Expand All @@ -685,7 +686,7 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
}
onRefresh={handleRefresh}
isExpanded={visualExpanded}
remoteDiffStats={chat.diff_status}
remoteDiffStats={diffStatus}
chatInputRef={editing.chatInputRef}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type RemoteDiffPanelProps = {
isExpanded: boolean;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
diffStyle: DiffStyle;
diffStatus?: TypesGen.ChatDiffStatus;
diffStatus: TypesGen.ChatDiffStatus;
};

export const RemoteDiffPanel: React.FC<RemoteDiffPanelProps> = ({
Expand All @@ -77,7 +77,7 @@ export const RemoteDiffPanel: React.FC<RemoteDiffPanelProps> = ({
// ---------------------------------------------------------------
const diffContentsQuery = useQuery({
...chatDiffContents(chatId),
enabled: Boolean(diffStatus?.url),
enabled: Boolean(diffStatus.url),
});

const diffContent = diffContentsQuery.data?.diff;
Expand Down Expand Up @@ -106,10 +106,10 @@ export const RemoteDiffPanel: React.FC<RemoteDiffPanelProps> = ({
// ---------------------------------------------------------------
// Header content
// ---------------------------------------------------------------
const pullRequestUrl = diffStatus?.url;
const pullRequestUrl = diffStatus.url;
const parsedPr = pullRequestUrl ? parsePullRequestUrl(pullRequestUrl) : null;
const baseBranch = diffStatus?.base_branch;
const headBranch = diffStatus?.head_branch;
const baseBranch = diffStatus.base_branch;
const headBranch = diffStatus.head_branch;

// ---------------------------------------------------------------
// Render
Expand Down Expand Up @@ -143,7 +143,7 @@ export const RemoteDiffPanel: React.FC<RemoteDiffPanelProps> = ({
)}
</div>
<div className="ml-auto flex shrink-0 items-center gap-1.5">
{diffStatus?.additions || diffStatus?.deletions ? (
{diffStatus.additions || diffStatus.deletions ? (
<DiffStatBadge
additions={diffStatus.additions}
deletions={diffStatus.deletions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ const makePrStatus = (
...overrides,
});

/** GitPanel args for a chat with a PR, as `AgentChatPageView` builds them. */
const makePrArgs = (
prNumber: number,
overrides: Partial<ChatDiffStatus> = {},
) => {
const diffStatus = makePrStatus(overrides);
return {
prTab: { prNumber, chatId: "test-chat", diffStatus },
remoteDiffStats: diffStatus,
};
};

const emptyPrStatus: ChatDiffStatus = {
...defaultDiffStatus,
pr_number: 23020,
};

// ---------------------------------------------------------------------------
// Meta
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -131,8 +148,7 @@ type Story = StoryObj<typeof GitPanel>;
/** PR is open with a title, head/base branches, and working changes. */
export const PullRequestAndWorkingChanges: Story = {
args: {
prTab: { prNumber: 23020, chatId: "test-chat" },
remoteDiffStats: makePrStatus(),
...makePrArgs(23020),
repositories: new Map([["/home/coder/coder", makeRepo()]]),
},
beforeEach: () => {
Expand All @@ -149,8 +165,7 @@ export const PullRequestAndWorkingChanges: Story = {
*/
export const ViewSwitcherOpen: Story = {
args: {
prTab: { prNumber: 23020, chatId: "test-chat" },
remoteDiffStats: makePrStatus({
...makePrArgs(23020, {
pull_request_title: "feat: multi-repo workspace support",
head_branch: "feat/multi-repo",
}),
Expand Down Expand Up @@ -196,8 +211,7 @@ export const ViewSwitcherOpen: Story = {
/** Draft PR with head/base branches. */
export const DraftPullRequest: Story = {
args: {
prTab: { prNumber: 22950, chatId: "test-chat" },
remoteDiffStats: makePrStatus({
...makePrArgs(22950, {
url: "https://github.com/coder/coder/pull/22950",
pull_request_title: "fix: resolve race condition in workspace builds",
pull_request_draft: true,
Expand All @@ -221,8 +235,7 @@ export const DraftPullRequest: Story = {
/** Merged PR. */
export const MergedPullRequest: Story = {
args: {
prTab: { prNumber: 23000, chatId: "test-chat" },
remoteDiffStats: makePrStatus({
...makePrArgs(23000, {
url: "https://github.com/coder/coder/pull/23000",
pull_request_title: "chore: update dependencies to latest",
pull_request_state: "merged",
Expand All @@ -243,8 +256,7 @@ export const MergedPullRequest: Story = {
/** Closed PR. */
export const ClosedPullRequest: Story = {
args: {
prTab: { prNumber: 22800, chatId: "test-chat" },
remoteDiffStats: makePrStatus({
...makePrArgs(22800, {
url: "https://github.com/coder/coder/pull/22800",
pull_request_title: "feat: experimental websocket transport",
pull_request_state: "closed",
Expand Down Expand Up @@ -285,8 +297,7 @@ export const WorkingChangesOnly: Story = {
/** Multiple repos with working changes. */
export const MultipleRepos: Story = {
args: {
prTab: { prNumber: 23020, chatId: "test-chat" },
remoteDiffStats: makePrStatus({
...makePrArgs(23020, {
pull_request_title: "feat: multi-repo workspace support",
head_branch: "feat/multi-repo",
additions: 500,
Expand Down Expand Up @@ -314,10 +325,14 @@ export const MultipleRepos: Story = {
},
};

/** No remote changes, no working changes — empty state. */
/**
* PR number known but no URL, remote changes, or working changes yet;
* empty state.
*/
export const EmptyState: Story = {
args: {
prTab: { prNumber: 23020, chatId: "test-chat" },
prTab: { prNumber: 23020, chatId: "test-chat", diffStatus: emptyPrStatus },
remoteDiffStats: emptyPrStatus,
},
};

Expand All @@ -343,8 +358,7 @@ export const GitStatusLoading: Story = {
*/
export const InlineCommentInput: Story = {
args: {
prTab: { prNumber: 23020, chatId: "test-chat" },
remoteDiffStats: makePrStatus(),
...makePrArgs(23020),
},
decorators: [
(Story) => (
Expand Down
19 changes: 10 additions & 9 deletions site/src/pages/AgentsPage/components/GitPanel/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ type DiffStats = {
deletions: number;
};

type PrTab = {
prNumber: number;
chatId: string;
/** Diff status of the chat, which is what the PR number came from. */
diffStatus: ChatDiffStatus;
};

type GitPanelProps = {
/** PR tab data. Omitted if no PR is associated. */
prTab?: {
prNumber: number;
chatId: string;
};
prTab?: PrTab;
/** Repository data from git watcher. */
repositories: ReadonlyMap<string, WorkspaceAgentRepoChanges>;
/** Callback to send a refresh to the git watcher. Returns false when disconnected. */
Expand Down Expand Up @@ -436,7 +440,6 @@ export const GitPanel: React.FC<GitPanelProps> = ({
isExpanded={isExpanded}
chatInputRef={chatInputRef}
diffStyle={diffStyle}
diffStatus={remoteDiffStats}
/>
) : (
<LocalRepoContent
Expand Down Expand Up @@ -584,21 +587,19 @@ const GitViewSwitcher: React.FC<GitViewSwitcherProps> = ({
// ---------------------------------------------------------------

const RemoteContent: React.FC<{
prTab?: { prNumber: number; chatId: string };
prTab?: PrTab;
hasGitContext: boolean;
isGitStatusLoading: boolean;
isExpanded: boolean;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
diffStyle: DiffStyle;
diffStatus?: ChatDiffStatus;
}> = ({
prTab,
hasGitContext,
isGitStatusLoading,
isExpanded,
chatInputRef,
diffStyle,
diffStatus,
}) => {
if (!prTab) {
return (
Expand Down Expand Up @@ -634,7 +635,7 @@ const RemoteContent: React.FC<{
isExpanded={isExpanded}
chatInputRef={chatInputRef}
diffStyle={diffStyle}
diffStatus={diffStatus}
diffStatus={prTab.diffStatus}
/>
);
};
Expand Down
Loading