Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"laravel/prompts": "^0.1|^0.2|^0.3",
"livewire/blaze": "^1.0",
"power-components/partials": "^0.2.0",
"power-components/turbine": "^0.14.0"
"power-components/turbine": "^0.14.1"
},
"conflict": {
"laravel/framework": "<12.0",
Expand Down
4 changes: 3 additions & 1 deletion src/Concerns/Listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public function toggleColumn(string $field): void
{
foreach ($this->columns as &$column) {
if (data_get($column, 'field') === $field) {
data_set($column, 'hidden', ! data_get($column, 'hidden'));
if (! data_get($column, 'forceHidden')) {
data_set($column, 'hidden', ! data_get($column, 'hidden'));
}

break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ private function neutralizeFormula(string $value): string

private function columnIsExportable(mixed $column): bool
{
if ((bool) data_get($column, 'forceHidden') && data_get($column, 'visibleInExport') !== true) {
return false;
}

return (bool) data_get($column, 'visibleInExport')
|| (! data_get($column, 'hidden') && is_null(data_get($column, 'visibleInExport')));
}
Expand Down
51 changes: 51 additions & 0 deletions tests/Feature/BatchExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,57 @@ public function columns(): array
});
})->requiresOpenSpout();

it('keeps hidden columns out of queued exports after toggling columns', function () {
Bus::fake();
Storage::fake('local');

$component = new class() extends PowerGridComponent
{
public string $tableName = 'test-batch-hidden-column';

public function datasource()
{
return collect([['id' => 1, 'name' => 'Dish 1', 'calories' => 9876]]);
}

public function setUp(): array
{
return [PowerGrid::exportable('export')->type(Exportable::TYPE_CSV)->queues(1)];
}

public function fields(): PowerGridFields
{
return PowerGrid::fields()->add('id')->add('name')->add('calories');
}

public function columns(): array
{
return [
Column::make('ID', 'id'),
Column::make('Name', 'name'),
Column::make('Calories', 'calories')->hidden(),
];
}
};

Livewire::test($component::class)->update(calls: [
['method' => 'toggleColumn', 'params' => ['calories'], 'path' => ''],
['method' => 'exportToCsv', 'params' => [false], 'path' => ''],
]);

Bus::assertBatched(function (PendingBatch $batch) {
$batch->jobs[0]->handle();

return true;
});

$content = collect(Storage::disk('local')->allFiles())
->map(fn (string $file) => Storage::disk('local')->get($file))
->implode('');

expect($content)->toContain('Dish 1')->not->toContain('9876');
})->requiresOpenSpout();

it('renders the user-supplied progressView below the header', function () {
view()->addNamespace('pg-test-views', __DIR__.'/../Concerns/views');

Expand Down
35 changes: 35 additions & 0 deletions tests/Feature/SearchableRawTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,38 @@ public function columns(): array
->assertDontSee('Dish 1')
->assertSee('Dish 2');
})->requiresSQLite();

it('keeps datasource constraints when searching raw columns', function (Closure $column) {
$component = new class() extends PowerGridComponent
{
public string $tableName = 'test-searchable-raw-datasource';

public static Closure $column;

public function datasource()
{
return Dish::query()->where('dishes.category_id', 1);
}

public function fields(): PowerGridFields
{
return PowerGrid::fields()->add('id')->add('name');
}

public function columns(): array
{
return [Column::make('Id', 'id'), (self::$column)()];
}
};

$component::$column = $column;

Livewire::test($component::class)
->set('search', 'Carne')
->assertSee('Carne Louca')
->set('search', 'Pastel')
->assertDontSee('Pastel de Nata');
})->with([
'searchableRaw' => [fn () => Column::make('Name', 'name')->searchableRaw('dishes.name LIKE ?')],
'searchableJson' => [fn () => Column::make('Name', 'name')->searchableJson('dishes')],
]);
Loading