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

PATCH: ensure that composite and nested form fields can be included #145

Closed
wants to merge 2 commits into from

Conversation

sunnysideup
Copy link
Contributor

@sunnysideup sunnysideup commented Jan 29, 2022

Issue #138

@GuySartorelli
Copy link
Member

Looks (at a quick glance) like this might fix #138

@dhensby
Copy link
Contributor

dhensby commented Jan 29, 2022

This needs linting fixes applied

@sunnysideup
Copy link
Contributor Author

sunnysideup commented Jan 29, 2022

@GuySartorelli @dhensby
Thank you for looking at this.

We need to make patching as easy as possible. I am looking at this:

FILE: /home/travis/build/silverstripe/silverstripe-reports/code/Report.php
--------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------
 309 | ERROR | [x] Blank line found at start of control structure
 313 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
 314 | ERROR | [x] Expected 1 space(s) after IF keyword; 0 found
 321 | ERROR | [x] Expected 1 space(s) after FOREACH keyword; 0 found
--------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------
Time: 124ms; Memory: 10MB

I might be reading this incorrectly, but is there a way that these fixes are applied automatically? We need to speed up our development and this sort of thing would just make everything easier and faster. I am particular looking at this:

PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY

@dhensby
Copy link
Contributor

dhensby commented Jan 29, 2022

@sunnysideup
Copy link
Contributor Author

@dhensby - thank you for your super quick replies.

what i mean is that any commits automatically get cleaned up for stuff like that. I looked if something like this exists - I could not find something obvious. I think GitHub Actions could solve this though. This would save oodles of time.

@GuySartorelli
Copy link
Member

@sunnysideup a pre-commit hook could do that - I believe you can use pre-commit hooks locally without affecting other developers' workflow.

@sunnysideup
Copy link
Contributor Author

@GuySartorelli - thank you for writing back.

The whole point is that it should not be a local thing, but rather a standardised server thing. If we want to make contributing as easy as possible then this would be a big time saver.

In other words, a way to save time for both committer and reviewer is to lint the code, centrally, when you make a commit.

i.e. in terms of the style errors that can be fixed automatically -

  • as a committer, I dont have know about linting standards, etc.... and I dont have to apply them with some extra command - I can be sure they are done auto-magically.

  • as a reviewer, I dont have to explain, or wait for the committer to fix them - they are already fixed.

@GuySartorelli
Copy link
Member

There are arguments that could be made both ways. It's also a good opportunity for developers to be mindful of the quality and style of their code.... In any case this discussion is probably better suited to the forums. It's definitely worth discussing and might be a useful change to make. The forums are where it has the best chance of getting attention from enough core committers to be implemented.

@dhensby
Copy link
Contributor

dhensby commented Jan 30, 2022

In my view it's pretty typical that a project expects contributors to be able to make sure their contributions adhere to the coding styles of the project. This is pretty simple and it's usually possible to automatically fix problems using the tooling provided (as in this case).

Sometimes the linting can't be fixed automatically and in those cases the author will need to manually rectify the problems.

The problem with automating this process and having CI or a linting bot do the fixes is that we then end up with commits that are solely for linting (which isn't great, but not a blocker) but what does happen is someone else starts contributing commits to the PR. That requires the author to provide the bot or maintainers with push rights to the branch and it also means the history in the PR diverges from the author's version.

Diverging PRs become a problem when authors don't realise that commits have been added and so start to get conflicts or issues when they try to update the PR. It is my experience that a typical contributor will not be aware of how to resolve these problems and probably won't understand why they've happened. I'd suggest that a contributor that doesn't know how to lint their code probably doesn't know how to deal with divergent branches in git either.

Automating linting for contributors is pretty straight forward too. IDEs often prompt visually to linting errors, provide automated fixes, and can be configured to lint-on-save. I do think it falls into the role of contributors to lint their code before supplying it and, as others have said, there are ways for people to automate that in their workflows.

On balance, I think any attempt at automating linting will cause greater pain over time than getting contributors to adopt good habits and to lint their contributions.

@sunnysideup
Copy link
Contributor Author

sunnysideup commented Jan 30, 2022

Thank you for your considerate and in-depth answers. Here are a couple of things to consider (if you have not already):

  • if we want SS to survive and shine,we should make contributing as easy as possible.
  • time is the key factor so any second we can save is good.
  • I am not so familiar with the coding standards for SS projects. I wholeheartedly agree with them, but it is not something I need to know in-depth I feel (e.g. Blank line found at start of control structure - totally agree, very good, I dont care). This rings especially true for people making their first contributions who make work on other projects (with other standards).
  • I made my pull request from the inline editor on github. This inline editor does not do anything for me in terms of fixing up this stuff. That is, I tried out the new code on a project I am working on and then changed it on this repo using the inline editor. This is a fast and efficient workflow. I could have run a linter, but that may have taken an extra minute.
  • I understand the issues around merge conflicts - maybe the code could be linted for non-automatable errors only and then, on merge, gets linted for automatable linting errors.
  • the hard part, it seems, is working out how to do the linting automation. Here is probably the easiest way to do it:
    a. only look for non-automatic fixable linting errors in PR - like you did in mine.
    b. from a server, once a day or so, lint the branch merged into for automatable fixes.

If you can see I have a point then I will post on the forum. If I am just trying to justify my own laziness then I am happy to shut up also ;-)

@GuySartorelli
Copy link
Member

I definitely thinks it's worth raising in the forum's; I've seen this pop up a few times in other PRs as well so you're not alone in wanting this. At the very least it would give a central place for this discussion.

@GuySartorelli
Copy link
Member

@dhensby discussion above notwithstanding, looks like the requested changes were made.

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Does not seem to work

Testing locally, the query string for a reqular checkboxe changed from ?filters[Chx]=1 to ?filters[filters[Chx]]=1 and thus stopped working

I tested this using the following code

<?php

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Reports\Report;

class MyReport extends Report
{
    public function title()
    {
        return 'My report';
    }

    public function sourceRecords($params = null)
    {
        $filters = [];
        if (isset($params['Chx']) || isset($params['Chx2'])) {
            $filters['Title'] = 'Contact Us';
        }
        if (isset($params['Chx3'])) {
            $filters['ID:GreaterThan'] = 5;
        }
        return SiteTree::get()->filter($filters);
    }

    public function columns()
    {
        return [
            "ID" => [
                "id" => "ID"
            ],
            "Title" => [
                "title" => "Title"
            ],
        ];
    }

    public function parameterFields()
    {
        return new FieldList(
            new CheckboxField('Chx', 'Filter Title by "Contact Us"'),
            new CompositeField([
                new CheckboxField('Chx2', 'Filter Title by "Contact Us"'),
                new CheckboxField('Chx3', 'Filter by ID > 5'),
            ])
        );
    }
}

@sunnysideup
Copy link
Contributor Author

sunnysideup commented May 18, 2022

@emteknetnz - thank you for testing. I wonder if that is something that is

  • an additional feature "I want to be able to port my existing fields to composite fields without changing the query string" or
  • broken in reports or
  • is broken in composite fields.
  • something that can be fixed in the suggested code (most likely I guess).

@wilr
Copy link
Member

wilr commented Sep 29, 2023

I believe this is related to #169 and should be sorted in latest release.

@wilr wilr closed this Sep 29, 2023
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.

5 participants