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

(improvements) Cell renderers in several reports #842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 14 additions & 40 deletions src/components/ChangeLogs/ChangeLogs.columns.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { Cell } from '@blueprintjs/table'

import JSONFormat from 'ui/JSONFormat'
import { getCellState, getColumnWidth, getTooltipContent } from 'utils/columns'
import {
getCell,
getCellState,
getColumnWidth,
getJsonFormattedCell,
} from 'utils/columns'

export const getColumns = ({
t,
Expand All @@ -18,15 +19,9 @@ export const getColumns = ({
nameStr: `${t('column.date')} (${timeOffset})`,
width: getColumnWidth('mtsCreate', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const timestamp = getFullTime(filteredData[rowIndex].mtsCreate)
return (
<Cell tooltip={getTooltipContent(timestamp, t)}>
{timestamp}
</Cell>
)
return getCell(timestamp, t)
},
copyText: rowIndex => getFullTime(filteredData[rowIndex].mtsCreate),
},
Expand All @@ -35,15 +30,9 @@ export const getColumns = ({
name: 'column.description',
width: getColumnWidth('log', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { log } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(log, t)}>
{log}
</Cell>
)
return getCell(log, t)
},
copyText: rowIndex => filteredData[rowIndex].log,
},
Expand All @@ -52,15 +41,9 @@ export const getColumns = ({
name: 'column.ip',
width: getColumnWidth('ip', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { ip } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(ip, t)}>
{ip}
</Cell>
)
return getCell(ip, t)
},
copyText: rowIndex => filteredData[rowIndex].ip,
},
Expand All @@ -69,18 +52,9 @@ export const getColumns = ({
name: 'column.meta',
width: getColumnWidth('userAgent', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { userAgent } = filteredData[rowIndex]

return (
<Cell>
<JSONFormat content={userAgent}>
{userAgent}
</JSONFormat>
</Cell>
)
return getJsonFormattedCell(userAgent)
},
copyText: rowIndex => filteredData[rowIndex].userAgent,
},
Expand Down
44 changes: 8 additions & 36 deletions src/components/ConcentrationRisk/ConcentrationRisk.columns.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react'
import { Cell } from '@blueprintjs/table'

import { fixedFloat } from 'ui/utils'
import { getCellState } from 'utils/columns'
import { getCell, getCellState } from 'utils/columns'

export const getColumns = ({
t,
data,
isNoData,
isLoading,
Expand All @@ -15,15 +13,9 @@ export const getColumns = ({
className: 'align-left',
width: 100,
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { currency } = data[rowIndex]
return (
<Cell tooltip={currency}>
{currency}
</Cell>
)
return getCell(currency, t)
},
copyText: rowIndex => data[rowIndex].currency,
},
Expand All @@ -32,19 +24,9 @@ export const getColumns = ({
name: 'column.balanceUsd',
width: 150,
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { balanceUsd } = data[rowIndex]
const fixedBalanceUsd = fixedFloat(balanceUsd)
return (
<Cell
className='bitfinex-text-align-right'
tooltip={fixedBalanceUsd}
>
{fixedBalanceUsd}
</Cell>
)
return getCell(fixedFloat(balanceUsd), t)
},
copyText: rowIndex => fixedFloat(data[rowIndex].balanceUsd),
},
Expand All @@ -53,19 +35,9 @@ export const getColumns = ({
name: 'column.percent',
width: 150,
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { percent } = data[rowIndex]
const fixedPercent = fixedFloat(percent)
return (
<Cell
className='bitfinex-text-align-right'
tooltip={fixedPercent}
>
{fixedPercent}
</Cell>
)
return getCell(fixedFloat(percent), t)
},
copyText: rowIndex => fixedFloat(data[rowIndex].percent),
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/ConcentrationRisk/ConcentrationRisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ class ConcentrationRisk extends PureComponent {
const filteredData = entries.filter(entry => entry.balanceUsd)

const { tableData, chartData } = this.parseData(filteredData)
const tableColumns = getColumns({ data: tableData, isNoData, isLoading })
const tableColumns = getColumns({
data: tableData, isNoData, isLoading, t,
})

let showContent
if (isNoData) {
Expand Down
84 changes: 20 additions & 64 deletions src/components/Logins/Logins.columns.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { Cell } from '@blueprintjs/table'

import JSONFormat from 'ui/JSONFormat'
import { getCellState, getColumnWidth, getTooltipContent } from 'utils/columns'
import {
getCell,
getCellState,
getColumnWidth,
getJsonFormattedCell,
} from 'utils/columns'

export const getColumns = ({
t,
Expand All @@ -19,15 +20,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('id', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { id } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(id, t)}>
{id}
</Cell>
)
return getCell(id, t)
},
copyText: rowIndex => filteredData[rowIndex].id,
},
Expand All @@ -37,15 +32,9 @@ export const getColumns = ({
nameStr: `${t('column.date')} (${timeOffset})`,
width: getColumnWidth('time', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const timestamp = getFullTime(filteredData[rowIndex].time)
return (
<Cell tooltip={getTooltipContent(timestamp, t)}>
{timestamp}
</Cell>
)
return getCell(timestamp, t)
},
copyText: rowIndex => getFullTime(filteredData[rowIndex].time),
},
Expand All @@ -55,15 +44,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('ip', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { ip } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(ip, t)}>
{ip}
</Cell>
)
return getCell(ip, t)
},
copyText: rowIndex => filteredData[rowIndex].ip,
},
Expand All @@ -73,15 +56,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('browser', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { browser } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(browser, t)}>
{browser}
</Cell>
)
return getCell(browser, t)
},
copyText: rowIndex => filteredData[rowIndex].browser,
},
Expand All @@ -91,15 +68,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('version', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { version } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(version, t)}>
{version}
</Cell>
)
return getCell(version, t)
},
copyText: rowIndex => filteredData[rowIndex].version,
},
Expand All @@ -109,15 +80,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('mobile', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { mobile } = filteredData[rowIndex]
return (
<Cell tooltip={getTooltipContent(mobile, t)}>
{mobile}
</Cell>
)
return getCell(mobile, t)
},
copyText: rowIndex => filteredData[rowIndex].mobile,
},
Expand All @@ -127,18 +92,9 @@ export const getColumns = ({
className: 'align-left',
width: getColumnWidth('extra', columnsWidth),
renderer: (rowIndex) => {
if (isLoading || isNoData) {
return getCellState(isLoading, isNoData)
}
if (isLoading || isNoData) return getCellState(isLoading, isNoData)
const { extra } = filteredData[rowIndex]
const formattedExtra = JSON.stringify(extra, undefined, 2)
return (
<Cell>
<JSONFormat content={formattedExtra}>
{formattedExtra}
</JSONFormat>
</Cell>
)
return getJsonFormattedCell(extra)
},
copyText: rowIndex => JSON.stringify(filteredData[rowIndex].extra, undefined, 2),
},
Expand Down
Loading