-
Notifications
You must be signed in to change notification settings - Fork 142
Expose generic backpack configuration #441
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
base: develop
Are you sure you want to change the base?
Conversation
…et of interfaces This allows other projects to specify their own backpack server implementation and API.
If the previous code ended up in this state - it was already invalid since the backpack was shown but it would say "No items" instead of indicating to the user that they are logged out
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.
Pull request overview
Expose a configurable backpack storage interface via GUIConfig, while preserving legacy backpack behavior through a new LegacyBackpackStorage adapter.
Changes:
- Added
GUIBackpackStorageinterfaces/types (session, item, serialization) to enable pluggable backpack backends. - Implemented legacy backpack backend as
LegacyBackpackStorageand wired it intoLegacyStorage. - Updated the Backpack container/UI to use
storage.backpackStorageinstead of legacybackpack-apifunctions, and gated rendering on configuration.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/scratch-gui/src/lib/legacy-storage.ts | Wires the new legacy backpack storage into LegacyStorage and registers backpack asset web store via the new helper. |
| packages/scratch-gui/src/lib/legacy-backpack-storage.ts | New legacy backpack backend implementing GUIBackpackStorage with host/session/auth handling and xhr calls. |
| packages/scratch-gui/src/lib/backpack/payload-serializable-data.ts | Adds an adapter to bridge existing payload builders to the new SerializableData interface. |
| packages/scratch-gui/src/lib/backpack-api.js | Removes old backpack CRUD/payload exports; keeps only fetch helpers for code/sprite retrieval. |
| packages/scratch-gui/src/index-standalone.tsx | Exposes LegacyBackpackStorage from the standalone entrypoint. |
| packages/scratch-gui/src/gui-config.ts | Introduces GUIBackpackStorage + related types and PropTypes; adds optional backpackStorage to GUIStorage. |
| packages/scratch-gui/src/containers/backpack.jsx | Migrates backpack CRUD to storage.backpackStorage and updates session propagation. |
| packages/scratch-gui/src/components/gui/gui.jsx | Prevents rendering Backpack UI unless a backpack storage is configured. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test report for scratch-gui 6 files +4 4 errors 62 suites ±0 9m 36s ⏱️ + 1m 5s For more details on these parsing errors and failures, see this check. Results for commit 42458e1. ± Comparison against base commit 40d5142. ♻️ This comment has been updated with latest results. |
|
@cwillisf Can you please review? There is a test failing but I would argue that it's incorrect/incomplete behaviour that it was testing, so I would vote for removing it if you agree. Here's what happens. This is the test: It tests opening the backpack with just the host set (without a logged-in user) and validates that it shows "Backpack is empty". I would argue that having the backpack show "Backpack is empty" when in fact it may not be (it's just that there is no user logged in) is incorrect behavior. In the changes I made - it would show an error instead. My thinking is - this shouldn't happen in scratch-www since when there is no session - the backpack is hidden, so the user can't click it. What do you think? |
This PR exposes a new set of functions through the GUIConfig interface (used by the standalone package) that allow for configuring a different backpack backend.
The interfaces are in
packages/scratch-gui/src/gui-config.ts.To keep backwards-compatibility, the new interface is implemented by default in
packages/scratch-gui/src/lib/legacy-backpack-storage.tsand used inpackages/scratch-gui/src/lib/legacy-storage.ts.The LegacyBackpackStorage class gets a constructor config
readAuth(session: BackpackSession | undefined): Promise<LegacyBackpackAuth>that allows controlling the session externally and through an async function (that has a chance to e.g. refresh a JWT before sending the request). The session parameter is a way to both allow externally-controlled session or the previous behavior where the session is taken from a Redux store that is shared between scratch-gui and scratch-www.