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

Playground: refactor component picker plugin #4836

Merged
merged 4 commits into from Sep 26, 2023

Conversation

thorn0
Copy link
Contributor

@thorn0 thorn0 commented Jul 27, 2023

No description provided.

@vercel
Copy link

vercel bot commented Jul 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 11:19am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 11:19am

@acywatson
Copy link
Contributor

Seems fine - what's the aim here?

@thorn0
Copy link
Contributor Author

thorn0 commented Jul 28, 2023

@acywatson I was reading through this code and noticed a bunch of small things.
Commit 1: local simplifications without moving code. E.g. getting rid of ts-ignore comments and redundancies like new RegExp(/foo/). Also it fixes a bug with filtering options by keywords.
Commit 2 extracts functions out of the component because shorter functions are easier to read and because useCallback isn't really needed when the function isn't passed to a prop.

Comment on lines 335 to 344
return (
regex.test(option.title) ||
option.keywords?.some((keyword) => regex.test(keyword))
);
Copy link
Contributor Author

@thorn0 thorn0 Jul 28, 2023

Choose a reason for hiding this comment

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

This is a bug fix (parens were missing around the ternary).

const regex = new RegExp(queryString, 'i');
return (
regex.test(option.title) ||
option.keywords?.some((keyword) => regex.test(keyword))
Copy link
Contributor

Choose a reason for hiding this comment

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

keywords is not nullable so ?. is redundant

);
}

return options;
Copy link
Contributor

Choose a reason for hiding this comment

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

Full and partial table matchers can be replaced with a single one:

const tableMatch = queryString.match(/^(\d{1,2})x?(\d{1,2})?$/);

if (tableMatch !== null) {
  const row = Number(tableMatch[1]);
  const cols = tableMatch[2]
    ? [Number(tableMatch[2])]
    : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

  return cols.map(col => ({
    icon: <i className="icon table" />,
    label: `${row}x${col} Table`,
    keywords: ['table'],
    onSelect: (_: string) => {
      ...
    },
  }));
}

Copy link
Contributor

@fantactuka fantactuka left a comment

Choose a reason for hiding this comment

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

LG!

@acywatson acywatson merged commit b5f392d into facebook:main Sep 26, 2023
43 of 45 checks passed
@thorn0 thorn0 deleted the refactor-component-picker branch October 8, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants