Skip to content

Commit 0a8ef6c

Browse files
authored
docs: document widget zones changes + caching support in cloud (#16217)
1 parent 2514635 commit 0a8ef6c

89 files changed

Lines changed: 432 additions & 4178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

www/apps/book/app/learn/customization/customize-admin/widget/page.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const highlights = [
7676
["19", "fields", "Specify the product's brand to be retrieved."],
7777
["23", "brandName", "Get brand name from the query request."],
7878
["53", "defineWidgetConfig", "Export the widget's configurations"],
79-
["54", "zone", "Show the widget at the top of the product details page."]
79+
["54", "zone", "Show the widget in the product details page."]
8080
]
8181

8282
```tsx title="src/admin/widgets/product-brand.tsx" highlights={highlights}
@@ -133,7 +133,7 @@ const ProductBrandWidget = ({
133133
}
134134

135135
export const config = defineWidgetConfig({
136-
zone: "product.details.before",
136+
zone: "product.details",
137137
})
138138

139139
export default ProductBrandWidget
@@ -144,7 +144,7 @@ A widget's file must export:
144144
- A React component to be rendered in the specified injection zone. The component must be the file's default export.
145145
- A configuration object created with `defineWidgetConfig` from the Admin Extension SDK. The function receives an object as a parameter that has a `zone` property, whose value is the zone to inject the widget to.
146146

147-
Since the widget is injected at the top of the product details page, the widget receives the product's details as a parameter.
147+
Since the widget is injected into the product details page, the widget receives the product's details as a parameter.
148148

149149
In the widget, you use [Tanstack (React) Query](https://tanstack.com/query/latest) to query the Medusa server. Tanstack Query provides features like asynchronous state management and optimized caching. In the `queryFn` function that executes the query, you use the JS SDK to send a request to the [Get Product API Route](!api!/admin/products/get-a-product), passing `+brand.*` in the `fields` query parameter to retrieve the product's brand.
150150

www/apps/book/app/learn/debugging-and-testing/feature-flags/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const ProductWidget = () => {
187187
}
188188

189189
export const config = defineWidgetConfig({
190-
zone: "product.details.after",
190+
zone: "product.details",
191191
})
192192

193193
export default ProductWidget

www/apps/book/app/learn/fundamentals/admin/constraints/page.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ const ProductWidget = () => {
3434
A widget zone's value must be wrapped in double or single quotes. It can't be a template literal or a variable. Otherwise, Medusa doesn't register the widget correctly.
3535

3636
export const zoneHighlights = [
37-
["3", "`product.details.before`", "Don't specify the value of `zone` as a template literal."],
37+
["3", "`product.details`", "Don't specify the value of `zone` as a template literal."],
3838
["9", "ZONE", "Don't specify a variable as the value of `zone`."],
39-
["14", `"product.details.before"`, "Wrap the value of `zone` in double or single quotes."]
39+
["14", `"product.details"`, "Wrap the value of `zone` in double or single quotes."]
4040
]
4141

4242
```ts highlights={zoneHighlights}
4343
// Don't
4444
export const config = defineWidgetConfig({
45-
zone: `product.details.before`,
45+
zone: `product.details`,
4646
})
4747

4848
// Don't
49-
const ZONE = "product.details.after"
49+
const ZONE = "product.details"
5050
export const config = defineWidgetConfig({
5151
zone: ZONE,
5252
})
5353

5454
// Do
5555
export const config = defineWidgetConfig({
56-
zone: "product.details.before",
56+
zone: "product.details",
5757
})
5858
```

www/apps/book/app/learn/fundamentals/admin/custom-injection-zones/page.mdx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,17 @@ Refer to the [LayoutComposer](!resources!/admin-components/components/layout-com
126126

127127
### Custom Zone Naming Convention
128128

129-
Custom injection zones should follow the pattern `{resource-name}.{page-context}.{position}`, where:
129+
Custom injection zones should follow the pattern `{resource-name}.{page-context}` for the main section, and `{resource-name}.{page-context}.{section}` for other sections, where:
130130

131131
- `resource-name`: The name of the resource being accessed in the page. For example, `brand` in the example above.
132132
- `page-context`: The page or section context. For example, `details` for a details page or `list` for a list page.
133-
- `position`: One of `before`, `after`, `side.before`, or `side.after`.
133+
- `section`: The name of the layout section the zone belongs to, if it isn't the main one. For example, `side` for the side section of a two-column layout.
134+
135+
<Note>
136+
137+
Don't add a `.before` or `.after` suffix to your zone names. These suffixes are deprecated since [Medusa v2.17.2](https://github.com/medusajs/medusa/releases/tag/v2.17.2), as admin users now change a widget's placement with [Layout Configurations](!user-guide!/tips/layout-configurations).
138+
139+
</Note>
134140

135141
This naming convention helps avoid conflicts between different plugins and makes zones easier to identify.
136142

@@ -145,10 +151,9 @@ To register the injection zones, augment the `InjectionZoneRegistry` interface t
145151
```ts title="index.d.ts"
146152
declare module "@medusajs/admin-shared" {
147153
interface InjectionZoneRegistry {
148-
"brand.details.before": true
149-
"brand.details.after": true
150-
"brand.details.side.before": true
151-
"brand.details.side.after": true
154+
"brand.details": true
155+
"brand.details.side": true
156+
"brand.list": true
152157
}
153158
}
154159
```
@@ -191,15 +196,15 @@ const BrandListWidget = () => {
191196
}
192197

193198
export const config = defineWidgetConfig({
194-
zone: "brand.list.before",
199+
zone: "brand.list",
195200
})
196201

197202
export default BrandListWidget
198203
```
199204

200-
In this example, the widget is injected into the `brand.list.before` zone, so it's rendered before the main content of the brand list page you added to your plugin.
205+
In this example, the widget is injected into the `brand.list` zone, so it's rendered in the main section of the brand list page you added to your plugin.
201206

202-
If you don't see `brand.list.before` in the autocompletion of the `zone` property, make sure your `src/admin/tsconfig.json` has the following in its `include` array:
207+
If you don't see `brand.list` in the autocompletion of the `zone` property, make sure your `src/admin/tsconfig.json` has the following in its `include` array:
203208

204209
```json title="src/admin/tsconfig.json"
205210
"include": [
@@ -248,10 +253,10 @@ const BrandWidget = ({
248253
}
249254

250255
export const config = defineWidgetConfig({
251-
zone: "brand.details.before",
256+
zone: "brand.details",
252257
})
253258

254259
export default BrandWidget
255260
```
256261

257-
In this example, the `BrandWidget` is injected into the `brand.details.before` zone, which is part of the brand details page you added to your plugin. Since you passed the `brand` object as data to the `LayoutComposer`, developers can access it in the widget through the `data` prop.
262+
In this example, the `BrandWidget` is injected into the `brand.details` zone, which is part of the brand details page you added to your plugin. Since you passed the `brand` object as data to the `LayoutComposer`, developers can access it in the widget through the `data` prop.

www/apps/book/app/learn/fundamentals/admin/environment-variables/page.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ProductWidget = () => {
5353
}
5454

5555
export const config = defineWidgetConfig({
56-
zone: "product.details.before",
56+
zone: "product.details",
5757
})
5858

5959
export default ProductWidget
@@ -189,7 +189,7 @@ const ProductWidget = () => {
189189
}
190190

191191
export const config = defineWidgetConfig({
192-
zone: "product.details.before",
192+
zone: "product.details",
193193
})
194194

195195
export default ProductWidget
@@ -228,7 +228,7 @@ const ProductWidget = () => {
228228
}
229229

230230
export const config = defineWidgetConfig({
231-
zone: "product.details.before",
231+
zone: "product.details",
232232
})
233233

234234
export default ProductWidget

www/apps/book/app/learn/fundamentals/admin/routing/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const ProductWidget = () => {
3939

4040
// The widget's configurations
4141
export const config = defineWidgetConfig({
42-
zone: "product.details.before",
42+
zone: "product.details",
4343
})
4444

4545
export default ProductWidget

www/apps/book/app/learn/fundamentals/admin/tips/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const ProductWidget = () => {
8282
}
8383

8484
export const config = defineWidgetConfig({
85-
zone: "product.list.before",
85+
zone: "product.list",
8686
})
8787

8888
export default ProductWidget
@@ -126,7 +126,7 @@ const ProductWidget = ({
126126
}
127127

128128
export const config = defineWidgetConfig({
129-
zone: "product.details.before",
129+
zone: "product.details",
130130
})
131131

132132
export default ProductWidget

www/apps/book/app/learn/fundamentals/admin/translations/page.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const ProductWidget = () => {
133133
}
134134

135135
export const config = defineWidgetConfig({
136-
zone: "product.details.before",
136+
zone: "product.details",
137137
})
138138

139139
export default ProductWidget
@@ -231,7 +231,7 @@ const ProductWidget = () => {
231231
}
232232

233233
export const config = defineWidgetConfig({
234-
zone: "product.details.before",
234+
zone: "product.details",
235235
})
236236

237237
export default ProductWidget
@@ -327,7 +327,7 @@ const ProductWidget = () => {
327327

328328
// The widget's configurations
329329
export const config = defineWidgetConfig({
330-
zone: "product.details.before",
330+
zone: "product.details",
331331
})
332332

333333
export default ProductWidget

www/apps/book/app/learn/fundamentals/admin/widgets/page.mdx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ const ProductWidget = () => {
5858

5959
// The widget's configurations
6060
export const config = defineWidgetConfig({
61-
zone: "product.details.before",
61+
zone: "product.details",
6262
})
6363

6464
export default ProductWidget
6565
```
6666

67-
In the example above, the widget is injected at the top of a product’s details.
67+
In the example above, the widget is injected at the end of a product’s details page.
6868

6969
You export the `ProductWidget` component, which displays the heading `Product Widget`. In the widget, you use [Medusa UI](!ui!) to customize the dashboard with the same components used to build it.
7070

@@ -87,15 +87,27 @@ To test out the widget, start the Medusa application:
8787
npm run dev
8888
```
8989

90-
Then, open a product’s details page. You’ll find your custom widget at the top of the page.
90+
Then, open a product’s details page. You’ll find your custom widget at the end of the page.
91+
92+
---
93+
94+
## Widget Placement
95+
96+
Prior to Medusa v2.17.2, widget zones ended with `.before` or `.after` to indicate whether the widget should be placed at the beginning or end of the zone. For example, `product.details.before` would place the widget at the top of the product details page, while `product.details.after` would place it at the bottom.
97+
98+
As of Medusa v2.17.2, the `.before` and `.after` suffixes have been deprecated in favor of [Layout Configurations](!user-guide!/tips/layout-configurations). The login page is the only exception. It isn't part of the layout configurations, so its `login.before` and `login.after` zones still place the widget before or after the login form.
99+
100+
Widgets are now placed at the end of the zone they're injected into. For example, if you inject a widget into the `product.details` zone, it will be placed at the end of the product details page. Then, users can customize the placement of the widget in the Medusa Admin dashboard using [Layout Configurations](!user-guide!/tips/layout-configurations). The widget can be moved to the top of the page or in between core components of the page.
101+
102+
If you're still using the `.before` or `.after` suffixes, you can continue to do so, but it's recommended to migrate to the new system. `.before` and `.after` (aside from the login page) have no effect on the placement of widgets in Medusa v2.17.2 and later, and may be removed in future versions.
91103

92104
---
93105

94106
## Props Passed to Widgets on Detail Pages
95107

96108
Widgets that are injected into a detail page receive a `data` prop, which is the main data of the details page.
97109

98-
For example, a widget injected into the `product.details.before` zone receives the product's details in the `data` prop:
110+
For example, a widget injected into the `product.details` zone receives the product's details in the `data` prop:
99111

100112
export const detailHighlights = [
101113
["10", "data", "Receive the data as a prop."],
@@ -128,7 +140,7 @@ const ProductWidget = ({
128140

129141
// The widget's configurations
130142
export const config = defineWidgetConfig({
131-
zone: "product.details.before",
143+
zone: "product.details",
132144
})
133145

134146
export default ProductWidget
@@ -195,7 +207,7 @@ const ProductWidget = ({
195207

196208
// The widget's configurations
197209
export const config = defineWidgetConfig({
198-
zone: "product.details.before",
210+
zone: "product.details",
199211
})
200212

201213
export default ProductWidget

www/apps/book/app/learn/introduction/from-v1-to-v2/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ const ProductWidget = () => {
17061706

17071707
// The widget's configurations
17081708
export const config = defineWidgetConfig({
1709-
zone: "product.details.before",
1709+
zone: "product.details",
17101710
})
17111711

17121712
export default ProductWidget
@@ -1808,7 +1808,7 @@ const ProductWidget = () => {
18081808

18091809
// The widget's configurations
18101810
export const config = defineWidgetConfig({
1811-
zone: "product.details.before",
1811+
zone: "product.details",
18121812
})
18131813

18141814
export default ProductWidget

0 commit comments

Comments
 (0)