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
Callback/sticky args refactor #1377
Conversation
src/Callback.php
Outdated
public function setUrlTrigger(string $trigger) | ||
{ | ||
$this->urlTrigger = $trigger; | ||
$this->app->stickyGet($this->urlTrigger); |
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 belive this concept is wrong, here is why, imagine the following structure:
- View elem
- - Form A elem with callback inside (this sets stickyGet)
- Form B elem with callback inside
if the last element does something with the URL, it will still add the sticky parameter
I think we should instead introduce sticky parameters per View element and then when we build URL for View, collect sticky parameters from the parents/owners.
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.
Not sure I follow what you mean. Settings stickyGet to App vs View will only ensure that the get argument will be set in URL, no matter which View required it. Thus ensuring the callback will run.
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 named elements in my example.
Now consider this:
- Form A callback is triggered
- and wants to return rendered Form B
now form B will have sticky GET from Form A
That is definitelly wrong - sticky GET should not be global, but per tree item and only self and parent items should contribute to the sticky GET params used for a new URL
src/Form/Control/Upload.php
Outdated
@@ -230,9 +228,10 @@ protected function renderView(): void | |||
} | |||
parent::renderView(); | |||
|
|||
if (!$this->_isCbRunning && (!$this->hasUploadCb || !$this->hasDeleteCb)) { | |||
if (!$this->_isCbRunning && !isset($_GET['__atk_reload']) && (!$this->hasUploadCb || !$this->hasDeleteCb)) { |
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.
this check is still triggering/throwing in the nested CRUD
-
nested CRUD testing demo (you should be able to open/nest CRUD unlimited times and submit it):
https://github.com/atk4/ui/tree/reload_not_working_after_upload -
we should test 3x (main + 2x) nested CRUD in tests
-
CRUD with upload (when you select a file and in uploads, then CRUD can not be submitted (it reloads and does not close))
https://github.com/atk4/ui/tree/reload_not_working_after_upload__add_submit_issue
@georgehristov - @mvorisek - Any idea why Behat Crud test is failing since last Data update? |
@ibelar you mean atk4/data update? If yes, than this is not true, the issue is not present on ui develop, this issue is solely in this PR. |
Issue is in develop
Nevermind, I see where the error comes from. |
- remove post trigger check for form; - revert callback desired_name to submit for test; - fix test urlTrigger via setUrlTrigger
- cs fixer - inline edit index value
src/Callback.php
Outdated
return $ret; | ||
} | ||
if ($this->isTriggered()) { | ||
$this->owner->stickyGet($this->urlTrigger); |
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 we should not registed sticky GET even inside owner, this can/will be issue if the owner contains two Callbacks and at least one directly
I think we do not need this at all - sticky GET set in self::getUrlArguments()
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.
Yes this is need, otherwise triggering element inside a callback will not run, i.e. callback in callback will not work without it.
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.
then we need to move everything related with Url inside View inside a trait or make Callback class extends View :)
Yes this is need, otherwise triggering element inside a callback will not run, i.e. callback in callback will not work without it.
I looked at the code now and I think it is currently not even possible as URL method names in Callback vs. View are different, I think Callback now expect owner to be an instance of View strictly
@mvorisek - Since your last changed, File upload demo (/demos/form-control/upload.php) and Wizard demo step 2 (/demos/interactive/wizard.php) are not working anymore. Please fix. |
src/Callback.php
Outdated
return $this->urlTrigger; | ||
} | ||
|
||
private function callWithAppStickyTrigger(\Closure $fx) |
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.
Why do we need this? All was working perfectly fine before...
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.
not, it was not - the described reload issue on Discord is not resolved (and even this does not solve it), I belive, it never will with app/global sticky args approach
This should be the same as before, but only the app/global sticky args are set when the callback is executing - once it is done, it is no longer app/global sticky - we need to converge to a solution without app/global sticky at all
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 do not see any issue using your branch describe on Discord. All was working fine for me locally. I can even click 'Add Country" three time and Add will still work using the third modal.
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.
@mvorisek - I revert Callback to the last working state. Let's merge this and we can look into your issue after. |
I fixed the revert to revert only the too strict code I belive these global sticky args must be removed, so I opened #1377 (comment) .
|
demos/_unit-test/callback_2.php
Outdated
$loader = Loader::addTo($app); | ||
$loader->loadEvent = false; | ||
|
||
$loader->set(function($p) use ($m) { |
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 be CRUD (as it uses Popup) and probably it should be defined with function, which can be called unlimited times
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.
This test is failing using the current develop branch. So should be enough for now.
But feel free to supply your own sample.
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.
basically in reload_not_working_after_upload__add_submit_issue
branch, addCrudDemo
, can be very simple, I even do not think we need upload, but it will be nice if crud (like there) can be used for input for field, this is quite complex test which will be needed if we will drop sticky global later...
the field should be used twice and both fields should be edited twice (to simulate issues with with sticky...)
Refactor Callback
Post trigger has been remove! Triggering callback is done only via a $_GET argument.
Small BC break:
Callback::triggered()
method was used for two purposes: get callback mode (type) or check if callback was triggered. These functionalities are now split in two separate methods:Callback::getTriggeredValue()
andCallback::isTriggered()