Skip to content

Commit

Permalink
Jump back to selected fixture in CP
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinaenache authored and ovidiuch committed Sep 8, 2017
1 parent e0c8896 commit 6ea3fe2
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,33 @@ const getFilteredFixtures = (fixtures, searchText) => {
}, {});
};

const isExistingFixtureSelected = (fixtures, component, fixture) => {
return (
component &&
fixture &&
fixtures[component] &&
fixtures[component].indexOf(fixture) !== -1
);
};

export default class FixtureList extends Component {
state = {
searchText: ''
};

componentDidMount() {
window.addEventListener('keydown', this.onWindowKey);
const { fixtures, urlParams: { component, fixture } } = this.props;

if (isExistingFixtureSelected(fixtures, component, fixture)) {
const node = this.refs[`componentName-${component}`];
// scrollIntoView doesn't seem to exist in Jest/jsdom
if (node.scrollIntoView) {
node.scrollIntoView({
behavior: 'smooth'
});
}
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -99,7 +119,10 @@ export default class FixtureList extends Component {
{components.map((component, i) => {
return (
<div key={i} className={styles.component}>
<div className={styles.componentName}>
<div
ref={`componentName-${component}`}
className={styles.componentName}
>
<FolderIcon />
<span>
{component}
Expand Down

0 comments on commit 6ea3fe2

Please sign in to comment.