Skip to content

Commit

Permalink
Add discount functions settings api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
devisscher committed Dec 18, 2024
1 parent c2092ff commit 1248670
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-knives-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

Add discount function settings api
1 change: 1 addition & 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,4 @@ 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 {DiscountFunctionSettingsApi} from './api/discount-function-settings/discount-function-settings';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ interface Metafield {
value: string;
type: string;
}

interface Validation {
/**
* the validation's gid when active in a shop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,4 @@
const supportedDefinitionTypes = [
'boolean',
'collection_reference',
'color',
'date',
'date_time',
'dimension',
'file_reference',
'json',
'metaobject_reference',
'mixed_reference',
'money',
'multi_line_text_field',
'number_decimal',
'number_integer',
'page_reference',
'product_reference',
'rating',
'rich_text_field',
'single_line_text_field',
'product_taxonomy_value_reference',
'url',
'variant_reference',
'volume',
'weight',
'list.collection_reference',
'list.color',
'list.date',
'list.date_time',
'list.dimension',
'list.file_reference',
'list.metaobject_reference',
'list.mixed_reference',
'list.number_decimal',
'list.number_integer',
'list.page_reference',
'list.product_reference',
'list.rating',
'list.single_line_text_field',
'list.url',
'list.variant_reference',
'list.volume',
'list.weight',
] as const;

export type SupportedDefinitionType = (typeof supportedDefinitionTypes)[number];
import {SupportedDefinitionType} from '../shared';

interface MetafieldUpdateChange {
type: 'updateMetafield';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';

const data: ReferenceEntityTemplateSchema = {
name: 'Discount Function Settings API',
description:
'This API is available to Discount Function Settings extensions. Refer to the [tutorial](/docs/apps/build/discounts/build-ui-extension) for more information. Note that the [`FunctionSettings`](/docs/api/admin-extensions/components/forms/functionsettings) component is required to build Discount Function Settings extensions.',
isVisualComponent: false,
type: 'API',
definitions: [
{
title: 'applyMetafieldChange',
description: 'Applies a change to the discount function settings.',
type: 'ApplyMetafieldChange',
},
{
title: 'data',
description:
'The object exposed to the extension that contains the discount function settings.',
type: 'DiscountFunctionSettingsData',
},
],
category: 'API',
subCategory: 'Target APIs',
related: [],
};

export default data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type {StandardApi} from '../standard/standard';
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets';

import {ApplyMetafieldChange} from './metafields';
import {DiscountFunctionSettingsData} from './launch-options';

export interface DiscountFunctionSettingsApi<
ExtensionTarget extends AnyExtensionTarget,
> extends StandardApi<ExtensionTarget> {
/**
* Applies a change to the discount function settings.
*/
applyMetafieldChange: ApplyMetafieldChange;
data: DiscountFunctionSettingsData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interface Metafield {
description?: string;
id: string;
namespace: string;
key: string;
value: string;
type: string;
}

export enum DiscountClass {
Product = 'PRODUCT',
Order = 'ORDER',
Shipping = 'SHIPPING',
}

interface Discount {
/**
* the discount's gid
*/
id: string;
}

/**
* The object that exposes the validation with its settings.
*/
export interface DiscountFunctionSettingsData {
id: Discount;
metafields: Metafield[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {SupportedDefinitionType} from '../shared';

interface MetafieldUpdateChange {
type: 'updateMetafield';
key: string;
namespace?: string;
value: string | number;
valueType?: SupportedDefinitionType;
}

interface MetafieldRemoveChange {
type: 'removeMetafield';
key: string;
namespace: string;
}

type MetafieldChange = MetafieldUpdateChange | MetafieldRemoveChange;
interface MetafieldChangeResultError {
type: 'error';
message: string;
}
interface MetafieldChangeSuccess {
type: 'success';
}
type MetafieldChangeResult =
| MetafieldChangeSuccess
| MetafieldChangeResultError;

export type ApplyMetafieldChange = (
change: MetafieldChange,
) => Promise<MetafieldChangeResult>;
44 changes: 44 additions & 0 deletions packages/ui-extensions/src/surfaces/admin/api/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,47 @@ export interface Data {
*/
selected: {id: string}[];
}

export type SupportedDefinitionType =
| 'boolean'
| 'collection_reference'
| 'color'
| 'date'
| 'date_time'
| 'dimension'
| 'file_reference'
| 'json'
| 'metaobject_reference'
| 'mixed_reference'
| 'money'
| 'multi_line_text_field'
| 'number_decimal'
| 'number_integer'
| 'page_reference'
| 'product_reference'
| 'rating'
| 'rich_text_field'
| 'single_line_text_field'
| 'product_taxonomy_value_reference'
| 'url'
| 'variant_reference'
| 'volume'
| 'weight'
| 'list.collection_reference'
| 'list.color'
| 'list.date'
| 'list.date_time'
| 'list.dimension'
| 'list.file_reference'
| 'list.metaobject_reference'
| 'list.mixed_reference'
| 'list.number_decimal'
| 'list.number_integer'
| 'list.page_reference'
| 'list.product_reference'
| 'list.rating'
| 'list.single_line_text_field'
| 'list.url'
| 'list.variant_reference'
| 'list.volume'
| 'list.weight';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ProductVariantDetailsConfigurationApi,
OrderRoutingRuleApi,
ValidationSettingsApi,
DiscountFunctionSettingsApi,
} from './api';
import {AnyComponentBuilder} from '../../shared';
import {PurchaseOptionsCardConfigurationApi} from './api/purchase-options-card-action/purchase-options-card-action';
Expand Down Expand Up @@ -100,7 +101,7 @@ export interface ExtensionTargets {
* See the [list of available components](/docs/api/admin-extensions/components).
*/
'admin.discount-details.function-settings.render': RenderExtension<
BlockExtensionApi<'admin.discount-details.function-settings.render'>,
DiscountFunctionSettingsApi<'admin.discount-details.function-settings.render'>,
AllComponents
>;

Expand Down

0 comments on commit 1248670

Please sign in to comment.