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

add uiFind icons, scroll to first match #367

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve VirtualizedTraceView shouldComponentUpdate
Signed-off-by: Everett Ross <reverett@uber.com>
  • Loading branch information
everett980 committed Apr 25, 2019
commit 73e86915e8c4fa72c1f8763e2283516feb8ec8a4
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('<VirtualizedTraceViewImpl>', () => {
});

describe('shouldScrollToFirstUiFindMatch', () => {
const propsWithTruthShouldScrollToFirstUiFindMatch = { ...props, shouldScrollToFirstUiFindMatch: true };
const propsWithTrueShouldScrollToFirstUiFindMatch = { ...props, shouldScrollToFirstUiFindMatch: true };

beforeEach(() => {
props.scrollToFirstVisibleSpan.mockReset();
Expand All @@ -359,33 +359,33 @@ describe('<VirtualizedTraceViewImpl>', () => {
expect(props.scrollToFirstVisibleSpan).not.toHaveBeenCalled();
expect(props.clearShouldScrollToFirstUiFindMatch).not.toHaveBeenCalled();

wrapper.setProps(propsWithTruthShouldScrollToFirstUiFindMatch);
wrapper.setProps(propsWithTrueShouldScrollToFirstUiFindMatch);
expect(props.scrollToFirstVisibleSpan).toHaveBeenCalledTimes(1);
expect(props.clearShouldScrollToFirstUiFindMatch).toHaveBeenCalledTimes(1);
});

describe('shouldComponentUpdate', () => {
it('returns true if props.shouldScrollToFirstUiFindMatch is unchanged', () => {
expect(wrapper.instance().shouldComponentUpdate(props)).toBe(true);
});

it('returns true if props.shouldScrollToFirstUiFindMatch changes to true', () => {
expect(wrapper.instance().shouldComponentUpdate(propsWithTruthShouldScrollToFirstUiFindMatch)).toBe(
expect(wrapper.instance().shouldComponentUpdate(propsWithTrueShouldScrollToFirstUiFindMatch)).toBe(
true
);
});

it('returns true if props.shouldScrollToFirstUiFindMatch changes to false and another props change', () => {
const propsWithOtherDifferenceAndTrueshouldScrollToFirstUiFindMatch = {
...propsWithTruthShouldScrollToFirstUiFindMatch,
...propsWithTrueShouldScrollToFirstUiFindMatch,
clearShouldScrollToFirstUiFindMatch: () => {},
};
wrapper.setProps(propsWithOtherDifferenceAndTrueshouldScrollToFirstUiFindMatch);
expect(wrapper.instance().shouldComponentUpdate(props)).toBe(true);
});

it('returns false if props.shouldScrollToFirstUiFindMatch changes to false and no other props change', () => {
wrapper.setProps(propsWithTruthShouldScrollToFirstUiFindMatch);
wrapper.setProps(propsWithTrueShouldScrollToFirstUiFindMatch);
expect(wrapper.instance().shouldComponentUpdate(props)).toBe(false);
});

it('returns false if all props are unchanged', () => {
expect(wrapper.instance().shouldComponentUpdate(props)).toBe(false);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ function getCssClasses(currentViewRange: [number, number]) {
}

// export from tests
// eslint-disable-next-line react/no-redundant-should-component-update
export class VirtualizedTraceViewImpl extends React.PureComponent<VirtualizedTraceViewProps> {
export class VirtualizedTraceViewImpl extends React.Component<VirtualizedTraceViewProps> {
clippingCssClasses: string;
listView: ListView | TNil;
rowStates: RowState[];
Expand All @@ -161,22 +160,17 @@ export class VirtualizedTraceViewImpl extends React.PureComponent<VirtualizedTra
}

shouldComponentUpdate(nextProps: VirtualizedTraceViewProps) {
if (
!nextProps.shouldScrollToFirstUiFindMatch &&
nextProps.shouldScrollToFirstUiFindMatch !== this.props.shouldScrollToFirstUiFindMatch
) {
const nextPropKeys = Object.keys(nextProps);
for (let i = 0; i < nextPropKeys.length; i += 1) {
if (
nextProps[nextPropKeys[i] as keyof VirtualizedTraceViewProps] !==
this.props[nextPropKeys[i] as keyof VirtualizedTraceViewProps] &&
nextPropKeys[i] !== 'shouldScrollToFirstUiFindMatch'
)
const nextPropKeys = Object.keys(nextProps) as (keyof VirtualizedTraceViewProps)[];
for (let i = 0; i < nextPropKeys.length; i += 1) {
if (nextProps[nextPropKeys[i]] !== this.props[nextPropKeys[i]]) {
if (nextPropKeys[i] === 'shouldScrollToFirstUiFindMatch') {
if (nextProps[nextPropKeys[i]]) return true;
tiffon marked this conversation as resolved.
Show resolved Hide resolved
} else {
return true;
}
}
return false;
}
return true;
return false;
}

componentWillUpdate(nextProps: VirtualizedTraceViewProps) {
Expand Down