Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Nov 10, 2021
1 parent 4d13f79 commit 017fb10
Show file tree
Hide file tree
Showing 20 changed files with 475 additions and 372 deletions.
18 changes: 8 additions & 10 deletions docs/03-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,24 @@ use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('header_image')
```

You may customize the image size by passing a `width()` and `height()`, or both with `size()`:
You may make the image fully `rounded()`, which is useful for rendering avatars:

```php
use Filament\Tables\Columns\ImageColumn;

ImageColumn::make('header_image')->width(200)

ImageColumn::make('header_image')->height(50)

ImageColumn::make('author.avatar')->size(40)
ImageColumn::make('author.avatar')->rounded()
```

You may make the image fully `rounded()`, which is useful for rendering avatars:
You may customize the image size by passing a `width()` and `height()`, or both with `size()`:

```php
use Filament\Tables\Columns\ImageColumn;

ImageColumn::make('author.avatar')
->rounded()
->size(40)
ImageColumn::make('header_image')->width(200)

ImageColumn::make('header_image')->height(50)

ImageColumn::make('author.avatar')->size(40)
```

By default, the `public` disk will be used to retrieve images. You may pass a custom disk name to the `disk()` method:
Expand Down
2 changes: 1 addition & 1 deletion resources/views/actions/link-action.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
:href="$getUrl()"
:target="$shouldOpenUrlInNewTab() ? '_blank' : null"
:color="$getColor()"
class="text-sm font-semibold"
class="text-sm font-medium"
>
{{ $getLabel() }}
</x-tables::link>
2 changes: 1 addition & 1 deletion resources/views/columns/badge-column.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="px-4 py-3">
@if ($state = $getFormattedState())
<span @class([
'inline-flex items-center justify-center h-6 px-2 text-sm font-semibold tracking-tight rounded-full',
'inline-flex items-center justify-center h-6 px-2 text-sm font-medium tracking-tight rounded-full',
$stateColor => $stateColor,
])>
{{ $state }}
Expand Down
28 changes: 18 additions & 10 deletions resources/views/columns/image-column.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<div class="px-4 py-3">
@if ($path = $getImagePath())
<img
src="{{ $path }}"
@class([
'rounded-full' => $isRounded(),
])
style="
{!! ($height = $getHeight()) !== null ? "height: {$height};" : null !!}
{!! ($width = $getWidth()) !== null ? "width: {$width};" : null !!}
"
>
@if ($isRounded())
<div
class="rounded-full bg-center bg-cover"
style="
background-image: url('{{ $path }}');
height: {{ $getHeight() ?? '40px' }};
width: {{ $getWidth() ?? '40px' }};
"
></div>
@else
<img
src="{{ $path }}"
style="
{!! ($height = $getHeight()) !== null ? "height: {$height};" : null !!}
{!! ($width = $getWidth()) !== null ? "width: {$width};" : null !!}
"
>
@endif
@endif
</div>
2 changes: 1 addition & 1 deletion resources/views/components/button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@php
$buttonClasses = [
'inline-flex items-center justify-center font-semibold tracking-tight transition rounded-lg focus:outline-none focus:ring-offset-2 focus:ring-2 focus:ring-inset',
'inline-flex items-center justify-center font-medium tracking-tight transition rounded-lg focus:outline-none focus:ring-offset-2 focus:ring-2 focus:ring-inset',
'bg-primary-600 hover:bg-primary-500 focus:bg-primary-700 focus:ring-offset-primary-700' => $color === 'primary',
'h-9 px-4' => $size === 'md',
'text-white shadow focus:ring-white' => $color !== 'secondary',
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/modal/heading.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h2 {{ $attributes->class(['text-xl font-semibold tracking-tight']) }}>
<h2 {{ $attributes->class(['text-xl font-bold tracking-tight']) }}>
{{ $slot }}
</h2>
</h2>
652 changes: 326 additions & 326 deletions resources/views/index.blade.php

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Action extends Component implements Htmlable
use Macroable;
use Tappable;

protected $isHidden = false;

final public function __construct(string $name)
{
$this->name($name);
Expand All @@ -46,6 +48,10 @@ protected function setUp(): void

public function call(array $data = [])
{
if ($this->isHidden()) {
return;
}

$action = $this->getAction();

if (! $action instanceof Closure) {
Expand All @@ -59,6 +65,29 @@ public function call(array $data = [])
]);
}

public function hidden(bool | callable $condition = true): static
{
$this->isHidden = $condition;

return $this;
}

public function isHidden(): bool
{
if (! $this->isHidden instanceof Closure) {
return $this->isHidden;
}

if (! $this->getRecord()) {
return false;
}

return app()->call($this->isHidden, [
'livewire' => $this->getLivewire(),
'record' => $this->getRecord(),
]);
}

public function toHtml(): string
{
return $this->render()->render();
Expand Down
5 changes: 5 additions & 0 deletions src/Actions/BulkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class BulkAction
{
use Concerns\BelongsToTable;
use Concerns\CanBeHidden;
use Concerns\CanDeselectRecordsAfterCompletion;
use Concerns\CanOpenModal;
use Concerns\CanRequireConfirmation;
Expand Down Expand Up @@ -43,6 +44,10 @@ protected function setUp(): void

public function call(array $data = [])
{
if ($this->isHidden()) {
return;
}

$action = $this->getAction();

if (! $action instanceof Closure) {
Expand Down
20 changes: 20 additions & 0 deletions src/Actions/Concerns/CanBeHidden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Filament\Tables\Actions\Concerns;

trait CanBeHidden
{
protected bool $isHidden = false;

public function hidden(bool $condition = true): static
{
$this->isHidden = $condition;

return $this;
}

public function isHidden(): bool
{
return $this->isHidden;
}
}
14 changes: 14 additions & 0 deletions src/Columns/Concerns/CanBeHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ trait CanBeHidden
{
protected ?string $hiddenFrom = null;

protected bool $isHidden = false;

protected ?string $visibleFrom = null;

public function hidden(bool $condition = true): static
{
$this->isHidden = $condition;

return $this;
}

public function hiddenFrom(string $breakpoint): static
{
$this->hiddenFrom = $breakpoint;
Expand All @@ -31,4 +40,9 @@ public function getVisibleFrom(): ?string
{
return $this->visibleFrom;
}

public function isHidden(): bool
{
return $this->isHidden;
}
}
40 changes: 20 additions & 20 deletions src/Columns/Concerns/InteractsWithTableQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ trait InteractsWithTableQuery
{
public function applyEagreLoading(Builder $query): Builder
{
if ($this->isHidden()) {
return $query;
}

if ($this->queriesRelationships()) {
$query->with([$this->getRelationshipName()]);
}
Expand All @@ -20,19 +24,24 @@ public function applyEagreLoading(Builder $query): Builder

public function applySearchConstraint(Builder $query, string $searchQuery, bool &$isFirst): Builder
{
if ($this->isHidden()) {
return $query;
}

if (! $this->isSearchable()) {
return $query;
}

$isRelationshipColumn = $this->queriesRelationships();
$relationshipName = $this->getRelationshipName();
$searchColumns = $this->getSearchColumns();
$searchOperator = $this->getQuerySearchOperator($query);
$searchOperator = match ($query->getConnection()->getDriverName()) {
'pgsql' => 'ilike',
default => 'like',
};
;

foreach ($searchColumns as $searchColumnName) {
if ($isRelationshipColumn) {
foreach ($this->getSearchColumns() as $searchColumnName) {
if (Str::of($searchColumnName)->contains('.')) {
$query->{$isFirst ? 'whereHas' : 'orWhereHas'}(
$relationshipName,
Str::of($searchColumnName)->beforeLast('.'),
fn ($query) => $query->where(
$searchColumnName,
$searchOperator,
Expand All @@ -55,6 +64,10 @@ public function applySearchConstraint(Builder $query, string $searchQuery, bool

public function applySort(Builder $query, string $direction = 'asc'): Builder
{
if ($this->isHidden()) {
return $query;
}

if (! $this->isSortable()) {
return $query;
}
Expand Down Expand Up @@ -90,11 +103,6 @@ public function queriesRelationships(): bool
return Str::of($this->getName())->contains('.');
}

protected function getRelationshipColumnName(): string
{
return Str::of($this->getName())->afterLast('.');
}

protected function getRelatedModel(Builder $query): Model
{
return $this->getRelationship($query)->getModel();
Expand All @@ -114,12 +122,4 @@ protected function getQueryModel(Builder $query): Model
{
return $query->getModel();
}

protected function getQuerySearchOperator(Builder $query): string
{
return match ($query->getConnection()->getDriverName()) {
'pgsql' => 'ilike',
default => 'like',
};
}
}
1 change: 1 addition & 0 deletions src/Concerns/HasActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait HasActions
public function cacheTableActions(): void
{
$this->cachedTableActions = collect($this->getTableActions())
->filter(fn (Action $action): bool => ! $action->isHidden())
->mapWithKeys(function (Action $action): array {
$action->table($this->getCachedTable());

Expand Down
1 change: 1 addition & 0 deletions src/Concerns/HasBulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait HasBulkActions
public function cacheTableBulkActions(): void
{
$this->cachedTableBulkActions = collect($this->getTableBulkActions())
->filter(fn (BulkAction $action): bool => ! $action->isHidden())
->mapWithKeys(function (BulkAction $action): array {
$action->table($this->getCachedTable());

Expand Down
1 change: 1 addition & 0 deletions src/Concerns/HasColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait HasColumns
public function cacheTableColumns(): void
{
$this->cachedTableColumns = collect($this->getTableColumns())
->filter(fn (Column $column): bool => ! $column->isHidden())
->mapWithKeys(function (Column $column): array {
$column->table($this->getCachedTable());

Expand Down
1 change: 1 addition & 0 deletions src/Concerns/HasFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait HasFilters
public function cacheTableFilters(): void
{
$this->cachedTableFilters = collect($this->getTableFilters())
->filter(fn (Filter $filter): bool => ! $filter->isHidden())
->mapWithKeys(function (Filter $filter): array {
$filter->table($this->getCachedTable());

Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/HasRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getTableRecords(): Collection | LengthAwarePaginator
$this->applySortingToTableQuery($query);

if ($this->isTablePaginationEnabled()) {
return $this->records = $query->paginate($this->getTableRecordsPerPage());
return $this->records = $query->paginate($this->getTableRecordsPerPage())->onEachSide(1);
} else {
return $this->records = $query->get();
}
Expand Down
20 changes: 20 additions & 0 deletions src/Filters/Concerns/CanBeHidden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Filament\Tables\Filters\Concerns;

trait CanBeHidden
{
protected bool $isHidden = false;

public function hidden(bool $condition = true): static
{
$this->isHidden = $condition;

return $this;
}

public function isHidden(): bool
{
return $this->isHidden;
}
}
4 changes: 4 additions & 0 deletions src/Filters/Concerns/InteractsWithTableQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ trait InteractsWithTableQuery

public function apply(Builder $query, array $data = []): Builder
{
if ($this->isHidden()) {
return $query;
}

if (! $this->hasQueryModificationCallback()) {
return $query;
}
Expand Down
1 change: 1 addition & 0 deletions src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Filter
{
use Concerns\BelongsToTable;
use Concerns\CanBeHidden;
use Concerns\HasFormSchema;
use Concerns\HasLabel;
use Concerns\HasName;
Expand Down

0 comments on commit 017fb10

Please sign in to comment.