inspheric / nova-indicator-field

A colour-coded indicator field for Laravel Nova
129 stars 10 forks source link

Change key => value order around to match Nova defaults #6

Closed lasseeee closed 5 years ago

lasseeee commented 5 years ago

The Database field => Display field pairs used in this package should be switched around to match Novas default (used in filters etc.) which is Display field => Database field.

kitbs commented 5 years ago

I know what you mean, but what Nova does is completely counterintuitive and actually prevents you from using the same display value for multiple database values. And in our case it would prevent you from using the same colour for multiple database values.

Take a contrived example of how this field currently works:

Indicator::make('Status')
    ->colors([
        'failed' => 'red',
        'inactive' => 'red',
        'success' => 'green',
        'active' => 'green',
    ])

This would be impossible if you switched the order around, because you can see the keys are no longer unique:

Indicator::make('Status')
    ->colors([
        'red' => 'failed',
        'red' => 'inactive',
        'green' => 'success',
        'green' => 'active',
    ])

Apart from the fact that this would be a breaking change, it is also not a good idea. Thanks for the suggestion though and I do appreciate trying to make things consistent! :-)