* Display suggested badges * E2e test for badge suggestion * Suggest resource returns example with pattern * Do not require preview in MarkupModalContent * Skip integration test for suggestion * Unmodifiable path in customizer * Use suggested link * Allow to change suggested badges * Enable skipped test * Enable skipped test * Code refactoring * Code refactoring * Code refactoring * Code refactoring * Code refactoring * Code refactoring * Unused code removed * Unused code removed * getExampleWithServiceByPattern helper added * BadgeExamples uses examples instead of services definitions * Revert "getExampleWithServiceByPattern helper added" This reverts commit80839fd705. * style removed from example * example.exact replaced with preview.buildFromExample * keywords are required again * Code refactoring * More e2e tests for suggestion feature * Code refactoring * Build add with a base url * showActualParams -> isPrefilled * A new schema for BadgeExamples * Link moved to queryParams * Updated documentation for the suggest reponse format * Link moved to queryParams - another test updated * Revert "Link moved to queryParams - another test updated" This reverts commitb5f811bb07. * Revert "Link moved to queryParams" This reverts commit3b54c6d2b4. * Disable changes in path in suggested badges * 'link' element documentation restored
97 lines
2.1 KiB
JavaScript
97 lines
2.1 KiB
JavaScript
import React from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import styled from 'styled-components'
|
|
import {
|
|
badgeUrlFromPattern,
|
|
staticBadgeUrl,
|
|
} from '../../core/badge-urls/make-badge-url'
|
|
import { examplePropType } from '../lib/service-definitions/example-prop-types'
|
|
import { Badge } from './common'
|
|
import { StyledCode } from './snippet'
|
|
|
|
const ExampleTable = styled.table`
|
|
min-width: 50%;
|
|
margin: auto;
|
|
|
|
th,
|
|
td {
|
|
text-align: left;
|
|
}
|
|
`
|
|
|
|
const ClickableTh = styled.th`
|
|
cursor: pointer;
|
|
`
|
|
|
|
const ClickableCode = styled(StyledCode)`
|
|
cursor: pointer;
|
|
`
|
|
|
|
function Example({ baseUrl, onClick, exampleData }) {
|
|
const { title, example, preview } = exampleData
|
|
|
|
const { pattern, namedParams, queryParams } = example
|
|
const exampleUrl = badgeUrlFromPattern({
|
|
baseUrl,
|
|
pattern,
|
|
namedParams,
|
|
queryParams,
|
|
})
|
|
|
|
let previewUrl
|
|
if (preview.buildFromExample) {
|
|
previewUrl = exampleUrl
|
|
} else {
|
|
const { label, message, color, style, namedLogo } = preview
|
|
previewUrl = staticBadgeUrl({
|
|
baseUrl,
|
|
label,
|
|
message,
|
|
color,
|
|
style,
|
|
namedLogo,
|
|
})
|
|
}
|
|
|
|
const handleClick = () => onClick(exampleData)
|
|
|
|
return (
|
|
<tr>
|
|
<ClickableTh onClick={handleClick}>{title}:</ClickableTh>
|
|
<td>
|
|
<Badge clickable onClick={handleClick} src={previewUrl} />
|
|
</td>
|
|
<td>
|
|
<ClickableCode onClick={handleClick}>{exampleUrl}</ClickableCode>
|
|
</td>
|
|
</tr>
|
|
)
|
|
}
|
|
Example.propTypes = {
|
|
exampleData: examplePropType.isRequired,
|
|
baseUrl: PropTypes.string,
|
|
onClick: PropTypes.func.isRequired,
|
|
}
|
|
|
|
export default function BadgeExamples({ examples, baseUrl, onClick }) {
|
|
return (
|
|
<ExampleTable>
|
|
<tbody>
|
|
{examples.map(exampleData => (
|
|
<Example
|
|
baseUrl={baseUrl}
|
|
exampleData={exampleData}
|
|
key={`${exampleData.title} ${exampleData.example.pattern}`}
|
|
onClick={onClick}
|
|
/>
|
|
))}
|
|
</tbody>
|
|
</ExampleTable>
|
|
)
|
|
}
|
|
BadgeExamples.propTypes = {
|
|
examples: PropTypes.arrayOf(examplePropType).isRequired,
|
|
baseUrl: PropTypes.string,
|
|
onClick: PropTypes.func.isRequired,
|
|
}
|