-
Notifications
You must be signed in to change notification settings - Fork 435
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
019de61
to
eff2731
Compare
eff2731
to
5c344a2
Compare
Component Testing Report Updated Oct 31, 2023 11:28 AM (UTC)
|
5c344a2
to
ac18b38
Compare
ac18b38
to
f8c36d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! This is going to be a fantastic feature.
Left some questions and a suggestion, happy to discuss.
Looking forward to this !
packages/sanity/src/core/comments/components/list/CommentDeleteDialog.tsx
Outdated
Show resolved
Hide resolved
packages/sanity/src/core/comments/hooks/useCommentOperations.ts
Outdated
Show resolved
Hide resolved
f8c36d2
to
8626182
Compare
8626182
to
9cd5562
Compare
9cd5562
to
12109fd
Compare
12109fd
to
293fcce
Compare
293fcce
to
db7852f
Compare
* Enter will submit the comment * Input field is reset after submission or discard * Setting focus is handled through the same function everywhere.
…and consumers This will let comment input key events propagate to the parent components for handling spesific functionality for that parent. This also reduces the need for additional key handlers in the parent components, and makes it easier to compose functionality as there is only one originating source of those events.
…tupProvider.tsx Co-authored-by: Robin Pyon <[email protected]>
a0ef933
to
a9e9748
Compare
packages/sanity/src/core/form/components/formField/FormFieldBaseHeader.tsx
Show resolved
Hide resolved
export function CommentsLayout(props: LayoutProps) { | ||
return ( | ||
<CommentsSetupProvider> | ||
<CommentsOnboardingProvider>{props.renderDefault(props)}</CommentsOnboardingProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change order of these, the onboarding provider should probably be outermost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @hermanwikner! As mentioned, another pass on desk components will be forthcoming, but all the core changes LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 🚀 ✨ 💬
Description
This pull request introduces a new comments feature, providing the ability to add comments to specific fields within documents. The comments specific logic is implemented in
desk
, and some updates have been made tocore
to enable comments to be configured from thedesk
plugin. Please note that this pull request aims to introduce comments as a beta feature and there is thus room for improvement in the implementation that will be adressed before GA.The changes made to
core
anddesk
respectively are divided into two sections below.What to review: core (
DX
+EX
)Field Comments:
Introduces a new
__internal_comments
prop for fields. This prop allows the configuration of fields with a comment action that is rendered along with Field Actions. Thedesk
plugin uses this prop, as demonstrated in the following example:Document Comments API:
Adds a new (unstable) API to enable/disable the comments feature for documents. In the initial beta release, the comments feature is opt-in, requiring explicit configuration. The API provides both a simple boolean option to enable/disable comments for all documents and a more granular configuration by using the
documentType
and/ordocumentId
values provided in the context parameter.Boolean example – Enable comments for all documents:
Context example – Enable comments only for 'article' documents:
New exports from the sanity package:
useDidUpdate
hook.resolveConditionalProperty
function: We use this function to determine if a comment should be visible or not, ensuring that only comments related to visible fields are displayed.useFeatureEnabled
hook: This hook is essential to check if the comments feature is enabled for the current plan.What to review: desk (
EX
)Summary of critical elements in the implementation:
CommentsProvider
: This provider is used inDocumentPaneProvider
and is responsible for handling all CRUD operations.CommentsSetupProvider
: This provider wraps the entire studio throughstudio.components.layout
. It is responsible for the setup of comments (using the setup endpoint) and configuring a client for the addon dataset. This client is accessed withuseCommentsSetup
inCommentsProvider
to enable CRUD operations on the addon dataset.CommentsOnboardingProvider
: This provider is relatively straightforward and is responsible for storing a value in local storage if the user dismisses the comments onboarding. It is implemented as a provider because, in the future, there may be multiple instances where onboarding needs to be displayed.useCommentOperations
: This hook manages the logic for creating, editing, updating, or deleting comments.useCommentsStore
: This hook initiates the initial fetch of all comments, subscribes to a real-time listener, and manages the state using a reducer. Thedispatch
function in this hook is exported to facilitate immediate and optimistic state updates with callbacks provided by theuseCommentOperations
. That is, whenever e.g. acreate
operation is executed, we optimistically update the state in the reducer to make the experience feel snappy and fast.useMentionOptions
: This hook returns a list of users who can be mentioned in the current document. The hook performs the following tasks:'*[_type == "system.group”]'
.read
access. If this is the case, it becomes possible to mention the user.useCommentsEnabled
: This hook checks whether the comments feature flag (studioComments
) are enabled for the project and resolvesdocument.unstable_comments.enabled
to determine if the comment feature should be enabled. The default value indocument.unstable_comments.enabled
should befalse
, and the user needs to explicitly enable comments in the config to try it out. This hook is used in three different locations:In
CommentField
to decide whether to render a field with a comment button or defer to the default field rendering.In the
useMenuItem
hook within the document inspector definition to determine whether the inspector button should be set ashidden: true
.In
CommentsProvider
to determine whether to set up listeners, and so forth, for comments. If not, the provider is still rendered with nullified values.buildCommentBreadcrumbs
: This function builds the breadcrumbs for a comment and evaluates the comment against the document value to determine whether it should be displayed. This evaluation is performed because we only want to display comments that have a corresponding field. If there is no associated field (e.g., if the schema definition has changed or an array item has been removed), the comment should not be displayed. This also applies if a conditionalhidden
callback returnsfalse
.buildCommentThreadItems
: This function maps over all the comments an groups them in a format that is easier to work with in the UI.Notes for release
n/a