diff --git a/app/components/HoverPreview/HoverPreviewPullRequest.tsx b/app/components/HoverPreview/HoverPreviewPullRequest.tsx index 11bcc67f70..ff830953ea 100644 --- a/app/components/HoverPreview/HoverPreviewPullRequest.tsx +++ b/app/components/HoverPreview/HoverPreviewPullRequest.tsx @@ -33,11 +33,7 @@ const HoverPreviewPullRequest = React.forwardRef( - <StyledPullRequestIcon - status={state.name} - color={state.color} - size={18} - /> + <StyledPullRequestIcon size={18} state={state} /> <span> <Backticks content={title} />  <Text type="tertiary">{id}</Text> diff --git a/plugins/github/server/github.ts b/plugins/github/server/github.ts index a5bb995818..8e5a140525 100644 --- a/plugins/github/server/github.ts +++ b/plugins/github/server/github.ts @@ -279,7 +279,8 @@ export class GitHub { }, state: { name: prState, - color: GitHubUtils.getColorForStatus(prState), + color: GitHubUtils.getColorForStatus(prState, !!pr.draft), + draft: pr.draft, }, createdAt: pr.created_at, transformed_unfurl: true, diff --git a/plugins/github/shared/GitHubUtils.ts b/plugins/github/shared/GitHubUtils.ts index 0ea545102d..a7eac82a42 100644 --- a/plugins/github/shared/GitHubUtils.ts +++ b/plugins/github/shared/GitHubUtils.ts @@ -45,10 +45,10 @@ export class GitHubUtils { return `${this.url}?install_request=true`; } - public static getColorForStatus(status: string) { + public static getColorForStatus(status: string, isDraftPR: boolean = false) { switch (status) { case "open": - return "#238636"; + return isDraftPR ? "#848d97" : "#238636"; case "done": return "#a371f7"; case "closed": diff --git a/shared/components/PullRequestIcon.tsx b/shared/components/PullRequestIcon.tsx index 298d39f962..6a42842e65 100644 --- a/shared/components/PullRequestIcon.tsx +++ b/shared/components/PullRequestIcon.tsx @@ -1,9 +1,9 @@ import * as React from "react"; import styled from "styled-components"; +import { UnfurlResourceType, UnfurlResponse } from "../types"; type Props = { - status: string; - color: string; + state: UnfurlResponse[UnfurlResourceType.PR]["state"]; size?: number; className?: string; }; @@ -11,10 +11,10 @@ type Props = { /** * Issue status icon based on GitHub pull requests, but can be used for any git-style integration. */ -export function PullRequestIcon({ size, className, ...rest }: Props) { +export function PullRequestIcon({ size, className, state }: Props) { return ( <Icon size={size} className={className}> - <BaseIcon {...rest} /> + <BaseIcon state={state} /> </Icon> ); } @@ -28,42 +28,32 @@ const Icon = styled.span<{ size?: number }>` justify-content: center; `; -function BaseIcon({ status, size, color, className }: Props) { - switch (status) { +function BaseIcon({ state }: Pick<Props, "state">) { + switch (state.name) { case "open": return ( - <svg - viewBox="0 0 16 16" - width={size} - height={size} - fill={color} - className={className} - > - <path d="M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z" /> + <svg viewBox="0 0 16 16" fill={state.color}> + {state.draft ? ( + <path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 14a2.25 2.25 0 1 1 0-4.5 2.25 2.25 0 0 1 0 4.5ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM14 7.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm0-4.25a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Z" /> + ) : ( + <path d="M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z" /> + )} </svg> ); case "merged": return ( - <svg - viewBox="0 0 16 16" - width={size} - height={size} - fill={color} - className={className} - > + <svg viewBox="0 0 16 16" fill={state.color}> <path d="M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218ZM4.25 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm8.5-4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM5 3.25a.75.75 0 1 0 0 .005V3.25Z" /> </svg> ); case "closed": return ( - <svg - viewBox="0 0 16 16" - width={size} - height={size} - fill={color} - className={className} - > - <path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" /> + <svg viewBox="0 0 16 16" fill={state.color}> + {state.draft ? ( + <path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" /> + ) : ( + <path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" /> + )} </svg> ); default: diff --git a/shared/editor/components/Mentions.tsx b/shared/editor/components/Mentions.tsx index 5a3dbeee86..1f9898ee4c 100644 --- a/shared/editor/components/Mentions.tsx +++ b/shared/editor/components/Mentions.tsx @@ -279,11 +279,7 @@ export const MentionPullRequest = observer((props: IssuePrProps) => { rel="noopener noreferrer nofollow" > <Flex align="center" gap={6}> - <PullRequestIcon - size={14} - status={pullRequest.state.name} - color={pullRequest.state.color} - /> + <PullRequestIcon size={14} state={pullRequest.state} /> <Flex align="center" gap={4}> <Text> <Backticks content={pullRequest.title} /> diff --git a/shared/types.ts b/shared/types.ts index 1ed45aaf47..bf08671624 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -461,7 +461,7 @@ export type UnfurlResponse = { /** Pull Request author */ author: { name: string; avatarUrl: string }; /** Pull Request status */ - state: { name: string; color: string }; + state: { name: string; color: string; draft?: boolean }; /** Pull Request creation time */ createdAt: string; };