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

[DP-276] Comments Viewing FrontEnd #370

Merged
merged 6 commits into from
Dec 18, 2023
Merged

Conversation

hazelyn11
Copy link
Collaborator

@hazelyn11 hazelyn11 commented Dec 14, 2023

Jira ticket

Now we can view comments both in the word pane and the paragraph pane!

One note-- in order to render comments immediately after they are submitted, I am currently also showing the collapsible Discussion panel even when it is empty. Otherwise, the pane has to be closed and re-opened in order for comments to show. Maybe there's a better way around this?

image

Copy link

netlify bot commented Dec 14, 2023

Deploy Preview for dailp ready!

Name Link
🔨 Latest commit 686a8c3
🔍 Latest deploy log https://app.netlify.com/sites/dailp/deploys/6580a2c068601b0008071e54
😎 Deploy Preview https://deploy-preview-370--dailp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hazelyn11 hazelyn11 marked this pull request as ready for review December 14, 2023 22:51
? css.tagColorStory
: p.comment.commentType === Dailp.CommentType.Suggestion
? css.tagColorSuggestion
: css.tagColorQuestion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to consider: You can have named style variants that share some common styling but diverge based on a parameter. Using a variant might clean up things here and lead to less redundant css.

read more: https://vanilla-extract.style/documentation/api/style-variants/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm trying this and it's fine to define a variant but I'm having trouble actually passing in the values I need to use it from the component without getting errors. If this is essential I can keep trying to figure out how to do it but I've spent a while on it and am struggling

) : p.parent.__typename === "AnnotatedForm" ? (
<WordCommentSection word={p.parent} />
) : (
""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parent cannot be undefined, null, or some other type. You can delete this embedded ternary to leave you with the following:

{p.parent.__typename === "DocumentParagraph" ? (
         <ParagraphCommentSection paragraph={p.parent} />
       ) : <WordCommentSection word={p.parent} />)}

Copy link
Collaborator Author

@hazelyn11 hazelyn11 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I try to delete the embedded ternary I get this error:

  Type '{ readonly __typename?: "DocumentParagraph" | undefined; } & Pick<DocumentParagraph, "id" | "index" | "translation"> & { readonly source: readonly (({ readonly __typename: "AnnotatedForm"; } & Pick<...> & { ...; }) | { ...; })[]; readonly comments: readonly ({ ...; } & Pick<...>)[]; }' is not assignable to type 'FormFieldsFragment'.
    Type '{ readonly __typename?: "DocumentParagraph" | undefined; } & Pick<DocumentParagraph, "id" | "index" | "translation"> & { readonly source: readonly (({ readonly __typename: "AnnotatedForm"; } & Pick<...> & { ...; }) | { ...; })[]; readonly comments: readonly ({ ...; } & Pick<...>)[]; }' is not assignable to type '{ readonly __typename?: "AnnotatedForm" | undefined; }'.
      Types of property '__typename' are incompatible.
        Type '"DocumentParagraph" | undefined' is not assignable to type '"AnnotatedForm" | undefined'.```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like typescript is not being nice to you. Sometimes nested fields will be like this when you try to do a type guard (checking if a value is of a certain type, like you do when you check the value of __typename) on a literal. You might see if this goes away if instead of taking in an object of params like this:

(p: {...prop type}): ReactElement

You instead "destructure" your props like this:

({parent}: {... prop type}): ReactElement

Here are some docs on "destructuring" in JS if that is new for you: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also fix this if we upgrade typescript somehow. This should work.

@hazelyn11
Copy link
Collaborator Author

@GracefulLemming I have addressed most of your comments and left follow-ups on two of them, lmk your thoughts!

Copy link
Collaborator

@CharlieMcVicker CharlieMcVicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to @GracefulLemming for final approval but this looks good to me.

Comment on lines +65 to +70
const commentTypeNames: Record<Dailp.CommentType, string> = {
// ... TS will then make sure you have an entry for everything on the "CommentTag" type that you import from the codegen
[Dailp.CommentType.Story]: "Story",
[Dailp.CommentType.Suggestion]: "Suggestion",
[Dailp.CommentType.Question]: "Question",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move this out of the function and make it a constant with SCREAM_CASE_NAMING if you wanted.

@hazelyn11
Copy link
Collaborator Author

Up to @GracefulLemming for final approval but this looks good to me.

thanks for your comments Charlie!

@GracefulLemming
Copy link
Contributor

@hazelyn11 if you want to finish the suggestions Charlie made, feel free to. Otherwise, you can merge!

@hazelyn11 hazelyn11 merged commit 24ff8f4 into main Dec 18, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants