Skip to content

Commit

Permalink
Merge branch 'master' into fix/ao-deleted-after-copy-DHIS2-15722
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott authored Sep 14, 2023
2 parents 1324f08 + 05d3d79 commit 30a5dd2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/components/Visualization/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const Visualization = ({
onError,
}) => {
const [uniqueLegendSets, setUniqueLegendSets] = useState([])
const [paginationMaxWidth, setPaginationMaxWidth] = useState(0)
const [{ sortField, sortDirection, pageSize, page }, setSorting] =
useReducer((sorting, newSorting) => ({ ...sorting, ...newSorting }), {
sortField: null,
Expand All @@ -123,6 +124,27 @@ export const Visualization = ({

const visualizationRef = useRef(visualization)

const containerCallbackRef = useCallback((node) => {
if (node === null || node.clientWidth === 0) {
return
}

const adjustSize = () => {
const containerInnerWidth = node.clientWidth
const scrollBox = node.querySelector('.tablescrollbox')
const scrollbarWidth = scrollBox.offsetWidth - scrollBox.clientWidth

setPaginationMaxWidth(containerInnerWidth - scrollbarWidth)
}

const sizeObserver = new window.ResizeObserver(adjustSize)
sizeObserver.observe(node)

adjustSize()

return sizeObserver.disconnect
}, [])

const setPage = useCallback(
(pageNum) =>
setSorting({
Expand Down Expand Up @@ -281,7 +303,7 @@ export const Visualization = ({
const isInModal = !!filters?.relativePeriodDate

return (
<div className={styles.pluginContainer}>
<div className={styles.pluginContainer} ref={containerCallbackRef}>
<div
data-test="line-list-loading-indicator"
className={cx(styles.fetchIndicator, {
Expand Down Expand Up @@ -413,6 +435,7 @@ export const Visualization = ({
styles.stickyNavigation,
sizeClass
)}
style={{ maxWidth: paginationMaxWidth }}
>
<PaginationComponent
offline={offline}
Expand Down

0 comments on commit 30a5dd2

Please sign in to comment.