-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Add Commentable Interface #882
Conversation
8e6a98b
to
7406e0e
Compare
@@ -22,11 +22,11 @@ | |||
feature.settings(:global) do |settings| | |||
settings.attribute :total_budget, type: :integer, default: 100_000_000 | |||
settings.attribute :vote_threshold_percent, type: :integer, default: 70 | |||
settings.attribute :comments_always_enabled, type: :boolean, default: true | |||
settings.attribute :comments_enabled, type: :boolean, default: true |
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.
We need a migration for these settings and current features
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.
@oriolgual If the setting is not found it uses the default value so the migration is not needed.
if comment.replies.size.positive? | ||
comment.replies.size + comment.replies.map { |reply| count_replies(reply) }.sum | ||
if comment.comments.size.positive? | ||
comment.comments.size + comment.comments.map { |reply| count_replies(reply) }.sum |
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.
No need to map & sum, you can sum directly
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.
Oh, I didn't know that! Great
@@ -21,6 +21,7 @@ ca: | |||
subject: Tens una nova resposta del teu comentari | |||
components: | |||
add_comment_form: | |||
account_message: "<a href=\"%{sign_in_url}\">Entra amb el teu compte</a> o <a href=\"%{sign_up_url}\">regístra't</a> per a deixar un comentari." |
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.
registra't
@@ -47,6 +48,7 @@ ca: | |||
comment_thread: | |||
title: Conversa amb %{authorName} | |||
comments: | |||
blocked_comments_warning: Els comentaris estan desactivats a la fase actual pero pots llegir els comentaris de les fases anteriors. |
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.
però
@@ -22,6 +22,8 @@ en: | |||
subject: You have a new reply of your comment | |||
components: | |||
add_comment_form: | |||
account_message: "<a href=\"%{sign_in_url}\">Sign in with your account</a> or <a href=\"%{sign_up_url}\">sign up</a> to leave your comment. |
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.
add your comment
@@ -21,6 +21,7 @@ es: | |||
subject: Uno de tus comentarios ha recibido respuesta | |||
components: | |||
add_comment_form: | |||
account_message: "<a href=\"%{sign_in_url}\">Entra con tu cuenta</a> o <a href=\"%{sign_up_url}\">regístratet</a> para dejar tu comentario." |
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.
regístrate
|
||
has_many :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment" | ||
|
||
def commentable? |
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.
Should all these methods be implemented in the models were we include this? If so I'd raise NotImplementedError
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 there is no need to implement those methods. They are just returning boolean values and not doing anything else. The default ones are just standard: enable comments without extra options. What do you think?
commentable_id = resource.id.to_s | ||
node_id = "comments-for-#{commentable_type.demodulize}-#{commentable_id}" | ||
def comments_for(resource) | ||
if resource.commentable? |
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.
return unless resource.commentable?
"{ addComment(body: \"#{body}\", alignment: #{alignment}) { body } }" | ||
} | ||
|
||
it "should call CreateComment command" do |
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.
it "calls
Codecov Report
@@ Coverage Diff @@
## master #882 +/- ##
==========================================
- Coverage 97.25% 97.23% -0.02%
==========================================
Files 370 374 +4
Lines 6075 6248 +173
==========================================
+ Hits 5908 6075 +167
- Misses 167 173 +6
Continue to review full report at Codecov.
|
ce6efc2
to
1e6e76b
Compare
@beagleknight, thanks for your PR! By analyzing the history of the files in this pull request, we identified @josepjaume and @oriolgual to be potential reviewers. |
@@ -1,12 +1,12 @@ | |||
fragment Comment on Comment { | |||
...CommentData | |||
replies { | |||
comments { |
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.
As a future opportunity, maybe we could flatten this query and build the tree it afterwards, and/or use query batching
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 agree. I think we can use another approach in order to allow infinite nesting (as long as the ui supports it).
@@ -46,7 +52,8 @@ describe('<Comments />', () => { | |||
|
|||
stubComponent(AddCommentForm, { | |||
fragments: { | |||
user: addCommentFragment | |||
session: addCommentFragmentSession, |
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.
Shouldn't this be addCommentSessionFragment
?
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.
No! It should be addCommentFormSessionFragment
😂
@@ -46,7 +52,8 @@ describe('<Comments />', () => { | |||
|
|||
stubComponent(AddCommentForm, { | |||
fragments: { | |||
user: addCommentFragment | |||
session: addCommentFragmentSession, | |||
commentable: addCommentFragmentCommentable |
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.
Same as up above.
description "A commentable object" | ||
|
||
interfaces [ | ||
Decidim::Comments::CommentableInterface |
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.
ULTRA NICE 🐇 🌈 🎈
|
||
has_many :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment" | ||
|
||
def commentable? |
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.
We should add docs indicating what all these defaults mean and what effect they have on comments.
1e6e76b
to
bd15299
Compare
🎩 What? Why?
I added two flags for managing comments in a specific feature:
Then I created the
Commentable
interface so any model can implement it. Since it include all the logic needed to render the comments component, the comment helper has been simplified:This changed pushed a few changes into the API:
Get commentable's comments:
Add a new comment:
These changes will be more effective when we start implementing other types for our current models like
Proposal
,Meeting
and so on.📌 Related Issues
📋 Subtasks
comments_always_enabled
general settingCommentable
interfaceCommentable
type and interface for graphqlAddCommentFormComponent
comments_enabled
andcomments_blocked
logic for all features using comments📷 Screenshots (optional)
👻 GIF