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

fix: attach workspace title to comments notification context #4992

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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
Loading