-
Notifications
You must be signed in to change notification settings - Fork 917
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
Add column default
attribute & make that default consistent across column types
#3936
Conversation
* add default
…nd-placeholders # Conflicts: # src/resources/views/crud/columns/json.blade.php # src/resources/views/crud/columns/markdown.blade.php # src/resources/views/crud/columns/number.blade.php # src/resources/views/crud/columns/phone.blade.php # src/resources/views/crud/columns/radio.blade.php # src/resources/views/crud/columns/relationship_count.blade.php # src/resources/views/crud/columns/table.blade.php # src/resources/views/crud/columns/textarea.blade.php
Another note on this, in some places the |
default
attribute & make that default consistent across column types
@promatik - I think In the end, I propose we do this:
While we're at it, since we're now adding a customizable
This way:
Sounds reasonable? @zachweix what do you think? |
# Conflicts: # src/resources/views/crud/columns/select_multiple.blade.php
The inspection completed: No new issues |
This was a lot of work and a lot of testing, but I think the result is good 👌 Columns are now much more standard. 🙌 The PR for the deprecation of |
I love it ❤️ Very clean and complete PR, good job @promatik ! This will make it easier to make I will test & merge it as it is now. No point in making any more stylistic changes. Perfect is the enemy of good. But... for future reference, it seems to me like most columns now have this order in the php logic:
I think it'd been cleaner if the value got calculated in just one spot, either:
or
For example in the - $column['value'] = $column['value'] ?? data_get($entry, $column['name']);
$column['escaped'] = $column['escaped'] ?? false;
$column['prefix'] = $column['prefix'] ?? '';
$column['suffix'] = $column['suffix'] ?? '';
+ $column['value'] = $column['value'] ?? data_get($entry, $column['name']);
if(is_callable($column['value'])) {
$column['value'] = $column['value']($entry);
}
// the value should be an array whether or not attribute casting is used
if (!is_array($column['value'])) {
$column['value'] = json_decode($column['value'], true);
} BUUT. It wouldn't have been as surgical. That's why I think we should NOT do the above right now. That's a task for future-us 😀 Again, perfect is the enemy of good - we should remember that more often 😅 Of course, if we wanted to be fancy, we could go as far as doing something like: - $column['value'] = $column['value'] ?? data_get($entry, $column['name']);
+ $column['value'] = (function($entry) uses ($column) {
+ // if the value is a closure, run it; if it's defined, use it; if null, get the attribute on the entry;
+ $value = is_callable($column['value']) ? $column['value']() : $column['value'] ?? data_get($entry, $column['name']);
+
+ // the value should be an array whether or not attribute casting is used
+ if (!is_array(value)) {
+ return json_decode($value, true);
+ }
+
+ return $value;
+ })();
$column['escaped'] = $column['escaped'] ?? false;
$column['prefix'] = $column['prefix'] ?? '';
$column['suffix'] = $column['suffix'] ?? '';
- if(is_callable($column['value'])) {
- $column['value'] = $column['value']($entry);
- }
But again. We're NOT doing that right now. No point - we'll be moving this logic into PHP classes in a few months. Again, good job on this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a few minor inconsistencies, but overall... looks to be VERY backwards-compatible. Good job @promatik .
if(!empty($column['value'])) { | ||
$column['text'] = $column['prefix'].count($column['value']).$column['suffix']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes behaviour when the relationship_count
value is zero. Before it was showing an empty cell. Now it's showing "0 items" which I don't think makes sense (especially if you add a link to it).
Why use !empty()
here @promatik ?
I would see the best case here as showing the $column['default']
like all other columns.
It's arguable though. More consistent would be to show 0 items
like it does now... I don't know...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok scratch that, I changed my mind. It's more consistent to show 0 items
- more important to be consistent with itself than with other columns. I'm ok with how this is now, showing 0 items
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No! 😅 I think you are right ...
array_count
works the same way, I think we should keep the cell empty ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this may happen in other fields where we just added the dash -
😬
Maybe I should refactor this a little bit more so that;
@if(!empty($column['value']))
@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_start')
{{ $column['prefix'] }}
@if($column['escaped'])
{{ $column['value'] }}
@else
{!! $column['value'] !!}
@endif
{{ $column['suffix'] }}
@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_end')
@else
{{ $column['default'] ?? '-' }}
@endif
This way, the empty dash will always be outside the wrapper ...
Let me know @tabacitu ✌, I know in advance – we shouldn't be worrying that much with perfection – but let's hope this is the last change ✌😅
I've just re-tested this and decided it's good enough as-is. We can of course find more quirks and inconsistencies and gradually do them, but for now... this will do. @promatik please add issues or make separate PRs in 4.2.x if you think there are more things to do in regard to this. But for now, merging 💪 🎉🎉🎉 |
This PR combines #3903 + #3437.
Questions from #3903;
Questions from #3437;
Since we are talking about it, should
[...]
be a config also? I would like to use the Unicode Character…
(U+2026) only 😅