Skip to content

Commit 2ae3978

Browse files
authored
feat(dashboard,types): add metadata form to Stock Location (#15025)
## Summary **What** — What changes are introduced in this PR? Add metadata form to Stock Location in Admin dashboard. **Why** — Why are these changes relevant or necessary? No way to see nor update metadata from the Dashboard. **How** — How have these changes been implemented? Added metadata from in new route. **Testing** — How have these changes been tested, or how can the reviewer test the feature? *Please provide answer here* --- ## Examples Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice. This helps with documentation and ensures maintainers can quickly understand and verify the change. ```ts // Example usage ``` --- ## Checklist Please ensure the following before requesting a review: - [x] I have added a **changeset** for this PR - Every non-breaking change should be marked as a **patch** - To add a changeset, run `yarn changeset` and follow the prompts - [ ] The changes are covered by relevant **tests** - [x] I have verified the code works as intended locally - [x] I have linked the related issue(s) if applicable --- ## Additional Context Add any additional context, related issues, or references that might help the reviewer understand this PR.
1 parent 22077f1 commit 2ae3978

File tree

8 files changed

+49
-3
lines changed

8 files changed

+49
-3
lines changed

.changeset/yummy-pets-invite.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
"@medusajs/types": patch
4+
---
5+
6+
feat(dashboard,types): add metadata form to Stock Location

packages/admin/dashboard/src/dashboard-app/routes/get-route.map.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,11 @@ export function getRouteMap({
12981298
"../../routes/locations/location-fulfillment-providers"
12991299
),
13001300
},
1301+
{
1302+
path: "metadata/edit",
1303+
lazy: () =>
1304+
import("../../routes/locations/location-metadata"),
1305+
},
13011306
{
13021307
path: "fulfillment-set/:fset_id",
13031308
children: [
@@ -1869,7 +1874,7 @@ export function getRouteMap({
18691874
},
18701875
],
18711876
},
1872-
...(settingsRoutes.flatMap(r => r?.children || [])),
1877+
...settingsRoutes.flatMap((r) => r?.children || []),
18731878
],
18741879
},
18751880
],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const LOCATION_DETAILS_FIELD =
2-
"name,*sales_channels,*address,fulfillment_sets.type,fulfillment_sets.name,*fulfillment_sets.service_zones.geo_zones,*fulfillment_sets.service_zones,*fulfillment_sets.service_zones.shipping_options,*fulfillment_sets.service_zones.shipping_options.rules,*fulfillment_sets.service_zones.shipping_options.shipping_profile,*fulfillment_providers"
2+
"name,metadata,*sales_channels,*address,fulfillment_sets.type,fulfillment_sets.name,*fulfillment_sets.service_zones.geo_zones,*fulfillment_sets.service_zones,*fulfillment_sets.service_zones.shipping_options,*fulfillment_sets.service_zones.shipping_options.rules,*fulfillment_sets.service_zones.shipping_options.shipping_profile,*fulfillment_providers"

packages/admin/dashboard/src/routes/locations/location-detail/location-detail.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const LocationDetail = () => {
4949
sideBefore: getWidgets("location.details.side.before"),
5050
}}
5151
data={location}
52+
showMetadata
5253
showJSON
5354
hasOutlet
5455
>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { LocationMetadata as Component } from "./location-metadata"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useParams } from "react-router-dom"
2+
import { MetadataForm } from "../../../components/forms/metadata-form"
3+
import { useStockLocation, useUpdateStockLocation } from "../../../hooks/api"
4+
5+
export const LocationMetadata = () => {
6+
const { location_id } = useParams()
7+
8+
const { stock_location, isPending, isError, error } = useStockLocation(
9+
location_id!,
10+
{ fields: "id,metadata" }
11+
)
12+
13+
const { mutateAsync, isPending: isMutating } = useUpdateStockLocation(
14+
location_id!
15+
)
16+
17+
if (isError) {
18+
throw error
19+
}
20+
21+
return (
22+
<MetadataForm
23+
metadata={stock_location?.metadata}
24+
hook={mutateAsync}
25+
isPending={isPending}
26+
isMutating={isMutating}
27+
/>
28+
)
29+
}

packages/core/types/src/http/stock-locations/admin/entities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export interface AdminStockLocation {
2424
* The name of the stock location.
2525
*/
2626
name: string
27+
/**
28+
* The metadata associated with the stock location.
29+
*/
30+
metadata: Record<string, unknown> | null
2731
/**
2832
* The ID of the address associated with the stock location.
2933
*/

packages/core/types/src/http/stock-locations/admin/payloads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export interface AdminUpdateStockLocation {
8282
/**
8383
* Custom key-value pairs that can be added to the stock location.
8484
*/
85-
metadata?: Record<string, unknown>
85+
metadata?: Record<string, unknown> | null
8686
}
8787

8888
export interface AdminUpdateStockLocationSalesChannels {

0 commit comments

Comments
 (0)