11import React from 'react'
22import styled from '@emotion/styled'
33import { Tag , Button , Popover } from 'antd'
4- import type { ButtonProps } from 'antd'
4+ import type { ButtonProps , TagProps } from 'antd'
55import {
66 CheckOutlined ,
77 DownOutlined ,
@@ -17,6 +17,8 @@ import DownloadFileButton from '../DownloadFileButton'
1717import ViewFileButton from '../ViewFileButton'
1818import CopyFileButton from '../CopyFileButton'
1919import type { Theme } from '../../../theme'
20+ import type { LineChangeT } from '../../../releases/types'
21+ import type { DiffType } from 'react-diff-view'
2022
2123export const testIDs = {
2224 collapseClickableArea : 'collapseClickableArea' ,
@@ -47,7 +49,15 @@ const FileRenameArrow = styled(RightOutlined)({
4749 color : '#f78206' ,
4850} )
4951
50- const FileName = ( { oldPath, newPath, type, appName } ) => {
52+ const FileName = ( {
53+ oldPath,
54+ newPath,
55+ type,
56+ } : {
57+ oldPath : string
58+ newPath : string
59+ type : LineChangeT
60+ } ) => {
5161 if ( type === 'delete' ) {
5262 return < span > { oldPath } </ span >
5363 }
@@ -63,7 +73,7 @@ const FileName = ({ oldPath, newPath, type, appName }) => {
6373 return < span > { newPath } </ span >
6474}
6575
66- function generatePathId ( oldPath , newPath ) {
76+ function generatePathId ( oldPath : string , newPath : string ) {
6777 const isMoved = oldPath !== newPath
6878 if ( newPath === '/dev/null' ) {
6979 newPath = 'deleted'
@@ -72,7 +82,12 @@ function generatePathId(oldPath, newPath) {
7282 return encodeURIComponent ( path . replace ( / [ / \\ ] / g, '-' ) )
7383}
7484
75- const FileStatus = ( { type, ...props } ) => {
85+ const FileStatus = ( {
86+ type,
87+ ...props
88+ } : {
89+ type : DiffType
90+ } & TagProps ) => {
7691 const colors = {
7792 add : 'blue' ,
7893 modify : 'green' ,
@@ -88,13 +103,16 @@ const FileStatus = ({ type, ...props }) => {
88103 }
89104
90105 return (
91- < Tag { ...props } color = { colors [ type ] } >
92- { labels [ type ] }
106+ < Tag { ...props } color = { colors [ type as keyof typeof colors ] } >
107+ { labels [ type as keyof typeof labels ] }
93108 </ Tag >
94109 )
95110}
96111
97- const BinaryBadge = ( { open, ...props } ) =>
112+ interface BinaryBadgeProps extends TagProps {
113+ open : boolean
114+ }
115+ const BinaryBadge = ( { open, ...props } : BinaryBadgeProps ) =>
98116 open ? (
99117 < Tag { ...props } color = "cyan" >
100118 BINARY
@@ -206,7 +224,7 @@ const CopyAnchorLinksToClipboardButton = styled(
206224 const onCopyContent = ( ) => setContent ( copyAnchorLinks . copied )
207225
208226 const url = React . useMemo ( ( ) => {
209- const url = new URL ( window . location )
227+ const url = new URL ( window . location . toString ( ) )
210228 url . hash = id
211229 url . searchParams . set ( 'from' , fromVersion )
212230 url . searchParams . set ( 'to' , toVersion )
@@ -244,8 +262,15 @@ const CollapseClickableArea = styled.div`
244262 }
245263`
246264
247- const CollapseDiffButton = styled ( ( { open, isDiffCollapsed, ...props } ) =>
248- open ? < Button { ...props } type = "link" icon = { < DownOutlined /> } /> : null
265+ interface CollapseDiffButtonProps extends ButtonProps {
266+ open : boolean
267+ isDiffCollapsed : boolean
268+ theme ?: Theme
269+ }
270+
271+ const CollapseDiffButton = styled (
272+ ( { open, isDiffCollapsed, ...props } : CollapseDiffButtonProps ) =>
273+ open ? < Button { ...props } type = "link" icon = { < DownOutlined /> } /> : null
249274) `
250275 color: ${ ( { theme } ) => theme . text } ;
251276 margin-right: 2px;
@@ -266,7 +291,7 @@ interface DiffHeaderProps extends WrapperProps {
266291 newPath : string
267292 fromVersion : string
268293 toVersion : string
269- type : string
294+ type : DiffType
270295 diffKey : string
271296 hasDiff : boolean
272297 isDiffCollapsed : boolean
@@ -330,7 +355,6 @@ const DiffHeader = ({
330355 oldPath = { sanitizedFilePaths . oldPath }
331356 newPath = { sanitizedFilePaths . newPath }
332357 type = { type }
333- appName = { appName }
334358 /> { ' ' }
335359 < FileStatus type = { type } />
336360 < BinaryBadge open = { ! hasDiff } />
0 commit comments