-
Notifications
You must be signed in to change notification settings - Fork 37
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 #2534 from Shopify/discount-function-settings-api
Add discount functions settings api docs
- Loading branch information
Showing
10 changed files
with
155 additions
and
48 deletions.
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 discount function settings api |
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
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
47 changes: 1 addition & 46 deletions
47
packages/ui-extensions/src/surfaces/admin/api/checkout-rules/metafields.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
27 changes: 27 additions & 0 deletions
27
...sions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.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,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; |
15 changes: 15 additions & 0 deletions
15
...xtensions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.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,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; | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/launch-options.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,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[]; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/metafields.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,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>; |
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
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