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

Allow Grid::addModalAction() button to be disabled #1868

Merged
merged 5 commits into from
Jan 30, 2024

Conversation

mkrecek234
Copy link
Contributor

@mkrecek234 mkrecek234 commented Sep 27, 2022

No description provided.

@mkrecek234
Copy link
Contributor Author

mkrecek234 commented Sep 27, 2022

Sample usage:

$grid->addModalAction(['icon'=>'flag'], ['title' => 'Move'], function ($v, $id) use ($grid) {
      ...
            });
        },[], function ($row) { return rand(0,1) == 1;});

@@ -542,9 +542,9 @@ public function addPopup($columnName, $popup = null, $icon = 'caret square down'
*
* @return View
*/
public function addModalAction($button, $title, \Closure $callback, $args = [])
public function addModalAction($button, $title, \Closure $callback, $args = [], $isDisabled = false)
Copy link
Member

@mvorisek mvorisek Sep 27, 2022

Choose a reason for hiding this comment

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

I belive this is not per row, not sure what usecase it should solve.

Copy link
Contributor Author

@mkrecek234 mkrecek234 Sep 27, 2022

Choose a reason for hiding this comment

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

Sure, the isDisabled is either boolean or closure, if you pass function($row) { return ($row->get('age') > 12); } you can dynamically set disabled per row as needed. @mvorisek Have many use cases where this is perfect - as it is just extends an already existing feature of addActionButton to addModalAction I'd appreciate if we could merge it

Copy link
Member

Choose a reason for hiding this comment

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

this need a phpdoc @param above the method like the enabled property phpdoc

https://dev.agiletoolkit.org/demos/tutorial/actions.php?atk_layout_maestro_wizard=3 - UA supports this natively, why do you want to extent this method? Advanced options should not be configureable by a custom parameter. One of my usecases was a different icon for example, should this be addressed by another param? No.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addAction button has this feature today and all I do is to allow also addModalAction to use this helpful feature. Not everyone is using UA - a lot are using addActionButton etc. to configure Crud which is helpful. I do not see why this is a problem. Or do you want to delete also the isDisabled feature from addActionButton? That would be a pity

Copy link
Member

Choose a reason for hiding this comment

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

creating UA with a seed should be the desired way to solve *any* related special settings, I am quite against the proposed changes

Copy link
Contributor Author

@mkrecek234 mkrecek234 Sep 27, 2022

Choose a reason for hiding this comment

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

Sure we could re-work this to flexibly have multiple advanced parameters - I'd say that would be an idea for future improvements. Alternative could be ActionButtons::onHook(HOOK_GET_HTML_TAGS, function ...) similar to
$table->onHook(Table\Column::HOOK_GET_HTML_TAGS, function (Table $table, Model $row) { ...where we return array of icon, disabled, title

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not see why you are against it? There are multiple ways to code, and UA is not always the best way, especially if you want to dynamically adjust Cruds' action buttons in certain views. We should not enforce one single way of coding, but keep room for alternatives, as we all do not have all use cases in mind.
This PR is nothing else than creating consistency between addActionButton and addModalAction with existing features. I am absolutely against removing isDisabled feature unless UA becomes much more easy to code with less lines of code. And even then there might be a lot of reasons why people do not want to use UA but call addActionButton/ addModalAction directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ibelar Any view on this PR and our pro / con discussion here?

@atk4 atk4 deleted a comment from mkrecek234 Sep 27, 2022
@mvorisek mvorisek marked this pull request as draft October 1, 2022 16:07
@mvorisek
Copy link
Member

rebase in one squashed commit onto develop, narrow \Closure phpdoc types, add Behat test and then let's review this PR

@mvorisek mvorisek changed the title Improve Grid addModalAction Allow Grid::addModalAction() button to be disabled Aug 17, 2023
@mvorisek
Copy link
Member

@mkrecek234 if you are interested to pursue this PR, let me know, now, I am closing it due inactivity

also see #1920 (comment), the "disable action" topic is much more complex and we need to support is uniformly for everything (or nothing)

for discussion, there is #1966 issue

@mvorisek mvorisek closed this Sep 30, 2023
@mvorisek mvorisek deleted the feature/action_button_disable branch September 30, 2023 21:34
@mvorisek mvorisek restored the feature/action_button_disable branch January 30, 2024 15:57
@mvorisek mvorisek reopened this Jan 30, 2024
@mvorisek mvorisek force-pushed the feature/action_button_disable branch from a17e5b6 to 1dbe024 Compare January 30, 2024 16:10
@mvorisek mvorisek marked this pull request as ready for review January 30, 2024 16:52
@mvorisek
Copy link
Member

I have reworked this PR to be consistent. The idea is good.

@mvorisek mvorisek merged commit 5aaca5b into develop Jan 30, 2024
49 checks passed
@mvorisek mvorisek deleted the feature/action_button_disable branch January 30, 2024 17:02
@mkrecek234
Copy link
Contributor Author

I have reworked this PR to be consistent. The idea is good.

Thank you, @mvorisek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants