don't needed crash if value is empty by xam8re · Pull Request #2793 · orchidsoftware/platform
To be more concrete here is my suggestion
Add new property and method into Orchid\Screen\TD class
protected $empty = ''; public function empty($empty) { $this->empty = $empty; return $this; }
Change a little buildTd method
- 'value' => $value, + 'value' => $value ?? $this->empty,
And renderComponent of Cell
protected function renderComponent(string $component, $value, array $params = []): ?string
{
+ if (is_null($value)) {
+ return $this->empty;
+ }
[$class, $view] = Blade::componentInfo($component);This way:
- We kept cell components strict types
- Prevent it from crashes when null value is being passed (it doesn't even get to cell component)
- Add extra flexibility for developer (if there is a
nullvalue empty string will be shown instead. But they are free to change it with whatever value they wish viaempty()method regardless of using you component or not)
Big question for me is what to be considered empty (for now this will check null value only, but when value is empty string '' - it is empty as well. Should we handle this case or null only? If not name empty will be confusing)
Or
Just change strict float type of Currency component (and every other) into ?float (null or float) - fixes error, leave everything else as it is, no extra feature (which could be considered as redundant)