Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify 'shopify' template schema #6161

Merged
merged 30 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf9512a
simplify 'shopify' template schema
SimeonGriggs Apr 2, 2024
7d81841
add groups to constants
SimeonGriggs Apr 2, 2024
ca61b8f
chore(renovate): pin framer-motion to known stable (#6166)
stipsan Apr 3, 2024
e7d77da
chore(prettier): fix unformatted files 🤖 ✨ (#6168)
ecospark[bot] Apr 3, 2024
17f8b6d
chore(deps): update dependency @sanity/icons to ^2.11.6 (#6169)
renovate[bot] Apr 3, 2024
6b3a73e
chore(deps): update dependency turbo to ^1.13.2 (#6170)
renovate[bot] Apr 3, 2024
4d7896f
chore(deps): update dependency vite to ^4.5.3 (#6171)
renovate[bot] Apr 3, 2024
e4f9174
chore(lockfile): update dependency @portabletext/react to v3.0.15 (#6…
renovate[bot] Apr 3, 2024
964217f
chore(lockfile): update dependency @sanity/color to v3.0.4 (#6173)
renovate[bot] Apr 3, 2024
8b68987
chore(lockfile): update dependency @sanity/logos to v2.1.8 (#6175)
renovate[bot] Apr 3, 2024
dd51aaa
fix(deps): Update react monorepo (#6176)
renovate[bot] Apr 3, 2024
a3a8b5b
fix(deps): update dependency @sanity/client to ^6.15.9 (#6177)
renovate[bot] Apr 3, 2024
63aab83
chore(deps): update dependency use-hot-module-reload to v2 (#6180)
renovate[bot] Apr 3, 2024
eaa442c
Revert "chore(deps): update dependency use-hot-module-reload to v2 (#…
stipsan Apr 3, 2024
e9e7864
fix(deps): update dependency @sanity/ui to ^2.0.13 (#6178)
renovate[bot] Apr 3, 2024
b276e94
fix(deps): update dependency get-it to ^8.4.17 (#6179)
renovate[bot] Apr 3, 2024
bbd3702
fix(deps): pin framer-motion to the same version used by `@sanity/ui`…
stipsan Apr 3, 2024
fee980f
chore: fix typings error
stipsan Apr 3, 2024
cbfff74
chore(deps): dedupe pnpm-lock.yaml (#6184)
ecospark[bot] Apr 3, 2024
c246c29
chore(deps): lock file maintenance (#6186)
renovate[bot] Apr 3, 2024
a986388
chore: pin `@sanity/eslint-config-i18n`
stipsan Apr 3, 2024
56c743e
chore: pin `@playwright/test`
stipsan Apr 3, 2024
21eda88
chore: pin `@playwright/experimental-ct-react`
stipsan Apr 3, 2024
d63429e
chore(deps): lock file maintenance (#6187)
renovate[bot] Apr 3, 2024
f40d172
fix: use named `styled` import for better ESM runtime compat (#6185)
stipsan Apr 3, 2024
2f57c07
update store ID format
thebiggianthead Apr 3, 2024
9ae1c9d
Merge branch 'next' into feat/shopify-template-simplify
SimeonGriggs Apr 3, 2024
90eecaf
fix product item preview
SimeonGriggs Apr 3, 2024
530103c
Merge branch 'feat/shopify-template-simplify' of github.com:sanity-io…
SimeonGriggs Apr 3, 2024
579c588
merge incoming from 'next' branch
SimeonGriggs Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {colorInput} from '@sanity/color-input'
import {imageHotspotArrayPlugin} from 'sanity-plugin-hotspot-array'
import {media, mediaAssetSource} from 'sanity-plugin-media'
import {customDocumentActions} from './plugins/customDocumentActions'
import Navbar from './components/studio/Navbar'

const devOnlyPlugins = [visionTool()]

Expand Down Expand Up @@ -47,6 +48,12 @@ export default defineConfig({
},
},
},

studio: {
components: {
navbar: Navbar,
},
},
})`

const shopifyTemplate: ProjectTemplate = {
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/cli/templates/shopify/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Sanity Studio for Shopify Projects

<p><img src="https://user-images.githubusercontent.com/209129/173606241-ae6694f7-57f0-4ed7-9d05-60c563c4233b.png" width="800" /></p>
<img width="1072" alt="Sanity Studio with Shopify products" src="https://github.com/sanity-io/learn/assets/9684022/13aed6ff-a028-4c3f-bc4b-15bf9ba4c6ff">

## About

This Sanity Studio is configured for headless Shopify projects that use the official [Sanity Connect app][sanity-shopify], allowing you to extend Shopify products and collections with your own rich editorial content.

It contains examples of customizing your [structure][docs-structure], [document actions][docs-document-actions] and [input components][docs-input-components].

This studio can be used with our [Hydrogen starter][hydrogen-demo], your frontend, or anywhere else you want your e-commerce content to go.
This studio can be used with any front end, or anywhere else you want your e-commerce content to go.

## Features

This studio comes preconfigured with Shopify-friendly content schema types and a whole host of customizations to make managing Shopify data in your Sanity studio easier.
This studio comes configured with Shopify-friendly content schema types and a whole host of customizations to make managing Shopify data in your Sanity studio easier.

It also comes with several convenient layout modules which can be re-used across various pages.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'


const ShopifyIcon = () => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'

import {WarningOutlineIcon} from '@sanity/icons'
import {StringFieldProps} from 'sanity'
import {Box, Card, Flex, Stack, Text} from '@sanity/ui'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Box, Button, Card, Flex} from '@sanity/ui'
import type {NavbarProps} from 'sanity'

import {SHOPIFY_STORE_ID} from '../../constants'
import ShopifyIcon from '../icons/Shopify'

export default function Navbar(props: NavbarProps) {
if (!SHOPIFY_STORE_ID) return props.renderDefault(props)

return (
<Card>
<Flex align="center">
<Box flex={1}>{props.renderDefault(props)}</Box>
<Card paddingY={2} paddingRight={2} borderBottom={true}>
<Button
as="a"
href={`https://admin.shopify.com/store/${SHOPIFY_STORE_ID}`}
mode="bleed"
title="Open Shopify Admin"
target="_blank"
padding={1}
>
<ShopifyIcon />
</Button>
</Card>
</Flex>
</Card>
)
}
32 changes: 31 additions & 1 deletion packages/@sanity/cli/templates/shopify/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Currency code (ISO 4217) to use when displaying prices in the studio

import ShopifyIcon from "./components/icons/Shopify"
import { ColorWheelIcon, ComposeIcon, SearchIcon } from '@sanity/icons'

// https://en.wikipedia.org/wiki/ISO_4217
export const DEFAULT_CURRENCY_CODE = 'USD'

Expand Down Expand Up @@ -26,6 +30,32 @@ export const PAGE_REFERENCES = [
export const SANITY_API_VERSION = '2022-10-25'

// Your Shopify store ID.
// This is your unique store URL (e.g. 'my-store-name.myshopify.com').
// This is the ID in your Shopify admin URL (e.g. 'my-store-name' in https://admin.shopify.com/store/my-store-name).
// You only need to provide the ID, not the full URL.
// Set this to enable helper links in document status banners and shortcut links on products and collections.
export const SHOPIFY_STORE_ID = ''

// Field groups used through schema types
export const GROUPS = [
{
name: 'theme',
title: 'Theme',
icon: ColorWheelIcon,
},
{
default: true,
name: 'editorial',
title: 'Editorial',
icon: ComposeIcon
},
{
name: 'shopifySync',
title: 'Shopify sync',
icon: ShopifyIcon,
},
{
name: 'seo',
title: 'SEO',
icon: SearchIcon
},
]
13 changes: 6 additions & 7 deletions packages/@sanity/cli/templates/shopify/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Read more about [document actions][docs-document-actions].

`/plugins/customDocumentActions/shopifyDelete.tsx`

Delete a product document including all its associated variants in your Sanity Content Lake. Without this document action, one would have to delete all variant document one-by-one.
Delete a product document including all its associated variants in your Sanity Content Lake. Without this document action, one would have to delete all variant documents one-by-one.

### Edit in Shopify shortcut

Expand All @@ -96,12 +96,11 @@ A simple wrapper around a regular [string input](string-input) that uses the val
**Usage:**

```javascript
{
defineField({
name: 'title',
title: 'Title',
type: 'placeholderString',
options: { field: 'store.title' }
},
}),
```

### Shopify document status (for collections, products and product variants)
Expand Down Expand Up @@ -129,12 +128,12 @@ Since we are using certain product fields from Shopify as the source of truth (s
**Usage**

```javascript
{
defineField({
title: 'Slug',
name: 'slugProxy',
type: 'proxyString',
options: { field: 'store.slug.current' }
}
options: {field: 'store.slug.current'},
})
```

### Shopify document status (preview component)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
import React from 'react'
import {defineField, defineType} from 'sanity'

import {defineArrayMember, defineField, defineType} from 'sanity'
import {PackageIcon} from '@sanity/icons'
import {getExtension} from '@sanity/asset-utils'
import pluralize from 'pluralize-esm'
import CollectionHiddenInput from '../../components/inputs/CollectionHidden'
import ShopifyIcon from '../../components/icons/Shopify'
import ShopifyDocumentStatus from '../../components/media/ShopifyDocumentStatus'
import { GROUPS } from '../../constants'

const GROUPS = [
{
name: 'theme',
title: 'Theme',
},
{
default: true,
name: 'editorial',
title: 'Editorial',
},
{
name: 'shopifySync',
title: 'Shopify sync',
icon: ShopifyIcon,
},
{
name: 'seo',
title: 'SEO',
},
]

export default defineType({
export const collectionType = defineType({
name: 'collection',
title: 'Collection',
type: 'document',
icon: PackageIcon,
groups: GROUPS,
fields: [
// Product hidden status
defineField({
name: 'hidden',
type: 'string',
Expand All @@ -47,29 +25,24 @@ export default defineType({
return !isDeleted
},
}),
// Title (proxy)
defineField({
name: 'titleProxy',
title: 'Title',
type: 'proxyString',
options: {field: 'store.title'},
}),
// Slug (proxy)
defineField({
name: 'slugProxy',
title: 'Slug',
type: 'proxyString',
options: {field: 'store.slug.current'},
}),
// Color theme
defineField({
name: 'colorTheme',
title: 'Color theme',
type: 'reference',
to: [{type: 'colorTheme'}],
group: 'theme',
}),
// Vector
defineField({
name: 'vector',
title: 'Vector artwork',
Expand All @@ -93,49 +66,41 @@ export default defineType({
return true
}),
}),
// Show hero
defineField({
name: 'showHero',
title: 'Show hero',
type: 'boolean',
description: 'If disabled, page title will be displayed instead',
group: 'editorial',
}),
// Hero
defineField({
name: 'hero',
title: 'Hero',
type: 'hero.collection',
type: 'hero',
hidden: ({document}) => !document?.showHero,
group: 'editorial',
}),
// Modules
defineField({
name: 'modules',
title: 'Modules',
type: 'array',
description: 'Editorial modules to associate with this collection',
of: [
{type: 'module.callout'},
{type: 'module.callToAction'},
{type: 'module.image'},
{type: 'module.instagram'},
defineArrayMember({type: 'callout'}),
defineArrayMember({type: 'callToAction'}),
defineArrayMember({type: 'image'}),
defineArrayMember({type: 'instagram'}),
],
group: 'editorial',
}),
// Shopify collection
defineField({
name: 'store',
title: 'Shopify',
type: 'shopifyCollection',
description: 'Collection data from Shopify (read-only)',
group: 'shopifySync',
}),
// SEO
defineField({
name: 'seo',
title: 'SEO',
type: 'seo.shopify',
type: 'seo',
group: 'seo',
}),
],
Expand All @@ -158,8 +123,7 @@ export default defineType({
rules: 'store.rules',
title: 'store.title',
},
prepare(selection) {
const {imageUrl, isDeleted, rules, title} = selection
prepare({imageUrl, isDeleted, rules, title}) {
const ruleCount = rules?.length || 0

return {
Expand Down
Loading
Loading