Skip to content

Commit

Permalink
chore: simplify code and remove redundant prop
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Oct 3, 2023
1 parent 89de6cf commit 0e147af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
18 changes: 3 additions & 15 deletions src/components/PivotTable/PivotTableTitleRow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tooltip } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useRef, useMemo, useState, useEffect } from 'react'
import React, { useRef, useState, useEffect } from 'react'
import { PivotTableCell } from './PivotTableCell.js'
import { usePivotTableEngine } from './PivotTableEngineContext.js'
import { cell as cellStyle } from './styles/PivotTable.style.js'
Expand All @@ -9,25 +9,14 @@ export const PivotTableTitleRow = ({
title,
scrollPosition,
containerWidth,
totalWidth,
}) => {
const containerRef = useRef(null)
const [scrollWidth, setScrollWidth] = useState(0)
const [isTitleTruncated, setIsTitleTruncated] = useState(false)
const engine = usePivotTableEngine()
const columnCount = engine.width + engine.rowDepth
const maxWidth = useMemo(
() => containerWidth - (engine.cellPadding * 2 + 2),
[containerWidth, engine.cellPadding]
)
const marginLeft = useMemo(
() =>
Math.max(
0,
Math.min(scrollPosition?.x ?? 0, totalWidth - containerWidth)
),
[containerWidth, scrollPosition.x, totalWidth]
)
const maxWidth = containerWidth - (engine.cellPadding * 2 + 2)
const marginLeft = Math.max(0, scrollPosition?.x ?? 0)

useEffect(() => {
if (containerRef.current) {
Expand Down Expand Up @@ -91,5 +80,4 @@ PivotTableTitleRow.propTypes = {
scrollPosition: PropTypes.shape({ x: PropTypes.number.isRequired })
.isRequired,
title: PropTypes.string.isRequired,
totalWidth: PropTypes.number.isRequired,
}
12 changes: 0 additions & 12 deletions src/components/PivotTable/PivotTableTitleRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ export const PivotTableTitleRows = ({ clippingResult, width }) => {
title={engine.options.title}
scrollPosition={clippingResult.scrollPosition}
containerWidth={width}
totalWidth={
engine.adaptiveClippingController.columns.totalSize +
engine.adaptiveClippingController.columns.headerSize
}
/>
) : null}
{engine.options.subtitle ? (
<PivotTableTitleRow
title={engine.options.subtitle}
scrollPosition={clippingResult.scrollPosition}
containerWidth={width}
totalWidth={
engine.adaptiveClippingController.columns.totalSize +
engine.adaptiveClippingController.columns.headerSize
}
/>
) : null}
{engine.visualization.filters?.length ? (
Expand All @@ -38,10 +30,6 @@ export const PivotTableTitleRows = ({ clippingResult, width }) => {
)}
scrollPosition={clippingResult.scrollPosition}
containerWidth={width}
totalWidth={
engine.adaptiveClippingController.columns.totalSize +
engine.adaptiveClippingController.columns.headerSize
}
/>
) : null}
</>
Expand Down

0 comments on commit 0e147af

Please sign in to comment.