Skip to content
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

Feature/import new components #52

Merged
merged 47 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d8eb971
WIP: Add ArrayObjectTable
gavinorland Jul 31, 2018
08b816e
Remove unnec stories file
gavinorland Aug 1, 2018
7552076
WIP: Add ObjectTable and its tests
gavinorland Aug 1, 2018
01b6aef
WIP: Update tests
gavinorland Aug 1, 2018
c889f4d
Remove surplus stories file
gavinorland Aug 2, 2018
262165e
Add hideWithNoValues and adjust title implementation
Loque- Aug 2, 2018
befce0a
Update story name
Loque- Aug 2, 2018
fdededa
ArrayObjectTable refactored
gavinorland Aug 2, 2018
ff486ab
Updates to ArrayObjectTable
gavinorland Aug 2, 2018
df67312
Add skipEmptyRows to ObjectTable too
gavinorland Aug 2, 2018
4737b02
Pass remaining props along in ObjectTable
gavinorland Aug 3, 2018
488fb4d
Remove conditional, adjust check with flag
Loque- Aug 3, 2018
6bec7d3
Added stories to help with development
Loque- Aug 3, 2018
ef8d936
Fix typo
Loque- Aug 3, 2018
43c1286
Hide table when there are no values
Loque- Aug 3, 2018
5b63ae2
Object table, with all its features, but no docs or tests : ))))
Loque- Aug 6, 2018
16c2811
Update comment about normalisation
Loque- Aug 6, 2018
a4e5ec7
Important comment for docs
Loque- Aug 6, 2018
f77fe9e
Shouting is not a TODO ~
Loque- Aug 6, 2018
15c9a85
Yet another doc note
Loque- Aug 6, 2018
edba0f9
Update docs
Loque- Aug 6, 2018
0513249
ArrayObjectTable updates:
gavinorland Aug 6, 2018
8c9ed6f
ArrayObjectTable - Add default render test
gavinorland Aug 6, 2018
eab9831
ArrayObjectTable - Bring tests to 100% coverage
gavinorland Aug 6, 2018
4d1285e
ArrayObjectTable - Tweak story
gavinorland Aug 6, 2018
6743e4b
ObjectTable - tweak stories
gavinorland Aug 6, 2018
883516c
ObjectTable - develop tests
gavinorland Aug 6, 2018
ed31d1c
ObjectTable - tweaks to stories
gavinorland Aug 6, 2018
f5301cc
ObjectTable - Documentation
gavinorland Aug 6, 2018
cbd44a9
ArrayObjectTable - Documentation
gavinorland Aug 6, 2018
78dd0b7
Enable docgen
gavinorland Aug 6, 2018
5569713
WIP!! Add support for names
Loque- Aug 6, 2018
e10e441
Nice fix for rows thingy
Loque- Aug 6, 2018
d692945
Code style improvement
Loque- Aug 6, 2018
a988733
TableUtils tests - rowsFromArray
gavinorland Aug 6, 2018
6d9684f
Add test for rowsFromObject
Loque- Aug 6, 2018
f952583
Fix whitespace issues
Loque- Aug 6, 2018
0ad6002
lint fixes for test
Loque- Aug 6, 2018
c558fc4
TableUtils - function tests
gavinorland Aug 6, 2018
a113349
Lurvely tests
Loque- Aug 6, 2018
2d97081
Add consideration for name attr to test
Loque- Aug 6, 2018
ed53cb4
TableUtils - Test default values
gavinorland Aug 6, 2018
b3498cc
TableUtils - Exempt else clause
gavinorland Aug 6, 2018
e0ef0df
Remove unnec. util functions import from docs
gavinorland Aug 7, 2018
9a45366
Add coverage for null case
Loque- Aug 7, 2018
749101b
Implement feedback on defaultTransform
Loque- Aug 7, 2018
51b732b
Three minor fixes
gavinorland Aug 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 130 additions & 16 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
ArrayObjectTable
================

### Import
```js
import ArrayObjectTable from '@govuk-frederic/array-object-table';
```
<!-- STORY -->

### Usage

Simple
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{ one: 'test', two: 'test' },
{ one: 'test' },
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title}/>;
```

With skipEmptyRows
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{},
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows/>
```

With skipEmptyRows and hideWithNoValues
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{},
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>;
```

### Properties
Prop | Required | Default | Type | Description
:--- | :------- | :------ | :--- | :----------
`array` | | ```[]``` | arrayOf[object Object] |
`fields` | | ```[]``` | arrayOf[object Object] |
`hideWithNoValues` | | ```false``` | bool |
`skipEmptyRows` | | ```false``` | bool |
`title` | | `````` | node |


ArrowLeft
=========

Expand Down Expand Up @@ -514,22 +581,6 @@ import { HashRouter, Link } from 'react-router-dom';
</CounterBar>
</HashRouter>
```
Use an active Link component for a counter
```jsx
import { HashRouter, Link } from 'react-router-dom';

<HashRouter>
<CounterBar>
<CounterBar.Total score={15}>All counters</CounterBar.Total>
<CounterBar.Counters>
<CounterBar.Counter score={1} component={Link} to="/courses/1/" active>Counter *1</CounterBar.Counter>
<CounterBar.Counter score={2}>Counter 2</CounterBar.Counter>
<CounterBar.Counter score={3}>Counter 3</CounterBar.Counter>
<CounterBar.Counter score={4}>Counter 4</CounterBar.Counter>
<CounterBar.Counter score={5}>Counter 5</CounterBar.Counter>
</CounterBar.Counters>
</CounterBar>
</HashRouter>

### Properties
Prop | Required | Default | Type | Description
Expand Down Expand Up @@ -664,6 +715,69 @@ Prop | Required | Default | Type | Description
`inlineBlock` | | `````` | bool |


ObjectTable
===========

### Import
```js
import ObjectTable from '@govuk-frederic/object-table';
```
<!-- STORY -->

### Usage

Simple
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
{ key: 'three', heading: 'Three' },
{ key: 'four', heading: 'Four' },
];
const object = { one: 'test', two: 'test', three: '', four: null };
const title = ['Heading'];

<ObjectTable fields={fields} object={object} title={title}/>;
```

With skipEmptyValues
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
{ key: 'three', heading: 'Three' },
{ key: 'four', heading: 'Four' },
];
const object = { one: 'test', two: 'test', three: '', four: null };
const title = ['Heading'];

<ObjectTable fields={fields} object={object} title={title} skipEmptyValues={false}/>
```

With hideWithNoValues
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const object = { };
const title = ['Heading'];

<ObjectTable fields={fields} object={object} title={title} hideWithNoValues />;
```

### Properties
Prop | Required | Default | Type | Description
:--- | :------- | :------ | :--- | :----------
`defaultTransform` | | `````` | func |
`fields` | | ```[]``` | arrayOf[object Object] |
`hideWithNoValues` | | ```false``` | bool |
`object` | | ```{}``` | object |
`skipEmptyValues` | | ```true``` | bool |
`skipMissingKeys` | | `````` | bool |
`title` | | `````` | node |


OpenButton
==========

Expand Down
67 changes: 67 additions & 0 deletions components/array-object-table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
ArrayObjectTable
================

### Import
```js
import ArrayObjectTable from '@govuk-frederic/array-object-table';
```
<!-- STORY -->

### Usage

Simple
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{ one: 'test', two: 'test' },
{ one: 'test' },
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title}/>;
```

With skipEmptyRows
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{},
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows/>
```

With skipEmptyRows and hideWithNoValues
```jsx
const fields = [
{ key: 'one', heading: 'One' },
{ key: 'two', heading: 'Two' },
];
const array = [
{},
{},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>;
```

### Properties
Prop | Required | Default | Type | Description
:--- | :------- | :------ | :--- | :----------
`array` | | ```[]``` | arrayOf[object Object] |
`fields` | | ```[]``` | arrayOf[object Object] |
`hideWithNoValues` | | ```false``` | bool |
`skipEmptyRows` | | ```false``` | bool |
`title` | | `````` | node |


34 changes: 34 additions & 0 deletions components/array-object-table/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@govuk-frederic/array-object-table",
"version": "0.0.1",
"dependencies": {
"@govuk-frederic/table": "^0.0.3",
"@govuk-frederic/utils": "^0.0.1"
},
"devDependencies": {
"@govuk-react/storybook-components": "^0.2.4",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really right?
i.e. govuk-react?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that is right, actually, but that's how it is for all the components in Frederic and that's where that package is. I'm not sure if there should be a duplicate of it in Frederic or if it should be elsewhere.

"@storybook/addon-knobs": "^3.4.2"
},
"peerDependencies": {
"emotion": ">=9",
"prop-types": ">=15",
"react": ">=16.2.0",
"react-emotion": ">=9"
},
"scripts": {
"build": "npm run build:lib && npm run build:es",
"build:lib": "rimraf lib && babel src -d lib --source-maps",
"build:es": "rimraf es && cross-env BABEL_ENV=es babel src -d es --source-maps",
"docs": "doc-component ./lib/index.js ./README.md"
},
"main": "lib/index.js",
"module": "es/index.js",
"author": "Gavin Orland",
"license": "MIT",
"homepage": "https://github.com/stevesims/govuk-frederic#readme",
"description": "govuk-frederic: Frederic project specific components.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the description for this package file not be about what ArrayObjectTable is and does?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ideally - this is something that needs doing for all Fred components (and govuk-react ones!). Added #54.

"private": false,
"publishConfig": {
"access": "public"
}
}
83 changes: 83 additions & 0 deletions components/array-object-table/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { Table } from 'govuk-frederic';

import { rowsFromArray, titlesFromFields } from '@govuk-frederic/utils';

/**
*
* ### Usage
*
* Simple
* ```jsx
* const fields = [
* { key: 'one', heading: 'One' },
* { key: 'two', heading: 'Two' },
* ];
* const array = [
* { one: 'test', two: 'test' },
* { one: 'test' },
* {},
* ];
* const title = ['Heading'];
*
* <ArrayObjectTable fields={fields} array={array} title={title}/>;
* ```
*
* With skipEmptyRows
* ```jsx
* const fields = [
* { key: 'one', heading: 'One' },
* { key: 'two', heading: 'Two' },
* ];
* const array = [
* {},
* {},
* ];
* const title = ['Heading'];
*
* <ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows/>
* ```
*
* With skipEmptyRows and hideWithNoValues
* ```jsx
* const fields = [
* { key: 'one', heading: 'One' },
* { key: 'two', heading: 'Two' },
* ];
* const array = [
* {},
* {},
* ];
* const title = ['Heading'];
*
* <ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>;
* ```
* */
const ArrayObjectTable = ({ fields = [], array = [], hideWithNoValues = false, skipEmptyRows = false, title, ...props }) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better/nicer to use defaultProps for hideWithNoValues and skipEmptyRows

let rows = rowsFromArray(array, fields, skipEmptyRows);
if (!rows.length && !hideWithNoValues) {
rows = rowsFromArray([{}], fields, false);
}
return rows.length ?
<Fragment>
{title ? title : null}
<Table rows={rows} titles={titlesFromFields(fields)} {...props}/>
</Fragment>
:
null;
};

ArrayObjectTable.propTypes = {
fields: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string.isRequired,
heading: PropTypes.string.isRequired,
transform: PropTypes.func,
})),
array: PropTypes.arrayOf(PropTypes.object),
hideWithNoValues: PropTypes.bool,
skipEmptyRows: PropTypes.bool,
title: PropTypes.node,
};

export default ArrayObjectTable;
Loading