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

Callback/sticky args refactor #1377

Merged
merged 40 commits into from Aug 1, 2020
Merged

Callback/sticky args refactor #1377

merged 40 commits into from Aug 1, 2020

Conversation

ibelar
Copy link
Contributor

@ibelar ibelar commented Jul 24, 2020

Refactor Callback

Post trigger has been remove! Triggering callback is done only via a $_GET argument.

Small BC break:

  • No more POST trigger;
  • 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() and Callback::isTriggered()

@ibelar ibelar marked this pull request as draft July 24, 2020 16:48
src/Callback.php Outdated Show resolved Hide resolved
src/Callback.php Outdated Show resolved Hide resolved
src/Callback.php Outdated Show resolved Hide resolved
src/Callback.php Outdated Show resolved Hide resolved
src/Callback.php Outdated
public function setUrlTrigger(string $trigger)
{
$this->urlTrigger = $trigger;
$this->app->stickyGet($this->urlTrigger);
Copy link
Member

@mvorisek mvorisek Jul 25, 2020

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.

Copy link
Contributor Author

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.

Copy link
Member

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/Callback.php Outdated Show resolved Hide resolved
src/Modal.php Show resolved Hide resolved
- set Url argument properly when isPostTriggered;
- clean up triggered() method
src/JsSortable.php Outdated Show resolved Hide resolved
@@ -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)) {
Copy link
Member

@mvorisek mvorisek Jul 25, 2020

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

@mvorisek mvorisek mentioned this pull request Jul 25, 2020
@ibelar
Copy link
Contributor Author

ibelar commented Jul 26, 2020

@georgehristov - @mvorisek - Any idea why Behat Crud test is failing since last Data update?
When in CRUD and search for "united kingdom", then edit the record, Normally after edit the CRUD reload and you should still see the United Kingdom record but it does not. The only change is that the query (_q) argument is changed from "united kingdom" to "united+kingdom" but this was working before...

@mvorisek
Copy link
Member

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.

@ibelar
Copy link
Contributor Author

ibelar commented Jul 26, 2020

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

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.

Nevermind, I see where the error comes from.

- remove app sticky;
- remove post triggering support;
- remove post triggereing test;
- fix wizard triggered value
- 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/Form.php Outdated Show resolved Hide resolved
src/Callback.php Outdated
return $ret;
}
if ($this->isTriggered()) {
$this->owner->stickyGet($this->urlTrigger);
Copy link
Member

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()

Copy link
Contributor Author

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.

Copy link
Member

@mvorisek mvorisek Jul 28, 2020

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

@ibelar
Copy link
Contributor Author

ibelar commented Jul 30, 2020

@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)
Copy link
Contributor Author

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...

Copy link
Member

@mvorisek mvorisek Jul 30, 2020

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

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 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.

Copy link
Member

Choose a reason for hiding this comment

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

@mvorisek
Copy link
Member

  • /demos/form-control/upload.php

fixed, support of multiple files already in #1380

  • /demos/interactive/wizard.php (Wizard demo step 2)

yes, this issue is related with b459488 , can you look at it?

@ibelar
Copy link
Contributor Author

ibelar commented Jul 30, 2020

@mvorisek - I revert Callback to the last working state. Let's merge this and we can look into your issue after.

@mvorisek
Copy link
Member

mvorisek commented Jul 30, 2020

@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) .

we should test 3x (main + 2x) nested CRUD in tests

  • please add some nested tests to this PR and then let's merge it
  • please also add test for Wizard demo (which will fail if we revert the revert)

$loader = Loader::addTo($app);
$loader->loadEvent = false;

$loader->set(function($p) use ($m) {
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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...)

@mvorisek mvorisek merged commit 08644a6 into develop Aug 1, 2020
@mvorisek mvorisek deleted the feature/refactor-callbacks branch August 1, 2020 19:44
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.

None yet

3 participants