Skip to content

Commit

Permalink
[desk-tool] Minor tweaks: production preview (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 30, 2018
1 parent 27c6f19 commit 2f1c2c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/@sanity/desk-tool/src/pane/Editor.js
Expand Up @@ -54,6 +54,7 @@ const getDiscardItem = (draft, published) => ({
action: 'discard',
title: 'Discard changes…',
icon: UndoIcon,
divider: true,
isDisabled: !draft || !published
})

Expand Down Expand Up @@ -83,12 +84,13 @@ const getInspectItem = (draft, published) => ({
})

const getProductionPreviewItem = (draft, published) => {
if (!resolveProductionPreviewUrl) {
const snapshot = draft || published
if (!snapshot || !resolveProductionPreviewUrl) {
return null
}
let previewUrl
try {
previewUrl = resolveProductionPreviewUrl(draft || published)
previewUrl = resolveProductionPreviewUrl(snapshot)
} catch (error) {
error.message = `An error was thrown while trying to get production preview url: ${error.message}`
// eslint-disable-next-line no-console
Expand All @@ -100,19 +102,17 @@ const getProductionPreviewItem = (draft, published) => {
action: 'production-preview',
title: <span>Open preview <code className={styles.hotkey}>Ctrl+Alt+O</code></span>,
icon: PublicIcon,
divider: true,
isDisabled: !(draft || published),
url: previewUrl
}
}

const getMenuItems = (draft, published) => ([
getProductionPreviewItem,
getDiscardItem,
getUnpublishItem,
getDuplicateItem,
getDeleteItem,
getInspectItem,
getProductionPreviewItem
getInspectItem
])
.map(fn => fn(draft, published))
.filter(Boolean)
Expand Down
2 changes: 1 addition & 1 deletion packages/test-studio/src/resolveProductionUrl.js
@@ -1,4 +1,4 @@
const PREVIEW_TYPES = ['document', 'author']
const PREVIEW_TYPES = ['book', 'author']

export default function resolveProductionUrl(document) {
return PREVIEW_TYPES.includes(document._type) && `https://example.com/preview/${document._id}`
Expand Down

0 comments on commit 2f1c2c0

Please sign in to comment.