fix: orderedBy wrapping in table header
This commit is contained in:
parent
bcda275177
commit
480548748a
2 changed files with 50 additions and 10 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { makeStyles } from '@material-ui/core'
|
||||||
|
import classnames from 'classnames'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
|
|
||||||
|
|
@ -11,6 +13,14 @@ import { startCase } from 'src/utils/string'
|
||||||
|
|
||||||
import TableCtx from './Context'
|
import TableCtx from './Context'
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
orderedBySpan: {
|
||||||
|
whiteSpace: 'nowrap'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
const groupSecondHeader = elements => {
|
const groupSecondHeader = elements => {
|
||||||
const [toSHeader, noSHeader] = R.partition(R.has('doubleHeader'))(elements)
|
const [toSHeader, noSHeader] = R.partition(R.has('doubleHeader'))(elements)
|
||||||
|
|
||||||
|
|
@ -31,6 +41,7 @@ const groupSecondHeader = elements => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
|
const classes = useStyles()
|
||||||
const {
|
const {
|
||||||
elements,
|
elements,
|
||||||
enableEdit,
|
enableEdit,
|
||||||
|
|
@ -61,12 +72,41 @@ const Header = () => {
|
||||||
const mapElement = (
|
const mapElement = (
|
||||||
{ name, width = DEFAULT_COL_SIZE, header, textAlign },
|
{ name, width = DEFAULT_COL_SIZE, header, textAlign },
|
||||||
idx
|
idx
|
||||||
) => (
|
) => {
|
||||||
|
const orderClasses = classnames({
|
||||||
|
[classes.orderedBySpan]:
|
||||||
|
R.isNil(header) && !R.isNil(orderedBy) && R.equals(name, orderedBy.code)
|
||||||
|
})
|
||||||
|
|
||||||
|
const attachOrderedByToComplexHeader = header => {
|
||||||
|
const cloneHeader = R.clone(header)
|
||||||
|
const children = R.path(['props', 'children'], cloneHeader)
|
||||||
|
const spanChild = R.find(it => R.equals(it.type, 'span'), children)
|
||||||
|
|
||||||
|
if (!R.isNil(orderedBy) && R.equals(name, orderedBy.code)) {
|
||||||
|
try {
|
||||||
|
spanChild.props.children = R.append(' -', spanChild.props.children)
|
||||||
|
return cloneHeader
|
||||||
|
} catch (e) {
|
||||||
|
return header
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return header
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<Td header key={idx} width={width} textAlign={textAlign}>
|
<Td header key={idx} width={width} textAlign={textAlign}>
|
||||||
{header || startCase(name)}{' '}
|
{!R.isNil(header) ? (
|
||||||
|
<>{attachOrderedByToComplexHeader(header) ?? header}</>
|
||||||
|
) : (
|
||||||
|
<span className={orderClasses}>
|
||||||
|
{startCase(name)}{' '}
|
||||||
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
|
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const [innerElements, HeaderElement] = groupSecondHeader(elements)
|
const [innerElements, HeaderElement] = groupSecondHeader(elements)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const ALL_COINS = {
|
||||||
code: 'ALL_COINS'
|
code: 'ALL_COINS'
|
||||||
}
|
}
|
||||||
|
|
||||||
const cashInAndOutHeaderStyle = { marginLeft: 6 }
|
const cashInAndOutHeaderStyle = { marginLeft: 6, whiteSpace: 'nowrap' }
|
||||||
|
|
||||||
const cashInHeader = (
|
const cashInHeader = (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -487,8 +487,8 @@ const getListCommissionsFields = (getData, currency, defaults) => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'cryptoCurrencies',
|
name: 'cryptoCurrencies',
|
||||||
display: 'Crypto Currency',
|
display: 'Crypto Currencydasdsa',
|
||||||
width: 265,
|
width: 255,
|
||||||
view: R.prop(0),
|
view: R.prop(0),
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
editable: false
|
editable: false
|
||||||
|
|
@ -510,7 +510,7 @@ const getListCommissionsFields = (getData, currency, defaults) => {
|
||||||
header: cashOutHeader,
|
header: cashOutHeader,
|
||||||
name: 'cashOut',
|
name: 'cashOut',
|
||||||
display: 'Cash-out',
|
display: 'Cash-out',
|
||||||
width: 130,
|
width: 140,
|
||||||
input: NumberInput,
|
input: NumberInput,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
greenText: true,
|
greenText: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue