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

fix: non-nullable check for block variable and removed ! in layout_ #7536

Merged
merged 10 commits into from
Sep 25, 2023

Conversation

rashmi29
Copy link
Contributor

@rashmi29 rashmi29 commented Sep 22, 2023

The basics

The details

Resolves

Fixes #7523

Proposed Changes

  • Check whether block is undefined after setting const block = item.block.
  • continue if block doesn't exist.
  • Remove ! from after the remaining uses of block within the for loop.

Reason for Changes

Non nullable check was not present in code. That might break the code when variable has no value assigned.

Test Coverage

I did npm run and tested all the buttons before and after and checked the entire functionality after my change.

Documentation

No documentation required

Additional Information

@rashmi29 rashmi29 requested a review from a team as a code owner September 22, 2023 22:34
@google-cla
Copy link

google-cla bot commented Sep 22, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@rachel-fenichel rachel-fenichel changed the title Fix : non-nullable check for block variable and removed ! in layout_ fix: non-nullable check for block variable and removed ! in layout_ Sep 22, 2023
@github-actions github-actions bot added the PR: fix Fixes a bug label Sep 22, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome! It looks like this is your first pull request in Blockly, so here are a couple of tips:

  • You can find tips about contributing to Blockly and how to
    validate your changes on our
    developer site.

  • All contributors must sign the Google Contributor License
    Agreement (CLA). If the google-cla bot leaves a comment on this
    PR, make sure you follow the instructions.

  • We use conventional commits
    to make versioning the package easier. Make sure your commit
    message is in the proper format
    or learn how to fix it.

  • If any of the other checks on this PR fail, you can click on
    them to learn why. It might be that your change caused a test
    failure, or that you need to double-check the
    style guide.

Thank you for opening this PR! A member of the Blockly team will review it soon.

@rachel-fenichel
Copy link
Collaborator

Thanks for grabbing this issue!

Next steps:

  • Run npm run format to fix some formatting issues and commit
  • Sign the CLA, following the instructions from the bot above

I'll keep an eye on this PR and approve workflow runs as needed.

@@ -233,29 +233,32 @@ export class VerticalFlyout extends Flyout {
for (let i = 0, item; (item = contents[i]); i++) {
if (item.type === 'block') {
const block = item.block;
const allBlocks = block!.getDescendants(false);
if(block == undefined || block == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be just if (block) {

@@ -233,29 +233,32 @@ export class VerticalFlyout extends Flyout {
for (let i = 0, item; (item = contents[i]); i++) {
if (item.type === 'block') {
const block = item.block;
const allBlocks = block!.getDescendants(false);
if (block == undefined || block == null) {

Choose a reason for hiding this comment

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

please squash your commits

@@ -233,29 +233,32 @@ export class VerticalFlyout extends Flyout {
for (let i = 0, item; (item = contents[i]); i++) {
if (item.type === 'block') {
const block = item.block;
const allBlocks = block!.getDescendants(false);
if (block == undefined || block == null) {

Choose a reason for hiding this comment

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

This check is redundant, block == null checks both null and undefined. We would both checks with strict equality i.e. block === undefined || block === null

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case if (block) will do fine, because we aren't trying to distinguish between the two cases.

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 I just add if (block) than it shows "'block' is possibly 'undefined'." error. So, I added condition if (block == null) as suggested by rachna.

@rachel-fenichel
Copy link
Collaborator

Hi @rashmi29,

I'm signing off for the weekend but I will take a look again on Monday. Thanks again for contributing, and have a great Grace Hopper if you're attending!

@humera811
Copy link
Contributor

humera811 commented Sep 24, 2023

nit: In the description section under Resolves you can add a link to the issue

  Resolves 
            Fixes #7523 : Check for undefined in vertical flyout layout function 

Comment on lines 236 to 245
if (block == null) {
continue;
}
const allBlocks = block.getDescendants(false);
for (let j = 0, child; (child = allBlocks[j]); j++) {
// Mark blocks as being inside a flyout. This is used to detect and
// prevent the closure of the flyout if the user right-clicks on such
// a block.
child.isInFlyout = true;
}
Copy link
Contributor

@humera811 humera811 Sep 24, 2023

Choose a reason for hiding this comment

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

Suggestion:

if (block) {
          const allBlocks = block.getDescendants(false);
          for (let j = 0, child; (child = allBlocks[j]); j++) {
            // Mark blocks as being inside a flyout.  This is used to detect and
            // prevent the closure of the flyout if the user right-clicks on such
            // a block.
            child.isInFlyout = true;
          }

or we could just do

if (!block) continue;
const allBlocks = block.getDescendants(false);
      for (let j = 0, child; (child = allBlocks[j]); j++) {
        // Mark blocks as being inside a flyout. This is used to detect and
        // prevent the closure of the flyout if the user right-clicks on such
        // a block.
        child.isInFlyout = true;
      }

@maribethb maribethb self-requested a review September 25, 2023 17:46
@maribethb maribethb self-assigned this Sep 25, 2023
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Sep 25, 2023
Copy link
Contributor

@maribethb maribethb left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you so much for the PR!

@maribethb maribethb merged commit 19e9115 into google:osd Sep 25, 2023
9 checks passed
@maribethb maribethb linked an issue Sep 27, 2023 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check for undefined in vertical flyout layout function
5 participants