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

feat(desk): implement comments (beta) #4886

Merged
merged 102 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
188f408
feat: comments wip
hermanwikner Sep 11, 2023
36c982c
add handle to commentslist, scroll down to comment fix
hermanwikner Sep 14, 2023
f544ede
fix(comments): only calculate current caret element on demand (#4935)
robinpyon Sep 15, 2023
c2c9bd2
feat(comments): minor UI updates (#4929)
robinpyon Sep 15, 2023
2bc5e87
feat: improve comment breadcrumbs
hermanwikner Sep 18, 2023
8dffbad
feat: disable replying/creating new comments when resolved
hermanwikner Sep 18, 2023
7871bbc
feat: scroll to comment when opening inspector
hermanwikner Sep 18, 2023
898248e
feat: use correct feature key in `useCommentsEnabled`
hermanwikner Sep 18, 2023
447bbff
refactor: scroll to thread, feature enable check, build breadcrumbs
hermanwikner Sep 20, 2023
d789ccc
feat: ui updates
hermanwikner Sep 25, 2023
c68f8b3
dev(test-studio): add comments debug schema
hermanwikner Sep 26, 2023
09b28d8
feat: ui updates, refactor, add array item schema title in breadcrumbs
hermanwikner Sep 26, 2023
8f544e5
refactor(comments): inline text filtering for mentions menu
skogsmaskin Sep 15, 2023
d3dd036
refactor(comments): remove unused 'expanded' context
skogsmaskin Sep 27, 2023
7891a0f
refactor(comments): introduce focus to end of content as explicit fn
skogsmaskin Sep 27, 2023
bb8d3b9
fix(comments): fix issue with focusing editor through effect
skogsmaskin Sep 27, 2023
41e36f4
feat: validate comments against schema and document value
hermanwikner Sep 29, 2023
bf82279
dev(test-studio): update comments debug schema
hermanwikner Sep 29, 2023
93d938a
feat: improve comment breadcrumbs
hermanwikner Sep 18, 2023
8f24b24
refactor(comments): remove unused 'expanded' context
skogsmaskin Sep 27, 2023
d2f5456
fix: resolve conflicts
hermanwikner Sep 29, 2023
6d59bb1
fix: scroll to comment
hermanwikner Sep 29, 2023
84ad242
refactor: types, add comments, clean up
hermanwikner Oct 2, 2023
7625a9a
fix: delete comment dialog message
hermanwikner Oct 2, 2023
e7e130a
feat: update pte list config
hermanwikner Oct 2, 2023
cbff1e0
fix(comments): create better placement for mentionmenu popover
skogsmaskin Oct 2, 2023
72cc3fe
fix: move static props outside the render scope, a11y improvements
hermanwikner Oct 2, 2023
7cce749
feat: add comment creation error handling
hermanwikner Oct 4, 2023
beeb231
dev(test-studio): update comments debug schema
hermanwikner Oct 5, 2023
f67c0ce
fix: sort order when creating a new thread + scroll to comment issues
hermanwikner Oct 5, 2023
01b5d44
refactor: minor improvements
hermanwikner Oct 9, 2023
dcf4021
feat: improve perf by memoizing the comments list component
hermanwikner Oct 9, 2023
9854fc8
fix: add proper tags to comments list
hermanwikner Oct 9, 2023
e4a7c06
feat: cache system groups response to prevent unnecessary requests
hermanwikner Oct 9, 2023
796219b
fix: breadcrumbs build
hermanwikner Oct 9, 2023
a75958f
test: build comment breadcrumbs
hermanwikner Oct 9, 2023
00f5c56
fix(core/comments): ensure proper authentication config on comment cl…
skogsmaskin Oct 9, 2023
1c424d0
dev(test-studio): temporarily disable `assist` and `tsdoc` plugins
hermanwikner Oct 10, 2023
09c64c6
refactor: move comments from `core` to `desk`
hermanwikner Oct 10, 2023
a20cf4d
feat: add `createPathWithParams` to pane router
hermanwikner Oct 13, 2023
c4ba81f
feat: implement comments setup
hermanwikner Oct 13, 2023
70773fb
feat: add `useCommentsSetup` hook
hermanwikner Oct 13, 2023
a779b53
feat: add `client` option to `useCommentsStore` and `useCommentOperat…
hermanwikner Oct 13, 2023
51f2b91
refactor: remove unused context
hermanwikner Oct 13, 2023
b292c70
test: update `buildCommentBreadcrumbs` test
hermanwikner Oct 13, 2023
910d6cb
feat: add copy link to comment feature, UI tweaks and clean up
hermanwikner Oct 13, 2023
a424d45
refactor: export `useMentionOptions` options interface
hermanwikner Oct 13, 2023
1d57654
refactor: update comment workshop stories
hermanwikner Oct 13, 2023
802e5d1
fix: attach workspace title to comments notification context (#4992)
robinpyon Oct 16, 2023
d75cb5f
feat: add highlight/scroll logic + general improvements
hermanwikner Oct 18, 2023
ae2a019
fix(comments): handle text overflow in editable surfaces, optically a…
robinpyon Oct 18, 2023
d1242c1
fix: field highlight effect array issue by using `AnimatePresence`
hermanwikner Oct 18, 2023
8f57e30
feat: implement comment discard logic
hermanwikner Oct 19, 2023
ffcc5a4
feat: disable comments by default
hermanwikner Oct 19, 2023
43b92ca
dev(test-studio): enable comments
hermanwikner Oct 19, 2023
734d151
fix: ensure created comments create URLs with inspect and comment par…
robinpyon Oct 19, 2023
bdbdcee
chore: add code owner for comments
hermanwikner Oct 19, 2023
f18a27e
fix: re-focus input when cancelling comment discard when creating new…
hermanwikner Oct 19, 2023
cd7d88d
refactor: simplify discard controller
hermanwikner Oct 20, 2023
dffc479
fix: reset comment id ref from params when scroll completed
hermanwikner Oct 20, 2023
04b6ffb
fix: move group to top when new thread is created + select the path
hermanwikner Oct 20, 2023
e81138c
fix: tweak field highlight overlay
hermanwikner Oct 20, 2023
5c6fae0
test(comments): add test-ids
skogsmaskin Oct 18, 2023
d9a12ee
refactor(comments): refactor focus handling in the CommentInput
skogsmaskin Oct 18, 2023
e58de82
test(playwright-ct): add tests for CommentInput
skogsmaskin Oct 19, 2023
ed305c0
fix(comments): use current editor value over snapshot to update comment
skogsmaskin Oct 20, 2023
7301212
test(playwright-ct): update props after refactor
skogsmaskin Oct 20, 2023
b2ed30f
fix: store document references as plain objects (#5021)
robinpyon Oct 20, 2023
a336d38
feat: implement breadcrumbs button
hermanwikner Oct 20, 2023
4a155fe
feat: reset select path when changing status view
hermanwikner Oct 20, 2023
51c7a15
fix: reset select path when closing inspector
hermanwikner Oct 20, 2023
09fb8cd
feat: improve selected path logic, update ui when creating new thread
hermanwikner Oct 23, 2023
03ceaf2
fix: revert the storing of cross dataset references in comment documents
hermanwikner Oct 23, 2023
bda06a0
feat: add to notification context (#5041)
hermanwikner Oct 23, 2023
a7b27ec
dev(test-studio): remove temporary workspace
hermanwikner Oct 23, 2023
bb8a3f2
dev(test-studio): re-enable `tsdoc` and `assist` plugins
hermanwikner Oct 23, 2023
bfa8a85
chore: update `yarn.lock`
hermanwikner Oct 23, 2023
a8e97ec
chore: bump sanity ui
hermanwikner Oct 23, 2023
d75c645
refactor: remove `useFieldCommentsCount` hook
hermanwikner Oct 23, 2023
2700d8b
feat: handle network connection reconnect in `useCommentsStore`
hermanwikner Oct 24, 2023
7ef94e3
feat: disable comments (input and actions) while running setup
hermanwikner Oct 24, 2023
fe2e656
fix: retry comment create issue
hermanwikner Oct 24, 2023
7b21242
fix: `focusOnMount` issue
hermanwikner Oct 24, 2023
e794314
chore: update yarn.lock
skogsmaskin Oct 25, 2023
889d6c2
feat: add comments onboarding
hermanwikner Oct 25, 2023
c67d55a
refactor: setup when creating the first comment
hermanwikner Oct 25, 2023
7765a7c
fix: update comments onboarding local storage key
hermanwikner Oct 26, 2023
3f53fa6
fix: scroll to comment
hermanwikner Oct 26, 2023
140f351
refactor(comments): refactor how input and focus is handled
skogsmaskin Oct 25, 2023
5651011
test(playwrigh-ct): add test for comment submission
skogsmaskin Oct 25, 2023
e7c47db
refactor(comments): Performance opt: Don't re-render replies every time.
skogsmaskin Oct 25, 2023
6fad4f6
refactor(comments): refactor key event handling in the comment input …
skogsmaskin Oct 26, 2023
bf14849
fix: comments onboarding copy
hermanwikner Oct 26, 2023
416b879
refactor: make code more readable in `FormFieldBaseHeader`
hermanwikner Oct 27, 2023
0b5d8f5
fix: incorrect interface name in `CommentsSetupProvider`
hermanwikner Oct 27, 2023
9415c33
fix: remove unused CSS in `CommentFieldButton`
hermanwikner Oct 27, 2023
fb778d4
fix: wrap local storage functions in try/catch in `CommentsOnboarding…
hermanwikner Oct 27, 2023
ec06d64
refactor: get rid of `satisfies` where possible
hermanwikner Oct 27, 2023
ef33f6e
fix(core): invalid tsdoc in `useDidUpdate`
hermanwikner Oct 27, 2023
3d6bfce
fix: add request tag in `CommentsSetupProvider`
hermanwikner Oct 27, 2023
dc40740
fix(studio-e2e-testing): remove `commentAction` field action
hermanwikner Oct 27, 2023
a9e9748
Update packages/sanity/src/desk/comments/src/context/setup/CommentsSe…
hermanwikner Oct 30, 2023
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
# Tom owns the Shopify templates
/packages/@sanity/cli/src/actions/init-project/templates/shopify* @thebiggianthead
/packages/@sanity/cli/templates/shopify* @thebiggianthead

/packages/sanity/src/desk/comments/ @hermanwikner
3 changes: 1 addition & 2 deletions dev/studio-e2e-testing/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {defaultDocumentNode, newDocumentOptions, structure} from 'sanity-test-st
import {presenceTool} from 'sanity-test-studio/plugins/presence'
import {copyAction} from 'sanity-test-studio/fieldActions/copyAction'
import {assistFieldActionGroup} from 'sanity-test-studio/fieldActions/assistFieldActionGroup'
import {commentAction} from 'sanity-test-studio/fieldActions/commentFieldAction'
import {customInspector} from 'sanity-test-studio/inspectors/custom'
import {pasteAction} from 'sanity-test-studio/fieldActions/pasteAction'
import {Branding} from './components/Branding'
Expand Down Expand Up @@ -45,7 +44,7 @@ const sharedSettings = definePlugin({
},
unstable_fieldActions: (prev, ctx) => {
if (['fieldActionsTest', 'stringsTest'].includes(ctx.documentType)) {
return [...prev, commentAction, assistFieldActionGroup, copyAction, pasteAction]
return [...prev, assistFieldActionGroup, copyAction, pasteAction]
}

return prev
Expand Down
22 changes: 0 additions & 22 deletions dev/test-studio/fieldActions/commentFieldAction.tsx

This file was deleted.

8 changes: 5 additions & 3 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {deskTool} from 'sanity/desk'
import {muxInput} from 'sanity-plugin-mux-input'
import {assist} from '@sanity/assist'
import {googleMapsInput} from '@sanity/google-maps-input'
// eslint-disable-next-line import/no-extraneous-dependencies
import {tsdoc} from '@sanity/tsdoc/studio'
import {theme as tailwindTheme} from './sanity.theme.mjs'
import {imageAssetSource} from './assetSources'
Expand Down Expand Up @@ -39,7 +38,6 @@ import {vercelTheme} from './themes/vercel'
import {GoogleLogo, TailwindLogo, VercelLogo} from './components/workspaceLogos'
import {copyAction} from './fieldActions/copyAction'
import {assistFieldActionGroup} from './fieldActions/assistFieldActionGroup'
import {commentAction} from './fieldActions/commentFieldAction'
import {customInspector} from './inspectors/custom'
import {pasteAction} from './fieldActions/pasteAction'

Expand Down Expand Up @@ -70,12 +68,16 @@ const sharedSettings = definePlugin({
},
unstable_fieldActions: (prev, ctx) => {
if (['fieldActionsTest', 'stringsTest'].includes(ctx.documentType)) {
return [...prev, commentAction, assistFieldActionGroup, copyAction, pasteAction]
return [...prev, assistFieldActionGroup, copyAction, pasteAction]
}

return prev
},
newDocumentOptions,

unstable_comments: {
enabled: true,
},
},
plugins: [
deskTool({
Expand Down
115 changes: 115 additions & 0 deletions dev/test-studio/schema/debug/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {defineType} from 'sanity'

const DESCRIPTION = 'Comments added to this field should be hidden when the toggle above is checked'

export const commentsDebug = defineType({
name: 'commentsDebug',
type: 'document',
title: 'Comments debug',
fields: [
{
name: 'string',
type: 'string',
title: 'String title',
},
{
name: 'hideFields',
type: 'boolean',
title: 'Hide fields',
},
{
type: 'object',
name: 'object',
title: 'Object title',
fields: [
{
type: 'string',
name: 'string',
title: 'String title',
hidden: ({document}) => Boolean(document?.hideFields),
description: DESCRIPTION,
},
{
type: 'number',
name: 'number',
title: 'Number title',
},
],
},
{
type: 'array',
name: 'arrayOfObjects',
title: 'Array 1',
of: [
{
name: 'arrayObject',
type: 'object',
title: 'Array object 1',
fields: [
{
name: 'string',
type: 'string',
title: 'String 1',
},
{
name: 'image',
type: 'image',
title: 'Image 1',
hidden: ({document}) => {
return Boolean(document?.hideFields)
},
description: DESCRIPTION,
},
{
name: 'nestedArray',
type: 'array',
title: 'Array 2',
of: [
{
name: 'nestedArrayObject1',
type: 'object',
title: 'Nested array object 1',
fields: [
{
name: 'string',
type: 'string',
title: 'String 2.1',
},
{
name: 'image',
type: 'image',
title: 'Image 2.1',
hidden: ({document}) => {
return Boolean(document?.hideFields)
},
description: DESCRIPTION,
},
],
},
{
type: 'object',
name: 'nestedArrayObject2',
title: 'Nested array object 2',
fields: [
{
name: 'string',
type: 'string',
title: 'String 2.2',
},
],
},
],
},
],
},
],
},
{
name: 'image',
type: 'image',
title: 'Image title',
hidden: ({document}) => Boolean(document?.hideFields),
description: DESCRIPTION,
},
],
})
2 changes: 2 additions & 0 deletions dev/test-studio/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import {circularCrossDatasetReferenceTest} from './debug/circularCrossDatasetRef
import {allNativeInputComponents} from './debug/allNativeInputComponents'
import fieldGroupsWithFieldsets from './debug/fieldGroupsWithFieldsets'
import ptReference from './debug/ptReference'
import {commentsDebug} from './debug/comments'

// @todo temporary, until code input is v3 compatible
const codeInputType = {
Expand Down Expand Up @@ -159,6 +160,7 @@ export const schemaTypes = [
code,
codeInputType, // @todo temporary, until code input is v3 compatible
color,
commentsDebug,
conditionalFields,
conditionalFieldset,
customBlock,
Expand Down
25 changes: 13 additions & 12 deletions dev/test-studio/structure/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,51 @@ export const PLUGIN_INPUT_TYPES = [
]

export const DEBUG_INPUT_TYPES = [
'languageFilterDebug',
'actionsTest',
'simpleArrayOfObjects',
'simpleReferences',
'formInputDebug',
'allNativeInputComponents',
'collapsibleObjects',
'commentsDebug',
'conditionalFieldsTest',
'customInputsTest',
'customInputsWithPatches',
'documentActionsTest',
'collapsibleObjects',
'documentWithHoistedPt',
'empty',
'fieldActionsTest',
'fieldComponentsTest',
'fieldsetsTest',
'fieldValidationInferReproDoc',
'focusTest',
'documentWithHoistedPt',
'formInputDebug',
'initialValuesTest',
'inspectorsTest',
'invalidPreviews',
'thesis',
'languageFilterDebug',
'manyFieldsTest',
'noTitleField',
'poppers',
'presence',
'previewImageUrlTest',
'previewMediaTest',
'previewSelectBugRepro',
'ptReference',
'radio',
'readOnlyTest',
'recursiveDocument',
'recursiveArraysTest',
'recursiveDocument',
'recursiveObjectTest',
'recursivePopoverTest',
'reservedKeywordsTest',
'scrollBug',
'select',
'simpleArrayOfObjects',
'simpleReferences',
'thesis',
'typeWithNoToplevelStrings',
'uploadsTest',
'validationTest',
'allNativeInputComponents',
'scrollBug',
'ptReference',
'virtualizationInObject',
'virtualizationDebug',
'virtualizationInObject',
]

export const CI_INPUT_TYPES = ['conditionalFieldset', 'validationCI', 'textsTest']
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"@sanity/logos": "^2.0.2",
"@sanity/mutator": "3.18.1",
"@sanity/portable-text-editor": "3.18.1",
"@portabletext/react": "^3.0.0",
"@sanity/schema": "3.18.1",
"@sanity/types": "3.18.1",
"@sanity/ui": "^1.8.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {expect, test} from '@playwright/experimental-ct-react'
import React from 'react'
import {testHelpers} from '../utils/testHelpers'
import {CommentsInputStory} from './CommentInputStory'

test.describe('Comments', () => {
test.describe('CommentInput', () => {
hermanwikner marked this conversation as resolved.
Show resolved Hide resolved
test('Should render', async ({mount, page}) => {
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeVisible()
})

test('Should be able to type into', async ({mount, page}) => {
const {insertPortableText} = testHelpers({page})
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeEditable()
await insertPortableText('My first comment!', $editable)
await expect($editable).toHaveText('My first comment!')
})

test('Should bring up mentions menu when typing @', async ({mount, page}) => {
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await $editable.waitFor({state: 'visible'})
await page.keyboard.type('@')
await expect(page.getByTestId('comments-mentions-menu')).toBeVisible()
})

test('Should be able to submit', async ({mount, page}) => {
const {insertPortableText} = testHelpers({page})
let submitted = false
const onSubmit = () => {
submitted = true
}
await mount(<CommentsInputStory onSubmit={onSubmit} />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeEditable()
// Test that blank comments can't be submitted
await page.keyboard.press('Enter')
expect(submitted).toBe(false)
await insertPortableText('This is a comment!', $editable)
await expect($editable).toHaveText('This is a comment!')
await page.keyboard.press('Enter')
expect(submitted).toBe(true)
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {useState} from 'react'
import {CurrentUser, PortableTextBlock} from '@sanity/types'
import {noop} from 'lodash'
import {CommentInput} from '../../../src/desk/comments/src/components/pte/comment-input/CommentInput'
import {TestWrapper} from '../formBuilder/utils/TestWrapper'

const currentUser: CurrentUser = {
email: '',
id: '',
name: '',
role: '',
roles: [],
profileImage: '',
provider: '',
}

const SCHEMA_TYPES: [] = []

export function CommentsInputStory({
onDiscardCancel = noop,
onDiscardConfirm = noop,
onSubmit = noop,
value = null,
}: {
onDiscardCancel?: () => void
onDiscardConfirm?: () => void
onSubmit?: () => void
value?: PortableTextBlock[] | null
}) {
const [valueState, setValueState] = useState<PortableTextBlock[] | null>(value)
return (
<TestWrapper schemaTypes={SCHEMA_TYPES}>
<CommentInput
focusOnMount
placeholder="Your comment..."
focusLock
currentUser={currentUser}
onChange={setValueState}
value={valueState}
mentionOptions={{data: [], error: null, loading: false}}
onDiscardConfirm={onDiscardConfirm}
onDiscardCancel={onDiscardCancel}
onSubmit={onSubmit}
/>
</TestWrapper>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const StaticUserAvatar = forwardRef(function StaticUserAvatar(
props: Omit<UserAvatarProps, 'user'> & {user: User},
ref: React.ForwardedRef<HTMLDivElement>,
) {
const {user, animateArrowFrom, position, size, status, tone} = props
const {user, animateArrowFrom, position, size, status, tone, ...restProps} = props
const [imageLoadError, setImageLoadError] = useState<null | Error>(null)
const userColor = useUserColor(user.id)
const imageUrl = imageLoadError ? undefined : user?.imageUrl
Expand All @@ -98,6 +98,7 @@ const StaticUserAvatar = forwardRef(function StaticUserAvatar(
size={typeof size === 'string' ? LEGACY_TO_UI_AVATAR_SIZES[size] : size}
status={status}
title={user?.displayName}
{...restProps}
/>
)
})
Expand Down
Loading
Loading