Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(task): larger gh pr section in task block sidepanel (#4332)

Seamusc6b15591b8ad
diff --git a/js/app/packages/app/component/side-panel/github-pull-request.tsx b/js/app/packages/app/component/side-panel/github-pull-request.tsx
new file mode 100644
index 0000000000..e15fd6da32
--- /dev/null
+++ b/js/app/packages/app/component/side-panel/github-pull-request.tsx
@@ -0,0 +1,262 @@
+import ArrowSquareOut from '@phosphor/arrow-square-out.svg';
+import CheckCircle from '@phosphor/check-circle.svg';
+import Circle from '@phosphor/circle.svg';
+import CircleNotch from '@phosphor/circle-notch.svg';
+import GitMerge from '@phosphor/git-merge.svg';
+import GitPullRequest from '@phosphor/git-pull-request.svg';
+import MinusCircle from '@phosphor/minus-circle.svg';
+import XCircle from '@phosphor/x-circle.svg';
+import type {
+ GithubPullRequest,
+ GithubPullRequestCheckRun,
+} from '@service-storage/generated/schemas';
+import { cn, Layer } from '@ui';
+import { type Accessor, For, Match, Show, Switch } from 'solid-js';
+import { SidePanel } from './SidePanel';
+
+type GithubPullRequestWithPanelDetails = GithubPullRequest & {
+ authorLogin?: string | null;
+};
+
+const STATUS_ICON_CLASS: Record<string, string> = {
+ open: 'text-success',
+ merged: 'text-note',
+ closed: 'text-failure',
+};
+
+const STATUS_TEXT_CLASS: Record<string, string> = {
+ open: 'text-success',
+ merged: 'text-note',
+ closed: 'text-failure',
+};
+
+const PR_PILL_CLASS =
+ 'inline-flex items-center gap-1.5 min-w-0 ring ring-edge-muted px-2 py-1 leading-tight text-left rounded-full bg-surface';
+
+function capitalize(value: string): string {
+ return value.charAt(0).toUpperCase() + value.slice(1);
+}
+
+function githubDisplayLogin(login: string): string {
+ return login.replace(/\[bot\]$/, '');
+}
+
+function githubAvatarUrl(login: string): string {
+ return `https://github.com/${githubDisplayLogin(login)}.png?size=48`;
+}
+
+function checksPassedCount(checks: GithubPullRequestCheckRun[]): number {
+ return checks.filter((check) => check.conclusion === 'success').length;
+}
+
+function checkDuration(check: GithubPullRequestCheckRun): string | null {
+ if (!check.startedAt || !check.completedAt) return null;
+ const ms = Date.parse(check.completedAt) - Date.parse(check.startedAt);
+ if (Number.isNaN(ms) || ms < 0) return null;
+ const seconds = Math.round(ms / 1000);
+ if (seconds < 60) return `${seconds}s`;
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
+}
+
+function GithubPullRequestCheckStatusIcon(props: {
+ check: GithubPullRequestCheckRun;
+}) {
+ return (
+ <Switch fallback={<Circle class="size-3.5 text-ink-placeholder" />}>
+ <Match when={props.check.status !== 'completed'}>
+ <CircleNotch class="size-3.5 text-ink-placeholder animate-spin" />
+ </Match>
+ <Match when={props.check.conclusion === 'success'}>
+ <CheckCircle class="size-3.5 text-success" />
+ </Match>
+ <Match
+ when={
+ props.check.conclusion === 'failure' ||
+ props.check.conclusion === 'timed_out'
+ }
+ >
+ <XCircle class="size-3.5 text-failure" />
+ </Match>
+ <Match
+ when={
+ props.check.conclusion === 'skipped' ||
+ props.check.conclusion === 'cancelled' ||
+ props.check.conclusion === 'neutral'
+ }
+ >
+ <MinusCircle class="size-3.5 text-ink-placeholder" />
+ </Match>
+ </Switch>
+ );
+}
+
+export function GithubPullRequestStatusIcon(props: {
+ status: string;
+ class?: string;
+}) {
+ return (
+ <Show
+ when={props.status === 'merged'}
+ fallback={
+ <GitPullRequest
+ class={cn('size-3.5', STATUS_ICON_CLASS[props.status], props.class)}
+ />
+ }
+ >
+ <GitMerge class={cn('size-3.5 text-note', props.class)} />
+ </Show>
+ );
+}
+
+export function GithubPullRequestStatusChip(props: {
+ status: string;
+ class?: string;
+}) {
+ return (
+ <Layer depth={2}>
+ <span
+ class={cn(
+ PR_PILL_CLASS,
+ 'shrink-0',
+ STATUS_TEXT_CLASS[props.status],
+ props.class
+ )}
+ >
+ <GithubPullRequestStatusIcon
+ status={props.status}
+ class="size-3 shrink-0"
+ />
+ {capitalize(props.status)}
+ </span>
+ </Layer>
+ );
+}
+
+export function GithubPullRequestDetailsContent(props: {
+ enrichment: Accessor<GithubPullRequestWithPanelDetails | undefined>;
+}) {
+ return (
+ <Show when={props.enrichment()} fallback={<SidePanel.Loading />}>
+ {(enrichment) => (
+ <SidePanel.Grid>
+ <GithubPullRequestDetailsRows enrichment={enrichment()} />
+ </SidePanel.Grid>
+ )}
+ </Show>
+ );
+}
+
+export function GithubPullRequestDetailsRows(props: {
+ enrichment: GithubPullRequestWithPanelDetails;
+}) {
+ return (
+ <>
+ <SidePanel.Row label="Author">
+ <SidePanel.Pill>
+ <Show
+ when={props.enrichment.authorLogin}
+ fallback={
+ <>
+ <span class="skeleton-shimmer size-3.5 rounded-full bg-ink/10" />
+ <span class="skeleton-shimmer h-3 w-16 rounded-full bg-ink/10" />
+ </>
+ }
+ >
+ {(authorLogin) => (
+ <>
+ <img
+ src={githubAvatarUrl(authorLogin())}
+ alt={authorLogin()}
+ class="size-3.5 rounded-full shrink-0"
+ loading="lazy"
+ />
+ <span class="truncate">{authorLogin()}</span>
+ </>
+ )}
+ </Show>
+ </SidePanel.Pill>
+ </SidePanel.Row>
+ <SidePanel.Row label="Repository">
+ <span class="truncate">
+ {props.enrichment.owner}/{props.enrichment.repo}
+ </span>
+ </SidePanel.Row>
+ <Show when={props.enrichment.status}>
+ {(status) => (
+ <SidePanel.Row label="Status">
+ <GithubPullRequestStatusChip
+ status={status()}
+ class="text-xs px-1.5 py-0.5 gap-1"
+ />
+ </SidePanel.Row>
+ )}
+ </Show>
+ <Show
+ when={
+ props.enrichment.additions != null ||
+ props.enrichment.deletions != null
+ }
+ >
+ <SidePanel.Row label="Changes">
+ <span class="text-success">+{props.enrichment.additions ?? 0}</span>
+ <span class="text-ink-extra-muted">/</span>
+ <span class="text-failure">−{props.enrichment.deletions ?? 0}</span>
+ </SidePanel.Row>
+ </Show>
+ <SidePanel.Row label="GitHub">
+ <a
+ href={props.enrichment.url}
+ target="_blank"
+ rel="noreferrer"
+ class="min-w-0 truncate underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2 hover:decoration-current"
+ >
+ {props.enrichment.displayName}
+ </a>
+ </SidePanel.Row>
+ </>
+ );
+}
+
+export function GithubPullRequestChecksContent(props: {
+ enrichment: Accessor<GithubPullRequestWithPanelDetails | undefined>;
+}) {
+ const checks = () => props.enrichment()?.checks ?? [];
+ return (
+ <Show
+ when={checks().length > 0}
+ fallback={<div class="text-ink-placeholder">No checks</div>}
+ >
+ <div class="flex flex-col gap-1 text-xs">
+ <div class="text-xs text-ink-muted">
+ {checksPassedCount(checks())} passed
+ </div>
+ <For each={checks()}>
+ {(check) => (
+ <div class="flex items-center gap-2 min-w-0 h-6">
+ <GithubPullRequestCheckStatusIcon check={check} />
+ <span class="truncate">{check.name}</span>
+ <span class="ml-auto flex items-center gap-1.5 shrink-0 text-ink-placeholder">
+ <Show when={checkDuration(check)}>
+ {(duration) => <span>{duration()}</span>}
+ </Show>
+ <Show when={check.url}>
+ {(url) => (
+ <a
+ href={url()}
+ target="_blank"
+ rel="noreferrer"
+ aria-label={`Open ${check.name} on GitHub`}
+ class="hover:opacity-70 transition-opacity"
+ >
+ <ArrowSquareOut class="size-3" />
+ </a>
+ )}
+ </Show>
+ </span>
+ </div>
+ )}
+ </For>
+ </div>
+ </Show>
+ );
+}
diff --git a/js/app/packages/app/component/side-panel/index.ts b/js/app/packages/app/component/side-panel/index.ts
index f1c1abff29..5971b1dbb3 100644
--- a/js/app/packages/app/component/side-panel/index.ts
+++ b/js/app/packages/app/component/side-panel/index.ts
@@ -1,2 +1,9 @@
export type {} from './context';
+export {
+ GithubPullRequestChecksContent,
+ GithubPullRequestDetailsContent,
+ GithubPullRequestDetailsRows,
+ GithubPullRequestStatusChip,
+ GithubPullRequestStatusIcon,
+} from './github-pull-request';
export { SidePanel, useSidePanel } from './SidePanel';
diff --git a/js/app/packages/block-md/component/InlineTaskGithubPullRequests.tsx b/js/app/packages/block-md/component/InlineTaskGithubPullRequests.tsx
index 6602f819a3..7ab8fff62f 100644
--- a/js/app/packages/block-md/component/InlineTaskGithubPullRequests.tsx
+++ b/js/app/packages/block-md/component/InlineTaskGithubPullRequests.tsx
@@ -1,3 +1,4 @@
+import { GithubPullRequestStatusIcon } from '@app/component/side-panel';
import { useBlockAliasedName, useBlockId } from '@core/block';
import GithubIcon from '@icon/mcp-github.svg';
import { useDocumentGithubPullRequestsQuery } from '@queries/storage/github-pull-requests';
@@ -90,7 +91,19 @@ function InlineTaskGithubPullRequestsContent(props: {
rel="noopener noreferrer"
title={pullRequestTitle(pr)}
>
- <GithubIcon class="size-3 shrink-0" aria-hidden="true" />
+ <Show
+ when={pr.status}
+ fallback={
+ <GithubIcon class="size-3 shrink-0" aria-hidden="true" />
+ }
+ >
+ {(status) => (
+ <GithubPullRequestStatusIcon
+ status={status()}
+ class="size-3 shrink-0"
+ />
+ )}
+ </Show>
<Show
when={name}
fallback={
diff --git a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
index cf166f3929..49e2d4540d 100644
--- a/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
+++ b/js/app/packages/block-md/component/sidepanel/MarkdownSidePanelSections.tsx
@@ -1,5 +1,8 @@
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
-import { SidePanel } from '@app/component/side-panel';
+import {
+ GithubPullRequestDetailsRows,
+ SidePanel,
+} from '@app/component/side-panel';
import { EntityPropertiesSection } from '@app/component/side-panel/properties';
import { useSplitLayout } from '@app/component/split-layout/layout';
import { useBlockAliasedName, useBlockId, useBlockName } from '@core/block';
@@ -21,9 +24,7 @@ import { tryMacroId, useDisplayName } from '@core/user';
import { type DateValue, formatDate } from '@core/util/date';
import { openExternalUrl } from '@core/util/url';
import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
-import GithubIcon from '@icon/mcp-github.svg';
import { useNotificationsForEntity } from '@notifications';
-import ArrowSquareOutIcon from '@phosphor/arrow-square-out.svg';
import ClockIcon from '@phosphor/clock.svg';
import {
getDefaultPinnedProperties,
@@ -31,14 +32,16 @@ import {
} from '@property/constants';
import { useAttachmentReferencesQuery } from '@queries/storage/attachment-references';
import { useDocumentMetadataQuery } from '@queries/storage/document-metadata';
-import { useDocumentGithubPullRequestsQuery } from '@queries/storage/github-pull-requests';
+import {
+ type GithubPullRequestWithDetails,
+ useDocumentGithubPullRequestsQuery,
+} from '@queries/storage/github-pull-requests';
import {
useDocumentTeamShareQuery,
useSetDocumentTeamShareMutation,
} from '@queries/storage/team-share';
import type { EntityType as PropertiesEntityType } from '@service-properties/generated/schemas/entityType';
import { blockNameToItemType } from '@service-storage/client';
-import type { GithubPullRequest } from '@service-storage/generated/schemas';
import { createCallback } from '@solid-primitives/rootless';
import { cn, InlineCheckbox } from '@ui';
import {
@@ -472,7 +475,7 @@ function GithubSectionConditional(props: {
);
const { openWithSplit } = useSplitLayout();
- const pullRequests = createMemo((): GithubPullRequest[] => {
+ const pullRequests = createMemo((): GithubPullRequestWithDetails[] => {
if (!props.isTask || query.isLoading || query.isError) return [];
return query.data?.pullRequests ?? [];
});
@@ -485,65 +488,52 @@ function GithubSectionConditional(props: {
title={<SidePanel.CountTitle label="GitHub" count={count()} />}
order={35}
>
- <SidePanel.Grid>
- <SidePanel.Row label={count() === 1 ? 'PR' : 'PRs'}>
- <div class="flex min-w-0 flex-wrap items-center gap-x-1">
- <For each={pullRequests()}>
- {(pr, i) => (
- <>
- <Show when={i() > 0}>
- <span class="text-ink-extra-muted">,</span>
- </Show>
- <button
- type="button"
- disabled={!pr.url}
- class={cn(
- 'inline-flex min-w-0 items-center gap-1 text-ink hover:text-ink',
- !pr.url &&
- 'cursor-not-allowed text-ink-placeholder hover:text-ink-placeholder'
- )}
- title={
- pr.name?.trim()
- ? `${pr.name.trim()} ${pr.displayName}`
- : pr.displayName
- }
- onClick={() => {
- if (USE_MACRO_PR_SUMMARY_BLOCK && pr.foreignEntityId) {
- openWithSplit(
- {
- type: 'pr',
- id: pr.foreignEntityId,
- },
- { referredFrom: null }
- );
- return;
- }
- if (pr.url) openExternalUrl(pr.url);
- }}
- >
- <GithubIcon
- class="size-3 shrink-0 text-ink-extra-muted"
- aria-hidden="true"
- />
- <span class="truncate underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2 hover:decoration-current">
- {pr.displayName}
- </span>
- </button>
- <a
- href={pr.url}
- target="_blank"
- rel="noopener noreferrer"
- aria-label={`Open ${pr.displayName} on GitHub`}
- class="shrink-0 text-ink-extra-muted hover:text-ink"
- >
- <ArrowSquareOutIcon class="size-3" aria-hidden="true" />
- </a>
- </>
- )}
- </For>
- </div>
- </SidePanel.Row>
- </SidePanel.Grid>
+ <div class="flex flex-col gap-4">
+ <For each={pullRequests()}>
+ {(pr, index) => {
+ const title = () => pr.name?.trim() || pr.displayName;
+ const openPullRequest = () => {
+ if (USE_MACRO_PR_SUMMARY_BLOCK && pr.foreignEntityId) {
+ openWithSplit(
+ {
+ type: 'pr',
+ id: pr.foreignEntityId,
+ },
+ { referredFrom: null }
+ );
+ return;
+ }
+ openExternalUrl(pr.url);
+ };
+
+ return (
+ <div
+ class={cn(
+ 'flex flex-col',
+ index() > 0 && 'border-t border-edge-muted pt-4'
+ )}
+ >
+ <SidePanel.Grid class="auto-rows-[minmax(1.75rem,auto)]">
+ <span class="text-ink-muted truncate self-start pt-[0.3125rem]">
+ PR
+ </span>
+ <div class="min-w-0 max-w-full overflow-hidden self-start py-0.5">
+ <button
+ type="button"
+ class="block min-w-0 max-w-full text-left whitespace-normal wrap-break-word leading-snug underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2 hover:decoration-current"
+ title={title()}
+ onClick={openPullRequest}
+ >
+ {title()}
+ </button>
+ </div>
+ <GithubPullRequestDetailsRows enrichment={pr} />
+ </SidePanel.Grid>
+ </div>
+ );
+ }}
+ </For>
+ </div>
</SidePanel.Section>
</Show>
);
diff --git a/js/app/packages/block-pr/component/sidepanel/PrSidePanelSections.tsx b/js/app/packages/block-pr/component/sidepanel/PrSidePanelSections.tsx
index db8bf270c0..40fba60826 100644
--- a/js/app/packages/block-pr/component/sidepanel/PrSidePanelSections.tsx
+++ b/js/app/packages/block-pr/component/sidepanel/PrSidePanelSections.tsx
@@ -1,167 +1,10 @@
-import { SidePanel } from '@app/component/side-panel';
-import ArrowSquareOut from '@phosphor/arrow-square-out.svg';
-import CheckCircle from '@phosphor/check-circle.svg';
-import Circle from '@phosphor/circle.svg';
-import CircleNotch from '@phosphor/circle-notch.svg';
-import MinusCircle from '@phosphor/minus-circle.svg';
-import XCircle from '@phosphor/x-circle.svg';
+import {
+ GithubPullRequestChecksContent,
+ GithubPullRequestDetailsContent,
+ SidePanel,
+} from '@app/component/side-panel';
import type { GithubPullRequestWithDetails } from '@queries/storage/github-pull-requests';
-import type { GithubPullRequestCheckRun } from '@service-storage/generated/schemas';
-import { type Accessor, For, Match, Show, Switch } from 'solid-js';
-
-import { githubAvatarUrl } from '../../util/githubMarkdown';
-import { PrStatusChip } from '../PrSplitHeader';
-
-function checksPassedCount(checks: GithubPullRequestCheckRun[]): number {
- return checks.filter((check) => check.conclusion === 'success').length;
-}
-
-function checkDuration(check: GithubPullRequestCheckRun): string | null {
- if (!check.startedAt || !check.completedAt) return null;
- const ms = Date.parse(check.completedAt) - Date.parse(check.startedAt);
- if (Number.isNaN(ms) || ms < 0) return null;
- const seconds = Math.round(ms / 1000);
- if (seconds < 60) return `${seconds}s`;
- return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
-}
-
-function CheckStatusIcon(props: { check: GithubPullRequestCheckRun }) {
- return (
- <Switch fallback={<Circle class="size-3.5 text-ink-placeholder" />}>
- <Match when={props.check.status !== 'completed'}>
- <CircleNotch class="size-3.5 text-ink-placeholder animate-spin" />
- </Match>
- <Match when={props.check.conclusion === 'success'}>
- <CheckCircle class="size-3.5 text-success" />
- </Match>
- <Match
- when={
- props.check.conclusion === 'failure' ||
- props.check.conclusion === 'timed_out'
- }
- >
- <XCircle class="size-3.5 text-failure" />
- </Match>
- <Match
- when={
- props.check.conclusion === 'skipped' ||
- props.check.conclusion === 'cancelled' ||
- props.check.conclusion === 'neutral'
- }
- >
- <MinusCircle class="size-3.5 text-ink-placeholder" />
- </Match>
- </Switch>
- );
-}
-
-function PrDetailsSectionContent(props: {
- enrichment: Accessor<GithubPullRequestWithDetails | undefined>;
-}) {
- return (
- <Show when={props.enrichment()} fallback={<SidePanel.Loading />}>
- {(enrichment) => (
- <SidePanel.Grid>
- <Show when={enrichment().authorLogin}>
- {(authorLogin) => (
- <SidePanel.Row label="Author">
- <SidePanel.Pill>
- <img
- src={githubAvatarUrl(authorLogin())}
- alt={authorLogin()}
- class="size-3.5 rounded-full shrink-0"
- loading="lazy"
- />
- <span class="truncate">{authorLogin()}</span>
- </SidePanel.Pill>
- </SidePanel.Row>
- )}
- </Show>
- <SidePanel.Row label="Repository">
- <span class="truncate">
- {enrichment().owner}/{enrichment().repo}
- </span>
- </SidePanel.Row>
- <Show when={enrichment().status}>
- {(status) => (
- <SidePanel.Row label="Status">
- <PrStatusChip
- status={status()}
- class="text-xs px-1.5 py-0.5 gap-1"
- />
- </SidePanel.Row>
- )}
- </Show>
- <Show
- when={
- enrichment().additions != null || enrichment().deletions != null
- }
- >
- <SidePanel.Row label="Changes">
- <span class="text-success">+{enrichment().additions ?? 0}</span>
- <span class="text-ink-extra-muted">/</span>
- <span class="text-failure">−{enrichment().deletions ?? 0}</span>
- </SidePanel.Row>
- </Show>
- <SidePanel.Row label="GitHub">
- <a
- href={enrichment().url}
- target="_blank"
- rel="noreferrer"
- class="min-w-0 truncate underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2 hover:decoration-current"
- >
- {enrichment().displayName}
- </a>
- </SidePanel.Row>
- </SidePanel.Grid>
- )}
- </Show>
- );
-}
-
-function PrChecksSectionContent(props: {
- enrichment: Accessor<GithubPullRequestWithDetails | undefined>;
-}) {
- const checks = () => props.enrichment()?.checks ?? [];
- return (
- <Show
- when={checks().length > 0}
- fallback={<div class="text-ink-placeholder">No checks</div>}
- >
- <div class="flex flex-col gap-1 text-xs">
- <div class="text-xs text-ink-muted">
- {checksPassedCount(checks())} passed
- </div>
- <For each={checks()}>
- {(check) => (
- <div class="flex items-center gap-2 min-w-0 h-6">
- <CheckStatusIcon check={check} />
- <span class="truncate">{check.name}</span>
- <span class="ml-auto flex items-center gap-1.5 shrink-0 text-ink-placeholder">
- <Show when={checkDuration(check)}>
- {(duration) => <span>{duration()}</span>}
- </Show>
- <Show when={check.url}>
- {(url) => (
- <a
- href={url()}
- target="_blank"
- rel="noreferrer"
- aria-label={`Open ${check.name} on GitHub`}
- class="hover:opacity-70 transition-opacity"
- >
- <ArrowSquareOut class="size-3" />
- </a>
- )}
- </Show>
- </span>
- </div>
- )}
- </For>
- </div>
- </Show>
- );
-}
+import type { Accessor } from 'solid-js';
export function PrSidePanelSections(props: {
enrichment: Accessor<GithubPullRequestWithDetails | undefined>;
@@ -169,11 +12,11 @@ export function PrSidePanelSections(props: {
return (
<>
<SidePanel.Section id="pr-details" title="Details" defaultOpen order={10}>
- <PrDetailsSectionContent enrichment={props.enrichment} />
+ <GithubPullRequestDetailsContent enrichment={props.enrichment} />
</SidePanel.Section>
<SidePanel.Section id="pr-checks" title="Checks" order={20}>
- <PrChecksSectionContent enrichment={props.enrichment} />
+ <GithubPullRequestChecksContent enrichment={props.enrichment} />
</SidePanel.Section>
</>
);