-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2458 from Shopify/ek/add-should-render-method
Add shouldRender method to ui-extensions
- Loading branch information
Showing
7 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/ui-extensions': minor | ||
--- | ||
|
||
Add shouldRender method to admin ui-extensions |
This file contains 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
19 changes: 19 additions & 0 deletions
19
packages/ui-extensions/src/surfaces/admin/api/should-render/should-render.doc.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'ShouldRender API', | ||
description: 'This API is available to all shouldRender extension types.', | ||
isVisualComponent: false, | ||
type: 'API', | ||
definitions: [ | ||
{ | ||
title: 'ShouldRenderApi', | ||
description: '', | ||
type: 'ShouldRenderApi', | ||
}, | ||
], | ||
category: 'API', | ||
related: [], | ||
}; | ||
|
||
export default data; |
11 changes: 11 additions & 0 deletions
11
packages/ui-extensions/src/surfaces/admin/api/should-render/should-render.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type {StandardApi} from '../standard/standard'; | ||
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets'; | ||
import type {Data} from '../shared'; | ||
|
||
export interface ShouldRenderApi<ExtensionTarget extends AnyExtensionTarget> | ||
extends StandardApi<ExtensionTarget> { | ||
/** | ||
* Information about the currently viewed or selected items. | ||
*/ | ||
data: Data; | ||
} |
265 changes: 265 additions & 0 deletions
265
packages/ui-extensions/src/surfaces/admin/should-render-targets.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
import type {RunnableExtension} from '../../extension'; | ||
|
||
import {ShouldRenderApi} from './api/should-render/should-render'; | ||
|
||
interface ShouldRenderOutput { | ||
display: boolean; | ||
} | ||
|
||
export interface ExtensionTargets { | ||
// Admin action shouldRender targets | ||
/** | ||
* Controls the render state of an admin action extension in the product details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.product-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the catalog details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.catalog-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.catalog-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the company details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.company-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.company-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the gift card details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.gift-card-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.gift-card-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the order details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.order-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the customer details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.customer-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.customer-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the customer segment details page. Open this extension from the "Use segment" button. | ||
*/ | ||
'admin.customer-segment-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.customer-segment-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the product index page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.product-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the order index page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.order-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the customer index page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.customer-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.customer-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the discount index page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.discount-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.discount-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the collection details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.collection-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.collection-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the collection index page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.collection-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.collection-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the abandoned checkout page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.abandoned-checkout-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.abandoned-checkout-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the product variant details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.product-variant-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-variant-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the draft order details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.draft-order-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.draft-order-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the draft orders page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.draft-order-index.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.draft-order-index.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the discount details page. Open this extension from the "More Actions" menu. | ||
*/ | ||
'admin.discount-details.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.discount-details.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the order fulfilled card. Open this extension from the "3-dot" menu inside the order fulfilled card. | ||
* Note: This extension will only be visible on orders which were fulfilled by your app. | ||
*/ | ||
'admin.order-fulfilled-card.action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-fulfilled-card.action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
// Admin bulk action shouldRender targets | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the product index page when multiple resources are selected. Open this extension from the "More Actions" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.product-index.selection-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-index.selection-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the order index page when multiple resources are selected. Open this extension from the "More Actions" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.order-index.selection-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-index.selection-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the customer index page when multiple resources are selected. Open this extension from the "More Actions" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.customer-index.selection-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.customer-index.selection-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin action extension in the draft order page when multiple resources are selected. Open this extension from the "3-dot" menu. | ||
*/ | ||
'admin.draft-order-index.selection-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.draft-order-index.selection-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
// Admin print action and bulk print action shouldRender targets | ||
|
||
/** | ||
* Controls the render state of an admin print action extension in the order index page when multiple resources are selected. Open this extension from the "Print" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.order-details.print-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-details.print-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin print action extension in the product index page when multiple resources are selected. Open this extension from the "Print" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.product-details.print-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-details.print-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin print action extension in the order index page when multiple resources are selected. Open this extension from the "Print" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.order-index.selection-print-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.order-index.selection-print-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
|
||
/** | ||
* Controls the render state of an admin print action extension in the product index page when multiple resources are selected. Open this extension from the "Print" menu of the resource list. The resource ids are available to this extension at runtime. | ||
*/ | ||
'admin.product-index.selection-print-action.render': RunnableExtension< | ||
ShouldRenderApi<'admin.product-index.selection-print-action.render'>, | ||
ShouldRenderOutput | ||
>; | ||
} | ||
|
||
export type ExtensionTarget = keyof ExtensionTargets; | ||
|
||
export type ExtensionForExtensionTarget<T extends ExtensionTarget> = | ||
ExtensionTargets[T]; | ||
|
||
/** | ||
* For a given extension target, returns the value that is expected to be | ||
* returned by that extension target’s callback type. | ||
*/ | ||
export type ReturnTypeForExtension<ID extends keyof ExtensionTargets> = | ||
ReturnType<ExtensionTargets[ID]>; | ||
|
||
/** | ||
* For a given extension target, returns the tuple of arguments that would | ||
* be provided to that extension target’s callback type. | ||
*/ | ||
export type ArgumentsForExtension<ID extends keyof ExtensionTargets> = | ||
Parameters<ExtensionTargets[ID]>; | ||
|
||
/** | ||
* A union type containing all of the extension targets that follow the pattern of | ||
* accepting a [`@remote-ui/core` `RemoteRoot`](https://github.com/Shopify/remote-dom/tree/remote-ui/packages/core) | ||
* and an additional `api` argument, and using those arguments to render | ||
* UI. | ||
*/ | ||
export type RenderExtensionTarget = { | ||
[ID in keyof ExtensionTargets]: ExtensionTargets[ID] extends RunnableExtension< | ||
any, | ||
any | ||
> | ||
? ID | ||
: never; | ||
}[keyof ExtensionTargets]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createDataRegistrationFunction} from '../../utilities/dataRegistration'; | ||
|
||
import type {ExtensionTargets} from './should-render-targets'; | ||
|
||
export const shouldRender = createDataRegistrationFunction<ExtensionTargets>(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface DataRegistrationFunctionFunction<ExtensionPoints> { | ||
<Target extends keyof ExtensionPoints>( | ||
target: Target, | ||
callback: ExtensionPoints[Target], | ||
): ExtensionPoints[Target]; | ||
} | ||
|
||
export function createDataRegistrationFunction< | ||
ExtensionPoints, | ||
>(): DataRegistrationFunctionFunction<ExtensionPoints> { | ||
const extensionWrapper: DataRegistrationFunctionFunction<ExtensionPoints> = ( | ||
target, | ||
callback, | ||
) => { | ||
(globalThis as any).shopify?.dataExtension(target, callback); | ||
return callback; | ||
}; | ||
|
||
return extensionWrapper; | ||
} |