mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Scraped titles run to hundreds of characters, so the view page heading
wrapped to eight lines and Filament's sm:items-center left the header
actions floating in the middle of it.
- Clamp the heading to 2 lines (3 from md) with the full title on hover,
via getHeading() so the browser tab title stays plain text.
- Align the header actions to the top of the heading on the product view.
- Strip the site name noise stores append to titles ("...: Mice:
Amazon.com.au") on save, using the store name where it is known.
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ProductResource\Pages;
|
|
|
|
use App\Enums\Icons;
|
|
use App\Filament\Actions\BaseAction;
|
|
use App\Filament\Resources\ProductResource;
|
|
use App\Models\Product;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
/**
|
|
* @property Product $record
|
|
*/
|
|
class ViewProduct extends ViewRecord
|
|
{
|
|
protected static string $resource = ProductResource::class;
|
|
|
|
protected static string $view = 'filament.resources.product-resource.pages.view';
|
|
|
|
public function getTitle(): string|Htmlable
|
|
{
|
|
return $this->record->title;
|
|
}
|
|
|
|
/**
|
|
* Scraped titles run long, so clamp the heading to a couple of lines rather than letting
|
|
* it push the header actions down the page. The full title stays available on hover.
|
|
*/
|
|
public function getHeading(): string|Htmlable
|
|
{
|
|
return new HtmlString(sprintf(
|
|
'<span class="block max-w-3xl line-clamp-2 md:line-clamp-3" title="%s">%s</span>',
|
|
e($this->record->title),
|
|
e($this->record->title),
|
|
));
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
ProductResource\Actions\AddUrlAction::make(),
|
|
ProductResource\Actions\FetchAction::make(),
|
|
BaseAction::make('edit_product')->icon(Icons::Edit->value)
|
|
->label(__('Edit'))
|
|
->resourceName('product')
|
|
->resourceUrl('edit', $this->record),
|
|
];
|
|
}
|
|
|
|
public function getFooterWidgetsColumns(): int|array
|
|
{
|
|
return 1;
|
|
}
|
|
}
|