Skip to content

Commit 30c566e

Browse files
Merge branch 'master' into gh-actions-api
2 parents 4768ce9 + fb186e2 commit 30c566e

File tree

5 files changed

+171
-77
lines changed

5 files changed

+171
-77
lines changed

frontend/components/badge-examples.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ function Example({
9292
<tr>
9393
<ClickableTh onClick={handleClick}>{title}:</ClickableTh>
9494
<td>
95-
<Badge clickable onClick={handleClick} src={previewUrl} />
95+
<Badge
96+
alt={`${title} badge`}
97+
clickable
98+
onClick={handleClick}
99+
src={previewUrl}
100+
/>
96101
</td>
97102
<td>
98103
<ClickableCode onClick={handleClick}>{exampleUrl}</ClickableCode>

frontend/components/common.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const noAutocorrect = Object.freeze({
55
autoComplete: 'off',
66
autoCorrect: 'off',
77
autoCapitalize: 'off',
8-
spellCheck: 'false',
8+
spellcheck: 'false',
99
})
1010

1111
export const nonBreakingSpace = '\u00a0'

frontend/components/customizer/customizer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function Customizer({
5656
}
5757
return (
5858
<p>
59-
<Badge display="block" src={src} />
59+
<Badge alt="preview badge" display="block" src={src} />
6060
</p>
6161
)
6262
}

frontend/components/customizer/path-builder.js renamed to frontend/components/customizer/path-builder.tsx

+52-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import React, { useState, useEffect } from 'react'
2-
import PropTypes from 'prop-types'
1+
import React, { useState, useEffect, ChangeEvent } from 'react'
32
import styled, { css } from 'styled-components'
4-
import pathToRegexp from 'path-to-regexp'
3+
import pathToRegexp, { Token, Key } from 'path-to-regexp'
54
import humanizeString from 'humanize-string'
6-
import { objectOfKeyValuesPropType } from '../../lib/service-definitions/service-definition-prop-types'
75
import { patternToOptions } from '../../lib/pattern-helpers'
86
import { noAutocorrect, StyledInput } from '../common'
97
import {
@@ -12,7 +10,11 @@ import {
1210
BuilderCaption,
1311
} from './builder-common'
1412

15-
const PathBuilderColumn = styled.span`
13+
interface PathBuilderColumnProps {
14+
withHorizPadding?: boolean
15+
}
16+
17+
const PathBuilderColumn = styled.span<PathBuilderColumnProps>`
1618
height: 78px;
1719
1820
float: left;
@@ -28,7 +30,11 @@ const PathBuilderColumn = styled.span`
2830
`};
2931
`
3032

31-
const PathLiteral = styled.div`
33+
interface PathLiteralProps {
34+
isFirstToken: boolean
35+
}
36+
37+
const PathLiteral = styled.div<PathLiteralProps>`
3238
margin-top: 39px;
3339
${({ isFirstToken }) =>
3440
isFirstToken &&
@@ -68,7 +74,13 @@ const NamedParamCaption = styled(BuilderCaption)`
6874
text-align: center;
6975
`
7076

71-
export function constructPath({ tokens, namedParams }) {
77+
export function constructPath({
78+
tokens,
79+
namedParams,
80+
}: {
81+
tokens: Token[]
82+
namedParams: { [k: string]: string }
83+
}) {
7284
let isComplete = true
7385
const path = tokens
7486
.map(token => {
@@ -96,6 +108,17 @@ export default function PathBuilder({
96108
exampleParams,
97109
onChange,
98110
isPrefilled,
111+
}: {
112+
pattern: string
113+
exampleParams: { [k: string]: string }
114+
onChange: ({
115+
path,
116+
isComplete,
117+
}: {
118+
path: string
119+
isComplete: boolean
120+
}) => void
121+
isPrefilled: boolean
99122
}) {
100123
const [tokens] = useState(() => pathToRegexp.parse(pattern))
101124
const [namedParams, setNamedParams] = useState(() =>
@@ -106,10 +129,14 @@ export default function PathBuilder({
106129
// objects.
107130
tokens
108131
.filter(t => typeof t !== 'string')
109-
.reduce((accum, { name }) => {
110-
accum[name] = ''
111-
return accum
112-
}, {})
132+
.map(t => t as Key)
133+
.reduce(
134+
(accum, { name }) => {
135+
accum[name] = ''
136+
return accum
137+
},
138+
{} as { [k: string]: string }
139+
)
113140
)
114141

115142
useEffect(() => {
@@ -120,25 +147,26 @@ export default function PathBuilder({
120147
}
121148
}, [tokens, namedParams, onChange])
122149

123-
function handleTokenChange(evt) {
124-
const { name, value } = evt.target
125-
150+
function handleTokenChange({
151+
target: { name, value },
152+
}: ChangeEvent<HTMLInputElement | HTMLSelectElement>) {
126153
setNamedParams({
127154
...namedParams,
128155
[name]: value,
129156
})
130157
}
131158

132-
function renderLiteral(literal, tokenIndex) {
159+
function renderLiteral(literal: string, tokenIndex: number) {
133160
return (
134161
<PathBuilderColumn key={`${tokenIndex}-${literal}`}>
135162
<PathLiteral isFirstToken={tokenIndex === 0}>{literal}</PathLiteral>
136163
</PathBuilderColumn>
137164
)
138165
}
139166

140-
function renderNamedParamInput(token) {
141-
const { name, pattern } = token
167+
function renderNamedParamInput(token: Key) {
168+
const { pattern } = token
169+
const name = `${token.name}`
142170
const options = patternToOptions(pattern)
143171

144172
const value = namedParams[name]
@@ -174,8 +202,13 @@ export default function PathBuilder({
174202
}
175203
}
176204

177-
function renderNamedParam(token, tokenIndex, namedParamIndex) {
178-
const { delimiter, name, optional } = token
205+
function renderNamedParam(
206+
token: Key,
207+
tokenIndex: number,
208+
namedParamIndex: number
209+
) {
210+
const { delimiter, optional } = token
211+
const name = `${token.name}`
179212

180213
const exampleValue = exampleParams[name] || '(not set)'
181214

@@ -209,9 +242,3 @@ export default function PathBuilder({
209242
</BuilderContainer>
210243
)
211244
}
212-
PathBuilder.propTypes = {
213-
pattern: PropTypes.string.isRequired,
214-
exampleParams: objectOfKeyValuesPropType,
215-
onChange: PropTypes.func,
216-
isPrefilled: PropTypes.bool,
217-
}

0 commit comments

Comments
 (0)