Skip to content

fix: select My Blocks category by ID after closing procedure editor#526

Open
cwillisf wants to merge 1 commit intodevelopfrom
fix/select-my-blocks-after-procedure-close
Open

fix: select My Blocks category by ID after closing procedure editor#526
cwillisf wants to merge 1 commit intodevelopfrom
fix/select-my-blocks-after-procedure-close

Conversation

@cwillisf
Copy link
Copy Markdown
Contributor

Resolves

Proposed Changes

selectCategoryByName('myBlocks') passes the toolbox item ID, where the method expects a translated display name. It also skips scrolling the flyout. Use getToolboxItemById + setSelectedItem instead, matching the pattern already used in handleCategorySelected.

Test Coverage

Added a test to verify that the correct item is selected.

HOLD

Since this is not a release-blocking issue, let's wait to merge this until after the initial release of the new scratch-blocks code.

selectCategoryByName('myBlocks') passes the toolbox item ID where the
method expects a translated display name. It also skips scrolling the
flyout. Use getToolboxItemById + setSelectedItem instead, matching the
pattern already used in handleCategorySelected.

Fixes scratchfoundation/scratch-blocks#3542
@cwillisf cwillisf requested a review from Copilot April 14, 2026 17:58
@cwillisf cwillisf requested a review from a team as a code owner April 14, 2026 17:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes category selection after closing the custom procedure editor by selecting the My Blocks toolbox category via its toolbox item ID (instead of treating the ID as a translated display name), and adds a unit test to prevent regressions.

Changes:

  • Update handleCustomProceduresClose to select My Blocks via getToolboxItemById('myBlocks') + setSelectedItem(...).
  • Add a unit test covering the translated-name mismatch scenario for My Blocks category selection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/scratch-gui/src/containers/blocks.jsx Switches My Blocks selection to ID-based lookup + setSelectedItem after closing the procedure editor.
packages/scratch-gui/test/unit/containers/blocks.test.js Adds a unit test ensuring My Blocks is selected even when its display name is translated.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +20
const toolbox = {
selectedItem: null,
getToolboxItemById: jest.fn(id => (id === 'myBlocks' ? myBlocksItem : null)),
// Simulates real selectCategoryByName: looks up by display name, not ID
selectCategoryByName: jest.fn(name => {
toolbox.selectedItem = (name === 'Mis Bloques') ? myBlocksItem : null;
}),
setSelectedItem: jest.fn(item => {
toolbox.selectedItem = item;
})
};
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This test only asserts the end state (selectedItem) and would still pass if the implementation switched to selectCategoryByName(<translated name>), which wouldn’t verify the intended fix (selecting by toolbox item ID / setSelectedItem path). Consider strengthening the test by asserting getToolboxItemById('myBlocks') and setSelectedItem(myBlocksItem) are called (and optionally that selectCategoryByName is not called), so the test fails if the implementation regresses to name-based selection.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Test Results

  3 files   -     1   69 suites   - 887   10m 34s ⏱️ - 2m 26s
404 tests  - 1 919  396 ✅  - 1 919  8 💤 ± 0  0 ❌ ±0 
426 runs   - 5 224  418 ✅  - 5 194  8 💤  - 30  0 ❌ ±0 

Results for commit 78ee55a. ± Comparison against base commit 1074d9e.

This pull request removes 1920 and adds 1 tests. Note that renamed tests count towards both.
test/integration/addSprite.js > default cat ‑ expect to not throw
test/integration/addSprite.js > default cat ‑ should be equal
test/integration/addSprite.js > default cat ‑ type is 1
test/integration/addSprite.js > default cat ‑ type is object
test/integration/addSprite.js > default cat ‑ type is string
test/integration/addSprite.js > spec ‑ type is function
test/integration/addSprite.js ‑ default cat
test/integration/addSprite.js ‑ spec
test/integration/block_to_workspace_comment_import.js > importing sb2 project where block comment is converted to workspace comment and block is deleted ‑ expect to not throw
test/integration/block_to_workspace_comment_import.js > importing sb2 project where block comment is converted to workspace comment and block is deleted ‑ should be equal
…
Blocks container handleCustomProceduresClose selects the My Blocks category after closing ‑ Blocks container handleCustomProceduresClose selects the My Blocks category after closing

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No scroll to the "My Blocks" category when a new one is made

2 participants