From 46ebcb36d65ca345ce2858b4ac877d9f21507afc Mon Sep 17 00:00:00 2001 From: Joseph Thomas Date: Wed, 27 May 2020 19:37:04 -0700 Subject: [PATCH] feat(sanity-plugin): use syncByID instead of byHandle --- .../src/ShopifyTool/Sync/Sync.tsx | 25 ++++--------------- .../ShopifySourceCollectionPreview.tsx | 8 +++--- .../ShopifySourceProductPreview.tsx | 8 +++--- .../src/sanityDocuments/collection.tsx | 6 ++--- .../src/sanityDocuments/product.tsx | 4 +-- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/packages/sanity-plugin/src/ShopifyTool/Sync/Sync.tsx b/packages/sanity-plugin/src/ShopifyTool/Sync/Sync.tsx index eb8e31b..6c4e969 100644 --- a/packages/sanity-plugin/src/ShopifyTool/Sync/Sync.tsx +++ b/packages/sanity-plugin/src/ShopifyTool/Sync/Sync.tsx @@ -12,8 +12,7 @@ interface State { } export interface SyncRenderProps extends State { - syncProductByHandle: (handle: string) => Promise - syncCollectionByHandle: (handle: string) => Promise + syncItemByID: (id: string) => Promise syncProducts: () => Promise syncCollections: () => Promise syncAll: () => Promise @@ -94,17 +93,10 @@ class SyncBase extends React.Component { /** Public Methods */ - public syncProductByHandle = async (handle: string) => { + public syncItemByID = async (id: string) => { await this.reset() this.setState({ syncState: 'syncing' as 'syncing' }) - this.props.syncingClient.syncProductByHandle(handle) - this.setState({ syncState: 'complete' as 'complete' }) - } - - public syncCollectionByHandle = async (handle: string) => { - await this.reset() - this.setState({ syncState: 'syncing' as 'syncing' }) - this.props.syncingClient.syncProductByHandle(handle) + this.props.syncingClient.syncItemByID(id) this.setState({ syncState: 'complete' as 'complete' }) } @@ -131,18 +123,11 @@ class SyncBase extends React.Component { public render() { const { children } = this.props - const { - syncProductByHandle, - syncCollectionByHandle, - syncProducts, - syncCollections, - syncAll, - } = this + const { syncItemByID, syncProducts, syncCollections, syncAll } = this const renderProps = { ...this.state, - syncProductByHandle, - syncCollectionByHandle, + syncItemByID, syncProducts, syncCollections, syncAll, diff --git a/packages/sanity-plugin/src/components/ShopifySourceCollectionPreview.tsx b/packages/sanity-plugin/src/components/ShopifySourceCollectionPreview.tsx index c4ae573..26fad9d 100644 --- a/packages/sanity-plugin/src/components/ShopifySourceCollectionPreview.tsx +++ b/packages/sanity-plugin/src/components/ShopifySourceCollectionPreview.tsx @@ -19,13 +19,13 @@ const ShopifySourceCollectionPreviewInner = ({ const { value: syncStateValue } = syncState if (!value) return null - const syncCollectionByHandle = syncingClient - ? syncingClient.syncCollectionByHandle + const syncItemByID = syncingClient + ? syncingClient.syncItemByID : () => undefined - const { title, handle, description } = value + const { title, id, description } = value const reSync = async () => { - syncCollectionByHandle(handle) + syncItemByID(id) } if (syncState.context.error) diff --git a/packages/sanity-plugin/src/components/ShopifySourceProductPreview.tsx b/packages/sanity-plugin/src/components/ShopifySourceProductPreview.tsx index 2cfcef6..a67d098 100644 --- a/packages/sanity-plugin/src/components/ShopifySourceProductPreview.tsx +++ b/packages/sanity-plugin/src/components/ShopifySourceProductPreview.tsx @@ -20,12 +20,12 @@ const ShopifySourceProductPreviewInner = ({ const { value: syncStateValue } = syncState if (!value) return null - const syncProductByHandle = syncingClient - ? syncingClient.syncProductByHandle + const syncItemByID = syncingClient + ? syncingClient.syncItemByID : () => undefined const { title, - handle, + id, tags, productType, availableForSale, @@ -38,7 +38,7 @@ const ShopifySourceProductPreviewInner = ({ }` const reSync = async () => { - syncProductByHandle(handle) + syncItemByID(id) } if (syncState.context.error) diff --git a/packages/sanity-plugin/src/sanityDocuments/collection.tsx b/packages/sanity-plugin/src/sanityDocuments/collection.tsx index ec3524f..e9bdc6a 100644 --- a/packages/sanity-plugin/src/sanityDocuments/collection.tsx +++ b/packages/sanity-plugin/src/sanityDocuments/collection.tsx @@ -43,9 +43,9 @@ export const createCollectionDocument = ({ { title: 'Title', name: 'title', - readOnly: true, + // readOnly: true, type: 'string', - hidden: true, + // hidden: true, ...namedFields.title, }, { @@ -80,7 +80,7 @@ export const createCollectionDocument = ({ name: 'products', type: 'array', description: 'Synced from Shopify', - readOnly: true, + // readOnly: true, of: [ { type: 'reference', diff --git a/packages/sanity-plugin/src/sanityDocuments/product.tsx b/packages/sanity-plugin/src/sanityDocuments/product.tsx index 99d3bc6..71177bb 100644 --- a/packages/sanity-plugin/src/sanityDocuments/product.tsx +++ b/packages/sanity-plugin/src/sanityDocuments/product.tsx @@ -172,9 +172,9 @@ export const createProductDocument = ({ { title: 'Title', name: 'title', - readOnly: true, + // readOnly: true, type: 'string', - hidden: true, + // hidden: true, ...namedFields.title, }, {