Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prototype] Metaobject details extensions #2533

Draft
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ui-extensions-react/src/surfaces/admin/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ export {URLField} from './components/URLField/URLField';
export type {URLFieldProps} from './components/URLField/URLField';
export {InternalLocationList} from './components/InternalLocationList/InternalLocationList';
export type {InternalLocationListProps} from './components/InternalLocationList/InternalLocationList';
export {InternalMetaobjectField} from './components/InternalMetaobjectField/InternalMetaobjectField';
export type {InternalMetaobjectFieldProps} from './components/InternalMetaobjectField/InternalMetaobjectField';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {InternalMetaobjectField as BaseInternalMetaobjectField} from '@shopify/ui-extensions/admin';
import {createRemoteReactComponent} from '@remote-ui/react';

export const InternalMetaobjectField = createRemoteReactComponent(
BaseInternalMetaobjectField,
);
export type {InternalMetaobjectFieldProps} from '@shopify/ui-extensions/admin';
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ You register targets in your \`shopify.extension.toml\` and inside the Javascrip
'This page shows information about a single gift card. The `admin.gift-card-details.action.render` target is available on this page. You can control the visibility of the action by using the `admin.gift-card-details.action.should-render` target.',
image: 'admin.gift-card-details.action.render.png',
},
{
title: 'Metaobject details',
description:
'This page shows information about a metaobject. The `admin.metaobject-details.action.render` target is available on this page. You can control the visibility of the action by using the `admin.metaobject-details.action.should-render` target.',
image: 'admin.metaobject-details.action.render.png',
},
{
title: 'Order details',
description:
Expand Down Expand Up @@ -231,6 +237,12 @@ You register targets in your \`shopify.extension.toml\` and inside the Javascrip
description:
'This page shows information about a single discount. The `admin.discount-details.function-settings.render` target is available on this page.',
},
{
title: 'Metaobject details',
description:
'This page shows information about a metaobject. The `admin.metaobject-details.block.render` target is available on this page.',
image: 'admin.metaobject-details.block.render.png',
},
{
title: 'Order details',
description:
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-extensions/src/surfaces/admin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export type {ProductDetailsConfigurationApi} from './api/product-configuration/p
export type {ProductVariantDetailsConfigurationApi} from './api/product-configuration/product-variant-details-configuration';
export type {OrderRoutingRuleApi} from './api/order-routing-rule/order-routing-rule';
export type {ValidationSettingsApi} from './api/checkout-rules/validation-settings';
export type {MetaobjectDetailsBlockApi} from './api/custom-data/metaobject-details';
export type {MetaobjectDetailsActionApi} from './api/custom-data/metaobject-details';
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ type MetafieldsChange =

export type SupportedDefinitionType = (typeof supportedDefinitionTypes)[number];
export type ApplyMetafieldsChange = (changes: MetafieldsChange[]) => void;

export interface Metafield {
id?: string | null;
key: string;
value?: string | null;
namespace?: string;
type?: SupportedDefinitionType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {BlockExtensionApi} from '../block/block';
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets';
import {ActionExtensionApi} from '../action/action';

import {ApplyMetafieldsChange} from './metafields';

export interface MetaobjectDetailsBlockApi<
ExtensionTarget extends AnyExtensionTarget,
> extends BlockExtensionApi<ExtensionTarget> {
applyMetafieldsChange: ApplyMetafieldsChange;
data: {
selected: {
id: string;
definitionType: string;
}[];
};
}

export interface MetaobjectDetailsActionApi<
ExtensionTarget extends AnyExtensionTarget,
> extends ActionExtensionApi<ExtensionTarget> {
applyMetafieldsChange: ApplyMetafieldsChange;
data: {
selected: {
id: string;
definitionType: string;
}[];
};
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import type {SupportedDefinitionType} from './metafields';

interface Metafield {
id?: string | null;
key: string;
value?: string | null;
namespace?: string;
type?: SupportedDefinitionType;
}
import type {Metafield} from '../custom-data/metafields';

interface OrderRoutingRule {
label: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {StandardApi} from '../standard/standard';
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets';

import {ApplyMetafieldsChange} from './metafields';
import {ApplyMetafieldsChange} from '../custom-data/metafields';
import {Data} from './data';

export interface OrderRoutingRuleApi<ExtensionTarget extends AnyExtensionTarget>
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-extensions/src/surfaces/admin/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ export {URLField} from './components/URLField/URLField';
export type {URLFieldProps} from './components/URLField/URLField';
export {InternalLocationList} from './components/InternalLocationList/InternalLocationList';
export type {InternalLocationListProps} from './components/InternalLocationList/InternalLocationList';
export {InternalMetaobjectField} from './components/InternalMetaobjectField/InternalMetaobjectField';
export type {InternalMetaobjectFieldProps} from './components/InternalMetaobjectField/InternalMetaobjectField';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {createRemoteComponent} from '@remote-ui/core';

export interface InternalMetaobjectFieldProps {
/**
* The id of the metaobject.
*/
id: string;

/**
* The definition type of the metaobject.
*/
definitionType: string;

/**
* The key of the metaobject field.
*/
fieldKey: string;
}

export const InternalMetaobjectField = createRemoteComponent<
'InternalMetaobjectField',
InternalMetaobjectFieldProps
>('InternalMetaobjectField');
27 changes: 27 additions & 0 deletions packages/ui-extensions/src/surfaces/admin/extension-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
ProductVariantDetailsConfigurationApi,
OrderRoutingRuleApi,
ValidationSettingsApi,
MetaobjectDetailsBlockApi,
MetaobjectDetailsActionApi,
} from './api';
import {AnyComponentBuilder} from '../../shared';
import {PurchaseOptionsCardConfigurationApi} from './api/purchase-options-card-action/purchase-options-card-action';
Expand Down Expand Up @@ -47,6 +49,10 @@ type OrderRoutingComponents = AnyComponentBuilder<
Pick<Components, 'InternalLocationList'>
>;

type CustomDataComponents = AnyComponentBuilder<
Pick<Components, 'InternalMetaobjectField'>
>;

/**
* See the [list of available components](/docs/api/admin-extensions/components).
*/
Expand All @@ -56,6 +62,7 @@ type AllComponents = AnyComponentBuilder<
| 'CustomerSegmentTemplate'
| 'InternalCustomerSegmentTemplate'
| 'InternalLocationList'
| 'InternalMetaobjectField'
>
>;

Expand Down Expand Up @@ -174,6 +181,16 @@ export interface ExtensionTargets {
AllComponents
>;

/**
* Renders an admin block in the metaobject details page.
*
* See the [list of available components](/docs/api/admin-extensions/components).
*/
'admin.metaobject-details.block.render': RenderExtension<
MetaobjectDetailsBlockApi<'admin.metaobject-details.block.render'>,
AllComponents | CustomDataComponents
>;

/**
* Renders an admin block in the gift card details page.
*
Expand Down Expand Up @@ -275,6 +292,16 @@ export interface ExtensionTargets {
AllComponents
>;

/**
* Renders an admin action extension in the metaobject details page. Open this extension from the "More Actions" menu.
*
* See the [list of available components](/docs/api/admin-extensions/components).
*/
'admin.metaobject-details.action.render': RenderExtension<
MetaobjectDetailsActionApi<'admin.metaobject-details.action.render'>,
AllComponents | CustomDataComponents
>;

/**
* Renders an admin action extension in the product index page. Open this extension from the "More Actions" menu.
*
Expand Down
Loading