Skip to content

Commit

Permalink
fix: attach workspace title to comments notification context (#4992)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon authored and hermanwikner committed Oct 18, 2023
1 parent 946c09c commit 0f535c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useCommentOperations(

const authorId = currentUser?.id

const {title, url, toolName} = useNotificationTarget({
const {documentTitle, toolName, url, workspaceTitle} = useNotificationTarget({
documentId,
documentType,
})
Expand All @@ -76,7 +76,11 @@ export function useCommentOperations(
payload: {
workspace,
},
notification: {title, url},
notification: {
documentTitle,
url,
workspaceTitle,
},
tool: toolName,
},
target: {
Expand Down Expand Up @@ -114,14 +118,15 @@ export function useCommentOperations(
client,
dataset,
documentId,
documentTitle,
documentType,
onCreate,
onCreateError,
projectId,
title,
toolName,
url,
workspace,
workspaceTitle,
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ interface NotificationTargetHookOptions {
}

interface NotificationTargetHookValue {
url: string
title: string
documentTitle: string
toolName: string
url: string
workspaceTitle: string
}

/** @internal */
Expand All @@ -21,7 +22,7 @@ export function useNotificationTarget(
): NotificationTargetHookValue {
const {documentId, documentType} = opts || {}
const schemaType = useSchema().get(documentType)
const {basePath, tools} = useWorkspace()
const {basePath, title: workspaceTitle, tools} = useWorkspace()

const activeToolName = useRouterState(
useCallback(
Expand All @@ -42,16 +43,17 @@ export function useNotificationTarget(
}, [documentId, documentPreviewStore, schemaType])

const {published, draft} = previewState || {}
const notificationTitle = (draft?.title || published?.title || 'Sanity document') as string
const documentTitle = (draft?.title || published?.title || 'Sanity document') as string

const currentUrl = new URL(window.location.href)
const deskToolSegment = currentUrl.pathname.split('/').slice(2, 3).join('')
currentUrl.pathname = `${basePath}/${deskToolSegment}/__edit__${documentId},type=${documentType}`
const notificationUrl = currentUrl.toString()

return {
url: notificationUrl,
title: notificationTitle,
documentTitle,
toolName: activeTool?.name || '',
url: notificationUrl,
workspaceTitle,
}
}
5 changes: 3 additions & 2 deletions packages/sanity/src/desk/comments/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export interface CommentPath {
interface CommentContext {
tool: string
payload?: Record<string, unknown>
notification: {
title: string
notification?: {
documentTitle: string
url: string
workspaceTitle: string
}
}

Expand Down

0 comments on commit 0f535c3

Please sign in to comment.