Skip to content

Commit 912544c

Browse files
committed
Infinite scroll for the details modal
1 parent 4770dca commit 912544c

2 files changed

Lines changed: 14 additions & 29 deletions

File tree

web/app/pages/Project/View/Panels.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { PROJECT_TABS } from '~/lib/constants'
5151
import { Entry } from '~/lib/models/Entry'
5252
import Button from '~/ui/Button'
5353
import Dropdown from '~/ui/Dropdown'
54+
import InfiniteScrollTrigger from '~/ui/InfiniteScrollTrigger'
5455
import Input from '~/ui/Input'
5556
import Sort from '~/ui/icons/Sort'
5657
import Spin from '~/ui/icons/Spin'
@@ -1834,7 +1835,7 @@ export interface PanelProps {
18341835
isRefetching?: boolean
18351836
/** Shows a centered spinner in place of the rows while the first page is being fetched. */
18361837
isLoading?: boolean
1837-
serverTotal?: number
1838+
/** Defined only while further pages remain; the details table autoloads them on scroll. */
18381839
onLoadMore?: () => void
18391840
loadingMore?: boolean
18401841
}
@@ -1851,7 +1852,6 @@ interface DetailsTableProps extends Pick<
18511852
| 'valueMapper'
18521853
| 'getFilterLink'
18531854
| 'activeTab'
1854-
| 'serverTotal'
18551855
| 'onLoadMore'
18561856
| 'loadingMore'
18571857
> {
@@ -1883,7 +1883,6 @@ const DetailsTable = ({
18831883
hidePercentageInDetails,
18841884
detailsExtraColumns,
18851885
activeTab = PROJECT_TABS.traffic,
1886-
serverTotal,
18871886
onLoadMore,
18881887
loadingMore,
18891888
}: DetailsTableProps) => {
@@ -2003,13 +2002,15 @@ const DetailsTable = ({
20032002
})
20042003
}
20052004

2005+
// Keyed on the dimension, not on `data` — appending a page gives `data` a new
2006+
// identity, and resetting on that would undo the user's sort mid-scroll.
20062007
useEffect(() => {
20072008
setSort({
20082009
label: 'quantity',
20092010
sortByAscend: false,
20102011
sortByDescend: false,
20112012
})
2012-
}, [data])
2013+
}, [activeTabId])
20132014

20142015
const numericColsCount =
20152016
1 + (detailsExtraColumns?.length || 0) + (!hidePercentageInDetails ? 1 : 0)
@@ -2209,28 +2210,17 @@ const DetailsTable = ({
22092210
)
22102211
})}
22112212
</div>
2212-
</div>
2213-
</div>
2214-
{onLoadMore ? (
2215-
<div className='mt-2 flex items-center justify-center gap-3'>
2216-
<Button
2217-
variant='secondary'
2218-
size='sm'
2219-
type='button'
2220-
onClick={onLoadMore}
2221-
disabled={loadingMore}
2222-
className='gap-1.5'
2223-
>
2224-
{loadingMore ? <Spin className='m-0!' /> : null}
2225-
{t('project.loadMore')}
2226-
</Button>
2227-
{serverTotal ? (
2228-
<Text size='sm' colour='muted'>
2229-
{data.length} / {nFormatter(serverTotal, 1)}
2230-
</Text>
2213+
2214+
{onLoadMore ? (
2215+
<InfiniteScrollTrigger
2216+
hasMore
2217+
isLoading={Boolean(loadingMore)}
2218+
onLoadMore={onLoadMore}
2219+
root={parentRef}
2220+
/>
22312221
) : null}
22322222
</div>
2233-
) : null}
2223+
</div>
22342224
</div>
22352225
)
22362226
}
@@ -2265,7 +2255,6 @@ const Panel = ({
22652255
rowTooltipFollowCursor = false,
22662256
isRefetching,
22672257
isLoading,
2268-
serverTotal,
22692258
onLoadMore,
22702259
loadingMore,
22712260
}: PanelProps) => {
@@ -2720,7 +2709,6 @@ const Panel = ({
27202709
hidePercentageInDetails={hidePercentageInDetails}
27212710
detailsExtraColumns={detailsExtraColumns}
27222711
activeTab={activeTab}
2723-
serverTotal={serverTotal}
27242712
onLoadMore={onLoadMore}
27252713
loadingMore={loadingMore}
27262714
/>

web/app/pages/Project/View/v2/BreakdownPanel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ export const BreakdownPanel = ({
150150
)
151151
}, [activeSubTab, versionsQuery.data, primaryMetric])
152152

153-
const total = query.data?.pages[0]?.meta.total
154-
155153
const containerTabs =
156154
flatSubTabs.length > 1
157155
? subTabs.map((tab) =>
@@ -210,7 +208,6 @@ export const BreakdownPanel = ({
210208
id={activeSubTab.dimension || activeSubTabId}
211209
name={name}
212210
data={entries}
213-
serverTotal={total}
214211
isLoading={isLoading}
215212
customRenderer={query.isError ? renderError : undefined}
216213
tabs={containerTabs}

0 commit comments

Comments
 (0)