Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Aug 16, 2024
2 parents f29ead0 + 8de1a8d commit d004ac7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/forms/resources/js/components/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,13 @@ export default function fileUploadFormComponent({
// FilePond has a weird English translation for the error message when a file of an unexpected
// type is uploaded, for example: `File of invalid type: Expects or image/*`. This is a
// hacky workaround to fix the message to be `File of invalid type: Expects image/*`.
this.error = `${error.main}: ${error.sub}`.replace('Expects or', 'Expects')
this.error = `${error.main}: ${error.sub}`.replace(
'Expects or',
'Expects',
)
})

this.pond.on('removefile', () => this.error = null)
this.pond.on('removefile', () => (this.error = null))
}
},

Expand Down
3 changes: 1 addition & 2 deletions packages/support/src/Concerns/HasCellState.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Stringable;
use Znck\Eloquent\Relations\BelongsToThrough;
Expand Down Expand Up @@ -98,7 +97,7 @@ public function getStateFromRecord(): mixed
{
$record = $this->getRecord();

$state = Arr::get($record, $this->getName());
$state = data_get($record, $this->getName());

if ($state !== null) {
return $state;
Expand Down
1 change: 1 addition & 0 deletions tests/database/migrations/create_posts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function up(): void
$table->unsignedTinyInteger('rating')->default(0);
$table->json('tags')->nullable();
$table->string('title');
$table->json('json_array_of_objects')->nullable();
$table->timestamps();
$table->softDeletes();
});
Expand Down
1 change: 1 addition & 0 deletions tests/src/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Post extends Model
protected $casts = [
'is_published' => 'boolean',
'tags' => 'array',
'json_array_of_objects' => 'array',
];

protected $guarded = [];
Expand Down
13 changes: 13 additions & 0 deletions tests/src/Tables/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@
->assertTableColumnFormattedStateNotSet('formatted_state', 'incorrect formatted state', $post);
});

it('can output values in a JSON array column of objects', function () {
$post = Post::factory()->create([
'json_array_of_objects' => [
['value' => 'foo'],
['value' => 'bar'],
['value' => 'baz'],
],
]);

livewire(PostsTable::class)
->assertTableColumnStateSet('json_array_of_objects.*.value', ['foo', 'bar', 'baz'], $post);
});

it('can state whether a column has extra attributes', function () {
$post = Post::factory()->create();

Expand Down
1 change: 1 addition & 0 deletions tests/src/Tables/Fixtures/PostsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function table(Table $table): Table
->state('correct state'),
Tables\Columns\TextColumn::make('formatted_state')
->formatStateUsing(fn () => 'formatted state'),
Tables\Columns\TextColumn::make('json_array_of_objects.*.value'),
Tables\Columns\TextColumn::make('extra_attributes')
->extraAttributes([
'class' => 'text-danger-500',
Expand Down

0 comments on commit d004ac7

Please sign in to comment.