-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Seems fine - what's the aim here? |
@acywatson I was reading through this code and noticed a bunch of small things. |
return ( | ||
regex.test(option.title) || | ||
option.keywords?.some((keyword) => regex.test(keyword)) | ||
); |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) => {
...
},
}));
}
972fab9
to
5f95647
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG!
No description provided.