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

fix/#746 Duplicate button and icon id #747

Merged
merged 6 commits into from
Jul 1, 2019

Conversation

ibelar
Copy link
Contributor

@ibelar ibelar commented Jun 18, 2019

Fix #746

@codecov
Copy link

codecov bot commented Jun 18, 2019

Codecov Report

❗ No coverage uploaded for pull request base (develop@c31574a). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             develop    #747   +/-   ##
=========================================
  Coverage           ?   66.1%           
  Complexity         ?    2226           
=========================================
  Files              ?     118           
  Lines              ?    5243           
  Branches           ?       0           
=========================================
  Hits               ?    3466           
  Misses             ?    1777           
  Partials           ?       0
Impacted Files Coverage Δ Complexity Δ
src/TableColumn/Actions.php 92.68% <100%> (ø) 15 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c31574a...eb97119. Read the comment docs.

@pkly
Copy link
Contributor

pkly commented Jun 19, 2019

Will this ensure the element is unique enough? The one genererated in the class attribute is not unique, it repeats every row anyway.

@ibelar
Copy link
Contributor Author

ibelar commented Jun 19, 2019

@pkly - This will ensure that the id attribute for button and icon is set to null and not get duplicate with a generic name like 'atk'. The class attribute name that get duplicate for each button is used as a selector for adding the click handler to the button.

$button->addClass('b_'.$name);
$this->table->on('click', '.b_'.$name, $callback, [$this->table->jsRow()->data('id'), 'confirm' => $confirm]);

This will send the row data-id with each callback when button is click.

Perhaps I do not see the use case to generate a unique id's for each button. Why do you need to set a unique id for each one's in table?

There would be a way to do so but that will require for you to pass your own button object.

For example using your own CRUD class your can override initUpdate and initDelete to set your own button:

$btn = new \atk4\ui\Button(['icon' => 'edit']);
$btn->init();
$btn->id = 'myButton_{$_id}';

$this->addAction($btn, new jsModal('Edit', $this->pageUpdate, [$this->name => $this->jsRow()->data('id'), $this->name.'_sort' => $this->getSortBy()]));

This will generate a template row for the table and the tag {$_id} would be replace with your model id as an example generating something like

<div id="myButton_8" class="ui b_atk_admin_crud_view_table_actions_action_2 compact icon button" style="">
</div>

@pkly
Copy link
Contributor

pkly commented Jun 21, 2019

Perhaps I do not see the use case to generate a unique id's for each button. Why do you need to set a unique id for each one's in table?

Wouldn't that break the actions with on, like

$myButton = $grid->addAction(['icon' => 'whatever']);
$myButton->on('click', function($a) {
   // whatever
});

Don't the js chains rely pretty much only on IDs of elements?
If the js actions can still be attached to this element after this commit I don't really have any issues with it, since IDs of elements are dynamic anyway there's no need for them to exist explicitly I suppose.

@romaninsh
Copy link
Member

romaninsh commented Jun 21, 2019

i think the correct fix would be to make $app->add(['Icon', 'id'=>false]); work correctly. The default value 'atk' should be a property value which can be overridden through a seed.

This annoying bit has been there for some time, but i was afraid to fix due to BC, now is a good time!

@romaninsh
Copy link
Member

Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

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

implement id=>false properly.

@ibelar
Copy link
Contributor Author

ibelar commented Jun 21, 2019

Perhaps I do not see the use case to generate a unique id's for each button. Why do you need to set a unique id for each one's in table?

Wouldn't that break the actions with on, like

$myButton = $grid->addAction(['icon' => 'whatever']);
$myButton->on('click', function($a) {
   // whatever
});

Don't the js chains rely pretty much only on IDs of elements?
If the js actions can still be attached to this element after this commit I don't really have any issues with it, since IDs of elements are dynamic anyway there's no need for them to exist explicitly I suppose.

I see, although $grid->addAction($name, $function) return a button and that you can still add a js_action to it. However, js_action added to it will not be render, probably because Table is in fact a Lister and the button is not an element of the table directly. I guess the only reason why a button is returned via Grid::addAction() method is to be able to modify button look.
Hope this help clarified. But you where still right in first place about duplicate id that should not get generated.

@romaninsh
Copy link
Member

We can use custom selector on jsAction. Something similar to Field->jsInput()

@ibelar
Copy link
Contributor Author

ibelar commented Jun 27, 2019

i think the correct fix would be to make $app->add(['Icon', 'id'=>false]); work correctly. The default value 'atk' should be a property value which can be overridden through a seed.

This annoying bit has been there for some time, but i was afraid to fix due to BC, now is a good time!

@romaninsh
Fix:

  • Can now use $app->add(['Icon', 'id'=>false]);
  • View now has defaultName property set to 'atk' that can be override.

@ibelar ibelar requested a review from romaninsh June 27, 2019 01:35
Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

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

This is perfect, thanks!

@romaninsh romaninsh merged commit 5ea0666 into develop Jul 1, 2019
@romaninsh romaninsh deleted the fix/#746-duplicate-button-id branch July 1, 2019 23:08
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.

CRUD and Grid contains duplicated element ids
3 participants