fix(xo-web/SortedTable): broken individual actions
Introduced by cdced7cdc1
This commit is contained in:
parent
51a137c4e5
commit
8342bb2bc8
@ -12,6 +12,7 @@ import { Portal } from 'react-overlays'
|
|||||||
import { routerShape } from 'react-router/lib/PropTypes'
|
import { routerShape } from 'react-router/lib/PropTypes'
|
||||||
import { Set } from 'immutable'
|
import { Set } from 'immutable'
|
||||||
import { Dropdown, MenuItem } from 'react-bootstrap-4/lib'
|
import { Dropdown, MenuItem } from 'react-bootstrap-4/lib'
|
||||||
|
import { injectState, provideState } from 'reaclette'
|
||||||
import {
|
import {
|
||||||
ceil,
|
ceil,
|
||||||
filter,
|
filter,
|
||||||
@ -208,44 +209,36 @@ const actionsShape = PropTypes.arrayOf(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
class IndividualAction extends Component {
|
const IndividualAction = [
|
||||||
_getIsDisabled = createSelector(
|
provideState({
|
||||||
() => this.props.disabled,
|
computed: {
|
||||||
() => this.props.item,
|
disabled: ({ item }, { disabled, userData }) =>
|
||||||
() => this.props.userData,
|
isFunction(disabled) ? disabled(item, userData) : disabled,
|
||||||
(disabled, item, userData) =>
|
handler: ({ item }, { handler, userData }) => () =>
|
||||||
isFunction(disabled) ? disabled(item, userData) : disabled
|
handler(item, userData),
|
||||||
)
|
icon: ({ item }, { icon, userData }) =>
|
||||||
_getLabel = createSelector(
|
isFunction(icon) ? icon(item, userData) : icon,
|
||||||
() => this.props.label,
|
item: (_, { item, grouped }) => (grouped ? [item] : item),
|
||||||
() => this.props.item,
|
label: ({ item }, { label, userData }) =>
|
||||||
() => this.props.userData,
|
isFunction(label) ? label(item, userData) : label,
|
||||||
(label, item, userData) =>
|
level: ({ item }, { level, userData }) =>
|
||||||
isFunction(label) ? label(item, userData) : label
|
isFunction(level) ? level(item, userData) : level,
|
||||||
)
|
},
|
||||||
|
}),
|
||||||
_executeAction = () => {
|
injectState,
|
||||||
const p = this.props
|
({ state, redirectOnSuccess, userData }) => (
|
||||||
return p.handler(p.item, p.userData)
|
<ActionRowButton
|
||||||
}
|
btnStyle={state.level}
|
||||||
|
data-item={state.item}
|
||||||
render () {
|
data-userData={userData}
|
||||||
const { icon, item, level, redirectOnSuccess, userData } = this.props
|
disabled={state.disabled}
|
||||||
|
handler={state.handler}
|
||||||
return (
|
icon={state.icon}
|
||||||
<ActionRowButton
|
redirectOnSuccess={redirectOnSuccess}
|
||||||
btnStyle={level}
|
tooltip={state.label}
|
||||||
data-item={item}
|
/>
|
||||||
data-userData={userData}
|
),
|
||||||
disabled={this._getIsDisabled()}
|
].reduceRight((value, decorator) => decorator(value))
|
||||||
handler={this._executeAction}
|
|
||||||
icon={icon}
|
|
||||||
redirectOnSuccess={redirectOnSuccess}
|
|
||||||
tooltip={this._getLabel()}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GroupedAction extends Component {
|
class GroupedAction extends Component {
|
||||||
_getIsDisabled = createSelector(
|
_getIsDisabled = createSelector(
|
||||||
@ -721,13 +714,27 @@ export default class SortedTable extends Component {
|
|||||||
_getIndividualActions = createSelector(
|
_getIndividualActions = createSelector(
|
||||||
() => this.props.individualActions,
|
() => this.props.individualActions,
|
||||||
() => this.props.actions,
|
() => this.props.actions,
|
||||||
(individualActions, actions) =>
|
(individualActions, actions) => {
|
||||||
sortBy(
|
const normalizedActions = map(actions, a => ({
|
||||||
|
disabled:
|
||||||
|
a.individualDisabled !== undefined
|
||||||
|
? a.individualDisabled
|
||||||
|
: a.disabled,
|
||||||
|
grouped: a.individualHandler === undefined,
|
||||||
|
handler:
|
||||||
|
a.individualHandler !== undefined ? a.individualHandler : a.handler,
|
||||||
|
icon: a.icon,
|
||||||
|
label: a.individualLabel !== undefined ? a.individualLabel : a.label,
|
||||||
|
level: a.level,
|
||||||
|
}))
|
||||||
|
|
||||||
|
return sortBy(
|
||||||
individualActions !== undefined && actions !== undefined
|
individualActions !== undefined && actions !== undefined
|
||||||
? individualActions.concat(actions)
|
? individualActions.concat(normalizedActions)
|
||||||
: individualActions || actions,
|
: individualActions || normalizedActions,
|
||||||
action => LEVELS.indexOf(action.level)
|
action => LEVELS.indexOf(action.level)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
_renderItem = (item, i) => {
|
_renderItem = (item, i) => {
|
||||||
@ -771,11 +778,8 @@ export default class SortedTable extends Component {
|
|||||||
{map(this._getIndividualActions(), (props, key) => (
|
{map(this._getIndividualActions(), (props, key) => (
|
||||||
<IndividualAction
|
<IndividualAction
|
||||||
{...props}
|
{...props}
|
||||||
disabled={props.individualDisabled || props.disabled}
|
item={item}
|
||||||
handler={props.individualHandler || props.handler}
|
|
||||||
item={props.individualHandler !== undefined ? item : [item]}
|
|
||||||
key={key}
|
key={key}
|
||||||
label={props.individualLabel || props.label}
|
|
||||||
userData={userData}
|
userData={userData}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
Loading…
Reference in New Issue
Block a user