Skip to content

Commit

Permalink
feature(frontend): adding auto scroll to assertion result (#2700)
Browse files Browse the repository at this point in the history
feature(frontend): adding auto scroll to asseriton result
  • Loading branch information
xoscar committed Jun 9, 2023
1 parent 0aab475 commit b588223
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion web/src/components/TestSpecDetail/Content.tsx
@@ -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
@@ -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;

0 comments on commit b588223

Please sign in to comment.