Skip to content

Commit

Permalink
feat(sanity-plugin): use syncByID instead of byHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
good-idea committed May 28, 2020
1 parent 5a3b997 commit 46ebcb3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
25 changes: 5 additions & 20 deletions packages/sanity-plugin/src/ShopifyTool/Sync/Sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ interface State {
}

export interface SyncRenderProps extends State {
syncProductByHandle: (handle: string) => Promise<void>
syncCollectionByHandle: (handle: string) => Promise<void>
syncItemByID: (id: string) => Promise<void>
syncProducts: () => Promise<void>
syncCollections: () => Promise<void>
syncAll: () => Promise<void>
Expand Down Expand Up @@ -94,17 +93,10 @@ class SyncBase extends React.Component<Props, State> {

/** 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' })
}

Expand All @@ -131,18 +123,11 @@ class SyncBase extends React.Component<Props, State> {

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +38,7 @@ const ShopifySourceProductPreviewInner = ({
}`

const reSync = async () => {
syncProductByHandle(handle)
syncItemByID(id)
}

if (syncState.context.error)
Expand Down
6 changes: 3 additions & 3 deletions packages/sanity-plugin/src/sanityDocuments/collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const createCollectionDocument = ({
{
title: 'Title',
name: 'title',
readOnly: true,
// readOnly: true,
type: 'string',
hidden: true,
// hidden: true,
...namedFields.title,
},
{
Expand Down Expand Up @@ -80,7 +80,7 @@ export const createCollectionDocument = ({
name: 'products',
type: 'array',
description: 'Synced from Shopify',
readOnly: true,
// readOnly: true,
of: [
{
type: 'reference',
Expand Down
4 changes: 2 additions & 2 deletions packages/sanity-plugin/src/sanityDocuments/product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export const createProductDocument = ({
{
title: 'Title',
name: 'title',
readOnly: true,
// readOnly: true,
type: 'string',
hidden: true,
// hidden: true,
...namedFields.title,
},
{
Expand Down

0 comments on commit 46ebcb3

Please sign in to comment.