Skip to content

Commit

Permalink
Fix regression maintaining scroll position (#3491)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
cynthia-sg authored Nov 17, 2023
1 parent 95c261e commit 6f48c8e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
4 changes: 2 additions & 2 deletions web/src/layout/package/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ const Details = (props: Props) => {
<div>
<SmallTitle text="Kind" />
{kinds.map((kind: string, index: number) => (
<p
<div
data-testid="keptnKind"
className={classnames('text-truncate', styles.text, { 'mb-1': index + 1 !== kinds.length })}
key={`keptn-kind-${kind}`}
Expand All @@ -383,7 +383,7 @@ const Details = (props: Props) => {
<span className="pe-1">&#183;</span>
<small>{kind}</small>
</div>
</p>
</div>
))}
</div>
)}
Expand Down
29 changes: 0 additions & 29 deletions web/src/layout/package/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,6 @@ describe('Package index', () => {
});
});

// describe('Go back button', () => {
// it('proper behaviour', async () => {
// const searchUrlReferer = {
// tsQueryWeb: 'test',
// filters: {},
// pageNumber: 1,
// deprecated: false,
// };
// const mockPackage = getMockPackage('4');
// mocked(API).getPackage.mockResolvedValue(mockPackage);

// render(
// <Router>
// <PackageView searchUrlReferer={searchUrlReferer} />
// </Router>
// );

// const goBack = await screen.findByRole('button', { name: /Back to results/ });
// expect(goBack).toBeInTheDocument();
// await userEvent.click(goBack);
// expect(mockHistoryPush).toHaveBeenCalledTimes(1);
// expect(mockHistoryPush).toHaveBeenCalledWith({
// pathname: '/packages/search',
// search: prepareQueryString(searchUrlReferer),
// state: { 'from-detail': true },
// });
// });
// });

describe('Repository button', () => {
it('renders repository link', async () => {
const mockPackage = getMockPackage('5');
Expand Down
4 changes: 2 additions & 2 deletions web/src/layout/package/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ const PackageView = () => {
}),
},
{
state: { 'from-detail': true },
state: { fromDetail: true },
}
);
}}
Expand Down Expand Up @@ -790,7 +790,7 @@ const PackageView = () => {
pathname: '/packages/starred',
},
{
state: { 'from-detail': true },
state: { fromDetail: true },
}
);
}}
Expand Down
10 changes: 3 additions & 7 deletions web/src/layout/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import isUndefined from 'lodash/isUndefined';
import { Fragment, useContext, useEffect, useState } from 'react';
import { FaFilter } from 'react-icons/fa';
import { IoMdCloseCircleOutline } from 'react-icons/io';
import { useLocation, useNavigate, useOutletContext } from 'react-router-dom';
import { NavigationType, useLocation, useNavigate, useNavigationType, useOutletContext } from 'react-router-dom';

import API from '../../api';
import { AppCtx, updateLimit } from '../../context/AppCtx';
Expand Down Expand Up @@ -52,6 +52,7 @@ const SearchView = () => {
const { ctx, dispatch } = useContext(AppCtx);
const navigate = useNavigate();
const location = useLocation();
const navType: NavigationType = useNavigationType();
const { tsQueryWeb, filters, pageNumber, deprecated, operators, verifiedPublisher, cncf, official, sort } =
buildSearchParams(location.search);
const sampleQueries = getSampleQueries();
Expand Down Expand Up @@ -309,12 +310,7 @@ const SearchView = () => {
setApiError('An error occurred searching packages, please try again later.');
} finally {
setIsSearching(false);
if (
// TODO - location.action === 'POP' ||
fromDetail &&
!isUndefined(viewedPackage) &&
!isUndefined(scrollPosition)
) {
if (navType === 'POP' || (fromDetail && !isUndefined(viewedPackage) && !isUndefined(scrollPosition))) {
setTimeout(() => {
scrollToTop(scrollPosition);
}, 200);
Expand Down

0 comments on commit 6f48c8e

Please sign in to comment.