CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

Add fluent field group

Open pxpm opened this issue 5 years ago • 16 comments

REFS: #2642

Address #2950

 CRUD::fieldGroup(
            CRUD::field('backpack')->label('backpacker'),
            CRUD::field('backpacker')->label('backpack')
        )->tab('Backpack Rocks')->label('Backpack Label Override Rocks.');

pxpm avatar Jun 18 '20 17:06 pxpm

Just. Freaking. Awesome. Great work @pxpm ! This is the kind PR I love - surgical. Good job! Totally agree we need this - I will test and give feedback as soon as you let me know it's ready.

Cheers!

tabacitu avatar Jun 19 '20 08:06 tabacitu

It's ok now @tabacitu you can test and merge.

Best, Pedro

pxpm avatar Jun 19 '20 09:06 pxpm

@pxpm if using this code, removing $field->save();

public function __call($method, $parameter)
    {
        foreach ($this->fields as $field) {
            $field->{$method}($parameter[0]);
        }

        return $this;
    }

its working with nested group) Like this

CRUD::fieldGroup(
            CRUD::fieldGroup(
                CRUD::field('title'),
                CRUD::field('descr')
            )->size(6),
            CRUD::fieldGroup(
                CRUD::field('word'),
                CRUD::field('char')
            )->size(8)
        )->tab('Test')
        ;

lotarbo avatar Jun 19 '20 10:06 lotarbo

Indeed, calling the method directly allow us to remove the save call.

Thanks

pxpm avatar Jun 19 '20 10:06 pxpm

@pxpm @tabacitu also, group works with colum) So...change method name to group?) Nice, pretty sugar CRUD::group();

lotarbo avatar Jun 19 '20 10:06 lotarbo

@pxpm @tabacitu also, group works with colum) So...change method name to group?) Nice, pretty sugar CRUD::group();

I don't dislike it, if @tabacitu agree I am ok with the change to make it seamless to work with fields and columns. Or create a columnGroup() helper in case group() is too vague.

pxpm avatar Jun 19 '20 10:06 pxpm

@pxpm @tabacitu also, group works with colum) So...change method name to group?) Nice, pretty sugar CRUD::group();

I don't dislike it, if @tabacitu agree I am ok with the change to make it seamless to work with fields and columns. Or create a columnGroup() helper in case group() is too vague.

But it works with column atm

CRUD::fieldGroup(
            CRUD::column('name'),
            CRUD::column('order')
        )->type('text');

lotarbo avatar Jun 19 '20 10:06 lotarbo

Excellent idea with group @lotarbo - I think it's intuitive because it's similar to Route groups in Laravel. So it'd be:

CRUD::group(
            CRUD::column('name'),
            CRUD::column('order')
        )->type('text');


CRUD::group(
            CRUD::field('name'),
            CRUD::field('order')
        )->type('text');

I think that's a great idea!

tabacitu avatar Jun 19 '20 11:06 tabacitu

What do you guys think of also supporting an array as parameter? (it's do the exact same thing)

It looks to me like it's easy to get confused what the parameter(s) for the group method should be, so it might be a good idea to support both.

CRUD::group(
            CRUD::column('name'),
            CRUD::column('order')
        )->type('text');

// or

CRUD::group([
            CRUD::column('name'),
            CRUD::column('order'),
        ])->type('text');

Not sure about this one - asking for opinion.

Personally I'd probably go with arrays in my projects because I like the fact that I can end all lines with a trailing comma. Though I believe it also works in parameters for PHP 7.3+ I believe... So that would render that argument mute 😆

tabacitu avatar Jun 19 '20 11:06 tabacitu

I think you are right about the 7.3 trailling commas. But if you think we should support arrays for < 7.3 i am ok with it, but i personally would not be using the array notation myself.

pxpm avatar Jun 19 '20 11:06 pxpm

trailing comma works since php7.3, and i think, no need support array

lotarbo avatar Jun 19 '20 11:06 lotarbo

Added support for array input and refactored name to CrudObjectGroup

pxpm avatar Jun 23 '20 10:06 pxpm

@pxpm @tabacitu any news with this?)

lotarbo avatar Sep 04 '20 07:09 lotarbo

Hello @lotarbo

This is pending review. We had some major bugs to work out first and freezed the introduction of features. I think it's stabilizing now and we should go back to features soon.

Did you tried this PR? It's working good? Give us some feedback it might help speed up the review process.

Best to you, Pedro

pxpm avatar Sep 04 '20 10:09 pxpm

The inspection completed: 505 Issues, 79 Patches

scrutinizer-notifier avatar Sep 06 '21 09:09 scrutinizer-notifier

hi, any progress in v6?

dwedaz avatar Sep 03 '23 04:09 dwedaz