Skip to content

Commit

Permalink
Merge branch 'develop' into fix/postgres-search
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Mar 11, 2021
2 parents 9603dd8 + dcd7cfc commit 1eb3719
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
FilePond.registerPlugin(FilePondPluginImageTransform)
let config = {
acceptedFileTypes: @json($formComponent->acceptedFileTypes),
acceptedFileTypes: {{ json_encode($formComponent->acceptedFileTypes) }},
files: [],
{{ $formComponent->imageCropAspectRatio !== null ? "imageCropAspectRatio: '{$formComponent->imageCropAspectRatio}'," : null }}
{{ $formComponent->imagePreviewHeight !== null ? "imagePreviewHeight: {$formComponent->imagePreviewHeight}," : null }}
Expand Down
10 changes: 5 additions & 5 deletions packages/tables/resources/views/cells/icon.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
@endphp

@if ($iconToShow)
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
>
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
@if ($column->shouldOpenUrlInNewTab)
target="_blank"
rel="noopener noreferrer"
target="_blank"
rel="noopener noreferrer"
@endif
>
<x-dynamic-component :component="$iconToShow" class="{{ $classes ?? null }} w-6 h-6" />
Expand Down
6 changes: 3 additions & 3 deletions packages/tables/resources/views/cells/image.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
>
<img
Expand All @@ -12,7 +12,7 @@ class="{{ $column->rounded ? 'rounded-full' : null }}"
"
/>
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
@if ($column->shouldOpenUrlInNewTab)
Expand Down
6 changes: 3 additions & 3 deletions packages/tables/resources/views/cells/text.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
@endphp

<div class="py-4">
@if ($column->action)
@if ($column->getAction($record) !== null)
<button
wire:click="{{ $column->action }}('{{ $record->getKey() }}')"
wire:click="{{ $column->getAction($record) }}('{{ $record->getKey() }}')"
type="button"
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"
>
{{ $column->getValue($record) }}
</button>
@elseif ($column->url)
@elseif ($column->getUrl($record) !== null)
<a
href="{{ $column->getUrl($record) }}"
class="{{ $primaryClasses }} hover:underline hover:text-primary-600 transition-colors duration-200"
Expand Down
13 changes: 13 additions & 0 deletions packages/tables/src/Columns/Concerns/CanCallAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@ public function action($action)

return $this;
}

public function getAction($record)
{
if ($this->action === null) return null;

if (is_callable($this->action)) {
$callback = $this->action;

return $callback($record);
}

return $this->action;
}
}
2 changes: 2 additions & 0 deletions packages/tables/src/Columns/Concerns/CanOpenUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ trait CanOpenUrl

public function getUrl($record)
{
if ($this->url === null) return null;

if (is_callable($this->url)) {
$callback = $this->url;

Expand Down
23 changes: 20 additions & 3 deletions packages/tables/src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ class Filter

protected $pendingIncludedContextModifications = [];

public function __construct($name, $callback = null)
public function __construct($name = null, $callback = null)
{
$this->name($name);
if ($name) {
$this->name($name);
}

$this->callback($callback);

$this->setUp();
}

protected function setUp()
{
//
}

public static function make($name, $callback = null)
public static function make($name = null, $callback = null)
{
return new static($name, $callback);
}
Expand All @@ -41,6 +51,13 @@ public function callback($callback)
return $this;
}

public function apply($query)
{
$callback = $this->callback;

return $callback($query);
}

public function context($context)
{
$this->context = $context;
Expand Down
4 changes: 1 addition & 3 deletions packages/tables/src/HasTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ public function getRecords()
collect($this->getTable()->filters)
->filter(fn ($filter) => $filter->name === $this->filter)
->each(function ($filter) use (&$query) {
$callback = $filter->callback;

$query = $callback($query);
$query = $filter->apply($query);
});
}

Expand Down
26 changes: 26 additions & 0 deletions packages/tables/src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Table

public $pagination = true;

public $primaryColumnAction;

public $primaryColumnUrl;

public $recordActions = [];

public $searchable = true;
Expand Down Expand Up @@ -138,6 +142,28 @@ public function pagination($enabled)
return $this;
}

public function primaryRecordAction($action)
{
$this->columns = collect($this->columns)
->map(function ($column) use ($action) {
return $column->action($action);
})
->toArray();

return $this;
}

public function primaryRecordUrl($url)
{
$this->columns = collect($this->columns)
->map(function ($column) use ($url) {
return $column->url($url);
})
->toArray();

return $this;
}

public function recordActions($actions)
{
$this->recordActions = $actions;
Expand Down
8 changes: 8 additions & 0 deletions src/Commands/Aliases/MakeFilterCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Filament\Commands\Aliases;

class MakeFilterCommand extends \Filament\Commands\MakeFilterCommand
{
protected $signature = 'filament:filter {name} {--R|resource}';
}
2 changes: 1 addition & 1 deletion src/Commands/MakeFieldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle()

$path = app_path(
(string) Str::of($field)
->prepend($this->option('resource') ? 'Filament\\Resources\\Forms\\Components\\' : "Filament\\Forms\\Components\\")
->prepend($this->option('resource') ? 'Filament\\Resources\\Forms\\Components\\' : 'Filament\\Forms\\Components\\')
->replace('\\', '/')
->append('.php'),
);
Expand Down
53 changes: 53 additions & 0 deletions src/Commands/MakeFilterCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Filament\Commands;

use Illuminate\Support\Str;
use Illuminate\Console\Command;

class MakeFilterCommand extends Command
{
use Concerns\CanManipulateFiles;

protected $description = 'Make a Filament filter class.';

protected $signature = 'make:filament-filter {name} {--R|resource}';

public function handle()
{
$filter = (string) Str::of($this->argument('name'))
->trim('/')
->trim('\\')
->trim(' ')
->replace('/', '\\');
$filterClass = (string) Str::of($filter)->afterLast('\\');
$filterNamespace = Str::of($filter)->contains('\\') ?
(string) Str::of($filter)->beforeLast('\\') :
'';

$path = app_path(
(string) Str::of($filter)
->prepend($this->option('resource') ? 'Filament\\Resources\\Tables\\Filters\\' : 'Filament\\Tables\\Filters\\')
->replace('\\', '/')
->append('.php'),
);

if ($this->checkForCollision([
$path,
])) return;

if (! $this->option('resource')) {
$this->copyStubToApp('Filter', $path, [
'class' => $filterClass,
'namespace' => 'App\\Filament\\Tables\\Filters' . ($filterNamespace !== '' ? "\\{$filterNamespace}" : ''),
]);
} else {
$this->copyStubToApp('ResourceFilter', $path, [
'class' => $filterClass,
'namespace' => 'App\\Filament\\Resources\\Tables\\Filters' . ($filterNamespace !== '' ? "\\{$filterNamespace}" : ''),
]);
}

$this->info("Successfully created {$filter}!");
}
}
6 changes: 3 additions & 3 deletions src/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function boot()
$this->bootLoaders();
$this->bootLivewireComponents();
$this->bootPublishing();

$this->configure();
}

Expand Down Expand Up @@ -65,6 +66,7 @@ protected function bootCommands()
Commands\MakeWidgetCommand::class,
Commands\MakeFieldCommand::class,
Commands\MakeThemeCommand::class,
Commands\MakeFilterCommand::class,
]);

$aliases = [];
Expand Down Expand Up @@ -195,9 +197,7 @@ protected function registerIcons()

protected function registerProviders()
{
$this->app->booted(function () {
$this->app->register(RouteServiceProvider::class);
});
$this->app->register(RouteServiceProvider::class);
}

protected function mergeConfigFrom($path, $key)
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/Pages/ListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public function getTable()
->context(static::class)
->filterable($this->filterable)
->pagination($this->pagination)
->primaryRecordUrl(function ($record) {
if (! Filament::can('update', $record)) return;

return $this->getResource()::generateUrl(
$this->recordRoute,
['record' => $record],
);
})
->recordActions([
RecordActions\Link::make('edit')
->label(static::$editRecordActionLabel)
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/RelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public function getTable()
return static::table(Table::make())
->filterable($this->filterable)
->pagination(false)
->primaryRecordAction(function ($record) {
if (! Filament::can('update', $record)) return;

return 'openEdit';
})
->recordActions([
RecordActions\Link::make('edit')
->label(static::$editRecordActionLabel)
Expand Down
Loading

0 comments on commit 1eb3719

Please sign in to comment.