Skip to content

Commit

Permalink
Move metafield and useApplyMetafieldsChange definition to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
sirgalleto committed Apr 17, 2024
1 parent 2bbad0c commit e9c1560
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 77 deletions.
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 '../shared';

interface OrderRoutingRule {
label: string;
Expand Down

This file was deleted.

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 '../shared';
import {Data} from './data';

export interface OrderRoutingRuleApi<ExtensionTarget extends AnyExtensionTarget>
Expand Down
76 changes: 76 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,79 @@ export interface Data {
*/
selected: {id: string}[];
}

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;

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

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

type MetafieldsChange =
| MetafieldUpdateChange
| MetafieldRemoveChange
| MetafieldUpdateChange[]
| MetafieldRemoveChange[];

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;
}

0 comments on commit e9c1560

Please sign in to comment.