* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { scrollToElement } from '../../../helpers/scrolling';
import { SecurityStandard } from '../../../types/security';
import {
- scrollToIssue,
serializeQuery,
shouldOpenSonarSourceSecurityFacet,
shouldOpenStandardsChildFacet,
});
});
-describe('scrollToIssue', () => {
- it('should scroll to the issue', () => {
- document.querySelector = jest.fn(() => ({}));
-
- scrollToIssue('issue1', false);
- expect(scrollToElement).toHaveBeenCalled();
- });
- it("should ignore issue if it doesn't exist", () => {
- document.querySelector = jest.fn(() => null);
-
- scrollToIssue('issue1', false);
- expect(scrollToElement).not.toHaveBeenCalled();
- });
- it('should scroll smoothly by default', () => {
- document.querySelector = jest.fn(() => ({}));
-
- scrollToIssue('issue1');
- expect(scrollToElement).toHaveBeenCalledWith(
- {},
- {
- bottomOffset: 100,
- smooth: true,
- topOffset: 250
- }
- );
- });
-});
-
describe('shouldOpenStandardsFacet', () => {
it('should open standard facet', () => {
expect(shouldOpenStandardsFacet({ standards: true }, { types: [] })).toBe(true);
import * as React from 'react';
import { BranchLike } from '../../../types/branch-like';
import { Component, Issue } from '../../../types/types';
-import { Query, scrollToIssue } from '../utils';
+import { Query } from '../utils';
import ListItem from './ListItem';
interface Props {
// list of issues. See https://jira.sonarsource.com/browse/SONAR-11681
setTimeout(() => {
this.setState({ prerender: false });
- if (this.props.selectedIssue) {
- scrollToIssue(this.props.selectedIssue.key, false);
- }
}, 42);
}
}
export default class ListItem extends React.PureComponent<Props> {
+ nodeRef: HTMLLIElement | null = null;
+
+ componentDidMount() {
+ const { selected } = this.props;
+ if (this.nodeRef && selected) {
+ this.nodeRef.scrollIntoView({ block: 'center', inline: 'center' });
+ }
+ }
+
+ componentDidUpdate(prevProps: Props) {
+ const { selected } = this.props;
+ if (!prevProps.selected && selected && this.nodeRef) {
+ this.nodeRef.scrollIntoView({ block: 'center', inline: 'center' });
+ }
+ }
+
handleFilter = (property: string, issue: TypeIssue) => {
const { onFilterChange } = this.props;
previousIssue.branch !== issue.branch;
return (
- <li className="issues-workspace-list-item">
+ <li className="issues-workspace-list-item" ref={node => (this.nodeRef = node)}>
{displayComponent && (
<div className="issues-workspace-list-component note">
<ComponentBreadcrumbs component={component} issue={this.props.issue} />
serializeString,
serializeStringArray
} from '../../helpers/query';
-import { scrollToElement } from '../../helpers/scrolling';
import { get, save } from '../../helpers/storage';
import { isDefined } from '../../helpers/types';
import { Facet, RawFacet } from '../../types/issues';
return getLocations(issue, selectedFlowIndex).every(location => !location.msg);
}
-// TODO: drop as it's useless now
-export function scrollToIssue(issue: string, smooth = true) {
- const element = document.querySelector(`[data-issue="${issue}"]`);
- if (element) {
- scrollToElement(element, { topOffset: 250, bottomOffset: 100, smooth });
- }
-}
-
export function shouldOpenStandardsFacet(
openFacets: Dict<boolean>,
query: Partial<Query>