Skip to content

Commit 5c426dd

Browse files
react: new design for report header (#1855)
* start adding FilteredResults stories * weird hack to fix storybook temporarily? * use better test data * restyle StatusesSummary, add test and story * improve story a bit * categorise stories * rationalise customisation stories * start to build a story * FIXUP start to build a story * spin out helpers for stories with envelopes * better padding and center align on status items * uppercase * add a story including ci * start to rewrite ExecutionSummary * show duration, get some styling in * some refactoring * add passed rate and execution count * refactoring * fix story props * add back other stuff for now * a bit of styling * get the collapsing borders (ish) * add another row * implementation * operating system * runtime * use node logo * styling * more styling tweaks * cleanup * refactor existing search bar tests * increase tests for search bar * add ci back in at bottom * clumnky first pass at ci and git * strip back searchbar styling * start to style the query field * finish styling search part * work ci stuff into exec summary * remove redundant component * rename for clarity * cleanup imports * pull some testing up to `FilteredResults` * split statuses filter out, move context orchestration up * move timestamp conversion down - rendering concern * fix date handling in story * style filters, style rest of header, fix some minor styling issues * animate the chevron * spacing between header and content * put search and filters back in a single thing * tweak accordion styling * tweak exec summary styles * fix logic and styling for no match message * tweak search styling a bit * redistribute some logic from the component * pull `pre` styles into components * move default styling, theming and custom rendering under `CucumberReact` component * add EnvelopesWrapper * add useQueries hook for brevity * update check in html formatter * improve testing of filtered results * fix coloring on node logo * make dark theme work for whole app * consistently use `em` for units * fix issues with lists in Background and MDG * style the html formatter sensibly * use cpy-cli from local install * add auto theme, use in html formatter * add hook for useSearch * remove some code we dont need * break search wrapper away from queries * clean up a bit * tweak search wording * update theme css vars example * improve logic for os and runtime matching * unused import * changelogs Co-authored-by: Aslak Hellesøy <[email protected]>
1 parent 32bdfee commit 5c426dd

File tree

78 files changed

+2006
-1155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2006
-1155
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
* Add `<EnvelopesWrapper/>` component to succinctly populate query contexts from an array of messages.
13+
* Add 'auto' theme, honouring platform light/dark preference.
14+
* Add `useQueries` and `useSearch` hooks to avoid accessing many contexts directly.
15+
1216
### Changed
1317

18+
* New `<CucumberReact/>` component is used as root component in consuming projects, replacing. `<CustomRendering/>`.
19+
* New visual designs for report-related components.
20+
* Move search-related props from `<QueriesWrapper/>` to new `<SearchWrapper/>` component.
21+
1422
### Deprecated
1523

1624
### Removed
1725

26+
* Remove global stylesheet, all styles are now encapsulated in appropriate components.
27+
1828
### Fixed
1929

2030
* Import correct stylesheet in the Children component. This also allows to override it using `CustomRendering`.
31+
* Display step list items correctly (i.e. without bullets) in Backgrounds and in MDX documents.
2132

2233
## [18.1.2] - 2021-09-08
2334

javascript/README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Cucumber-React is a set of React components for rendering Gherkin documents and
1111
The source code for screenshots above is:
1212

1313
```jsx
14-
<Wrapper envelopes={envelopes}>
14+
<EnvelopesWrapper envelopes={envelopes}>
1515
<GherkinDocumentList />
16-
</Wrapper>
16+
</EnvelopesWrapper>
1717
```
1818

1919
The [`<GherkinDocumentList>`](src/components/app/GherkinDocumentList.tsx) React component,
@@ -36,36 +36,38 @@ To render a `<GherkinDocument>` with results and highlighted [Cucumber Expressio
3636

3737
## Styling
3838

39-
There are several ways you can apply different styling to the components.
39+
The standard styling comes from wrapping your top-level usage with the `CucumberReact` component (sans-props). There are several ways you can apply different styling to the components.
4040

4141
### Built-in themes
4242

43-
Besides the default, we have a few other built-in themes:
43+
These are the built-in themes:
4444

45+
- `light` (default)
4546
- `dark`
47+
- `auto` (honours your operating system preference for either light or dark)
4648

47-
You can activate one of these by wrapping your top-level usage with the `Theme` component:
49+
You can activate one of these by passing the `theme` prop to the `CucumberReact` component:
4850

4951
```jsx
50-
<Theme theme="dark">
52+
<CucumberReact theme="dark">
5153
<GherkinDocument />
52-
</Theme>
54+
</CucumberReact>
5355
```
5456

5557
### Custom themes
5658

57-
You can also provide your own theme with a small amount of CSS. Pass the `Theme` component an appropriate name:
59+
You can also provide your own theme with a small amount of CSS. Pass the `CucumberReact` component a class name instead of a theme name:
5860

5961
```jsx
60-
<Theme theme="acme-widgets">
62+
<CucumberReact className="acme-widgets">
6163
<GherkinDocument />
62-
</Theme>
64+
</CucumberReact>
6365
```
6466

65-
That name will act as a suffix for a classname `cucumber-theme--acme-widgets`, against which you can override the supported [custom property](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) values as desired. Here's the CSS that drives the built-in "dark" theme:
67+
In your CSS for the `acme-widgets` class, you can override the supported [custom property](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) values as desired. Here's the CSS that drives the built-in "dark" theme:
6668

6769
```css
68-
.cucumber-theme--dark {
70+
.darkTheme {
6971
--cucumber-background-color: #1d1d26;
7072
--cucumber-text-color: #c9c9d1;
7173
--cucumber-anchor-color: #4caaee;
@@ -77,6 +79,9 @@ That name will act as a suffix for a classname `cucumber-theme--acme-widgets`, a
7779
--cucumber-error-text-color: #222;
7880
--cucumber-code-background-color: #282a36;
7981
--cucumber-code-text-color: #f8f8f2;
82+
--cucumber-panel-background-color: #282a36;
83+
--cucumber-panel-accent-color: #313442;
84+
--cucumber-panel-text-color: #f8f8f2;
8085
}
8186
```
8287

@@ -97,16 +102,16 @@ Let's say you want to do something totally different with the typography of doc
97102
}
98103
```
99104

100-
Then, you can wrap your usage in the `CustomRendering` component and provide an object that declares which class names you're going to override and what with:
105+
Then, you can provide a `customRendering` prop to the `CucumberReact` component, in the form of an object that declares which class names you're going to override and what with:
101106

102107
```jsx
103-
<CustomRendering support={{
108+
<CucumberReact customRendering={{
104109
DocString: {
105110
docString: 'acme-docstring'
106111
}
107112
}}>
108113
<GherkinDocument />
109-
</CustomRendering>
114+
</CucumberReact>
110115
```
111116

112117
Some components have multiple styling hooks - e.g. the `<Tags>` component has the `tags` class name for the list, and the `tag` class name for each item. In these cases, you can provide custom class names for just the ones you want to change, and any you omit will pick up the built-in styling like normal.
@@ -115,10 +120,10 @@ Some components have multiple styling hooks - e.g. the `<Tags>` component has th
115120

116121
To change the rendering of some components entirely, you can selectively provide your own component implementations to be used instead of the built-in ones.
117122

118-
Staying with the doc string example, you can use the same `CustomRendering` wrapper, but this time instead of an object with class names, you provide a React functional component, giving you full control over the rendering:
123+
Staying with the doc string example, you can use the same `customRendering` prop, but this time instead of an object with class names, you provide a React functional component, giving you full control over the rendering:
119124

120125
```jsx
121-
<CustomRendering support={{
126+
<CucumberReact customRendering={{
122127
DocString: (props) => (
123128
<>
124129
<p>I am going to render this doc string in a textarea:</p>
@@ -127,7 +132,7 @@ Staying with the doc string example, you can use the same `CustomRendering` wrap
127132
)
128133
}}>
129134
<GherkinDocument />
130-
</CustomRendering>
135+
</CucumberReact>
131136
```
132137

133138
In each case where you provide your own component, it will receive the same props as the default component, plus two more:

javascript/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "Aslak Hellesøy",
1212
"license": "MIT",
1313
"scripts": {
14-
"prepare": "make .codegen && npx -y cpy-cli '**/*.scss' '../dist/src' --cwd='src' --parents",
14+
"prepare": "make .codegen && cpy '**/*.scss' '../dist/src' --cwd='src' --parents",
1515
"test": "mocha",
1616
"storybook": "start-storybook -p 6006",
1717
"build-storybook": "build-storybook"
@@ -28,6 +28,7 @@
2828
"@types/elasticlunr": "0.9.4",
2929
"ansi-to-html": "0.7.2",
3030
"color": "4.1.0",
31+
"date-fns": "2.27.0",
3132
"elasticlunr": "0.9.5",
3233
"hast-util-sanitize": "3.0.2",
3334
"highlight-words": "1.2.0",
@@ -53,6 +54,7 @@
5354
"@storybook/manager-webpack5": "6.4.9",
5455
"@storybook/react": "6.4.9",
5556
"@testing-library/react": "12.1.2",
57+
"@testing-library/user-event": "13.5.0",
5658
"@types/color": "3.0.2",
5759
"@types/glob": "7.2.0",
5860
"@types/jsdom": "16.2.14",

javascript/src/EnvelopesQueryContext.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export class EnvelopesQuery {
1515
public filter(predicate: (envelope: messages.Envelope) => boolean): messages.Envelope[] {
1616
return this.envelopes.filter(predicate)
1717
}
18+
19+
public getMeta(): messages.Meta {
20+
return this.find((envelope) => !!envelope.meta)?.meta
21+
}
22+
23+
public getTestRunStarted(): messages.TestRunStarted {
24+
return this.find((envelope) => !!envelope.testRunStarted)?.testRunStarted
25+
}
26+
27+
public getTestRunFinished(): messages.TestRunFinished {
28+
return this.find((envelope) => !!envelope.testRunFinished)?.testRunFinished
29+
}
1830
}
1931

2032
export default React.createContext(new EnvelopesQuery())
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@import '../styles/theming';
2+
3+
.cucumberReact {
4+
font-size: 14px;
5+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
6+
color: $textColor;
7+
background: $backgroundColor;
8+
}
9+
10+
@mixin dark-theme {
11+
--cucumber-background-color: #1d1d26;
12+
--cucumber-text-color: #c9c9d1;
13+
--cucumber-anchor-color: #4caaee;
14+
--cucumber-keyword-color: #d89077;
15+
--cucumber-parameter-color: #4caaee;
16+
--cucumber-tag-color: #85a658;
17+
--cucumber-docstring-color: #66a565;
18+
--cucumber-error-background-color: #cf6679;
19+
--cucumber-error-text-color: #222;
20+
--cucumber-code-background-color: #282a36;
21+
--cucumber-code-text-color: #f8f8f2;
22+
--cucumber-panel-background-color: #282a36;
23+
--cucumber-panel-accent-color: #313442;
24+
--cucumber-panel-text-color: #f8f8f2;
25+
}
26+
27+
.darkTheme {
28+
@include dark-theme;
29+
}
30+
31+
.autoTheme {
32+
@media all and (prefers-color-scheme: dark) {
33+
@include dark-theme;
34+
}
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { FunctionComponent } from 'react'
2+
import { CustomRenderingContext, CustomRenderingSupport, IncludedTheme } from './customise'
3+
import styles from './CucumberReact.module.scss'
4+
5+
interface IProps {
6+
theme?: IncludedTheme
7+
customRendering?: CustomRenderingSupport
8+
className?: string
9+
}
10+
11+
export const CucumberReact: FunctionComponent<IProps> = ({
12+
children,
13+
theme = 'light',
14+
customRendering = {},
15+
className,
16+
}) => {
17+
const classes = [styles.cucumberReact, styles[`${theme}Theme`], className]
18+
return (
19+
<CustomRenderingContext.Provider value={customRendering}>
20+
<div data-testid="cucumber-react" className={classes.filter((c) => !!c).join(' ')}>
21+
{children}
22+
</div>
23+
</CustomRenderingContext.Provider>
24+
)
25+
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import * as messages from '@cucumber/messages'
33
import ciCommitLink from '../../ciCommitLink'
4+
import { faLink } from '@fortawesome/free-solid-svg-icons'
5+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
46

57
interface IProps {
68
ci: messages.Ci
@@ -10,7 +12,16 @@ export const CICommitLink: React.FunctionComponent<IProps> = ({ ci: ci }) => {
1012
const commitLink = ciCommitLink(ci)
1113

1214
if (commitLink) {
13-
return <a href={commitLink}>#{ci.git.revision}</a>
15+
return (
16+
<>
17+
<FontAwesomeIcon icon={faLink} />
18+
<a href={commitLink}>{ci.git.revision.substring(0, 7)}</a>
19+
</>
20+
)
1421
}
15-
return <span>#{ci.git.revision}</span>
22+
return (
23+
<>
24+
<FontAwesomeIcon icon={faLink} /> {ci.git.revision.substring(0, 7)}
25+
</>
26+
)
1627
}

javascript/src/components/app/Duration.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { FunctionComponent, useMemo } from 'react'
2+
import * as messages from '@cucumber/messages'
3+
import { Query as GherkinQuery } from '@cucumber/gherkin-utils'
4+
import { Query as CucumberQuery } from '@cucumber/query'
5+
import { QueriesWrapper } from './QueriesWrapper'
6+
import { EnvelopesQuery } from '../../EnvelopesQueryContext'
7+
8+
interface IProps {
9+
envelopes: readonly messages.Envelope[]
10+
}
11+
12+
export const EnvelopesWrapper: FunctionComponent<IProps> = ({ envelopes, children }) => {
13+
const { gherkinQuery, cucumberQuery, envelopesQuery } = useMemo(() => {
14+
const gherkinQuery = new GherkinQuery()
15+
const cucumberQuery = new CucumberQuery()
16+
const envelopesQuery = new EnvelopesQuery()
17+
for (const envelope of envelopes) {
18+
gherkinQuery.update(envelope)
19+
cucumberQuery.update(envelope)
20+
envelopesQuery.update(envelope)
21+
}
22+
return { gherkinQuery, cucumberQuery, envelopesQuery }
23+
}, [envelopes])
24+
return (
25+
<QueriesWrapper
26+
gherkinQuery={gherkinQuery}
27+
cucumberQuery={cucumberQuery}
28+
envelopesQuery={envelopesQuery}
29+
>
30+
{children}
31+
</QueriesWrapper>
32+
)
33+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@import '../../styles/theming';
2+
3+
.backdrop {
4+
background-color: $panelAccentColor;
5+
border: 1px solid transparent;
6+
}
7+
8+
.list {
9+
display: grid;
10+
grid-template-columns: repeat(12, 1fr);
11+
grid-template-rows: 1fr 1fr;
12+
gap: 1px;
13+
margin: 0;
14+
text-align: center;
15+
}
16+
17+
.item {
18+
grid-column-end: span 4;
19+
display: flex;
20+
flex-direction: column-reverse;
21+
justify-content: center;
22+
padding: 1.5em;
23+
background-color: $backgroundColor;
24+
color: $textColor;
25+
26+
&Ci,
27+
&Ci ~ & {
28+
grid-column-end: span 3;
29+
}
30+
}
31+
32+
.value {
33+
font-weight: bold;
34+
font-size: 1.25em;
35+
margin: 0;
36+
37+
svg {
38+
max-width: 2em;
39+
}
40+
}
41+
42+
.suffix {
43+
font-size: 1em;
44+
margin-top: 0.25em;
45+
color: $codeTextColor;
46+
}
47+
48+
.gitItem {
49+
display: inline-flex;
50+
gap: 0.25em;
51+
52+
& + & {
53+
margin-left: 1em;
54+
}
55+
56+
a {
57+
color: $anchorColor;
58+
}
59+
}

0 commit comments

Comments
 (0)