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

Table rowgroups #393

Merged
merged 23 commits into from
Jun 18, 2018
Merged

Table rowgroups #393

merged 23 commits into from
Jun 18, 2018

Conversation

fczuardi
Copy link
Contributor

@fczuardi fczuardi force-pushed the table-rowgroups branch 8 times, most recently from d66dfa8 to 7d3f778 Compare June 15, 2018 05:11
@fczuardi fczuardi changed the title [WIP] Table rowgroups Table rowgroups Jun 15, 2018
@fczuardi fczuardi changed the title Table rowgroups [WIP] Table rowgroups Jun 15, 2018
@fczuardi
Copy link
Contributor Author

fczuardi commented Jun 15, 2018

still missing from the patch is the small blue "L" icon on the rows that are grouped

// iterate over all rows and sub-rows to create
// a hash table of rows indexed by keys in the
// format "<index>,<subIndex>"
const rowsMap = this.props.data.reduce((entries, row, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when rows are added to props.data after the component is mounted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would break selection checkboxes :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually is the selectionData passed to selectionHeader that breaks, it wont pass a selected row if the data about that row was added afterwards, I will update the index on component update to fix this (and write tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with 77910db

RED_ORANGE: "#ff4411",
INDIGO_MILK_CAP: "#3498db",
INDIGO_MILK_CAP_06: "rgba(52,152,219,0.06)",
Copy link
Member

Choose a reason for hiding this comment

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

How about we use a tool like: https://polished.js.org/docs/#transparentize to generate this color?
If some day we change the value for INDIGO_MILK_CAP, the transparent one will be updated along with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed on d968410

@@ -58,6 +58,8 @@ core of the whole thing, it should be an array of objects, each item representin
| selectionHeader | function ``(selectedRows, clearFunction) => React.node`` | a function that receives an array of selected rows data plus a function to clear selection; and should return a react node to be rendered as an action bar on top of the table, there is a helper component SelectionBar that can be used as the return of this function, or you can create your own... see the stories files for usage examples |
| width | string | use this to manually change the width of the table |
| rowHeight | string | use this to manually change the height of the body rows of the table, the package exports a set of named values as ``rowHeights``, you can import them and use ``rowHeights.SMALL`` to have a more compact table |
| rowGroupKey | string | if you have rows that contains sub-rows as a list under a key, you can pass this property with the name of the key, to have a table with row groups generated |
| collapsed | boolean | if row groups are used, this flag will add a button column with buttons that works as expand/collapse toggle on the start of row groups. The groups will start collapsed. |
Copy link
Member

@vNakamura vNakamura Jun 15, 2018

Choose a reason for hiding this comment

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

This could be split into 2 props: collapsible and startCollapsed. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how will this be used? will we have tables that starts expanded? if so, maybe we can have an expanded for that case

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we don't need to worry about it now

_renderRow = (row, index, subIndex = "", group = false) => {
const { selectableRows, collapsed, children } = this.props;
const rowKey = `${index},${subIndex}`;
const selected = this.state.selectedRows.indexOf(rowKey) !== -1;
Copy link
Member

Choose a reason for hiding this comment

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

I preferincludes over indexOf because it's declarative.

A downside is that it's not supported by IE.
We could add an indication of this restriction in the readme, so the use of a polyfill would be decided at the application using this component.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

Anyway, this is minor and I'm OK if we decide to keep indexOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed on b60cce8

? [
...oldExpandedRows.slice(0, expandedIndexOf),
...oldExpandedRows.slice(expandedIndexOf + 1)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

image

We could use filter here...

const expandedRows = 
  expandedIndexOf !== -1
    ? oldExpandedRows.filter((element, index) => index !== expandedIndexOf)
    : [...oldExpandedRows, index]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed on 01af33d

fczuardi added 11 commits June 18, 2018 09:39
affects: @crave/farmblocks-table

test(table): update README and stories to match the expected api

affects: @crave/farmblocks-table
affects: @crave/farmblocks-table
…groud for grouped rows

affects: @crave/farmblocks-table, @crave/farmblocks-theme

feat(table): include new color on the palette and use it for row hover

affects: @crave/farmblocks-table, @crave/farmblocks-theme
affects: @crave/farmblocks-table
… row groups

affects: @crave/farmblocks-table
fczuardi added 4 commits June 18, 2018 11:22
…ected rows to selection header

affects: @crave/farmblocks-table
affects: @crave/farmblocks-table
…h css

affects: @crave/farmblocks-table

this is to prevent a Chrome glitch that causes a blink on first expand
@fczuardi fczuardi force-pushed the table-rowgroups branch 3 times, most recently from 8d70891 to d968410 Compare June 18, 2018 14:45
@fczuardi fczuardi changed the title [WIP] Table rowgroups Table rowgroups Jun 18, 2018
@fgameiro fgameiro merged commit 4d148d4 into master Jun 18, 2018
@alcferreira alcferreira deleted the table-rowgroups branch June 18, 2018 18:27
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.

Make table row expandable/collapsible
4 participants