1 import { HttpTypes } from "@medusajs/types"
2 import type { SearchEntityDefinition } from "./search-entities"
3
4 /**
5 * Built-in admin search entities, including their "Jump to" shortcuts. The
6 * registry in `./search-entities` seeds itself from this map when it is
7 * evaluated, which always happens before any app or plugin
8 * `search-entities.tsx` file runs — registering an entity requires importing
9 * the registry module first. That makes overrides safe in every bundling order
10 * without any registration-time bookkeeping.
11 */
12 export const DEFAULT_SEARCH_ENTITIES: Record<string, SearchEntityDefinition> = {
13 order: {
14 shortcut: {
15 keys: { Mac: ["G", "O"] },
16 label: (t) => t("app.keyboardShortcuts.navigation.goToOrders"),
17 to: "/orders",
18 },
19 transform: (order: HttpTypes.AdminOrder) => ({
20 id: order.id,
21 title: `#${order.display_id}`,
22 subtitle: order.email ?? undefined,
23 to: `/orders/${order.id}`,
24 value: `order:${order.id}`,
25 }),
26 },
27 product: {
28 shortcut: {
29 keys: { Mac: ["G", "P"] },
30 label: (t) => t("app.keyboardShortcuts.navigation.goToProducts"),
31 to: "/products",
32 },
33 transform: (product: HttpTypes.AdminProduct) => ({
34 id: product.id,
35 title: product.title,
36 to: `/products/${product.id}`,
37 thumbnail: product.thumbnail ?? undefined,
38 value: `product:${product.id}`,
39 }),
40 },
41 product_variant: {
42 transform: (variant: HttpTypes.AdminProductVariant) => ({
43 id: variant.id,
44 title: variant.title!,
45 subtitle: variant.sku ?? undefined,
46 to: `/products/${variant.product_id}/variants/${variant.id}`,
47 value: `variant:${variant.id}`,
48 }),
49 },
50 product_category: {
51 shortcut: {
52 keys: { Mac: ["G", "A"] },
53 label: (t) => t("app.keyboardShortcuts.navigation.goToCategories"),
54 to: "/categories",
55 },
56 transform: (category: HttpTypes.AdminProductCategory) => ({
57 id: category.id,
58 title: category.name,
59 to: `/categories/${category.id}`,
60 value: `category:${category.id}`,
61 }),
62 },
63 inventory_item: {
64 shortcut: {
65 keys: { Mac: ["G", "I"] },
66 label: (t) => t("app.keyboardShortcuts.navigation.goToInventory"),
67 to: "/inventory",
68 },
69 transform: (inventory: HttpTypes.AdminInventoryItem) => ({
70 id: inventory.id,
71 title: inventory.title ?? "",
72 subtitle: inventory.sku ?? undefined,
73 to: `/inventory/${inventory.id}`,
74 value: `inventory:${inventory.id}`,
75 }),
76 },
77 customer: {
78 shortcut: {
79 keys: { Mac: ["G", "U"] },
80 label: (t) => t("app.keyboardShortcuts.navigation.goToCustomers"),
81 to: "/customers",
82 },
83 transform: (customer: HttpTypes.AdminCustomer) => {
84 const name = [customer.first_name, customer.last_name]
85 .filter(Boolean)
86 .join(" ")
87 return {
88 id: customer.id,
89 title: name || customer.email,
90 subtitle: name ? customer.email : undefined,
91 to: `/customers/${customer.id}`,
92 value: `customer:${customer.id}`,
93 }
94 },
95 },
96 customer_group: {
97 shortcut: {
98 keys: { Mac: ["G", "G"] },
99 label: (t) => t("app.keyboardShortcuts.navigation.goToCustomerGroups"),
100 to: "/customer-groups",
101 },
102 transform: (customerGroup: HttpTypes.AdminCustomerGroup) => ({
103 id: customerGroup.id,
104 title: customerGroup.name!,
105 to: `/customer-groups/${customerGroup.id}`,
106 value: `customerGroup:${customerGroup.id}`,
107 }),
108 },
109 product_collection: {
110 shortcut: {
111 keys: { Mac: ["G", "C"] },
112 label: (t) => t("app.keyboardShortcuts.navigation.goToCollections"),
113 to: "/collections",
114 },
115 transform: (collection: HttpTypes.AdminCollection) => ({
116 id: collection.id,
117 title: collection.title,
118 to: `/collections/${collection.id}`,
119 value: `collection:${collection.id}`,
120 }),
121 },
122 promotion: {
123 shortcut: {
124 keys: { Mac: ["G", "M"] },
125 label: (t) => t("app.keyboardShortcuts.navigation.goToPromotions"),
126 to: "/promotions",
127 },
128 transform: (promotion: HttpTypes.AdminPromotion) => ({
129 id: promotion.id,
130 title: promotion.code!,
131 to: `/promotions/${promotion.id}`,
132 value: `promotion:${promotion.id}`,
133 }),
134 },
135 campaign: {
136 shortcut: {
137 keys: { Mac: ["G", "K"] },
138 label: (t) => t("app.keyboardShortcuts.navigation.goToCampaigns"),
139 to: "/campaigns",
140 },
141 transform: (campaign: HttpTypes.AdminCampaign) => ({
142 id: campaign.id,
143 title: campaign.name,
144 to: `/campaigns/${campaign.id}`,
145 value: `campaign:${campaign.id}`,
146 }),
147 },
148 price_list: {
149 shortcut: {
150 keys: { Mac: ["G", "L"] },
151 label: (t) => t("app.keyboardShortcuts.navigation.goToPriceLists"),
152 to: "/price-lists",
153 },
154 transform: (priceList: HttpTypes.AdminPriceList) => ({
155 id: priceList.id,
156 title: priceList.title,
157 to: `/price-lists/${priceList.id}`,
158 value: `priceList:${priceList.id}`,
159 }),
160 },
161 // Navigable, but a reservation is a quantity against an inventory item and a
162 // location, with nothing readable to match on — so no `transform`.
163 reservation: {
164 shortcut: {
165 keys: { Mac: ["G", "R"] },
166 label: (t) => t("app.keyboardShortcuts.navigation.goToReservations"),
167 to: "/reservations",
168 },
169 },
170 user: {
171 shortcut: {
172 keys: { Mac: ["G", ",", "U"] },
173 label: (t) => t("app.keyboardShortcuts.settings.goToUsers"),
174 type: "settingShortcut",
175 to: "/settings/users",
176 },
177 transform: (user: HttpTypes.AdminUser) => ({
178 id: user.id,
179 title: `${user.first_name} ${user.last_name}`,
180 subtitle: user.email,
181 to: `/settings/users/${user.id}`,
182 value: `user:${user.id}`,
183 }),
184 },
185 region: {
186 shortcut: {
187 keys: { Mac: ["G", ",", "R"] },
188 label: (t) => t("app.keyboardShortcuts.settings.goToRegions"),
189 type: "settingShortcut",
190 to: "/settings/regions",
191 },
192 transform: (region: HttpTypes.AdminRegion) => ({
193 id: region.id,
194 title: region.name,
195 to: `/settings/regions/${region.id}`,
196 value: `region:${region.id}`,
197 }),
198 },
199 tax_region: {
200 shortcut: {
201 keys: { Mac: ["G", ",", "T"] },
202 label: (t) => t("app.keyboardShortcuts.settings.goToTaxRegions"),
203 type: "settingShortcut",
204 to: "/settings/tax-regions",
205 },
206 transform: (taxRegion: HttpTypes.AdminTaxRegion) => ({
207 id: taxRegion.id,
208 title:
209 taxRegion.province_code?.toUpperCase() ??
210 taxRegion.country_code!.toUpperCase(),
211 subtitle: taxRegion.province_code ? taxRegion.country_code! : undefined,
212 to: `/settings/tax-regions/${taxRegion.id}`,
213 value: `taxRegion:${taxRegion.id}`,
214 }),
215 },
216 return_reason: {
217 shortcut: {
218 keys: { Mac: ["G", ",", "M"] },
219 label: (t) => t("app.keyboardShortcuts.settings.goToReturnReasons"),
220 type: "settingShortcut",
221 to: "/settings/return-reasons",
222 },
223 transform: (returnReason: HttpTypes.AdminReturnReason) => ({
224 id: returnReason.id,
225 title: returnReason.label,
226 subtitle: returnReason.value,
227 to: `/settings/return-reasons/${returnReason.id}/edit`,
228 value: `returnReason:${returnReason.id}`,
229 }),
230 },
231 sales_channel: {
232 shortcut: {
233 keys: { Mac: ["G", ",", "A"] },
234 label: (t) => t("app.keyboardShortcuts.settings.goToSalesChannels"),
235 type: "settingShortcut",
236 to: "/settings/sales-channels",
237 },
238 transform: (salesChannel: HttpTypes.AdminSalesChannel) => ({
239 id: salesChannel.id,
240 title: salesChannel.name,
241 to: `/settings/sales-channels/${salesChannel.id}`,
242 value: `salesChannel:${salesChannel.id}`,
243 }),
244 },
245 product_type: {
246 shortcut: {
247 keys: { Mac: ["G", ",", "P"] },
248 label: (t) => t("app.keyboardShortcuts.settings.goToProductTypes"),
249 type: "settingShortcut",
250 to: "/settings/product-types",
251 },
252 transform: (productType: HttpTypes.AdminProductType) => ({
253 id: productType.id,
254 title: productType.value,
255 to: `/settings/product-types/${productType.id}`,
256 value: `productType:${productType.id}`,
257 }),
258 },
259 product_tag: {
260 transform: (productTag: HttpTypes.AdminProductTag) => ({
261 id: productTag.id,
262 title: productTag.value,
263 to: `/settings/product-tags/${productTag.id}`,
264 value: `productTag:${productTag.id}`,
265 }),
266 },
267 stock_location: {
268 shortcut: {
269 keys: { Mac: ["G", ",", "L"] },
270 label: (t) => t("app.keyboardShortcuts.settings.goToLocations"),
271 type: "settingShortcut",
272 to: "/settings/locations",
273 },
274 transform: (location: HttpTypes.AdminStockLocation) => ({
275 id: location.id,
276 title: location.name,
277 to: `/settings/locations/${location.id}`,
278 value: `location:${location.id}`,
279 }),
280 },
281 shipping_profile: {
282 transform: (shippingProfile: HttpTypes.AdminShippingProfile) => ({
283 id: shippingProfile.id,
284 title: shippingProfile.name,
285 to: `/settings/locations/shipping-profiles/${shippingProfile.id}`,
286 value: `shippingProfile:${shippingProfile.id}`,
287 }),
288 },
289 publishable_api_key: {
290 shortcut: {
291 keys: { Mac: ["G", ",", "J"] },
292 label: (t) => t("app.keyboardShortcuts.settings.goToPublishableApiKeys"),
293 type: "settingShortcut",
294 to: "/settings/publishable-api-keys",
295 },
296 transform: (apiKey: HttpTypes.AdminApiKeyResponse["api_key"]) => ({
297 id: apiKey.id,
298 title: apiKey.title,
299 subtitle: apiKey.redacted,
300 to: `/settings/publishable-api-keys/${apiKey.id}`,
301 value: `publishableApiKey:${apiKey.id}`,
302 }),
303 },
304 secret_api_key: {
305 shortcut: {
306 keys: { Mac: ["G", ",", "K"] },
307 label: (t) => t("app.keyboardShortcuts.settings.goToSecretApiKeys"),
308 type: "settingShortcut",
309 to: "/settings/secret-api-keys",
310 },
311 transform: (apiKey: HttpTypes.AdminApiKeyResponse["api_key"]) => ({
312 id: apiKey.id,
313 title: apiKey.title,
314 subtitle: apiKey.redacted,
315 to: `/settings/secret-api-keys/${apiKey.id}`,
316 value: `secretApiKey:${apiKey.id}`,
317 }),
318 },
319 }