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

The action's visible block is not respected in the action show control #1769

Closed
adrianthedev opened this issue May 26, 2023 · 8 comments · Fixed by #1833
Closed

The action's visible block is not respected in the action show control #1769

adrianthedev opened this issue May 26, 2023 · 8 comments · Fixed by #1833
Assignees
Labels
Bug Something isn't working

Comments

@adrianthedev
Copy link
Collaborator

Describe the bug

If an action has self.visible = -> {false}, the action is still displayed on the page if the show_controls uses it action TheAction

@adrianthedev adrianthedev added the Bug Something isn't working label May 26, 2023
@adrianthedev
Copy link
Collaborator Author

Let's add the visible block to the action control

  self.show_controls = -> do
    action ReleaseFish visible: -> {false}
  end

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 5, 2023

@adrianthedev I'm not sure about the visible block on the action control.

I think we should call the action's self.visible block even if the action is on show_controls. We can inject the "render_type" where that action is rendered.

Example: (random logic)

self.visible = -> {
  if user.admin? && render_type == :show_control
    true
  elsif render_type == :row_control
    true
  else
    false
  end
}

On the example above the action is rendered on show_controls only for admins, on row_controls for everyone and is not rendered anywhere else...

In my opinion, employing a visible block to handle row, show, and other controls for actions, while relying on the self.visible attribute for other actions, can complicate maintenance and development. This becomes especially challenging when the developer needs to apply the same logic to all action instances. However, if the developer has access to resource, record, "render_type", user, view, and possibly the parent resource and model, they can centralize and maintain all the logic around the self.visible class attribute of the action.

@adrianthedev
Copy link
Collaborator Author

Ok. I agree with you. One place to set the visibility.
We need to think about a system.

The use can render this action on:

  • index - as index control or in action list
  • show - as show control or in action list
  • edit - as edit control or in action list
  • row - as row control or in action list

So we can use the view object, and maybe the render_type will be :{row|show|index|edit}_control or :action_list?
Open to suggestions.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 5, 2023

I think the suggested nomenclature is on point but :action_list is not a render_type, it should be a boolean that indicates whenever the action is rendered inside or outside a list.

Example:

...
if render_type == :row_control && inside_list?
...

Not sure if this is easy to implement but I think this will offer the most granular configuration for the developers

@adrianthedev
Copy link
Collaborator Author

it should be a boolean that indicates whenever the action is rendered inside or outside a list.

It's too complicated. You already need to remember view and renderr_type, now you also have to remember another boolean. Too many things to remember.

Another suggestion I have is render_type is :{row|show|index|edit}_control or :{row|show|index|edit}_list. I'm not 100% convinced with this one.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 5, 2023

We already touched multiples possibilities:

1

  • render_type can be :{row|show|index|edit}_control if not on a list
  • render_type can be :{row|show|index|edit}_list if on a list

2

  • render_type can be only :{row|show|index|edit}_control
  • Being or not on a list is controlled by a boolean (inside_list or something similar...)

3

We can dynamically generate the methods and instead if render_type == :row_control developers can directly use if is_row_control? or instead if render_type == :row_list developers can directly use if inside_row_list?

Personally I think that option 1 have much more to remember than option 2. But option 2 can be harder to implement. Anyway I would prefer to work with option 3 because we generate the methods and we can change the logic inside them, if necessary, without changing the API.

I agree that it's a lot to remember in any of the 3 possibilities, it is crucial to thoroughly document the API.

We can't give this level of granular configuration without some complexity.

@adrianthedev
Copy link
Collaborator Author

not sure how difficult version 3 is to implement. can you flesh out an MVP in 30 minutes?

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Jul 5, 2023

Check the related PR. The PR fixes the reported issue, the visible block is now respected on show controls too. Right now on Avo2 is possible to verify if is show control or not from the view, if view == :show...

The MVP should be implemented on Avo3, there is where we have all the controls (row, index, edit, ...).

Let me know if I should implement it right now or should we let it for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants