Skip to content

Commit

Permalink
Introduces InternalCustomerSegmentTemplate component
Browse files Browse the repository at this point in the history
  • Loading branch information
PrescilliaA committed Aug 23, 2023
1 parent 402776a commit f537b08
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-lies-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/ui-extensions': patch
'@shopify/ui-extensions-react': patch
---

Introduces InternalCustomerSegmentTemplate component
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 @@ -28,6 +28,8 @@ export {Image} from './components/Image/Image';
export type {ImageProps} from './components/Image/Image';
export {InlineStack} from './components/InlineStack/InlineStack';
export type {InlineStackProps} from './components/InlineStack/InlineStack';
export {InternalCustomerSegmentTemplate} from './components/InternalCustomerSegmentTemplate/InternalCustomerSegmentTemplate';
export type {InternalCustomerSegmentTemplateProps} from './components/InternalCustomerSegmentTemplate/InternalCustomerSegmentTemplate';
export {Link} from './components/Link/Link';
export type {LinkProps} from './components/Link/Link';
export {NumberField} from './components/NumberField/NumberField';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {InternalCustomerSegmentTemplate as BaseInternalCustomerSegmentTemplate} from '@shopify/ui-extensions/admin';
import {createRemoteReactComponent} from '@remote-ui/react';

export const InternalCustomerSegmentTemplate = createRemoteReactComponent(
BaseInternalCustomerSegmentTemplate,
);
export type {InternalCustomerSegmentTemplateProps} from '@shopify/ui-extensions/admin';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import {
reactExtension,
InternalCustomerSegmentTemplate,
} from '@shopify/ui-extensions-react/admin';

function App({i18n, enabledFeatures}) {
const productsPurchasedOnTagsEnabled = enabledFeatures.includes('productsPurchasedByTags');
const query = productsPurchasedOnTagsEnabled
? 'products_purchased(tag: (product_tag)) = true'
: 'products_purchased(id: (product_id)) = true';
const queryToInsert = productsPurchasedOnTagsEnabled
? 'products_purchased(tag:'
: 'products_purchased(id:';

return (
<>
<InternalCustomerSegmentTemplate
title={i18n.translate('product.title')}
description={i18n.translate('product.description')}
icon='productsMajor'
query={query}
queryToInsert={queryToInsert}
createdOn={new Date('2023-01-15').toISOString()}
category="reEngageCustomers"
/>
<InternalCustomerSegmentTemplate
title={i18n.translate('location.title')}
description={[i18n.translate('location.firstParagraph'), i18n.translate('location.secondParagraph')]}
icon='locationMajor'
query="customer_cities CONTAINS 'US-NY-NewYorkCity'"
category='location'
/>
</>
);
}

reactExtension('admin.customers.segmentation-templates.render', ({i18n, __enabledFeatures}) => <App i18n={i18n} enabledFeatures={__enabledFeatures} />);
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 @@ -28,6 +28,8 @@ export {Icon} from './components/Icon/Icon';
export type {IconProps} from './components/Icon/Icon';
export {InlineStack} from './components/InlineStack/InlineStack';
export type {InlineStackProps} from './components/InlineStack/InlineStack';
export {InternalCustomerSegmentTemplate} from './components/InternalCustomerSegmentTemplate/InternalCustomerSegmentTemplate';
export type {InternalCustomerSegmentTemplateProps} from './components/InternalCustomerSegmentTemplate/InternalCustomerSegmentTemplate';
export {Image} from './components/Image/Image';
export type {ImageProps} from './components/Image/Image';
export {Link} from './components/Link/Link';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CustomerSegmentTemplateProps {
/* Localized description(s) of the template. */
description: string | string[];
/* DEPRECATED - Code snippet to render in the template with syntax highlighting. */
templateQuery: string;
templateQuery?: string;
/* Code snippet to render in the template with syntax highlighting. */
query: string;
/* DEPRECATED - Code snippet to insert in the segment editor. If missing, `templateQuery` will be used. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface CustomerSegmentationTemplateProps {
/* Icon identifier for the template. This property is ignored for non-1P Segmentation templates as we fallback to the app icon */
icon?: CustomerSegmentTemplateIcon;
/* DEPRECATED - Code snippet to render in the template with syntax highlighting. */
templateQuery: string;
templateQuery?: string;
/* Code snippet to render in the template with syntax highlighting. */
query: string;
/* DEPRECATED - Code snippet to insert in the segment editor. If missing, `templateQuery` will be used. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {createRemoteComponent} from '@remote-ui/core';

export const customerSegmentTemplateIcons = [
'categoriesMajor',
'firstVisitMajor',
'heartMajor',
'marketingMajor',
'checkoutMajor',
'ordersMajor',
'locationMajor',
'emailNewsletterMajor',
'firstOrderMajor',
'billingStatementDollarMajor',
'diamondAlertMajor',
'abandonedCartMajor',
'calendarMajor',
'productsMajor',
'globeMajor',
'flagMajor',
'uploadMajor',
'buyButtonMajor',
'followUpEmailMajor',
'confettiMajor',
'viewMajor',
'buyButtonMajor',
] as const;

export type CustomerSegmentTemplateIcon =
typeof customerSegmentTemplateIcons[number];

export const customerSegmentTemplateCategories = [
'firstTimeBuyers',
'highValueCustomers',
'reEngageCustomers',
'abandonedCheckout',
'purchaseBehaviour',
'location',
] as const;

export type CustomerSegmentTemplateCategory =
typeof customerSegmentTemplateCategories[number];

/**
* Reserved namespace and key for the customer standard metafield used in the template's query.
* More info - https://shopify.dev/docs/apps/custom-data/metafields/definitions/standard
*/
type CustomerStandardMetafieldDependency = 'facts.birth_date';

export interface InternalCustomerSegmentTemplateProps {
/* Localized title of the template. */
title: string;
/* Localized description(s) of the template. */
description: string | string[];
/* Icon identifier for the template. This property is ignored for non-1P Segmentation templates as we fallback to the app icon */
icon?: CustomerSegmentTemplateIcon;
/* DEPRECATED - Code snippet to render in the template with syntax highlighting. */
templateQuery?: string;
/* Code snippet to render in the template with syntax highlighting. */
query: string;
/* DEPRECATED - Code snippet to insert in the segment editor. If missing, `templateQuery` will be used. */
templateQueryToInsert?: string;
/* Code snippet to insert in the segment editor. If missing, `templateQuery` will be used. */
queryToInsert?: string;
/* DEPRECATED - List of customer standard metafield used in the template's query. */
standardMetafieldDependencies?: CustomerStandardMetafieldDependency[];
/* List of customer standard metafields or custom metafields used in the template's query. */
dependencies?: {
standardMetafields?: CustomerStandardMetafieldDependency[];
customMetafields?: string[];
};
/* DEPRECATED - ISO 8601-encoded date and time string. A "New" badge will be rendered for recently introduced templates. */
dateAdded?: string;
/* ISO 8601-encoded date and time string. A "New" badge will be rendered for recently introduced templates. */
createdOn?: string;
/* The category in which the template will be visible.
When provided, the template will show in its respective category and aggregate sections.
When missing, the template will show in the aggregate sections only */
category?: CustomerSegmentTemplateCategory;
}

/**
* Customer segment templates are used to give merchants a starting point to create segments.
*/
export const InternalCustomerSegmentTemplate = createRemoteComponent<
'InternalCustomerSegmentTemplate',
InternalCustomerSegmentTemplateProps
>('InternalCustomerSegmentTemplate');
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
extension,
InternalCustomerSegmentTemplate,
} from '@shopify/ui-extensions/admin';

export default extension(
'admin.customers.segmentation-templates.render',
(root, {i18n, __enabledFeatures}) => {
const productsPurchasedOnTagsEnabled = __enabledFeatures.includes('productsPurchasedByTags');
const productTemplate = root.createComponent(InternalCustomerSegmentTemplate, {
title: i18n.translate('product.title'),
description: i18n.translate('product.description'),
icon: 'productsMajor',
query: productsPurchasedOnTagsEnabled
? 'products_purchased(tag: (product_tag)) = true'
: 'products_purchased(id: (product_id)) = true',
queryToInsert: productsPurchasedOnTagsEnabled
? 'products_purchased(tag:'
: 'products_purchased(id:',
dateAdded: new Date('2023-01-15').toISOString(),
category: 'reEngageCustomers',
});

const locationTemplate = root.createComponent(InternalCustomerSegmentTemplate, {
title: i18n.translate('location.title'),
description: [i18n.translate('location.firstParagraph'), i18n.translate('location.secondParagraph')],
icon: 'locationMajor',
query: "customer_cities CONTAINS 'US-NY-NewYorkCity'",
category: 'location',
});

root.appendChild(productTemplate);
root.appendChild(locationTemplate);

root.mount();
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import type {
import {AnyComponentBuilder} from '../../shared';

type CustomerSegmentationTemplateComponent = AnyComponentBuilder<
Pick<Components, 'CustomerSegmentationTemplate' | 'CustomerSegmentTemplate'>
Pick<
Components,
| 'CustomerSegmentationTemplate'
| 'CustomerSegmentTemplate'
| 'InternalCustomerSegmentTemplate'
>
>;

type ProductConfigurationComponents = AnyComponentBuilder<
Expand Down

0 comments on commit f537b08

Please sign in to comment.