[upstream #4918] fix(dashboard): Fix stock location deletion and add stock transfer on delete - #26
Open
ayim wants to merge 5 commits into
Open
[upstream #4918] fix(dashboard): Fix stock location deletion and add stock transfer on delete#26ayim wants to merge 5 commits into
ayim wants to merge 5 commits into
Conversation
… delete
Deleting a stock location from the dashboard always failed with a "Failed to
delete N stock locations" toast. The shared DeleteBulkAction sends its
variables as `{ ids: [...] }` (the `deleteX(ids: [ID!]!)` convention used by
every other entity), but `deleteStockLocations` uniquely takes
`input: [DeleteStockLocationInput!]!`, so the required `$input` variable was
never provided and the request failed GraphQL validation — surfacing via the
onError branch as the toast, regardless of whether the location held stock.
Rather than only fix the variable shape, expose the transfer capability that
core already supports: `DeleteStockLocationInput.transferToLocationId` moves a
location's stock to another location on delete, but no admin UI ever surfaced
it. Replace the plain confirm with a dedicated delete dialog that lets the
admin choose, per delete, to transfer remaining stock to another location or
discard it, then sends the correct `input` array.
Fixes vendurehq#4641
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Invalidate the transfer-target list cache on delete so a just-deleted location can't be offered as a transfer target on the next open. - Disable the target picker while its query is loading, so "Discard" cannot masquerade as "no transfer options exist". - Type the mutation result via ResultOf instead of `any` + hand-rolled cast. - Clarify dialog copy that all selected locations transfer into the single chosen target, and note the 100-location picker cap. - Replace the generic CRUD bulk-delete coverage (which drove the old confirm dialog) with an e2e test that drives the new transfer/discard dialog and guards against regressing the mutation variable shape. Relates to vendurehq#4641 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Reset the transfer target when the dialog opens, so a choice from a previous
delete can't be sent as a to-be-deleted location's transferToLocationId.
- Only run success cleanup (refetch/reset/close) when at least one location was
actually deleted; keep the dialog open if every item failed.
- Adapt to the v3.7 @vendure-io/ui Select: pass the required `items` map and
handle the nullable onValueChange value.
- Keep the bulk-action dropdown open (closeOnClick={false}) so opening the
dialog in the same tick doesn't race with the menu unmounting.
- Extract the new user-facing strings into the Lingui catalogs (they otherwise
render as raw message IDs in the built app).
- Make the e2e test self-contained (seeds its own location via the API) and
update it for the v3.7 bulk-action UI ("Actions" menu + custom dialog).
Skipped CodeRabbit's suggestions to import UI primitives from @vendure-io/ui
and api from @/graphql/api.js: every sibling route component uses
@/vdb/components/ui/* and @/vdb/graphql/api.js, and @/graphql/* isn't a tsconfig
path — following them would break the build and diverge from convention.
Relates to vendurehq#4641
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…cap) The delete dialog's transfer-target picker capped the query at 100 locations, silently hiding valid destinations on stores with more. Paginate through all pages instead so every location is offerable. Relates to vendurehq#4641 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrored from vendurehq#4918 for the Overwatch review demo.
Original author: @biggamesmallworld
Summary
Fixes the dashboard bug where deleting a Stock Location always fails with a "Failed to delete N stock locations" toast (reported in vendurehq#4641 / OSS-493), and — since core already supports it — exposes transferring the location's stock to another location on delete.
Root cause
The generic
DeleteBulkActionsends its mutation variables as{ ids: [...] }, matching thedeleteX(ids: [ID!]!)convention used by every other entity's bulk delete. ButdeleteStockLocationsis the one exception — it takesinput: [DeleteStockLocationInput!]!(so it can carry a per-locationtransferToLocationId):So the required
$inputvariable was never provided and the request failed GraphQL validation:That error hits the
DeleteBulkActiononErrorbranch, producing the hard-codedFailed to delete N stock locationstoast (no trailing message) — which matches the reporter's screenshot exactly. It fails for every stock location, with or without stock, so the "zero stock" detail in the report was a red herring.Note: this is not a missing FK-cascade bug in core (as investigated on the issue) — a well-formed
deleteStockLocation(s)request via the Admin API already works. The failure is purely the dashboard sending the wrong variable shape.Reproduction
After reading the comment from @grolmus on the Linear task, I saw that he couldn't reproduce the error via the API. When I went to reproduce it via the UI I was able to reproduce it, with the API response in the network tab returning this:
The true issue at hand, not the FK issue originally thought.
Fix + feature
DeleteStockLocationInput.transferToLocationIdalready lets core move a location's stock (levels + allocations) to another location on delete — but no admin UI ever surfaced it (neither the dashboard nor the legacy Angular app). So instead of only correcting the variable shape:inputarray withtransferToLocationIdper location.DeleteBulkActionis left untouched (still{ ids }for all other entities).Steps to verify
$input ... was not providedin the network tabScreen recording
Screen.Recording.2026-07-03.at.14.51.20.mov
Testing
Added a dashboard e2e test (
packages/dashboard/e2e/tests/settings/stock-locations.spec.ts) that drives the real delete dialog end-to-end (select → Delete → choose "Discard remaining stock" → confirm) and asserts the location is removed — guarding against any regression back to the wrong mutation variable shape. The stock-location CRUD suite's generic bulk-delete (which drove the old confirm dialog) was replaced by this dialog-aware test.Notes
useDetailPage/list pages unchanged; no core changes.Fixes vendurehq#4641