Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(conversation): align PR panel loading header with the loaded one (#19847)

Inneida2e9a7f973e
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/Head.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/Head.tsx
new file mode 100644
index 00000000000..c1d53d32b85
--- /dev/null
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/Head.tsx
@@ -0,0 +1,127 @@
+import type { DeviceGitLinkedPullRequest } from '@lobechat/types';
+import { Flexbox, Icon } from '@lobehub/ui';
+import { createStaticStyles } from 'antd-style';
+import type { ReactNode } from 'react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { rowStyles } from '../Overview/OverviewRow';
+import { sectionStyles } from '../Overview/sectionStyles';
+import { getDetailVisual } from './prVisual';
+
+export const headStyles = createStaticStyles(({ css, cssVar }) => ({
+ actions: css`
+ flex-shrink: 0;
+ margin-block-start: -2px;
+ `,
+ meta: css`
+ flex-wrap: wrap;
+
+ margin-block-start: 6px;
+
+ font-size: 12px;
+ line-height: 18px;
+ color: ${cssVar.colorTextTertiary};
+ `,
+ ref: css`
+ overflow: hidden;
+
+ max-width: 160px;
+ padding-block: 1px;
+ padding-inline: 6px;
+ border-radius: 4px;
+
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: 11px;
+ color: ${cssVar.colorTextSecondary};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+
+ background: ${cssVar.colorFillSecondary};
+ `,
+ refButton: css`
+ cursor: pointer;
+ display: inline-flex;
+ gap: 3px;
+ align-items: center;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ background: ${cssVar.colorFillTertiary};
+ }
+ `,
+ root: css`
+ padding-block: 10px 8px;
+ padding-inline: 8px;
+ `,
+ stats: css`
+ font-variant-numeric: tabular-nums;
+ `,
+ title: css`
+ flex: 1;
+
+ min-width: 0;
+
+ font-size: 15px;
+ font-weight: 600;
+ line-height: 22px;
+ color: ${cssVar.colorText};
+ overflow-wrap: anywhere;
+ `,
+}));
+
+export const PrTitle = memo<{ number: number; title: string }>(({ number, title }) => (
+ <span className={headStyles.title}>
+ <span className={rowStyles.num}>#{number}</span>
+ {title}
+ </span>
+));
+
+PrTitle.displayName = 'PrTitle';
+
+export const PrStatePill = memo<{
+ pr: Pick<DeviceGitLinkedPullRequest, 'isDraft' | 'mergedAt' | 'state'>;
+}>(({ pr }) => {
+ const { t } = useTranslation('chat');
+ const visual = getDetailVisual(pr);
+ return (
+ <span
+ className={sectionStyles.pill}
+ style={{
+ background: `color-mix(in srgb, ${visual.color} 12%, transparent)`,
+ color: visual.color,
+ }}
+ >
+ <Icon icon={visual.icon} size={12} />
+ {t(`workingPanel.pr.state.${visual.state}`)}
+ </span>
+ );
+});
+
+PrStatePill.displayName = 'PrStatePill';
+
+interface PrHeadProps {
+ actions?: ReactNode;
+ meta: ReactNode;
+ title: ReactNode;
+}
+
+const PrHead = memo<PrHeadProps>(({ actions, meta, title }) => (
+ <div className={headStyles.root}>
+ <Flexbox horizontal align={'flex-start'} gap={6}>
+ {title}
+ {actions && (
+ <Flexbox horizontal className={headStyles.actions} gap={2}>
+ {actions}
+ </Flexbox>
+ )}
+ </Flexbox>
+ <Flexbox horizontal align={'center'} className={headStyles.meta} gap={6}>
+ {meta}
+ </Flexbox>
+ </div>
+));
+
+PrHead.displayName = 'PrHead';
+
+export default PrHead;
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
index 90bf808c6f9..e787cb8e22d 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/Header.tsx
@@ -1,7 +1,7 @@
import type { DeviceGitPullRequestAction, DeviceGitPullRequestDetail } from '@lobechat/types';
-import { copyToClipboard, Flexbox, Icon } from '@lobehub/ui';
+import { copyToClipboard, Icon } from '@lobehub/ui';
import { ActionIcon, type DropdownItem, DropdownMenu, toast } from '@lobehub/ui/base-ui';
-import { createStaticStyles, cx } from 'antd-style';
+import { cx } from 'antd-style';
import {
ArrowRightIcon,
ChevronDownIcon,
@@ -16,69 +16,7 @@ import { electronSystemService } from '@/services/electron/system';
import { useGitRemoteBranches } from '@/store/device';
import { rowStyles } from '../Overview/OverviewRow';
-import { sectionStyles } from '../Overview/sectionStyles';
-import { getDetailVisual } from './prVisual';
-
-const styles = createStaticStyles(({ css, cssVar }) => ({
- actions: css`
- flex-shrink: 0;
- margin-block-start: -2px;
- `,
- head: css`
- padding-block: 10px 8px;
- padding-inline: 8px;
- `,
- meta: css`
- flex-wrap: wrap;
-
- margin-block-start: 6px;
-
- font-size: 12px;
- line-height: 18px;
- color: ${cssVar.colorTextTertiary};
- `,
- ref: css`
- overflow: hidden;
-
- max-width: 160px;
- padding-block: 1px;
- padding-inline: 6px;
- border-radius: 4px;
-
- font-family: ${cssVar.fontFamilyCode};
- font-size: 11px;
- color: ${cssVar.colorTextSecondary};
- text-overflow: ellipsis;
- white-space: nowrap;
-
- background: ${cssVar.colorFillSecondary};
- `,
- refButton: css`
- cursor: pointer;
- display: inline-flex;
- gap: 3px;
- align-items: center;
-
- &:hover {
- color: ${cssVar.colorText};
- background: ${cssVar.colorFillTertiary};
- }
- `,
- stats: css`
- font-variant-numeric: tabular-nums;
- `,
- title: css`
- flex: 1;
-
- min-width: 0;
-
- font-size: 15px;
- font-weight: 600;
- line-height: 22px;
- color: ${cssVar.colorText};
- overflow-wrap: anywhere;
- `,
-}));
+import PrHead, { headStyles, PrStatePill, PrTitle } from './Head';
interface HeaderProps {
activityLoaded?: boolean;
@@ -91,7 +29,6 @@ interface HeaderProps {
const Header = memo<HeaderProps>(
({ activityLoaded = true, detail, deviceId, onAction, workingDirectory }) => {
const { t } = useTranslation('chat');
- const visual = getDetailVisual(detail);
const canChangeBase = detail.viewerCanWrite && detail.state === 'open';
const [basePickerOpen, setBasePickerOpen] = useState(false);
const { data: remoteBranches } = useGitRemoteBranches(
@@ -144,13 +81,10 @@ const Header = memo<HeaderProps>(
];
return (
- <div className={styles.head}>
- <Flexbox horizontal align={'flex-start'} gap={6}>
- <span className={styles.title}>
- <span className={rowStyles.num}>#{detail.number}</span>
- {detail.title}
- </span>
- <Flexbox horizontal className={styles.actions} gap={2}>
+ <PrHead
+ title={<PrTitle number={detail.number} title={detail.title} />}
+ actions={
+ <>
<ActionIcon
icon={ExternalLinkIcon}
size={'small'}
@@ -160,54 +94,47 @@ const Header = memo<HeaderProps>(
<DropdownMenu items={menuItems} placement={'bottomRight'}>
<ActionIcon icon={EllipsisIcon} size={'small'} />
</DropdownMenu>
- </Flexbox>
- </Flexbox>
- <Flexbox horizontal align={'center'} className={styles.meta} gap={6}>
- <span
- className={sectionStyles.pill}
- style={{
- background: `color-mix(in srgb, ${visual.color} 12%, transparent)`,
- color: visual.color,
- }}
- >
- <Icon icon={visual.icon} size={12} />
- {t(`workingPanel.pr.state.${visual.state}`)}
- </span>
- <span className={styles.ref} title={detail.headRefName}>
- {detail.headRefName}
- </span>
- <Icon icon={ArrowRightIcon} size={11} />
- {canChangeBase ? (
- <DropdownMenu
- virtual
- items={baseItems}
- placement={'bottomLeft'}
- onOpenChange={setBasePickerOpen}
- >
- <span
- className={cx(styles.ref, styles.refButton)}
- role={'button'}
- tabIndex={0}
- title={t('workingPanel.pr.header.changeBase')}
+ </>
+ }
+ meta={
+ <>
+ <PrStatePill pr={detail} />
+ <span className={headStyles.ref} title={detail.headRefName}>
+ {detail.headRefName}
+ </span>
+ <Icon icon={ArrowRightIcon} size={11} />
+ {canChangeBase ? (
+ <DropdownMenu
+ virtual
+ items={baseItems}
+ placement={'bottomLeft'}
+ onOpenChange={setBasePickerOpen}
>
+ <span
+ className={cx(headStyles.ref, headStyles.refButton)}
+ role={'button'}
+ tabIndex={0}
+ title={t('workingPanel.pr.header.changeBase')}
+ >
+ {detail.baseRefName}
+ <Icon icon={ChevronDownIcon} size={10} />
+ </span>
+ </DropdownMenu>
+ ) : (
+ <span className={headStyles.ref} title={detail.baseRefName}>
{detail.baseRefName}
- <Icon icon={ChevronDownIcon} size={10} />
</span>
- </DropdownMenu>
- ) : (
- <span className={styles.ref} title={detail.baseRefName}>
- {detail.baseRefName}
+ )}
+ {activityLoaded && (
+ <span>· {t('workingPanel.pr.header.commits', { count: detail.commits.length })}</span>
+ )}
+ <span className={headStyles.stats}>
+ <span className={rowStyles.changeAdditions}>+{detail.additions}</span>{' '}
+ <span className={rowStyles.changeDeletions}>−{detail.deletions}</span>
</span>
- )}
- {activityLoaded && (
- <span>· {t('workingPanel.pr.header.commits', { count: detail.commits.length })}</span>
- )}
- <span className={styles.stats}>
- <span className={rowStyles.changeAdditions}>+{detail.additions}</span>{' '}
- <span className={rowStyles.changeDeletions}>−{detail.deletions}</span>
- </span>
- </Flexbox>
- </div>
+ </>
+ }
+ />
);
},
);
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/Skeleton.tsx b/src/features/Conversation/WorkingSidebar/PullRequest/Skeleton.tsx
index 4fae1874bab..2a27ea28621 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/Skeleton.tsx
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/Skeleton.tsx
@@ -3,11 +3,9 @@ import { Flexbox } from '@lobehub/ui';
import { Skeleton } from '@lobehub/ui/base-ui';
import { createStaticStyles } from 'antd-style';
import { memo } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { getPullRequestState } from '@/features/AgentSidebar/Topic/List/Item/metaCardData';
import { sectionStyles } from '../Overview/sectionStyles';
+import PrHead, { PrStatePill, PrTitle } from './Head';
const styles = createStaticStyles(({ css, cssVar }) => ({
dock: css`
@@ -16,10 +14,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
padding-inline: 8px;
border-block-start: 1px solid ${cssVar.colorBorderSecondary};
`,
- head: css`
- padding-block: 10px 8px;
- padding-inline: 8px;
- `,
root: css`
flex: 1;
min-height: 0;
@@ -50,31 +44,29 @@ const SectionTitle = ({ width = 64 }: { width?: number }) => (
);
const PullRequestSkeleton = memo(({ summary }: { summary?: DeviceGitLinkedPullRequest }) => {
- const { t } = useTranslation('chat');
return (
<Flexbox className={styles.root}>
<Flexbox className={styles.root}>
- <div className={styles.head}>
- {summary ? (
+ <PrHead
+ meta={
<>
- <div>
- #{summary.number} {summary.title}
- </div>
- <div>
- {t(
- `workingPanel.pr.state.${summary.isDraft && getPullRequestState(summary) === 'open' ? 'draft' : getPullRequestState(summary)}`,
- )}
- </div>
+ {summary ? (
+ <PrStatePill pr={summary} />
+ ) : (
+ <Skeleton height={20} radius={6} width={56} />
+ )}
+ <Skeleton height={18} radius={4} width={96} />
+ <Skeleton height={18} radius={4} width={64} />
</>
- ) : (
- <Skeleton.Text fontSize={15} rows={2} width={['92%', '60%']} />
- )}
- <Flexbox horizontal align={'center'} gap={6} style={{ marginBlockStart: 6 }}>
- <Skeleton height={20} radius={6} width={56} />
- <Skeleton height={18} radius={4} width={96} />
- <Skeleton height={18} radius={4} width={64} />
- </Flexbox>
- </div>
+ }
+ title={
+ summary ? (
+ <PrTitle number={summary.number} title={summary.title} />
+ ) : (
+ <Skeleton.Text fontSize={15} rows={2} width={['92%', '60%']} />
+ )
+ }
+ />
<Flexbox className={sectionStyles.section}>
<SectionTitle width={72} />
<div className={styles.sectionBody}>
diff --git a/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts b/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
index 9c0edda95f4..9e8f1076e59 100644
--- a/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
+++ b/src/features/Conversation/WorkingSidebar/PullRequest/prVisual.ts
@@ -1,4 +1,4 @@
-import type { DeviceGitPullRequestCheck, DeviceGitPullRequestDetail } from '@lobechat/types';
+import type { DeviceGitLinkedPullRequest, DeviceGitPullRequestCheck } from '@lobechat/types';
import { cssVar } from 'antd-style';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
@@ -52,7 +52,9 @@ export const DOCK_ICON: Record<DockIcon, LucideIcon> = {
export type PullRequestVisualState = 'closed' | 'draft' | 'merged' | 'open';
-export const getDetailVisual = (detail: DeviceGitPullRequestDetail) => {
+export const getDetailVisual = (
+ detail: Pick<DeviceGitLinkedPullRequest, 'isDraft' | 'mergedAt' | 'state'>,
+) => {
const state = getPullRequestState(detail);
if (state === 'open' && detail.isDraft)
return {