Remove duplication in poll actions tables

We were using the same logic in four different places, so we're creating
a new class to handle that logic.

Note that I didn't find a way to delegate the `content` method to a
`Admin::TableActionsComponent`, so we're delegating the `action` method
instead. That means we need to create a method returning an
`Admin::TableActionsComponent`. We also need to cache this object;
otherwise we were getting an error when calling `actions.action` from
the `Admin::Poll::Questions::TableActionsComponent`.
This commit is contained in:
Javi Martín
2022-09-18 17:51:18 +02:00
parent 4c8f247de7
commit 518af3eb97
11 changed files with 91 additions and 40 deletions

View File

@@ -1,14 +1,7 @@
class Admin::Poll::Questions::Answers::TableActionsComponent < ApplicationComponent
attr_reader :answer
delegate :can?, to: :helpers
def initialize(answer)
@answer = answer
end
private
def actions
[:edit, :destroy].select { |action| can?(action, answer) }
end
end