Skip to content

Refactor/workspace layout controller#7768

Merged
walterbender merged 4 commits into
sugarlabs:masterfrom
vanshika2720:refactor/workspace-layout-controller
Jul 9, 2026
Merged

Refactor/workspace layout controller#7768
walterbender merged 4 commits into
sugarlabs:masterfrom
vanshika2720:refactor/workspace-layout-controller

Conversation

@vanshika2720

Copy link
Copy Markdown
Contributor

Summary

This PR extracts the workspace layout and Home button functionality from activity.js into a dedicated WorkspaceLayoutController, following the existing controller architecture used throughout the project. The refactor preserves existing behavior while improving modularity and maintainability.

Changes

  • Added js/activity/workspace-layout-controller.js
  • Introduced WorkspaceLayoutController and setupWorkspaceLayoutController(activity)
  • Moved workspace layout and Home button logic into the new controller
  • Replaced the extracted implementation in activity.js with delegation stubs
  • Registered the controller in loader.js
  • Updated internal call sites to use the controller

Extracted Functionality

  • findBlocks
  • _findBlocks
  • setHomeContainers
  • repositionBlocks
  • _handleRepositionBlocksOnResize

The controller also manages the _isFirstHomeClick state used for toggling the Home button layout behavior.

Tests

Added:

  • js/activity/__tests__/workspace-layout-controller.test.js

Coverage includes:

  • Controller setup and delegation
  • Home button toggle behavior
  • Row and column layout logic
  • Responsive block repositioning
  • Resize event handling
  • Turtle home reset and pen state preservation
  • Empty, single-block, and large workspace scenarios

Also updated:

  • js/__tests__/activity_toolbar_integration.test.js

to mock setupWorkspaceLayoutController.

Verification

  • ✅ ESLint passes on all modified files
  • ✅ Prettier passes on all modified files
  • ✅ Behavioral tests added for the extracted controller
  • ✅ Existing functionality preserved

…roller

Move the Home button workspace layout responsibilities (_findBlocks,
repositionBlocks, setHomeContainers, _isFirstHomeClick toggle) out of
activity.js into js/activity/workspace-layout-controller.js, following
the same controller-extraction pattern used for GridController,
SearchController and SelectionController. activity.js now instantiates
the controller and keeps thin delegation stubs so existing callers are
unaffected.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Cover setup/wiring, findBlocks, the row/column _findBlocks toggle,
repositionBlocks breakpoint handling, resize delegation,
setHomeContainers, turtle reset behavior, and edge cases such as
empty, single-block and large workspaces.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
…helpfulWheelDiv

document.getElementById("helpfulWheelDiv") can return null; accessing
.style on it would throw. The pre-extraction code had the same gap,
so guard it now that the code is being touched.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
…ce test duplication

Use controller.method.bind(controller) instead of arrow-function
wrappers for the activity-level delegation stubs, and add a
setupActivity() test helper to collapse the repeated
makeActivity()+setupWorkspaceLayoutController() pairing across the
suite. Also correct a misleading comment (the DOM lookup isn't
cached, it's just done once).

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
@vanshika2720 vanshika2720 marked this pull request as ready for review July 9, 2026 17:01
@walterbender

Copy link
Copy Markdown
Member

Looks good but do you know what is going on with the test failures?

@vanshika2720

Copy link
Copy Markdown
Contributor Author

@walterbender current master is carrying two Jest regressions introduced by the recently merged test coverage PRs

#7646 – test/pitchstaircase-widget-coverage: pitchstaircase.test.js fails with TypeError: Cannot set properties of undefined (setting 'backgroundColor') and a failing replaceChildren expectation.

#7647 – test/musickeyboard-widget-coverage: musickeyboard.test.js fails in _sortLayout, expecting ["do", "sol", "hertz"] but receiving the full unsorted pitch array.

That's why the test is failing.
Ashutosh raised the fix for that #7766
i tested it locally .works fine.

@walterbender walterbender merged commit 8d77289 into sugarlabs:master Jul 9, 2026
15 of 18 checks passed
rakshityadav1868 pushed a commit to rakshityadav1868/musicblocks that referenced this pull request Jul 9, 2026
* refactor(activity): extract workspace layout into WorkspaceLayoutController

Move the Home button workspace layout responsibilities (_findBlocks,
repositionBlocks, setHomeContainers, _isFirstHomeClick toggle) out of
activity.js into js/activity/workspace-layout-controller.js, following
the same controller-extraction pattern used for GridController,
SearchController and SelectionController. activity.js now instantiates
the controller and keeps thin delegation stubs so existing callers are
unaffected.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>

* test(workspace-layout-controller): add behavioral test coverage

Cover setup/wiring, findBlocks, the row/column _findBlocks toggle,
repositionBlocks breakpoint handling, resize delegation,
setHomeContainers, turtle reset behavior, and edge cases such as
empty, single-block and large workspaces.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>

* fix(workspace-layout-controller): guard findBlocks against a missing helpfulWheelDiv

document.getElementById("helpfulWheelDiv") can return null; accessing
.style on it would throw. The pre-extraction code had the same gap,
so guard it now that the code is being touched.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>

* refactor(workspace-layout-controller): bind delegation stubs and reduce test duplication

Use controller.method.bind(controller) instead of arrow-function
wrappers for the activity-level delegation stubs, and add a
setupActivity() test helper to collapse the repeated
makeActivity()+setupWorkspaceLayoutController() pairing across the
suite. Also correct a misleading comment (the DOM lookup isn't
cached, it's just done once).

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>

---------

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants