-
Notifications
You must be signed in to change notification settings - Fork 71
PD-381: Port MongoDB Charts Pipeline summary component to LeafyGreen (CHARTS-2864) #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
368604f
feat: Port Pipeline and Stage component from MongoDB Charts to LeafyG…
matt-d-rat 234f9c4
chore: Upgrade jest-dom to latest version (@testing-library/jest-dom)…
matt-d-rat f7c26ad
chore: Add typings for external react-merge-refs dependency
matt-d-rat 05110b6
chore: Move IntersectionObserver mock to pipeline src
matt-d-rat e50c168
fix: Missing title prop from MenuItemProps typescript interface
matt-d-rat fcba14e
Revert "fix: Missing title prop from MenuItemProps typescript interface"
matt-d-rat 6665587
fix: Remove deprecated title prop from MenuItem
matt-d-rat 8d0d945
chore: Pipeline package version set to v0.9.0. Updated all dependenci…
matt-d-rat 014c105
chore: Fix incorrect references in JSDoc
matt-d-rat 103c66c
chore: PR feedback (deconstruct style, export interface, remove named…
matt-d-rat 6f05937
chore: PR feedback (prefer flex-grow, flex-shrink, flex-basis over fl…
matt-d-rat 0756bbb
chore: PR feedback (Add data attributes using createDataProp)
matt-d-rat 01da661
chore: PR feedback (default util function exports. Remove named exports)
matt-d-rat 8730911
chore: PR feedback (prefer native Array.flatMap instead of lodash met…
matt-d-rat c1dec5f
chore: PR feedback (update getPupelineCounterTooltip util. Prefer nat…
matt-d-rat aac05ee
chore: PR feedback (rename isStageElement.spec.ts -> packages/pipelin…
matt-d-rat 2777e6f
chore: PR feedback (set default values in function params for Stage /…
matt-d-rat 1cc74e6
fix: getPipelineCounterTooltip to use lodash flatMap, as native flatM…
matt-d-rat 414ed72
fix: Failing test in Logo due to upgrade of jest-dom to testing-libra…
matt-d-rat c1660c3
fix: Trigger observer side effects when Pipeline childList updates.
matt-d-rat 6d0ee4f
chore: PR feedback (remove React defaultProps in favour of destructur…
matt-d-rat a3b2df5
chore: Resolve yarn.lock conflict following rebase
matt-d-rat 4f4a0e9
chore: PR feedback - provide one way of importing (remove default exp…
matt-d-rat b413193
chore: PR feedback - fix spelling mistakes. Add .vscode directory to …
matt-d-rat 4295dad
chore: PR feedback - prefer ? syntax for optional types
matt-d-rat d2a3cfc
chore: PR feedback - update lodash import to use subpackage for bette…
matt-d-rat d15f443
chore: PR feedback - don't export StateForStyles interface. Unnecessary
matt-d-rat beadd1d
chore: PR feedback - don't export Props interface. Unnecessary
matt-d-rat c863adc
chore: PR feedback - rename _children to a more semantic name: childr…
matt-d-rat 416a209
chore: PR feedback - improve the description of the isElementOverflow…
matt-d-rat b178135
chore: PR feedback - move IntersectionObserver mock to root mocks fol…
matt-d-rat cccf6d1
fix: Remove --parallel flag from yarn build command. CircleCI exhaust…
matt-d-rat b054431
Revert "chore: PR feedback - move IntersectionObserver mock to root m…
matt-d-rat 0cf5485
chore: PR feedback. Remove .vscode .gitignore entry (prefer adding to…
matt-d-rat b6c1bc0
chore: PR feedback - Remove Variant feature from Pipeline and associa…
matt-d-rat c743f4c
chore: Generate change logs
matt-d-rat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@leafygreen-ui/pipeline': major | ||
'@leafygreen-ui/menu': patch | ||
--- | ||
|
||
Initial release of @leafygreen-ui/pipeline component. Removed deprecated title prop from the @leafygreen-ui/menu component propTypes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Pipeline | ||
|
||
 | ||
|
||
## Usage | ||
|
||
```shell | ||
npm install @leafygreen-ui/pipeline | ||
``` | ||
|
||
### Example | ||
|
||
```js | ||
<Pipeline size="xsmall" className="my-pipeline"> | ||
<Stage>$match</Stage> | ||
<Stage>$addFields</Stage> | ||
<Stage>$limit</Stage> | ||
</Pipeline> | ||
``` | ||
|
||
### Output HTML | ||
|
||
```html | ||
<div data-leafygreen-ui="pipeline" class="leafygreen-ui-1hmty9x my-pipeline"> | ||
<ol data-leafygreen-ui="pipeline-stages" class="leafygreen-ui-7mx6fb"> | ||
<li | ||
data-leafygreen-ui="pipeline-stage" | ||
class="leafygreen-ui-11gdvjk" | ||
data-stage-visible="true" | ||
> | ||
$match | ||
<div | ||
data-leafygreen-ui="pipeline-stage-chevron" | ||
class="leafygreen-ui-pglvth" | ||
/> | ||
</li> | ||
<li | ||
data-leafygreen-ui="pipeline-stage" | ||
class="leafygreen-ui-11gdvjk leafygreen-ui-pipeline-stage--last-visible" | ||
data-stage-visible="true" | ||
> | ||
$addFields | ||
<div | ||
data-leafygreen-ui="pipeline-stage-chevron" | ||
class="leafygreen-ui-pglvth" | ||
/> | ||
</li> | ||
<li | ||
data-leafygreen-ui="pipeline-stage" | ||
class="leafygreen-ui-11gdvjk" | ||
data-stage-visible="false" | ||
> | ||
$limit | ||
<div | ||
data-leafygreen-ui="pipeline-stage-chevron" | ||
class="leafygreen-ui-pglvth" | ||
/> | ||
</li> | ||
</ol> | ||
<div data-leafygreen-ui="pipeline-counter" class="leafygreen-ui-1iicq0p"> | ||
<div | ||
data-leafygreen-ui="pipeline-counter-chevron" | ||
class="leafygreen-ui-18yu2oo" | ||
/> | ||
</div> | ||
</div> | ||
``` | ||
|
||
## Properties | ||
|
||
### Pipeline | ||
|
||
| Prop | Type | Description | Default | | ||
matt-d-rat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | | ||
| `className` | `String` | Adds a className to the class attribute. | `''` | | ||
| `children` | `Node` | The content that will render inside of the component. If any nodes other than `Stage` components are passed in as children, the `Pipeline` component will automatically wrap them with `Stage` components. | `undefined` | | ||
| `size` | `String` | Sets the size variant of the Pipeline. Valid sizes are: `'xsmall'`, `'small'`, `'normal'`, and `'large'` | `'xsmall'` | | ||
|
||
_All other props will be spread onto the root element._ | ||
|
||
### Stage | ||
|
||
| Prop | Type | Description | Default | | ||
| ------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | | ||
| `className` | `String` | Adds a className to the class attribute. | `''` | | ||
| `children` | `Node` | The content that will render inside of the component. | `undefined` | | ||
| `intersectionNode` | `Element` | The DOM element to observe intersections with. When used with the `Pipeline` component, this prop is automatically set to the element rendered by the `Pipeline`. | `window` | | ||
| `threshold` | `Number` | Either a single number or an array of numbers which indicate at what percentage of the target's visibility, the observer's callback should be executed. | `0.8` | | ||
| `size` | `String` | Sets the size variant of the Pipeline. Valid sizes are: `'xsmall'`, `'small'`, `'normal'`, and `'large'` | `'xsmall'` | | ||
|
||
_All other props will be spread onto the root element. The Pipeline component will also decorate the child Stage components with the `size` prop that it is supplied with._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@leafygreen-ui/pipeline", | ||
"version": "0.9.0", | ||
"description": "LeafyGreen UI Kit Pipeline", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "../../node_modules/.bin/webpack --config ../../webpack.config.js" | ||
}, | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
matt-d-rat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"@leafygreen-ui/emotion": "^1.0.6", | ||
"@leafygreen-ui/hooks": "^1.1.0", | ||
"@leafygreen-ui/lib": "^3.2.0", | ||
"@leafygreen-ui/palette": "^1.1.0", | ||
"@leafygreen-ui/tooltip": "^2.0.0", | ||
"lodash": "^4.17.15", | ||
"react-children-utilities": "^2.0.0", | ||
"react-intersection-observer": "^8.25.1", | ||
"react-merge-refs": "^1.0.0" | ||
}, | ||
"gitHead": "dd71a2d404218ccec2e657df9c0263dc1c15b9e0" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { render, cleanup } from '@testing-library/react'; | ||
import { typeIs } from '@leafygreen-ui/lib'; | ||
import Counter from './Counter'; | ||
import { Size } from './styles'; | ||
|
||
const className = 'test-counter-class'; | ||
|
||
function renderCounter(props = {}) { | ||
const utils = render(<Counter {...props} size={Size.XSmall} />); | ||
|
||
if (!typeIs.element(utils.container.firstChild)) { | ||
throw new Error('Counter element not found'); | ||
} | ||
|
||
return { | ||
...utils, | ||
element: utils.container.firstChild, | ||
}; | ||
} | ||
|
||
afterAll(cleanup); | ||
|
||
describe('packages/pipeline/Counter', () => { | ||
test(`renders "${className}" in the stage's classList`, () => { | ||
const { element } = renderCounter({ className }); | ||
expect(element.classList.contains(className)).toBe(true); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import React, { forwardRef, ReactElement, ReactNode, Ref } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css, cx } from '@leafygreen-ui/emotion'; | ||
|
||
import { | ||
getRootStyle, | ||
getChildStyle, | ||
getChevronStyle, | ||
Size, | ||
layout, | ||
colors, | ||
counterAttr, | ||
counterChevronAttr, | ||
} from './styles'; | ||
|
||
interface StateForStyles { | ||
size?: Size; | ||
} | ||
|
||
interface CounterProps { | ||
matt-d-rat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Content that will appear inside of the Counter component. | ||
*/ | ||
children?: ReactNode; | ||
|
||
/** | ||
* Classname applied to Counter content container. | ||
**/ | ||
className?: string; | ||
|
||
/** | ||
* Alter the rendered size of the component. Inherited from the parent Pipeline component. | ||
*/ | ||
size: Size; | ||
} | ||
|
||
const getBaseStyle = ({ size = Size.XSmall }: StateForStyles): string => { | ||
const { chevron, fontSize, fontWeight, gutter, height, lineHeight } = layout[ | ||
size | ||
]; | ||
|
||
const { color, secondary } = colors; | ||
const outerSize = height / 2; | ||
const offset = outerSize + chevron.size * 2; | ||
|
||
return cx( | ||
getRootStyle({ size }), | ||
getChildStyle({ size }), | ||
css` | ||
background-color: ${secondary.backgroundColor}; | ||
color: ${color}; | ||
padding: ${gutter.vertical}px ${gutter.horizontal}px; | ||
margin-right: ${offset}px; | ||
font-size: ${fontSize}px; | ||
font-weight: ${fontWeight}; | ||
line-height: ${lineHeight}; | ||
flex: 1 1 auto; | ||
white-space: nowrap; | ||
z-index: 2; | ||
|
||
&::before { | ||
white-space: nowrap; | ||
content: '+' counter(hiddenCount); | ||
} | ||
`, | ||
); | ||
}; | ||
|
||
const getCounterChevronStyle = ({ | ||
size = Size.XSmall, | ||
}: StateForStyles): string => { | ||
const { chevron, height } = layout[size]; | ||
const { secondary } = colors; | ||
const outerSize = height / 2; | ||
|
||
return cx( | ||
getChevronStyle({ size }), | ||
css` | ||
&::before { | ||
background-color: ${secondary.backgroundColor}; | ||
box-shadow: 0 0 0 ${chevron.size}px transparent, | ||
0 0 0 ${outerSize}px transparent; | ||
} | ||
`, | ||
); | ||
}; | ||
|
||
const getStatefulStyles = (state: StateForStyles) => ({ | ||
base: getBaseStyle(state), | ||
chevron: getCounterChevronStyle(state), | ||
}); | ||
|
||
/** | ||
* # Counter | ||
* | ||
* React Component to render the counter for the number of hidden stages in the Pipeline component. | ||
* | ||
* ``` | ||
* <Counter /> | ||
* ``` | ||
* @param props.className Classname applied to Counter content container. | ||
*/ | ||
const Counter = forwardRef( | ||
( | ||
{ className = '', children, size, ...rest }: CounterProps, | ||
ref: Ref<HTMLDivElement>, | ||
): ReactElement => { | ||
const { base: baseStyle, chevron: chevronStyle } = getStatefulStyles({ | ||
size, | ||
}); | ||
|
||
return ( | ||
<div | ||
{...rest} | ||
{...counterAttr.prop} | ||
data-testid="pipeline-counter" | ||
className={cx(baseStyle, className)} | ||
ref={ref} | ||
> | ||
{/* Children will be the tooltip provided by the Pipeline component */} | ||
{children} | ||
|
||
<div | ||
{...counterChevronAttr.prop} | ||
data-testid="pipeline-counter-chevron" | ||
className={chevronStyle} | ||
/> | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
Counter.displayName = 'Counter'; | ||
|
||
Counter.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
size: PropTypes.oneOf(Object.values(Size)).isRequired, | ||
}; | ||
|
||
export default Counter; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.