Show a badge pattern instead of a badge url (#3438)

* Show patterns instead of real paths

* realBadge property instead of preview.buildFromExample

* E2e test for displaying a badge

* Check bagde url in badge wrapper

* expectBadgeExample helper function

* Remove a hostname from badge url

* Simpler Cypress assertions

* realBadge -> isBadgeSuggestion

* Do not show regexp in patterns
This commit is contained in:
Marcin Mielnicki
2019-05-29 21:17:27 +02:00
committed by GitHub
parent f50fcac107
commit 9008c4ef0f
7 changed files with 92 additions and 20 deletions

View File

@@ -2,10 +2,12 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {
badgeUrlFromPath,
badgeUrlFromPattern,
staticBadgeUrl,
} from '../../core/badge-urls/make-badge-url'
import { examplePropType } from '../lib/service-definitions/example-prop-types'
import { removeRegexpFromPattern } from '../lib/pattern-helpers'
import { Badge } from './common'
import { StyledCode } from './snippet'
@@ -28,18 +30,18 @@ const ClickableCode = styled(StyledCode)`
`
function Example({ baseUrl, onClick, exampleData }) {
const { title, example, preview } = exampleData
const { title, example, preview, isBadgeSuggestion } = exampleData
const { pattern, namedParams, queryParams } = example
const exampleUrl = badgeUrlFromPattern({
baseUrl,
pattern,
namedParams,
queryParams,
})
let exampleUrl
let previewUrl
if (preview.buildFromExample) {
if (isBadgeSuggestion) {
exampleUrl = badgeUrlFromPattern({
baseUrl,
pattern,
namedParams,
queryParams,
})
previewUrl = exampleUrl
} else {
const { label, message, color, style, namedLogo } = preview
@@ -51,6 +53,11 @@ function Example({ baseUrl, onClick, exampleData }) {
style,
namedLogo,
})
exampleUrl = badgeUrlFromPath({
path: removeRegexpFromPattern(pattern),
namedParams,
queryParams,
})
}
const handleClick = () => onClick(exampleData)

View File

@@ -16,7 +16,8 @@ export default function MarkupModalContent({ example, baseUrl }) {
documentation,
example: { pattern, namedParams, queryParams },
link,
preview: { style: initialStyle, buildFromExample } = {},
preview: { style: initialStyle } = {},
isBadgeSuggestion,
} = example
return (
@@ -30,7 +31,7 @@ export default function MarkupModalContent({ example, baseUrl }) {
exampleNamedParams={namedParams}
exampleQueryParams={queryParams}
initialStyle={initialStyle}
isPrefilled={buildFromExample}
isPrefilled={isBadgeSuggestion}
link={link}
pattern={pattern}
title={title}

View File

@@ -72,7 +72,8 @@ export default class SuggestionAndSearch extends React.Component {
title,
link,
example,
preview: { ...preview, buildFromExample: true },
preview,
isBadgeSuggestion: true,
documentation,
})
)