8000 Bugfix v4: Structure mode toggle button disappearing from toolbar by fsbraun · Pull Request #7272 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Bugfix v4: Structure mode toggle button disappearing from toolbar #7272

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

Merged
merged 23 commits into from
May 25, 2022

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Mar 23, 2022

Description

When editing with the structure board open any change in the page, e.g. by moving a plugin to a new position, will make the toggle button in the toolbar disappear as @marksweb reported here: https://django-cmsworkspace.slack.com/archives/C01E6NMK540/p1645542305165849

Please note the empty upper right corner.

image

Related resources

  • The disappearing of the button happens in two steps:

    1. The toolbar is reloaded after each editing step (I am not sure this is necessary, btw.)

    2. If the page content has changed, the page is reloaded using xhr. The reload includes the toolbar.

  • The first step failed to send the current placeholder as get parameters since the url was encoded twice. As a result the backend returns the toolbar with just the create button and without edit button. This new toolbar is rendered in the browser window.

  • When the page reload delivers the correct toolbar, it is used to patch the current toolbar. This leads fails to restore the toggle button since there is no button to patch.

The fix removes the call to Helpers.updateUrlWithPath which encodes the already encoded url a second time replacing the get parameter separator & by &.

NOTE: Helpers.updateUrlWithPath can also change the url path according to some rules. This is not the case in the call affected (imho).

The double xhr call to the backend is unnecessary and the first call can be dropped. This PR does that by rearranging the code. It leads to better responsiveness of the frontend editing experience.

This PR should be ported to v3 also. I expect it to solve issue #7222 .

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #workgroup-pr-review on Slack to find a “pr review buddy” who is going to review my pull request.

@fsbraun fsbraun changed the title Bugfix: Structure mode toggle button disappearing from toolbar Bugfix v4: Structure mode toggle button disappearing from toolbar Mar 23, 2022
@marksweb marksweb closed this Mar 23, 2022
@marksweb marksweb reopened this Mar 23, 2022
…quest_pass or the toolbar will be wrongly configured
@fsbraun
Copy link
Member Author
fsbraun commented Mar 23, 2022

Additional fix in settingsadmin.py:

  • If the only the toolbar is loaded by the js, the toolbar settings need to be set for the calling page (supplied in the cms_page get parameter). The toolbar class accounts for it and expects that the request object passed on initialization in that case contains a property resolver_match.

  • This property was not set in settingsadmin.py leading to the toolbar not recognizing it already is in editing mode.

  • As a result a copy operation (only operation that leads to this situation) would generate a wrong toolbar clicking upon which would lead not to edit but to structure mode and potentially to a dead endpoint (get instead of post). See image (Edit button despite open structure board).

  • Finally, I have removed three lines for python 2 support.

@@ -1070,12 +1068,17 @@ class StructureBoard {
const placeholderIds = getPlaceholderIds(CMS._plugins).map(id => `placeholders[]=${id}`).join('&');

return $.ajax({
url: Helpers.updateUrlWithPath(
url: (
Copy link
Contributor

Choose a reason for hiding this comment

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

What were you thoughts when removing: Helpers.updateUrlWithPath?

Copy link
Member Author
@fsbraun fsbraun Mar 24, 2022

Choose a reason for hiding this comment

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

Helpers.updateUrlWithPath is the root cause of the bug. It replaces query separator& by &amps. Since it is used in many places within django CMS, I did not change it. I cannot anticipate the side effects.

In any case: Helpers.updateUrlWithPath('/local_url?x=1&y=2') returns '/local_url?x=1&y=2&cms_path=%2Fadmin%2Fcms%2Fplaceholder%2Fobject%2F10%2F' which is not a meanigful path to get the toolbar for. The fix in the same situation creates a meaningful url: '/local_url?x=1&y=2&cms_path=%2Fadmin%2Fcms%2Fplaceholder%2Fobject%2F10%2F'

Frankly, I still struggle to comprehend the implementation of Helpers.makeUrl which is called by Helpers.updateUrlWithPath:

makeURL: function makeURL(url, params = []) {
let newUrl = new URL(URL.decode(url.replace(/&/g, '&')));
params.forEach(pair => {
const [key, value] = pair;
newUrl.removeSearch(key);
newUrl.addSearch(key, value);
});
return newUrl
.toString()
.split('#')
.map((part, i) => {
return i === 0 ? part.replace(/&/g, '&') : part;
})
.join('#');
},

Line 305 is highly questionable if you have more than one get parameter!

Copy link
Member Author
@fsbraun fsbraun Mar 24, 2022

Choose a reason for hiding this comment

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

Hide comment

@Aiky30 An alternative way would be to drop the urljs dependence and use the browsers' URLSearchParams interface. This would allow to have Helpers.updateUrlWithPath to be present. It should build correct urls. But it also requires a small change in cms.pagetree.js. Overall this is probably cleaner but a be it small change deep in the code.

If you think that is better, I'll give it a go!

Copy link
Member Author

Choose a reason for hiding this comment

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

After more pondering I come to the conclusion to essentially remove lines 303-307 in makeURL: It seems to never have worked right with more than one query parameter. Overall, this deems to be the most systematic solution.

I still have to make the discrimination test for Resolver404 work.

@fsbraun
Copy link
Member Author
fsbraun commented Mar 25, 2022
8000

@Aiky30 The resolver test ist implemented and works.

I have refactored the patch to change the underlying Helpers.makeUrl. I now believe this has never worked correctly. Also the test were testing for incorrect behavior? I have not found a single browser that accepts & as a search parameter delimiter in js. (It seems ok for html.)

Test action fails when testing the documents build (which incidentally works in the separate automation). The reason seems to be sphinx 1.8 importing incorrectly from jinja2. Certainly nothing to do with this PR. I suggest to remove the fix to Sphinx==1.8.x in the requirements and backport the changes f3285b6 to the documentation (highlight etc.)

@fsbraun
Copy link
Member Author
fsbraun commented May 5, 2022

@Aiky30 What are your thoughts on getting this merged?

@Aiky30
Copy link
Contributor
Aiky30 commented May 17, 2022

@fsbraun I haven't forgotten about your changes here. The makeUrl function replacing & with & appears to have been a quick and dirty workaround here: #3404. I guess you may already know this.

Once I understand the reason for it's existence I'll be able to approve your rework. My fear right now is any regression, especially if this is used in other parts of the CMS / external packages.

@Aiky30
Copy link
Contributor
Aiky30 commented May 17, 2022

The original bug that needs a test case for, this then ensures that we don't reintroduce the same bug for someone to then undo these changes forever going in a cycle: #3434

@Aiky30
Copy link
Contributor
Aiky30 commented May 17, 2022

A frontend test that replicates this bug: #3434

Then we can see with these changes if that issue has been reintroduced.

@fsbraun
Copy link
Member Author
fsbraun commented May 17, 2022

I understand your concerns. The "quick and dirty workaround" from 2014 does not work in the first place, it does break every url with more than one parameter as of Django 2.2.19. See nichoski's discussion in #7113. In Django < 2.2.19 things only work accidentally.

The underlying jQuery bug has been fixed. I did not research the exact version but tested it with CMS' jQuery verision.

To mitigate your concerns please be aware that this has also been corrected and in the field with v3.10 (PR #7114).

Finally, also "Add page type" works in 3.10 with the proposed fix. In v4 page types are gone, hence nothing to test there.

@Aiky30
Copy link
Contributor
Aiky30 commented May 18, 2022

I understand your concerns. The "quick and dirty workaround" from 2014 does not work in the first place, it does break every url with more than one parameter as of Django 2.2.19. See nichoski's discussion in #7113. In Django < 2.2.19 things only work accidentally.

The underlying jQuery bug has been fixed. I did not research the exact version but tested it with CMS' jQuery verision.

To mitigate your concerns please be aware that this has also been corrected and in the field with v3.10 (PR #7114).

Finally, also "Add page type" works in 3.10 with the proposed fix. In v4 page types are gone, hence nothing to test there.

@fsbraun I could see the change was made to django-cms 3.10 and I guess as you mentioned the issue was in an older release of django. PageType is still in v4 but it just hasn't been configured in to use the edit, preview and structure endpoints.

@Aiky30
Copy link
Contributor
Aiky30 commented May 18, 2022

After seeing the various tickets listing bugs and fixes I'm happy to allow this reverse of the fix.

Copy link
Contributor
@Aiky30 Aiky30 left a comment

Choose a reason for hiding this comment

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

Minor formatting changes required, the only one I can't use GH suggestions for I have proposed a comment.

fsbraun and others added 5 commits May 18, 2022 12:11
Reverse formatting change

Co-authored-by: Aiky30 <Aiky30@users.noreply.github.com>
Correct formatting

Co-authored-by: Aiky30 <Aiky30@users.noreply.github.com>
Comment above not at end of line

Co-authored-by: Aiky30 <Aiky30@users.noreply.github.com>
Update method doc
Remove trailing space
Copy link
Contributor
@Aiky30 Aiky30 left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks.

We have a release queued for tomorrow morning first thing, that release will be merged back into develop-4 then I can merge your PR in to keep the order of changes correct.

The release queued for tomorrow morning: #7317

Once the above is complete we can merge this PR and the generate a release straight away to test on.

@Aiky30 Aiky30 merged commit 7dafe84 into django-cms:develop-4 May 25, 2022
@fsbraun
Copy link
Member Author
fsbraun commented Oct 11, 2022 via email

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.

3 participants
0