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/table refactor #38

Merged
merged 24 commits into from
Aug 6, 2018
Merged

Feature/table refactor #38

merged 24 commits into from
Aug 6, 2018

Conversation

taranchauhan
Copy link
Collaborator

@taranchauhan taranchauhan commented Jul 19, 2018

CHANGELOG:

  • Sort out Table padding
  • Add verticalAlign style override to allow for pass in of optional 'top' alignment (defaults to 'baseline')
  • Allow TableHeading's to be named e.g. 'heading'
  • TableData can now be named based on horizontal row/vertical column grouping dependent on if headings are on left (rowIncludesHeading is specified) or on top (default).

This closes #7 and closes #9

Tarandeep Singh Chauhan and others added 14 commits July 13, 2018 15:30
…dings are grouped horizontally instead of vertically e.g. first row of values are all named row ‘one’

Headings for Column names are still named incrementally e.g. one, two, three, four
This is proposed padding to fix our issue #7 . If it's acceptable we could use the same on govuk-react.
@taranchauhan taranchauhan requested a review from stevesims July 19, 2018 16:48
@codecov
Copy link

codecov bot commented Jul 19, 2018

Codecov Report

Merging #38 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #38   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines         158    168   +10     
  Branches       21     24    +3     
=====================================
+ Hits          158    168   +10
Impacted Files Coverage Δ
components/table/src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f249a25...326f97a. Read the comment docs.

@@ -86,7 +93,7 @@ const Table = ({ name, names = [], rowIncludesHeading, titles, rows, flexibleCol
{titles.map((title, index) => (
// disable false-positive rule - this is an access into an array of strings, not object access
// eslint-disable-next-line security/detect-object-injection
<TableHeading key={title.key || index} name={names[index]}>
Copy link
Owner

Choose a reason for hiding this comment

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

i'd prefer this to remain as it was

whilst the use-case for headings being named may be slightly dubious, we shouldn't prevent that from happening

);

const getName = (names, row, column, rowIncludesHeading) => {
return (rowIncludesHeading) ? names.values[row] : names.values[column];
Copy link
Owner

Choose a reason for hiding this comment

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

changing the mode of operation of names so that it's now an object rather than an array is very inconvenient - we have dozens of uses of this component that are expecting the array style - we should change the format of names back so that it's expecting a simple array again

Copy link
Owner

Choose a reason for hiding this comment

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

we may also wish to consider using a different prop than rowIncludesHeading to indicate that our use of names should be based on vertical arrangement - it may be the case that we're including headings on rows, but that we still have multiple columns of data that should get differing names based on column number

perhaps this should be a boolean called nameByRow

i think that would work very nicely for the majority of cases

for a minority use-case (when nameByRow is false) the other idea we had of using a 2-d array of names would allow us to provide explicit names for every single cell on the table. the usefulness of this however is slightly dubious

Copy link
Owner

Choose a reason for hiding this comment

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

additionally with the current code this will fail if the names object doesn't include a values array

@@ -99,13 +106,13 @@ const Table = ({ name, names = [], rowIncludesHeading, titles, rows, flexibleCol
{row.map(
(item, itemIndex) =>
rowIncludesHeading && itemIndex === 0 ? (
<TableHeading rowHeading columnCount={row.length} key={item.key || itemIndex}>
<TableHeading rowHeading columnCount={row.length} key={item.key || itemIndex} verticalAlign={verticalAlign} name={names.headings}>
Copy link
Owner

Choose a reason for hiding this comment

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

not sure about the wisdom or usefulness of this version of name here
arguably it should use getName

@@ -119,10 +126,24 @@ const Table = ({ name, names = [], rowIncludesHeading, titles, rows, flexibleCol
Table.propTypes = {
flexibleColumns: PropTypes.bool,
name: PropTypes.string,
names: PropTypes.arrayOf(PropTypes.string),
names: PropTypes.shape({
Copy link
Owner

Choose a reason for hiding this comment

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

as noted above, this change will break every place where this component is used

});
})(
cellStyles,
({ verticalAlign }) => ({ verticalAlign }),
Copy link
Owner

Choose a reason for hiding this comment

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

i'm not entirely sure/convinced about allowing verticalAlign to be explicitly set and/or passed through

having a default style of verticalAlign: 'top' i think is OK for our current use-cases

Tarandeep Singh Chauhan added 8 commits July 20, 2018 11:59
- Add nameByRow prop to decide if naming should be applied across columns or rows
- Ensure names array allows for entire rows/columns to be named the same or cells can have completely individual names
Update inline documentation for table and regenerate doc files
@@ -107,13 +151,13 @@ const Table = ({ name, names, rowIncludesHeading, titles, rows, flexibleColumns,
{row.map(
(item, itemIndex) =>
rowIncludesHeading && itemIndex === 0 ? (
<TableHeading rowHeading columnCount={row.length} key={item.key || itemIndex} verticalAlign={verticalAlign} name={names.headings}>
<TableHeading rowHeading columnCount={row.length} key={item.key || itemIndex} name={getName(names, calculateIndex(titles, nameByRow, index), itemIndex, nameByRow)}>
Copy link
Owner

Choose a reason for hiding this comment

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

this line is far too wide and should be triggering a linting error as it's over 120 chars long 😁

Copy link
Collaborator

@gavinorland gavinorland Jul 27, 2018

Choose a reason for hiding this comment

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

Let's make a call on #5 when we can. Also on whether to introduce Prettier. Maybe Ali is looking at this side of things. I think Prettier may be worth it but we'd need to be prepared to see a few commits which just (or also!) change formatting.

Copy link
Owner

@stevesims stevesims left a comment

Choose a reason for hiding this comment

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

one linting thing to fix

besides that i think it's all good 👍

@stevesims stevesims merged commit 060244e into master Aug 6, 2018
@stevesims stevesims deleted the feature/table-refactor branch August 6, 2018 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table needs better solutions for naming fields Table has some funky formatting
4 participants