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

feat(highlight): Promote and show staged highlight annotation #563

Merged
merged 3 commits into from
Sep 1, 2020

Conversation

mxiao6
Copy link
Contributor

@mxiao6 mxiao6 commented Aug 27, 2020

  • Tests

src/highlight/HighlightAnnotations.tsx Outdated Show resolved Hide resolved
src/highlight/HighlightAnnotations.tsx Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
// empty list, push current
if (!prev) {
dedupedRects.push(curr);
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to avoid multiple returns (outside of guard clauses) because it can make the function more difficult to step through.

Copy link
Contributor Author

@mxiao6 mxiao6 Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pop() may return undefined, so this is a guard clause. I removed an unnecessary return below.

import { SelectionItem } from './types';
import { Shape } from '../../@types';

export type SelectionArg = {
location: number;
pageRect: DOMRect;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be stored?

Copy link
Contributor Author

@mxiao6 mxiao6 Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's needed. If we get page rect on rendering, and if user selects text then scrolls page before clicks promotion button, the page x/y will not match with selection x/y. Have to get them and store them at the same moment.

Copy link
Contributor

@ConradJChan ConradJChan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the selection is more than the promoter since explicit highlight mode will make use of it as well. Should we move this promoter store to be highlight store or something else instead?

src/highlight/HighlightAnnotations.tsx Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
src/highlight/highlightUtil.ts Outdated Show resolved Hide resolved
groups[roundedY] = groups[roundedY] || [];
groups[roundedY].push(rect);
return groups;
}, {} as Record<number, Shape[]>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we be able to get rid of this cast if we defined rows as Record<number, Shape[]>?

Copy link
Contributor Author

@mxiao6 mxiao6 Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried, doesn't work. It seems like TS is not able to infer accumulator's type from result's type, unfortunately.

@mxiao6
Copy link
Contributor Author

mxiao6 commented Aug 28, 2020

I think the selection is more than the promoter since explicit highlight mode will make use of it as well. Should we move this promoter store to be highlight store or something else instead?

Renaming will change a lot of files, which makes harder to review this PR. I'm thinking to do it in a separate PR.

@mxiao6 mxiao6 force-pushed the promote-staged-2 branch 2 times, most recently from f43f7ff to 36c7ec9 Compare August 28, 2020 23:33
const xThreshold = getThreshold(prevWidth, width, threshold);
const yThreshold = getThreshold(prevHeight, height, threshold);

if (Math.abs(prevX - x) <= xThreshold && Math.abs(prevY - y) <= yThreshold) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should width and height still be taken into account in determining duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If two rects have the same x and y, one must be the duplicate of the other, right? So I think only comparing x and y is enough for determining duplications.

@mxiao6 mxiao6 marked this pull request as ready for review August 29, 2020 00:59
@mxiao6 mxiao6 requested a review from a team as a code owner August 29, 2020 00:59
@mxiao6 mxiao6 force-pushed the promote-staged-2 branch 2 times, most recently from 584391b to 1766326 Compare September 1, 2020 18:00
ConradJChan
ConradJChan previously approved these changes Sep 1, 2020
src/highlight/HighlightAnnotations.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@ConradJChan ConradJChan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, probably want to update the description to remove the link to the box-content-preview PR

@mergify mergify bot merged commit f569bfc into box:master Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants