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

feature(frontend): adding auto scroll to assertion result #2700

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion web/src/components/TestSpecDetail/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useMemo} from 'react';
import {useEffect, useMemo} from 'react';

import {SemanticGroupNames} from 'constants/SemanticGroupNames.constants';
import {useTestRun} from 'providers/TestRun/TestRun.provider';
Expand All @@ -7,6 +7,7 @@ import TestSpecsSelectors from 'selectors/TestSpecs.selectors';
import AssertionService from 'services/Assertion.service';
import {TAssertionResultEntry} from 'models/AssertionResults.model';
import {useTest} from 'providers/Test/Test.provider';
import useScrollTo from 'hooks/useScrollTo';
import Assertion from './Assertion';
import Header from './Header';
import SpanHeader from './SpanHeader';
Expand Down Expand Up @@ -46,6 +47,11 @@ const Content = ({
} = useAppSelector(state => TestSpecsSelectors.selectSpecBySelector(state, selector)) || {};
const totalPassedChecks = useMemo(() => AssertionService.getTotalPassedChecks(resultList), [resultList]);
const results = useMemo(() => AssertionService.getResultsHashedBySpanId(resultList), [resultList]);
const scrollTo = useScrollTo();

useEffect(() => {
scrollTo(`assertion-result-${selectedSpan}`);
}, [scrollTo, selectedSpan]);

return (
<>
Expand Down Expand Up @@ -81,6 +87,7 @@ const Content = ({
type="inner"
$isSelected={spanId === selectedSpan}
$type={span?.type ?? SemanticGroupNames.General}
id={`assertion-result-${spanId}`}
>
<S.AssertionsContainer onClick={() => onSelectSpan(span?.id ?? '')}>
{checkResults.map(checkResult => (
Expand Down
15 changes: 15 additions & 0 deletions web/src/hooks/useScrollTo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const useScrollTo = () => {
const scrollTo = (id: string) => {
const element = document.getElementById(id);

if (element) {
element.scrollIntoView({
behavior: 'smooth',
});
}
};

return scrollTo;
};

export default useScrollTo;