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
fix: When using the toolbox-search, auto select the found dropdown item #2222
base: master
Are you sure you want to change the base?
Conversation
Fixes: google#1940 Uses the Block State as suggested here: google#2004 (comment) Fixes: bug that didn't indexed the last trigram from a word
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.
Generally LGTM! I'll give it a more thorough review after the first round of changes have been fixed.
blockState.id = undefined; | ||
blockState.extraState = undefined; | ||
blockState.data = undefined; | ||
const stateString = JSON.stringify(blockState); |
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.
Is there a reason you need to stringify this? I think you should be able to add it to a Set<Blockly.serialization.blocks.State>
. If the stringification is for deduplication or something, could you add a comment inline?
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.
Yes, the reason was duplication, without stringify we would have ended with a lot of duplication. I will put a comment in the code
if (blockState.fields) { | ||
return { | ||
kind: 'block', | ||
type: blockState.type, | ||
fields: blockState.fields, | ||
}; | ||
} else | ||
return { | ||
kind: 'block', | ||
type: blockState.type, | ||
}; |
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.
if (blockState.fields) { | |
return { | |
kind: 'block', | |
type: blockState.type, | |
fields: blockState.fields, | |
}; | |
} else | |
return { | |
kind: 'block', | |
type: blockState.type, | |
}; | |
return {kind: 'block', ...blockState}; |
if (blockState != null) { | ||
this.indexBlockText(blockType.replaceAll('_', ' '), blockState); | ||
block.inputList.forEach((input) => { | ||
input.fieldRow.forEach((field) => { | ||
this.indexDropdownOption(field, blockState); | ||
this.indexBlockText(field.getText(), blockState); | ||
}); | ||
}); | ||
}); | ||
} |
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.
Instead of wrapping this could you use an early return?
if (!blockState) return;
this.indexBlockText // etc...
This function already has a lot of nesting and I'd prefer to avoid adding more if we can :P
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.
Agree, I will fix it
if (state.fields == undefined) { | ||
state.fields = {}; | ||
} |
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.
I think this case should be impossible since you assing to state.fields
above. Was the typescript compiler giving you warnings about this?
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.
I think it was the compiler complaining. I don't exactly remember
state.fields[field.name] = option[1]; | ||
} | ||
this.indexBlockText(option[0], state); | ||
this.indexBlockText(option[1], state); |
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.
I don't think we should be indexing the language-neutral text.
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.
Well, I added this on some blocks the language-neutral text was more informative than the block text. I don't remember now a clear example, but I take a look. BTW, sorry for replaying so late, but lately I am little busy with an internal project. I would try to find some time to fix your comments.
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.
No rush! It took us three weeks to get back to you so we can't expect you to be more responsive :P
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.
Added some more comments for when you have time to take a look!
@@ -3,6 +3,12 @@ | |||
All notable changes to this project will be documented in this file. | |||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | |||
|
|||
## [1.2.7](https://github.com/google/blockly-samples/compare/@blockly/toolbox-search@1.2.6...@blockly/toolbox-search@1.2.7) (2024-02-23) |
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.
Can you revert this? The CHANGELOG doesn't need to be edited manually (it gets updated automatically based on submitted PRs)
if (typeof option[0] === 'string') { | ||
this.indexBlockText(option[0], blockType); | ||
if (state.fields == undefined) { |
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.
Throughout, can you replace ==
with ===
and !=
with !==
?
private indexDropdownOption( | ||
field: Blockly.Field, | ||
blockState: Blockly.serialization.blocks.State, | ||
) { | ||
if (field instanceof Blockly.FieldDropdown) { |
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.
Can you switch this to use an early return as well? (not your code but I think it would make it more readable).
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.
Can you add a jsdoc comment to the trigramsToBlocks
map that specifies that the Set<string>
contains stringified JSON?
]; | ||
const resultState = result.map((item) => JSON.parse(item)); | ||
return resultState; |
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.
You should be able to set this up to just return
from the top. But I can't put a suggestion over this whole function b/c github :P
]; | |
const resultState = result.map((item) => JSON.parse(item)); | |
return resultState; | |
].map(JSON.parse); |
blockState.extraState = undefined; | ||
blockState.data = undefined; |
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.
Why are these being removed? It seems like they should probably be kept.
*/ | ||
blockTypesMatching(query: string): string[] { | ||
return [ | ||
blockTypesMatching(query: string): Blockly.serialization.blocks.State[] { |
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.
Because this is public, changing the return type of this method is actually a breaking change. Could you create another method blockStatesMatching
that has the current behavior here? And then modify this to only return the block /types/ not the full state. You'll need to update other places to use your new blockStatesMatching
method.
@constantinIliescu are you still interested in working on this? If not I'll close this on Friday! |
Hi Beka, |
All good no rush! Just wanted to check in in case you wanted to hand it over to someone else =) |
Fixes: #1940
Uses the Block State as suggested here:
#2004 (comment)
Fixes: bug that didn't indexed the last trigram from a word
The basics
The details
Resolves
Fixes #1940
Proposed Changes
Use block state for efficient indexing
Reason for Changes
Have the found drop down item automatically selected in the drop down
Test Coverage
Unit test have been added to cover the false positive, false negative and duplicate cases
Documentation
Additional Information