diff --git a/app/components/HoverPreview/HoverPreviewIssue.tsx b/app/components/HoverPreview/HoverPreviewIssue.tsx index bf71e62ac4..4eee531ef0 100644 --- a/app/components/HoverPreview/HoverPreviewIssue.tsx +++ b/app/components/HoverPreview/HoverPreviewIssue.tsx @@ -1,7 +1,11 @@ import * as React from "react"; import { Trans } from "react-i18next"; import { IssueStatusIcon } from "@shared/components/IssueStatusIcon"; -import { UnfurlResourceType, UnfurlResponse } from "@shared/types"; +import { + IntegrationService, + UnfurlResourceType, + UnfurlResponse, +} from "@shared/types"; import { Avatar } from "~/components/Avatar"; import Flex from "~/components/Flex"; import Text from "../Text"; @@ -23,6 +27,11 @@ const HoverPreviewIssue = React.forwardRef(function _HoverPreviewIssue( ref: React.Ref ) { const authorName = author.name; + const urlObj = new URL(url); + const service = + urlObj.hostname === "github.com" + ? IntegrationService.GitHub + : IntegrationService.Linear; return ( @@ -31,7 +40,7 @@ const HoverPreviewIssue = React.forwardRef(function _HoverPreviewIssue( - <IssueStatusIcon status={state.name} color={state.color} /> + <IssueStatusIcon service={service} state={state} /> <span> {title} <Text type="tertiary">{id}</Text> </span> diff --git a/plugins/linear/server/linear.ts b/plugins/linear/server/linear.ts index ff1e06bb0f..ff5240ae73 100644 --- a/plugins/linear/server/linear.ts +++ b/plugins/linear/server/linear.ts @@ -109,6 +109,7 @@ export class Linear { color: label.color, })), state: { + type: state.type, name: state.name, color: state.color, }, diff --git a/shared/components/IssueStatusIcon.tsx b/shared/components/IssueStatusIcon/GitHubIssueStatusIcon.tsx similarity index 55% rename from shared/components/IssueStatusIcon.tsx rename to shared/components/IssueStatusIcon/GitHubIssueStatusIcon.tsx index 0b3e77c3c3..3239f92dff 100644 --- a/shared/components/IssueStatusIcon.tsx +++ b/shared/components/IssueStatusIcon/GitHubIssueStatusIcon.tsx @@ -1,43 +1,18 @@ -import * as React from "react"; -import styled from "styled-components"; +import React from "react"; +import { BaseIconProps } from "."; -type Props = { - status: string; - color: string; - size?: number; - className?: string; -}; +export function GitHubIssueStatusIcon(props: BaseIconProps) { + const { state, className } = props; -/** - * Issue status icon based on GitHub issue status, but can be used for any git-style integration. - */ -export function IssueStatusIcon({ size, ...rest }: Props) { - return ( - <Icon size={size}> - <BaseIcon {...rest} /> - </Icon> - ); -} - -const Icon = styled.span<{ size?: number }>` - display: inline-flex; - flex-shrink: 0; - width: ${(props) => props.size ?? 24}px; - height: ${(props) => props.size ?? 24}px; - align-items: center; - justify-content: center; -`; - -function BaseIcon(props: Props) { - switch (props.status) { + switch (state.name) { case "open": return ( <svg viewBox="0 0 16 16" width="16" height="16" - fill={props.color} - className={props.className} + fill={state.color} + className={className} > <path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z" /> <path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z" /> @@ -49,8 +24,8 @@ function BaseIcon(props: Props) { viewBox="0 0 16 16" width="16" height="16" - fill={props.color} - className={props.className} + fill={state.color} + className={className} > <path d="M11.28 6.78a.75.75 0 0 0-1.06-1.06L7.25 8.69 5.78 7.22a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.06 0l3.5-3.5Z" /> <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 1 0-13 0 6.5 6.5 0 0 0 13 0Z" /> @@ -62,8 +37,8 @@ function BaseIcon(props: Props) { viewBox="0 0 16 16" width="16" height="16" - fill={props.color} - className={props.className} + fill={state.color} + className={className} > <path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm9.78-2.22-5.5 5.5a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l5.5-5.5a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Z" /> </svg> diff --git a/shared/components/IssueStatusIcon/LinearIssueStatusIcon.tsx b/shared/components/IssueStatusIcon/LinearIssueStatusIcon.tsx new file mode 100644 index 0000000000..d3e2932dee --- /dev/null +++ b/shared/components/IssueStatusIcon/LinearIssueStatusIcon.tsx @@ -0,0 +1,75 @@ +import * as React from "react"; +import { useTheme } from "styled-components"; +import { isSafari } from "../../utils/browser"; +import { BaseIconProps } from "."; + +enum StateType { + Triage = "triage", + Backlog = "backlog", + Unstarted = "unstarted", + Started = "started", + Completed = "completed", + Canceled = "canceled", +} + +/** Renders an icon for a specific workflow state type, animating the change of state type and completion percentage. */ +export function LinearIssueStatusIcon(props: BaseIconProps) { + const theme = useTheme(); + const { state } = props; + const percentage = + state.type === StateType.Triage || + state.type === StateType.Backlog || + state.type === StateType.Unstarted + ? 0 + : state.type === StateType.Started + ? 0.5 + : 1; + const isTriage = state.type === StateType.Triage; + const isBacklog = state.type === StateType.Backlog; + const isCompleted = state.type === StateType.Completed; + // Due to some rendering issues and differences between browsers, the logical constant 4 in the rendering below + // needs to be a bit less to make 50% look like half a circle. + const magicFour = isSafari() ? 3.895 : 3.98; + return ( + <svg width="14" height="14" viewBox="0 0 14 14" fill="none"> + <circle + cx={7} + cy={7} + r={isTriage ? 3.5 : 6} + fill="none" + stroke={state.color} + strokeWidth={isTriage ? 7 : 1.5} + strokeDasharray={isTriage ? "2 0" : isBacklog ? "1.4 1.74" : "3.14 0"} + strokeDashoffset={isTriage ? 3.2 : isBacklog ? 0.65 : -0.7} + /> + <circle + cx={7} + cy={7} + r={percentage === 1 ? 3 : 2} + fill="none" + stroke={state.color} + strokeWidth={percentage === 1 ? 6 : 4} + strokeDasharray={`${ + percentage * Math.PI * (percentage === 1 ? 6 : magicFour) + } 100`} + strokeDashoffset={0} + transform={`rotate(-90 7 7)`} + /> + {(isTriage || percentage === 1) && ( + <path + className="icon" + stroke="none" + d={isTriage ? triageIcon : isCompleted ? checkMarkIcon : closeIcon} + fill={theme.background} + /> + )} + </svg> + ); +} + +const checkMarkIcon = + "M10.951 4.24896C11.283 4.58091 11.283 5.11909 10.951 5.45104L5.95104 10.451C5.61909 10.783 5.0809 10.783 4.74896 10.451L2.74896 8.45104C2.41701 8.11909 2.41701 7.5809 2.74896 7.24896C3.0809 6.91701 3.61909 6.91701 3.95104 7.24896L5.35 8.64792L9.74896 4.24896C10.0809 3.91701 10.6191 3.91701 10.951 4.24896Z"; +const triageIcon = + "M8.0126 7.98223V9.50781C8.0126 9.92901 8.52329 10.1548 8.85102 9.87854L11.8258 7.37066C12.0581 7.17486 12.0581 6.82507 11.8258 6.62927L8.85102 4.12139C8.52329 3.84509 8.0126 4.07092 8.0126 4.49212V6.01763H5.98739V4.49218C5.98739 4.07098 5.4767 3.84515 5.14897 4.12146L2.17419 6.62933C1.94194 6.82513 1.94194 7.17492 2.17419 7.37072L5.14897 9.8786C5.4767 10.1549 5.98739 9.92907 5.98739 9.50787V7.98223H8.0126Z"; +const closeIcon = + "M3.73657 3.73657C4.05199 3.42114 4.56339 3.42114 4.87881 3.73657L5.93941 4.79716L7 5.85775L9.12117 3.73657C9.4366 3.42114 9.94801 3.42114 10.2634 3.73657C10.5789 4.05199 10.5789 4.56339 10.2634 4.87881L8.14225 7L10.2634 9.12118C10.5789 9.4366 10.5789 9.94801 10.2634 10.2634C9.94801 10.5789 9.4366 10.5789 9.12117 10.2634L7 8.14225L4.87881 10.2634C4.56339 10.5789 4.05199 10.5789 3.73657 10.2634C3.42114 9.94801 3.42114 9.4366 3.73657 9.12118L4.79716 8.06059L5.85775 7L3.73657 4.87881C3.42114 4.56339 3.42114 4.05199 3.73657 3.73657Z"; diff --git a/shared/components/IssueStatusIcon/index.tsx b/shared/components/IssueStatusIcon/index.tsx new file mode 100644 index 0000000000..b85a1e6402 --- /dev/null +++ b/shared/components/IssueStatusIcon/index.tsx @@ -0,0 +1,42 @@ +import * as React from "react"; +import styled from "styled-components"; +import { + IntegrationService, + IssueTrackerIntegrationService, + UnfurlResourceType, + UnfurlResponse, +} from "../../types"; +import { GitHubIssueStatusIcon } from "./GitHubIssueStatusIcon"; +import { LinearIssueStatusIcon } from "./LinearIssueStatusIcon"; + +export type BaseIconProps = { + state: UnfurlResponse[UnfurlResourceType.Issue]["state"]; + className?: string; +}; + +type Props = BaseIconProps & { + size?: number; + service: IssueTrackerIntegrationService; +}; + +export function IssueStatusIcon(props: Props) { + return <Icon size={props.size}>{getIcon(props)}</Icon>; +} + +function getIcon({ service, ...rest }: Props) { + switch (service) { + case IntegrationService.GitHub: + return <GitHubIssueStatusIcon {...rest} />; + case IntegrationService.Linear: + return <LinearIssueStatusIcon {...rest} />; + } +} + +const Icon = styled.span<{ size?: number }>` + display: inline-flex; + flex-shrink: 0; + width: ${(props) => props.size ?? 24}px; + height: ${(props) => props.size ?? 24}px; + align-items: center; + justify-content: center; +`; diff --git a/shared/editor/components/Mentions.tsx b/shared/editor/components/Mentions.tsx index 0ec427b553..2c33d34dfc 100644 --- a/shared/editor/components/Mentions.tsx +++ b/shared/editor/components/Mentions.tsx @@ -19,10 +19,11 @@ import Text from "../../components/Text"; import useIsMounted from "../../hooks/useIsMounted"; import useStores from "../../hooks/useStores"; import theme from "../../styles/theme"; -import type { - JSONValue, - UnfurlResourceType, - UnfurlResponse, +import { + IntegrationService, + type JSONValue, + type UnfurlResourceType, + type UnfurlResponse, } from "../../types"; import { cn } from "../styles/utils"; import { ComponentProps } from "../types"; @@ -187,6 +188,12 @@ export const MentionIssue = observer((props: IssuePrProps) => { const issue = unfurl as UnfurlResponse[UnfurlResourceType.Issue]; + const url = new URL(issue.url); + const service = + url.hostname === "github.com" + ? IntegrationService.GitHub + : IntegrationService.Linear; + return ( <a {...attrs} @@ -198,11 +205,7 @@ export const MentionIssue = observer((props: IssuePrProps) => { rel="noopener noreferrer nofollow" > <Flex align="center" gap={6}> - <IssueStatusIcon - size={14} - status={issue.state.name} - color={issue.state.color} - /> + <IssueStatusIcon size={14} service={service} state={issue.state} /> <Flex align="center" gap={4}> <Text>{issue.title}</Text> <Text type="tertiary">{issue.id}</Text> diff --git a/shared/types.ts b/shared/types.ts index 8178c75a3b..ddb9ea64da 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -132,11 +132,12 @@ export const ImportableIntegrationService = { export type IssueTrackerIntegrationService = Extract< IntegrationService, - IntegrationService.GitHub + IntegrationService.GitHub | IntegrationService.Linear >; export const IssueTrackerIntegrationService = { GitHub: IntegrationService.GitHub, + Linear: IntegrationService.Linear, } as const; export type UserCreatableIntegrationService = Extract< @@ -435,7 +436,7 @@ export type UnfurlResponse = { /** Issue's labels */ labels: Array<{ name: string; color: string }>; /** Issue's status */ - state: { name: string; color: string }; + state: { type?: string; name: string; color: string }; /** Issue's creation time */ createdAt: string; }; diff --git a/shared/utils/browser.ts b/shared/utils/browser.ts index 3ff106450f..f159989bfe 100644 --- a/shared/utils/browser.ts +++ b/shared/utils/browser.ts @@ -33,6 +33,18 @@ export function isWindows(): boolean { return window.navigator.platform === "Win32"; } +export function isSafari(): boolean { + if (!isBrowser) { + return false; + } + const userAgent = window.navigator.userAgent; + return ( + userAgent.includes("Safari") && + !userAgent.includes("Chrome") && + !userAgent.includes("Chromium") + ); +} + let supportsPassive = false; try {