Skip to content

Commit

Permalink
Update sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasKn committed Jan 10, 2024
1 parent f0c64f5 commit ef402c2
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 429 deletions.
2 changes: 1 addition & 1 deletion create-headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"picocolors": "^1.0.0",
"proxy-agent": "^6.3.1",
"recursive-readdir": "^2.2.3",
"sanity": "^3.23.4",
"sanity": "^3.24.1",
"tar-fs": "^3.0.4"
}
}
416 changes: 108 additions & 308 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/hydrogen-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"framer-motion": "^10.18.0",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"groq": "^3.23.4",
"groq": "^3.24.1",
"groqd": "^0.15.10",
"isbot": "^4.3.0",
"react": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions templates/hydrogen-theme/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"@sanity/language-filter": "^3.2.1",
"@sanity/presentation": "^1.5.1",
"@sanity/ui": "2.0.0-beta.15",
"@sanity/util": "^3.23.4",
"@sanity/util": "^3.24.1",
"@sanity/uuid": "^3.0.2",
"@sanity/vision": "^3.23.4",
"@sanity/vision": "^3.24.1",
"@shopify/polaris": "^12.7.0",
"@shopify/polaris-icons": "^7.13.0",
"groq": "^3.23.4",
"groq": "^3.24.1",
"lodash": "^4.17.21",
"lodash.get": "^4.4.2",
"lucide-react": "^0.309.0",
Expand All @@ -38,7 +38,7 @@
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"rxjs": "^7.8.1",
"sanity": "^3.23.4",
"sanity": "^3.24.1",
"sanity-plugin-internationalized-array": "^1.10.4",
"sanity-plugin-media": "^2.2.4",
"styled-components": "^6.1.8"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,102 +1,107 @@
import React, {useState} from 'react'
import {TrashIcon} from '@sanity/icons'
import {Stack, Text, useToast} from '@sanity/ui'
import React, {useState} from 'react';
import {TrashIcon} from '@sanity/icons';
import {Stack, Text, useToast} from '@sanity/ui';
import {
type DocumentActionDescription,
type DocumentActionConfirmDialogProps,
useClient,
} from 'sanity'
import {useRouter} from 'sanity/router'
import type {ShopifyDocument, ShopifyDocumentActionProps} from './types'
import {projectDetails} from '../../project.details'
} from 'sanity';
import {useRouter} from 'sanity/router';
import type {ShopifyDocument, ShopifyDocumentActionProps} from './types';
import {projectDetails} from '../../project.details';

const apiVersion = projectDetails.apiVersion
const apiVersion = projectDetails.apiVersion;

export default (props: ShopifyDocumentActionProps): DocumentActionDescription | undefined => {
export default (
props: ShopifyDocumentActionProps,
): DocumentActionDescription | undefined => {
const {
draft,
onComplete,
type,
published,
}: {
draft: ShopifyDocument
published: ShopifyDocument
type: string
onComplete: () => void
} = props
draft: ShopifyDocument;
published: ShopifyDocument;
type: string;
onComplete: () => void;
} = props;

const [dialogOpen, setDialogOpen] = useState(false)
const [dialogOpen, setDialogOpen] = useState(false);

const router = useRouter()
const toast = useToast()
const client = useClient({apiVersion})
const router = useRouter();
const toast = useToast();
const client = useClient({apiVersion});

let dialog: DocumentActionConfirmDialogProps | null = null
let dialog: DocumentActionConfirmDialogProps | null = null;

if (type === 'product') {
dialog = {
message: (
<Stack space={4}>
<Text>Delete the current product and all associated variants in your dataset.</Text>
<Text>
Delete the current product and all associated variants in your
dataset.
</Text>
<Text weight="medium">No content on Shopify will be deleted.</Text>
<Text>
To completely hide or remove a product from the storefront, you also need to remove it
from Shopify.
To completely hide or remove a product from the storefront, you also
need to remove it from Shopify.
</Text>
</Stack>
),
onCancel: onComplete,
onConfirm: async () => {
const productId = published?.store?.id
const productId = published?.store?.id;

// Find product variant documents with matching Shopify Product ID
let productVariantIds: string[] = []
let productVariantIds: string[] = [];
if (productId) {
productVariantIds = await client.fetch(
`*[
_type == "productVariant"
&& store.productId == $productId
]._id`,
{productId}
)
{productId},
);
}

// Delete current document (including draft)
const transaction = client.transaction()
const transaction = client.transaction();
if (published?._id) {
transaction.delete(published._id)
transaction.delete(published._id);
}
if (draft?._id) {
transaction.delete(draft._id)
transaction.delete(draft._id);
}

// Delete all product variants with matching IDs
productVariantIds?.forEach((documentId) => {
if (documentId) {
transaction.delete(documentId)
transaction.delete(`drafts.${documentId}`)
transaction.delete(documentId);
transaction.delete(`drafts.${documentId}`);
}
})
});

try {
await transaction.commit()
await transaction.commit();
// Navigate back to products root
router.navigateUrl({path: '/desk/products'})
router.navigateUrl({path: '/structure/products'});
} catch (err) {
let message = 'Unknown Error'
if (err instanceof Error) message = err.message
let message = 'Unknown Error';
if (err instanceof Error) message = err.message;

toast.push({
status: 'error',
title: message,
})
});
} finally {
// Signal that the action is complete
onComplete()
onComplete();
}
},
type: 'confirm',
}
};
}

if (type === 'collection') {
Expand All @@ -106,45 +111,45 @@ export default (props: ShopifyDocumentActionProps): DocumentActionDescription |
<Text>Delete the current collection in your dataset.</Text>
<Text weight="medium">No content on Shopify will be deleted.</Text>
<Text>
To completely hide or remove a collection from the storefront, you also need to remove
it from Shopify.
To completely hide or remove a collection from the storefront, you
also need to remove it from Shopify.
</Text>
</Stack>
),
onCancel: onComplete,
onConfirm: async () => {
// Delete current document (including draft)
const transaction = client.transaction()
const transaction = client.transaction();
if (published?._id) {
transaction.delete(published._id)
transaction.delete(published._id);
}
if (draft?._id) {
transaction.delete(draft._id)
transaction.delete(draft._id);
}

try {
await transaction.commit()
await transaction.commit();
// Navigate back to collections root
router.navigateUrl({path: '/desk/collections'})
router.navigateUrl({path: '/structure/collections'});
} catch (err) {
let message = 'Unknown Error'
if (err instanceof Error) message = err.message
let message = 'Unknown Error';
if (err instanceof Error) message = err.message;

toast.push({
status: 'error',
title: message,
})
});
} finally {
// Signal that the action is complete
onComplete()
onComplete();
}
},
type: 'confirm',
}
};
}

if (!dialog) {
return
return;
}

return {
Expand All @@ -154,5 +159,5 @@ export default (props: ShopifyDocumentActionProps): DocumentActionDescription |
label: 'Delete',
onHandle: () => setDialogOpen(true),
shortcut: 'Ctrl+Alt+D',
}
}
};
};
8 changes: 4 additions & 4 deletions templates/hydrogen-theme/studio/sanity.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defineConfig, isDev} from 'sanity';
import {deskTool} from 'sanity/desk';
import {structureTool} from 'sanity/structure';
import {visionTool} from '@sanity/vision';
import {internationalizedArray} from 'sanity-plugin-internationalized-array';
import {media, mediaAssetSource} from 'sanity-plugin-media';
Expand All @@ -11,11 +11,11 @@ import {presentationTool} from '@sanity/presentation';
import {languageFilter} from '@sanity/language-filter';

import {schemaTypes} from './schemas';
import {defaultDocumentNode, structure} from './desk';
import {defaultDocumentNode, structure} from './structure';
import {projectDetails} from './project.details';
import {getAllLanguages} from '../countries';
import {customDocumentActions} from './plugins/customDocumentActions';
import {singletonActions, singletonsTypes} from './desk/singletons';
import {singletonActions, singletonsTypes} from './structure/singletons';
import {locate} from './presentation/locate';
import {PreviewIcon} from './components/icons/Preview';

Expand All @@ -42,7 +42,7 @@ export default defineConfig({
rangeSlider(),
colorPicker(),
codeInput(),
deskTool({structure, defaultDocumentNode}),
structureTool({structure, defaultDocumentNode}),
customDocumentActions(),
media(),
presentationTool({
Expand Down
11 changes: 6 additions & 5 deletions templates/hydrogen-theme/studio/schemas/documents/blogPost.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {defineField, defineType} from 'sanity'
import {SlugInt, validateIntSlug} from '../../utils/slug'
import {defineField, defineType} from 'sanity';
import {SlugInt, validateIntSlug} from '../../utils/slug';

export default defineType({
name: 'blogPost',
title: 'Blog posts',
type: 'document',
__experimental_formPreviewTitle: false,
fields: [
defineField({
name: 'title',
Expand All @@ -21,7 +22,7 @@ export default defineType({
title: 'Slug',
validation: (Rule) =>
Rule.required().custom((slugArray: SlugInt[], context) =>
validateIntSlug({slugArray, context})
validateIntSlug({slugArray, context}),
),
}),
],
Expand All @@ -32,7 +33,7 @@ export default defineType({
prepare({title}) {
return {
title: title?.[0]?.value || 'No title',
}
};
},
},
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default defineType({
name: 'collection',
title: 'Collection',
type: 'document',
__experimental_formPreviewTitle: false,
icon: PackageIcon,
groups: GROUPS,
fields: [
Expand Down
1 change: 1 addition & 0 deletions templates/hydrogen-theme/studio/schemas/documents/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineType({
name: 'colorScheme',
title: 'Color schemes',
type: 'document',
__experimental_formPreviewTitle: false,
icon: IconPalette,
preview: {
select: {
Expand Down
1 change: 1 addition & 0 deletions templates/hydrogen-theme/studio/schemas/documents/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default defineType({
name: 'page',
title: 'Pages',
type: 'document',
__experimental_formPreviewTitle: false,
fields: [
defineField({
name: 'title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineType({
name: 'product',
title: 'Product',
type: 'document',
__experimental_formPreviewTitle: false,
groups: GROUPS,
fields: [
defineField({
Expand Down
Loading

0 comments on commit ef402c2

Please sign in to comment.