-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPivotTableValueCell.js
More file actions
99 lines (91 loc) · 2.83 KB
/
PivotTableValueCell.js
File metadata and controls
99 lines (91 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import PropTypes from 'prop-types'
import React, { useRef } from 'react'
import i18n from '../../locales/index.js'
import { applyLegendSet } from '../../modules/pivotTable/applyLegendSet.js'
import { CELL_TYPE_VALUE } from '../../modules/pivotTable/pivotTableConstants.js'
import {
isNumericValueType,
isBooleanValueType,
} from '../../modules/valueTypes.js'
import { PivotTableCell } from './PivotTableCell.js'
import { PivotTableEmptyCell } from './PivotTableEmptyCell.js'
import { usePivotTableEngine } from './PivotTableEngineContext.js'
export const PivotTableValueCell = ({
row,
column,
onToggleContextualMenu,
}) => {
const engine = usePivotTableEngine()
const cellRef = useRef(undefined)
const cellContent = engine.get({
row,
column,
})
const isClickable =
onToggleContextualMenu &&
cellContent.cellType === CELL_TYPE_VALUE &&
cellContent.ouId
const classes = [
cellContent.cellType,
cellContent.valueType,
isClickable && 'clickable',
]
const onClick = () => {
onToggleContextualMenu(cellRef.current, { ouId: cellContent.ouId })
}
if (!cellContent || cellContent.empty) {
return (
<PivotTableEmptyCell
onClick={isClickable ? onClick : undefined}
ref={cellRef}
classes={[cellContent.cellType, isClickable && 'clickable']}
/>
)
}
const legendStyle =
cellContent.cellType === CELL_TYPE_VALUE &&
(isNumericValueType(cellContent.valueType) ||
isBooleanValueType(cellContent.valueType))
? applyLegendSet(
cellContent.rawValue,
cellContent.dxDimension,
engine
)
: undefined
const width =
engine.adaptiveClippingController.columns.sizes[
engine.columnMap[column]
].size
const height =
engine.adaptiveClippingController.rows.sizes[engine.rowMap[row]].size
const style = {
...legendStyle,
width,
height,
whiteSpace: 'pre-line',
}
return (
<PivotTableCell
key={column}
classes={classes}
title={
cellContent.titleValue ??
i18n.t('Value: {{value}}', {
value: cellContent.renderedValue,
nsSeparator: '^^',
})
}
style={style}
onClick={isClickable ? onClick : undefined}
ref={cellRef}
dataTest={'visualization-value-cell'}
>
{cellContent.renderedValue ?? null}
</PivotTableCell>
)
}
PivotTableValueCell.propTypes = {
column: PropTypes.number.isRequired,
row: PropTypes.number.isRequired,
onToggleContextualMenu: PropTypes.func,
}