Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.52k stars 223 forks source link

optionLabel is Overridden in execute Method of FilterEnumSelect.php #1679

Closed YashShah20 closed 2 months ago

YashShah20 commented 2 months ago

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

Yes - I didn't work.

Is there an error in the console?

No

PHP Version

No response

PowerGrid

No response

Laravel

No response

Livewire

No response

Alpine JS

No response

Theme

Bootstrap

Describe the bug.

In the FilterEnumSelect class, the execute method has an issue where the $optionLabel is always set to 'value' at the beginning of the method. This behavior overrides any previous attempts to set a custom label field for the filter, leading to unexpected results.

Problem:

The $optionLabel variable is initialized with 'value' and is only updated to 'name' if a specific condition is met. This initialization means that the initial value ('value') always overrides any previously set label field, which can cause issues if users want to customize the label field for their filters.

Expected Behavior:

The optionLabel should retain any user-defined label fields rather than being overwritten by the default 'value'.

To Reproduce...

No response

Extra information

public function execute(): FilterEnumSelect
{
    $optionLabel = 'value';

    $collection = collect($this->dataSource)->map(function ($case) use (&$optionLabel) {
        $option = (array) $case;

        if (method_exists($case, 'labelPowergridFilter')) {
            $option['name'] = $case->labelPowergridFilter();
            $optionLabel    = 'name';
        }

        return $option;
    });

    $this->dataSource($collection);

    $this->optionLabel($optionLabel);

    $this->optionValue($this->optionValue);

    return $this;
}
luanfreitasdev commented 2 months ago

Thank you

https://github.com/Power-Components/livewire-powergrid/releases/tag/v5.10.6