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

[WIP] 🧪 Experimental Table #718

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c5a7ba1
Refactor BulkActions and Checkbox to functional components
matheusps Jul 11, 2019
24c5e48
Fix compile errors, Refactor toolbar to FC
matheusps Jul 11, 2019
d7d574b
Break Toolbar input into a separate component
matheusps Jul 11, 2019
8d8af3c
Break density button into a separate component
matheusps Jul 11, 2019
e754828
Break fields button into a separate component
matheusps Jul 11, 2019
ca116d8
Remove composeIndex
matheusps Jul 11, 2019
f3ac236
Memorized height for fields box
matheusps Jul 11, 2019
4ffc1e3
Create generic toolbar button
matheusps Jul 11, 2019
17750a1
Rename buttons
matheusps Jul 11, 2019
da161da
Fix warnings on Toggle
matheusps Jul 12, 2019
fde1d39
Create NewlineButton component
matheusps Jul 12, 2019
ad01658
Create ExtraActions component
matheusps Jul 12, 2019
7257953
SimpleTable as function
matheusps Jul 17, 2019
39a55f0
Table as functional component
matheusps Jul 17, 2019
9e7807c
Separate states from component
matheusps Jul 18, 2019
f01034e
Separate pagination
matheusps Jul 18, 2019
d2f63f4
Complete hook refactor
matheusps Jul 18, 2019
70ae7d0
Separate toolbar folder
matheusps Jul 19, 2019
7853320
Folder structure
matheusps Jul 19, 2019
4f24753
Expose ButtonFields
matheusps Jul 19, 2019
6de1fca
Fix update table height on change pagination
matheusps Jul 19, 2019
f07bf9b
Better performance on inherit state
matheusps Jul 19, 2019
3d826fe
Improve hook rendering
matheusps Jul 22, 2019
f81c887
Export elementary actions
matheusps Jul 22, 2019
b4170e4
Export ToolbarContainer
matheusps Jul 22, 2019
19fa467
Avoid exporting useTableState (upcomming feature)
matheusps Jul 22, 2019
6a971a9
Export SearchInput and fix Proptypes
matheusps Jul 23, 2019
e2e8e57
Update CHANGELOG
matheusps Jul 23, 2019
cca1a01
Unite utils
matheusps Jul 23, 2019
fdaa974
Remove useless component
matheusps Jul 23, 2019
2d9243e
Call function inside of memo
matheusps Jul 23, 2019
d521d1f
Fix some PR issues
matheusps Jul 23, 2019
748b7e2
Document composites props
matheusps Jul 24, 2019
a7a3aa8
Remove eslint disable on hook
matheusps Jul 24, 2019
e2a3114
Update docs
matheusps Jul 24, 2019
d221b12
Use contants instead of magic values
matheusps Jul 24, 2019
f67d0fb
Create Box component
matheusps Jul 25, 2019
3d518c4
Create menu component
matheusps Jul 25, 2019
7b77efd
Using Menu for Density and Fields
matheusps Jul 25, 2019
72d5ca1
getButton function
matheusps Jul 25, 2019
1fb953a
PR issues
matheusps Jul 26, 2019
0b1171d
Change margin from string to number
matheusps Jul 26, 2019
2cc20f1
Added children constraints
matheusps Jul 26, 2019
bd65f92
Export MenuToolbar, so that users can create custom menus
matheusps Jul 26, 2019
9fb4b68
Improve error messages
matheusps Jul 26, 2019
85652a7
Toolbar no longer is passed via children
matheusps Jul 26, 2019
f694cf3
Prepare room for autocomplete
matheusps Jul 26, 2019
8eff722
Rename InputToolbar
matheusps Jul 26, 2019
bf459c7
Table as experimental
matheusps Aug 2, 2019
dfa71aa
TableFallback
matheusps Aug 2, 2019
1902db2
Merge branch 'master' into feature/composable-table
matheusps Aug 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,7 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [8.67.0] - 2019-07-22
### Changed

- Turn `Toolbar` into a compound component.

## [9.67.0] - 2019-07-22

### Changed

- Get changes made at version `v8.67.0` & fix version.

## [9.63.1] - 2019-07-22

### Changed

- Get changes made at version `v8.66.1`.

## [9.63.0] - 2019-07-16

### Changed

- Get changes made at version `v8.63.0`.

### Added

Expand Down Expand Up @@ -73,6 +93,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Security vulnerabilities

### Changed

- Get changes made at version 'v8.60.3'

## [8.60.3] - 2019-07-08

### Fixed
Expand Down
173 changes: 80 additions & 93 deletions react/components/Table/BulkActions.js
@@ -1,4 +1,4 @@
import React, { PureComponent } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

Expand All @@ -7,105 +7,92 @@ import ButtonWithIcon from '../ButtonWithIcon'
import ActionMenu from '../ActionMenu'
import Close from '../icon/Close'

import BulkActionsSelectedRows from './BulkActionsSelectedRows'

const close = <Close />

class BulkActions extends PureComponent {
render() {
const {
hasPrimaryBulkAction,
hasSecondaryBulkActions,
selectedRows,
bulkActions,
allLinesSelected,
onSelectAllLines,
onDeselectAllLines,
} = this.props

const hasBulkActions = hasPrimaryBulkAction || hasSecondaryBulkActions
const selectedRowsLength = selectedRows.length
const hasRowsSelected = selectedRowsLength > 0
const BulkActions = ({
hasPrimaryBulkAction,
hasSecondaryBulkActions,
selectedRows,
bulkActions,
allLinesSelected,
onSelectAllLines,
onDeselectAllLines,
}) => {
const hasBulkActions = hasPrimaryBulkAction || hasSecondaryBulkActions
const selectedRowsLength = selectedRows.length
const hasRowsSelected = selectedRowsLength > 0

const bulkActionsReturnedParameters = allLinesSelected
? { allLinesSelected: true }
: { selectedRows }
const bulkActionsReturnedParameters = allLinesSelected
? { allLinesSelected: true }
: { selectedRows }

return (
<div
className={classNames(
'flex flex-row justify-between bg-action-primary c-on-action-primary br3 br--top ph4',
{
pv4: hasRowsSelected,
}
)}
style={{
height: hasRowsSelected ? '56px' : 0,
overflow: hasRowsSelected ? 'auto' : 'hidden',
transition: 'height 0.2s ease-in-out, padding 0.2s ease-in-out',
}}>
{hasBulkActions && (
<div className="flex flex-row">
{hasPrimaryBulkAction && (
<div className="mr4">
<Button
variation="secondary"
size="small"
onClick={() =>
bulkActions.main.handleCallback(
bulkActionsReturnedParameters
)
}>
{bulkActions.main.label}
</Button>
</div>
)}
{hasSecondaryBulkActions && (
<ActionMenu
label={bulkActions.texts.secondaryActionsLabel}
buttonProps={{ variation: 'secondary', size: 'small' }}
options={bulkActions.others.map(el => ({
label: el.label,
onClick: () =>
el.handleCallback(bulkActionsReturnedParameters),
}))}
/>
)}
</div>
)}
<div className="tr flex flex-row items-center">
{!allLinesSelected && bulkActions && bulkActions.texts && (
<span className="mr4 c-muted-4">
{bulkActions.texts.rowsSelected(
<BulkActionsSelectedRows
selectedRowsLength={selectedRowsLength}
/>
)}
</span>
)}
<span className="mr2">
{allLinesSelected ? (
bulkActions &&
bulkActions.texts &&
bulkActions.texts.allRowsSelected(
<span className="b">{bulkActions.totalItems}</span>
)
) : (
<Button onClick={() => onSelectAllLines()}>
<span className="ttu">
{bulkActions &&
`${bulkActions.texts && bulkActions.texts.selectAll} ${
bulkActions.totalItems
}`}
</span>
return (
<div
className={classNames(
'flex flex-row justify-between bg-action-primary c-on-action-primary br3 br--top ph4',
{
pv4: hasRowsSelected,
}
)}
style={{
height: hasRowsSelected ? '56px' : 0,
overflow: hasRowsSelected ? 'auto' : 'hidden',
transition: 'height 0.2s ease-in-out, padding 0.2s ease-in-out',
}}>
{hasBulkActions && (
<div className="flex flex-row">
{hasPrimaryBulkAction && (
<div className="mr4">
<Button
variation="secondary"
size="small"
onClick={() =>
bulkActions.main.handleCallback(bulkActionsReturnedParameters)
}>
{bulkActions.main.label}
</Button>
)}
</span>
<ButtonWithIcon icon={close} onClick={() => onDeselectAllLines()} />
</div>
)}
{hasSecondaryBulkActions && (
<ActionMenu
label={bulkActions.texts.secondaryActionsLabel}
buttonProps={{ variation: 'secondary', size: 'small' }}
options={bulkActions.others.map(el => ({
label: el.label,
onClick: () => el.handleCallback(bulkActionsReturnedParameters),
}))}
/>
)}
</div>
)}
<div className="tr flex flex-row items-center">
{!allLinesSelected && bulkActions && bulkActions.texts && (
<span className="mr4 c-muted-4">
{bulkActions.texts.rowsSelected(selectedRowsLength)}
</span>
)}
<span className="mr2">
{allLinesSelected ? (
bulkActions &&
bulkActions.texts &&
bulkActions.texts.allRowsSelected(
<span className="b">{bulkActions.totalItems}</span>
)
) : (
<Button onClick={() => onSelectAllLines()}>
<span className="ttu">
{bulkActions &&
`${bulkActions.texts && bulkActions.texts.selectAll} ${
bulkActions.totalItems
}`}
</span>
</Button>
)}
</span>
<ButtonWithIcon icon={close} onClick={() => onDeselectAllLines()} />
</div>
)
}
</div>
)
}

BulkActions.defaultProps = {
Expand Down
23 changes: 0 additions & 23 deletions react/components/Table/BulkActionsSelectedRows.js

This file was deleted.

64 changes: 30 additions & 34 deletions react/components/Table/CheckboxContainer.js
@@ -1,43 +1,39 @@
import React, { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'

import Checkbox from '../Checkbox'

class CheckboxContainer extends Component {
static defaultProps = {
partial: false,
disabled: false,
}

static propTypes = {
checked: PropTypes.bool.isRequired,
partial: PropTypes.bool,
onClick: PropTypes.func.isRequired,
disabled: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}
const CheckboxContainer = ({ checked, partial, id, onClick, disabled }) => {
return (
<div
onClick={e => {
e.stopPropagation()
// prevents the onRowClick event from happening
}}>
<Checkbox
checked={checked}
partial={partial}
value={`${id}`}
id={`${id}`}
Klynger marked this conversation as resolved.
Show resolved Hide resolved
name={`row_${id}`}
onChange={() => onClick(id)}
disabled={disabled}
/>
</div>
)
}

render() {
const { checked, partial, id, onClick, disabled } = this.props
CheckboxContainer.defaultProps = {
partial: false,
disabled: false,
}

return (
<div
onClick={e => {
e.stopPropagation()
// prevents the onRowClick event from happening
}}>
<Checkbox
checked={checked}
partial={partial}
value={`${id}`}
id={`${id}`}
name={`row_${id}`}
onChange={() => onClick(id)}
disabled={disabled}
/>
</div>
)
}
CheckboxContainer.propTypes = {
checked: PropTypes.bool.isRequired,
partial: PropTypes.bool,
onClick: PropTypes.func.isRequired,
disabled: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

export default CheckboxContainer