Skip to content

Commit a25a2e4

Browse files
committed
Start fixing typescript issues with themeing.
1 parent db77bfa commit a25a2e4

22 files changed

+514
-217
lines changed

@types/emotion.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import '@emotion/react'
2+
3+
import { Theme as EmotionTheme } from '../src/theme'
4+
5+
export {}
6+
7+
declare module '@emotion/react' {
8+
export interface Theme extends EmotionTheme {}
9+
}

@types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './emotion'

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "EXTEND_ESLINT=true react-app-rewired build",
88
"docker-test-e2e": "yarn start-and-wait && react-app-rewired test --watchAll=false --onlyChanged=false --testPathPattern='/__tests__/.*(\\.|).e2e.spec.(js|jsx|ts|tsx)?$'",
99
"lint": "eslint . --cache --report-unused-disable-directives",
10+
"typecheck": "tsc --noEmit",
1011
"prepare": "husky install",
1112
"start": "EXTEND_ESLINT=true react-app-rewired start",
1213
"start-and-wait": "yarn start & wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 30 http://localhost:3000/",
@@ -15,8 +16,8 @@
1516
},
1617
"dependencies": {
1718
"@ant-design/icons": "4.0.3",
18-
"@emotion/react": "^11.10.6",
19-
"@emotion/styled": "^11.10.6",
19+
"@emotion/react": "^11.11.3",
20+
"@emotion/styled": "^11.11.0",
2021
"antd": "5.2.3",
2122
"date-fns": "^2.29.3",
2223
"framer-motion": "^2.9.5",
@@ -35,13 +36,14 @@
3536
"use-persisted-state": "^0.3.3"
3637
},
3738
"devDependencies": {
38-
"@emotion/babel-preset-css-prop": "^11.10.0",
39-
"@emotion/eslint-plugin": "^11.10.0",
39+
"@emotion/babel-preset-css-prop": "^11.11.0",
40+
"@emotion/eslint-plugin": "^11.11.0",
4041
"@jest/globals": "^29.7.0",
4142
"@testing-library/react": "^14.0.0",
4243
"@types/jest": "^29.5.12",
44+
"@types/markdown-to-jsx": "^7.0.1",
4345
"@types/node": "^20.11.16",
44-
"@types/react": "^18.2.52",
46+
"@types/react": "18.2.0",
4547
"@types/react-copy-to-clipboard": "^5.0.7",
4648
"@types/react-dom": "^18.2.18",
4749
"@types/use-persisted-state": "^0.3.4",
@@ -73,7 +75,7 @@
7375
]
7476
},
7577
"eslintConfig": {
76-
"parser": "@babel/eslint-parser",
78+
"parser": "@typescript-eslint/parser",
7779
"extends": [
7880
"react-app"
7981
],

src/components/common/BinaryDownload.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import React from 'react'
22
import { Button, Popover as AntdPopover, Tooltip } from 'antd'
3+
import type { PopoverProps as AntdPopoverProps } from 'antd'
34
import styled from '@emotion/styled'
45
import DownloadFileButton from './DownloadFileButton'
56
import { removeAppPathPrefix } from '../../utils'
7+
import type { Theme } from '../../theme'
68

79
const Container = styled.div`
810
padding-right: 10px;
911
`
1012

11-
const BinaryRow = styled.div`
13+
interface BinaryRowProps {
14+
index: number
15+
theme?: Theme
16+
}
17+
18+
const BinaryRow = styled.div<BinaryRowProps>`
1219
display: flex;
1320
justify-content: space-between;
1421
align-items: center;
@@ -22,16 +29,30 @@ const BinaryRow = styled.div`
2229
padding: 10px 15px;
2330
border-bottom: 1px solid ${({ theme }) => theme.border};
2431
`
25-
26-
const Popover = styled(({ className, ...props }) => (
32+
interface PopoverProps extends Omit<AntdPopoverProps, 'overlayClassName'> {
33+
className?: string
34+
}
35+
const Popover = styled(({ className, ...props }: PopoverProps) => (
2736
<AntdPopover overlayClassName={className} {...props} />
2837
))`
2938
.ant-popover-inner-content {
3039
padding: 0;
3140
}
3241
`
3342

34-
const BinaryList = ({ binaryFiles, toVersion, appName, packageName }) =>
43+
interface BinaryListProps {
44+
binaryFiles: { newPath: string }[]
45+
toVersion: string
46+
appName: string
47+
packageName: string
48+
}
49+
50+
const BinaryList = ({
51+
binaryFiles,
52+
toVersion,
53+
appName,
54+
packageName,
55+
}: BinaryListProps) =>
3556
binaryFiles.map(({ newPath }, index) => {
3657
return (
3758
<BinaryRow key={index} index={index}>
@@ -46,14 +67,20 @@ const BinaryList = ({ binaryFiles, toVersion, appName, packageName }) =>
4667
</BinaryRow>
4768
)
4869
})
49-
70+
interface BinaryDownloadProps {
71+
diff: any[]
72+
fromVersion: string
73+
toVersion: string
74+
appName: string
75+
packageName: string
76+
}
5077
const BinaryDownload = ({
5178
diff,
5279
fromVersion,
5380
toVersion,
5481
appName,
5582
packageName,
56-
}) => {
83+
}: BinaryDownloadProps) => {
5784
const binaryFiles = diff.filter(
5885
({ hunks, type }) => hunks.length === 0 && type !== 'delete'
5986
)

src/components/common/CompletedFilesCounter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from '@emotion/styled'
33
import { keyframes, css } from '@emotion/react'
44
import Confetti from 'react-dom-confetti'
55
import { Popover } from 'antd'
6+
import type { Theme } from '../../theme'
67

78
const shake = keyframes`
89
0% {
@@ -32,6 +33,7 @@ interface CompletedFilesCounterProps
3233
total: number
3334
popoverContent: string
3435
popoverCursorType: string
36+
theme: Theme
3537
}
3638

3739
const CompletedFilesCounter = styled(

src/components/common/Diff/Diff.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import {
1010
import DiffHeader from './DiffHeader'
1111
import { getComments } from './DiffComment'
1212
import { replaceAppDetails } from '../../../utils'
13+
import type { Theme } from '../../../theme'
1314

1415
const copyPathPopoverContentOpts = {
1516
default: 'Click to copy file path',
1617
copied: 'File path copied!',
1718
}
1819

19-
const Container = styled.div`
20+
const Container = styled.div<{ theme?: Theme }>`
2021
border: 1px solid ${({ theme }) => theme.border};
2122
border-radius: 3px;
2223
margin-bottom: 16px;

src/components/common/Diff/DiffComment.tsx

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
import React, { useState } from 'react'
22
import styled from '@emotion/styled'
3-
import { motion } from 'framer-motion'
3+
import { HTMLMotionProps, motion } from 'framer-motion'
44
import { removeAppPathPrefix, getVersionsContentInDiff } from '../../../utils'
55
import Markdown from '../Markdown'
6+
import type { Theme } from '../../../theme'
7+
interface ContainerProps extends HTMLMotionProps<'div'> {
8+
isCommentOpen: boolean
9+
lineChangeType: 'add' | 'delete'
10+
theme?: Theme
11+
}
612

7-
const Container = styled(({ isCommentOpen, children, ...props }) => {
8-
return (
9-
<motion.div
10-
{...props}
11-
variants={{
12-
open: {
13-
height: 'auto',
14-
},
15-
hidden: { height: 10 },
16-
}}
17-
initial={isCommentOpen ? 'open' : 'hidden'}
18-
animate={isCommentOpen ? 'open' : 'hidden'}
19-
transition={{
20-
duration: 0.5,
21-
}}
22-
inherit={false}
23-
>
24-
<div children={children} />
25-
</motion.div>
26-
)
27-
})`
13+
const Container = styled(
14+
({ isCommentOpen, children, ...props }: ContainerProps) => {
15+
return (
16+
<motion.div
17+
{...props}
18+
variants={{
19+
open: {
20+
height: 'auto',
21+
},
22+
hidden: { height: 10 },
23+
}}
24+
initial={isCommentOpen ? 'open' : 'hidden'}
25+
animate={isCommentOpen ? 'open' : 'hidden'}
26+
transition={{
27+
duration: 0.5,
28+
}}
29+
inherit={false}
30+
>
31+
<div children={children} />
32+
</motion.div>
33+
)
34+
}
35+
)`
2836
overflow: hidden;
2937
3038
& > div {
@@ -42,7 +50,10 @@ const Container = styled(({ isCommentOpen, children, ...props }) => {
4250
}
4351
`
4452

45-
const ContentContainer = styled.div`
53+
interface ContentContainerProps extends React.HTMLAttributes<HTMLDivElement> {
54+
theme?: Theme
55+
}
56+
const ContentContainer = styled.div<ContentContainerProps>`
4657
flex: 1;
4758
position: relative;
4859
padding: 16px;
@@ -51,7 +62,12 @@ const ContentContainer = styled.div`
5162
user-select: none;
5263
`
5364

54-
const ShowButton = styled(({ isCommentOpen, ...props }) => (
65+
interface ShowButtonProps extends DivProps {
66+
isCommentOpen: boolean
67+
theme?: Theme
68+
}
69+
70+
const ShowButton = styled(({ isCommentOpen, ...props }: ShowButtonProps) => (
5571
<motion.div
5672
{...props}
5773
variants={{
@@ -92,10 +108,25 @@ const LINE_CHANGE_TYPES = {
92108
NEUTRAL: 'N',
93109
}
94110

95-
const getLineNumberWithType = ({ lineChangeType, lineNumber }) =>
96-
`${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}`
97-
98-
const getComments = ({ packageName, newPath, fromVersion, toVersion }) => {
111+
const getLineNumberWithType = ({
112+
lineChangeType,
113+
lineNumber,
114+
}: {
115+
lineChangeType: 'add' | 'delete' | 'neutral'
116+
lineNumber: number
117+
}) => `${LINE_CHANGE_TYPES[lineChangeType.toUpperCase()]}${lineNumber}`
118+
119+
const getComments = ({
120+
packageName,
121+
newPath,
122+
fromVersion,
123+
toVersion,
124+
}: {
125+
packageName: string
126+
newPath: string
127+
fromVersion: string
128+
toVersion: string
129+
}) => {
99130
const newPathSanitized = removeAppPathPrefix(newPath)
100131

101132
const versionsInDiff = getVersionsContentInDiff({

src/components/common/Diff/DiffCommentReminder.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import React from 'react'
22
import styled from '@emotion/styled'
3-
import { motion } from 'framer-motion'
3+
import { motion, HTMLMotionProps } from 'framer-motion'
44
import { InfoCircleOutlined } from '@ant-design/icons'
55
import { getTransitionDuration } from '../../../utils'
6+
import type { Theme } from '../../../theme'
7+
8+
interface DiffCommentReminderProps extends HTMLMotionProps<'div'> {
9+
comments: Record<string, string>
10+
isDiffCollapsed: boolean
11+
uncollapseDiff: () => void
12+
theme?: Theme
13+
}
614

715
const DiffCommentReminder = styled(
8-
({ comments, isDiffCollapsed, uncollapseDiff, ...props }) => {
16+
({
17+
comments,
18+
isDiffCollapsed,
19+
uncollapseDiff,
20+
...props
21+
}: DiffCommentReminderProps) => {
922
const numberOfComments = Object.keys(comments).length
1023
const isOpen = isDiffCollapsed && numberOfComments > 0
1124

@@ -16,7 +29,7 @@ const DiffCommentReminder = styled(
1629
open: { opacity: 1, cursor: 'pointer' },
1730
closed: { opacity: 0, cursor: 'initial' },
1831
}}
19-
animate={isOpen > 0 ? 'open' : 'closed'}
32+
animate={isOpen ? 'open' : 'closed'}
2033
transition={{
2134
duration: getTransitionDuration(0.5),
2235
}}

0 commit comments

Comments
 (0)