Skip to content

Commit

Permalink
[BUG] Allow clicking back to top in Discover
Browse files Browse the repository at this point in the history
The original window.scrollTo(0, 0) will reset the window back but not
table. In this PR, we add a table wrapper to allow scroll back on table.

Issue Resolve:
opensearch-project#6006

Signed-off-by: Anan Zhuang <[email protected]>
  • Loading branch information
ananzh committed Mar 3, 2024
1 parent 2c8d9d3 commit c8e9cdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,8 @@ table {
}
}
}

.tableWrapper {
max-height: 75vh;
overflow-y: auto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const LegacyDiscoverTable = ({
defaultSortOrder,
showPagination,
}: DefaultDiscoverTableProps) => {
const scrollableDivRef = useRef<HTMLDivElement>(null);
const displayedColumns = getLegacyDisplayedColumns(
columns,
indexPattern,
Expand Down Expand Up @@ -113,9 +114,15 @@ export const LegacyDiscoverTable = ({
setActivePage(pageNumber);
};

const backToTop = () => {
if (scrollableDivRef.current) {
scrollableDivRef.current.scrollTop = 0;
}
};

return (
indexPattern && (
<>
<div ref={scrollableDivRef} className="tableWrapper">
{showPagination ? (
<Pagination
pageCount={pageCount}
Expand Down Expand Up @@ -173,7 +180,7 @@ export const LegacyDiscoverTable = ({
values={{ sampleSize }}
/>

<EuiButtonEmpty onClick={() => window.scrollTo(0, 0)}>
<EuiButtonEmpty onClick={backToTop}>
<FormattedMessage id="discover.backToTopLinkText" defaultMessage="Back to top." />
</EuiButtonEmpty>
</EuiCallOut>
Expand All @@ -189,7 +196,7 @@ export const LegacyDiscoverTable = ({
sampleSize={sampleSize}
/>
) : null}
</>
</div>
)
);
};

0 comments on commit c8e9cdb

Please sign in to comment.