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

Port betterbuttons to framework #8569

Merged

Conversation

bergice
Copy link
Contributor

@bergice bergice commented Nov 5, 2018

This adds Previous, Next and Add buttons to the edit form. It should also retain the search filters from the grid field where it was opened from.

Fixes #436

_config/buttons.yml Outdated Show resolved Hide resolved
@bergice bergice force-pushed the pulls/4/436-port-betterbuttons branch from 8a8a0dc to a9f3c77 Compare November 5, 2018 22:41
Copy link

@unclecheese unclecheese left a comment

Choose a reason for hiding this comment

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

Nice work. Biggest thing is I see a lot of artefacts from BetterButtons that don't apply here, such as owner and Controller::curr(), in addition to a number of other syntactical issues.

Second major thing is these will need unit tests.

Otherwise, I think you've done a good job of containing the story and not blowing up the API too much in the interest of parity with BetterButtons. We can improve upon this in a future story.

src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldEditButton.php Outdated Show resolved Hide resolved
_config/buttons.yml Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
@bergice bergice force-pushed the pulls/4/436-port-betterbuttons branch 4 times, most recently from c68d5a7 to 1759224 Compare November 7, 2018 05:17
@bergice bergice dismissed unclecheese’s stale review November 8, 2018 21:59

Rectified all the requested changes.

@bergice bergice force-pushed the pulls/4/436-port-betterbuttons branch from 6e20bda to 2ae244b Compare November 12, 2018 05:14
Copy link

@unclecheese unclecheese left a comment

Choose a reason for hiding this comment

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

Getting there. High level points:

  • Change showNext and showPrev to a monolithic showPagination
  • Refactor getPreviousID() and getNextID() to be more scalable. Current implementation is inherently flawed.

src/Forms/GridField/GridFieldDetailForm.php Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
{
Controller::curr()->getResponse()->addHeader("X-Pjax", "Content");
$link = $this->getEditLink($this->getNextRecordID());
return Controller::curr()->redirect($link);

Choose a reason for hiding this comment

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

getResponse() isn't available on RequestHandler. Let's use $this->getTopLevelController()->getResponse() and $this->redirect().

src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
src/Forms/GridField/GridFieldDetailForm_ItemRequest.php Outdated Show resolved Hide resolved
@unclecheese
Copy link

unclecheese commented Nov 14, 2018

The changes to GridFieldPaginator are likely incompatible with the #1 installed module in the SS ecosystem, gridfieldextensions, which offers a GridFieldConfigurablePaginator component that uses its own itemsPerPage state.

We haven't broken any APIs, so this is safe to merge into a minor release, but I think we should at least check in with the maintainers to let them know about this change so they can issue a 4.4.x compatible release. CC @robbieaverill @NightJar

@robbieaverill
Copy link
Contributor

Thank for checking @unclecheese, we'll test it out. Hopefully nothing breaks, it might get a little hairy to adjust the code to support both versions if it does - we'll see =)

bergice and others added 5 commits November 19, 2018 10:49
If the form is opened via a grid field, the filters will be retained so the previous/next record opened will be correct
…xt` and `Add` buttons at a `GridField` level
…elds

- Update documentation
- Improve performance for next/previous buttons by not fetching all list records
- Refactoring
@unclecheese
Copy link

Awesome. Tests were failing because $state->getData('GridFieldPaginator') wasn't always defined. Have put a guard in against that.

Other minor points:

  • Consistency with single/double quotes. Prefer single, unless doing variable interpolation
  • Private members should be used sparingly, as they're antithetical to extensibility.
  • Don't assume config vars are set ($formConfig['showAdd']), as it tightly couples your code to the config.

Merge on green.

@unclecheese unclecheese merged commit cc71289 into silverstripe:4 Nov 18, 2018
@unclecheese unclecheese deleted the pulls/4/436-port-betterbuttons branch November 18, 2018 22:06
@robbieaverill
Copy link
Contributor

Consistency with single/double quotes. Prefer single, unless doing variable interpolation

We should add this to phpcs rules. Related: #8343

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.

4 participants