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

#8636: fix search/insert for variable popover using optional chaining #8637

Merged
merged 5 commits into from
Jun 17, 2024

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Jun 16, 2024

What does this PR do?

Discussion

  • Eventually we probably want to do real lexing/parsing to generate an AST that can also be used to re-generate the expression

Future Work

Checklist

  • Add jest or playwright tests and/or storybook stories
  • Designate a primary reviewer: @fungairino

@twschiller twschiller added page editor bug Something isn't working labels Jun 16, 2024
@twschiller twschiller changed the base branch from main to feature/8404-variable-text-toggle June 16, 2024 19:07
Copy link

codecov bot commented Jun 16, 2024

Codecov Report

Attention: Patch coverage is 96.82540% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.71%. Comparing base (c32e86f) to head (41afd27).

Files Patch % Lines
.../fields/schemaFields/widgets/varPopup/VarPopup.tsx 50.00% 1 Missing ⚠️
...ields/schemaFields/widgets/varPopup/menuFilters.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8637      +/-   ##
==========================================
+ Coverage   73.69%   73.71%   +0.01%     
==========================================
  Files        1344     1344              
  Lines       41566    41596      +30     
  Branches     7775     7778       +3     
==========================================
+ Hits        30633    30663      +30     
  Misses      10933    10933              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jun 16, 2024

Playwright test results

passed  75 passed
skipped  2 skipped

Details

report  Open report ↗︎
stats  77 tests across 26 suites
duration  10 minutes, 47 seconds
commit  41afd27

Skipped tests

chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
edge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@twschiller twschiller added this to the 2.0.3 milestone Jun 16, 2024
@twschiller twschiller marked this pull request as ready for review June 16, 2024 20:56
Base automatically changed from feature/8404-variable-text-toggle to main June 17, 2024 16:17
8636: extract getFullVariableName

8636: handle optional chaining corner cases

Clarify method comment
src/runtime/pathHelpers.ts Show resolved Hide resolved
| string
| number
| { part: string | number; isOptional: boolean },
): { part: string; isOptional: boolean; isBrackets: boolean } {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this would be a useful type to refactor and name to reuse in other places.

Comment on lines +164 to +176
expectMatch(["user"], "user");
expectMatch(["users", 0], "users[0]");
expectMatch(["users", 0, "name"], "users[0].name");
expectMatch(["users", ""], 'users[""]');
expectMatch(["names", "Dante Alighieri"], 'names["Dante Alighieri"]');
expectMatch(
["Ugo Foscolo", "User Location"],
'["Ugo Foscolo"]["User Location"]',
);
expectMatch(["User List", 100, "id"], '["User List"][100].id');
expectMatch(
["User List", 100_000_000, "The name"],
'["User List"][100000000]["The name"]',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tests that verify a wide range of inputs are better suited to using the built-in jest.each. This improves the test output and makes it so that if one expect fails, all others still run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally agree, was keeping existing style. You'd need to use a table format since the expected value differs per test

/**
* Returns true if the value is null or is likely plain text/not a variable.
*/
function isTextOrNull(value: string | null): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is specific to variable strings, I'd rename this to something like isTextOrNullVar.

As an aside, if you want to get fancy with TS you can also return a predicate informing the rest of the code that the value is a valid Var. Ex:

type Var = `@${NonEmptyString}`;
const a: Var = "@a";

function isTextOrNullVar(value:string | null): value is Var {

At least this would be nice if defining NonEmptyString weren't so hard in TS:
https://stackoverflow.com/questions/46253340/how-to-write-a-string-type-that-does-not-contain-an-empty-string-in-typescript

Best we can do for string template types is use something like:

type Character = 'a' | 'b' | 'c' | ...;
type NonEmptyString = `${Character}${string}`;

Which I thought type-fest would have, but it doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I'm going to punt on the type -- it doesn't add much value relative to effort given the method is only applicable in the context of the module

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@twschiller twschiller added the do not merge Merging of this PR is blocked by another one label Jun 17, 2024
@twschiller
Copy link
Contributor Author

twschiller commented Jun 17, 2024

@fungairino I discovered another corner case (see failing test). I'm going to timebox looking at generating an AST vs. trying to play whack-a-mole with regex rules a bit later this week. We could use an off the shelf parser except for @ not being valid in identifier

@twschiller
Copy link
Contributor Author

Update: I created a separate issue for the corner case: #8638

@twschiller twschiller enabled auto-merge (squash) June 17, 2024 18:14
@twschiller twschiller removed the do not merge Merging of this PR is blocked by another one label Jun 17, 2024
@twschiller twschiller merged commit 68b0ef0 into main Jun 17, 2024
19 checks passed
@twschiller twschiller deleted the feature/8636-popover-chaining branch June 17, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working page editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable popover doesn't show results when using optional chaining
2 participants