Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Discover] Enable 'Back to Top' Feature in Discover for scrolling to top #6008

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG][Discover] Allow saved sort from search embeddable to load in Dashboard ([#5934](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5934))
- [BUG][Discover] Add key to index pattern options for support deplicate index pattern names([#5946](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5946))
- [Discover] Fix table cell content overflowing in Safari ([#5948](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5948))
- [BUG][MD]Fix schema for test connection to separate validation based on auth type([#5997](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5997))
- [BUG][MD]Fix schema for test connection to separate validation based on auth type ([#5997](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5997))
- [BUG][Discover] Enable 'Back to Top' Feature in Discover for scrolling to top ([#6008](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6008))
ananzh marked this conversation as resolved.
Show resolved Hide resolved

### 🚞 Infrastructure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface DataGridTableProps {
isContextView?: boolean;
isLoading?: boolean;
showPagination?: boolean;
scrollToTop?: () => void;
}

export const DataGridTable = ({
Expand All @@ -67,6 +68,7 @@ export const DataGridTable = ({
isContextView = false,
isLoading = false,
showPagination,
scrollToTop,
}: DataGridTableProps) => {
const services = getServices();
const [inspectedHit, setInspectedHit] = useState<OpenSearchSearchHit | undefined>();
Expand Down Expand Up @@ -179,6 +181,7 @@ export const DataGridTable = ({
isShortDots={isShortDots}
hideTimeColumn={hideTimeColumn}
defaultSortOrder={defaultSortOrder}
scrollToTop={scrollToTop}
/>
),
[
Expand All @@ -197,6 +200,7 @@ export const DataGridTable = ({
defaultSortOrder,
hideTimeColumn,
isShortDots,
scrollToTop,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface DefaultDiscoverTableProps {
hideTimeColumn: boolean;
defaultSortOrder: SortDirection;
showPagination?: boolean;
scrollToTop?: () => void;
}

export const LegacyDiscoverTable = ({
Expand All @@ -52,6 +53,7 @@ export const LegacyDiscoverTable = ({
hideTimeColumn,
defaultSortOrder,
showPagination,
scrollToTop,
}: DefaultDiscoverTableProps) => {
const displayedColumns = getLegacyDisplayedColumns(
columns,
Expand Down Expand Up @@ -173,7 +175,7 @@ export const LegacyDiscoverTable = ({
values={{ sampleSize }}
/>

<EuiButtonEmpty onClick={() => window.scrollTo(0, 0)}>
<EuiButtonEmpty onClick={scrollToTop}>
<FormattedMessage id="discover.backToTopLinkText" defaultMessage="Back to top." />
</EuiButtonEmpty>
</EuiCallOut>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
addColumn,
moveColumn,
removeColumn,
reorderColumn,
setColumns,
setSort,
useDispatch,
Expand All @@ -27,9 +26,10 @@ import { popularizeField } from '../../helpers/popularize_field';

interface Props {
rows?: OpenSearchSearchHit[];
scrollToTop?: () => void;
}

export const DiscoverTable = ({ rows }: Props) => {
export const DiscoverTable = ({ rows, scrollToTop }: Props) => {
const { services } = useOpenSearchDashboards<DiscoverViewServices>();
const {
uiSettings,
Expand Down Expand Up @@ -115,6 +115,7 @@ export const DiscoverTable = ({ rows }: Props) => {
displayTimeColumn={displayTimeColumn}
title={savedSearch?.id ? savedSearch.title : ''}
description={savedSearch?.id ? savedSearch.description : ''}
scrollToTop={scrollToTop}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import './discover_canvas.scss';

// eslint-disable-next-line import/no-default-export
export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewProps) {
const panelRef = useRef<HTMLDivElement>(null);
const { data$, refetch$, indexPattern } = useDiscoverContext();
const {
services: { uiSettings },
Expand Down Expand Up @@ -89,9 +90,15 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
}, [dispatch, filteredColumns, indexPattern]);

const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined;
const scrollToTop = () => {
if (panelRef.current) {
panelRef.current.scrollTop = 0;
}
};

return (
<EuiPanel
panelRef={panelRef}
hasBorder={false}
hasShadow={false}
color="transparent"
Expand All @@ -114,7 +121,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
{fetchState.status === ResultStatus.READY && (
<EuiPanel hasShadow={false} paddingSize="none" className="dscCanvas_results">
<MemoizedDiscoverChartContainer {...fetchState} />
<MemoizedDiscoverTable rows={rows} />
<MemoizedDiscoverTable rows={rows} scrollToTop={scrollToTop} />
</EuiPanel>
)}
</EuiPanel>
Expand Down
Loading