Skip to content

Commit

Permalink
Fix labels for attach/associate multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Nov 30, 2023
1 parent 09d226a commit 11a5adf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/tables/src/Actions/AssociateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,18 @@ public function getRecordSelect(): Select
->required()
->searchable($this->getRecordSelectSearchColumns() ?? true)
->getSearchResultsUsing(static fn (Select $component, string $search): array => $getOptions(optionsLimit: $component->getOptionsLimit(), search: $search, searchColumns: $component->getSearchColumns()))
->getOptionLabelUsing(fn ($value): string => $this->getRecordTitle(Relation::noConstraints(fn () => $table->getRelationship())->getQuery()->find($value)))
->getOptionLabelUsing(function ($value) use ($table): string {
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

return $this->getRecordTitle($relationship->getQuery()->find($value));
})
->getOptionLabelsUsing(function (array $values) use ($table): array {
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

return $relationship->getQuery()->find($values)
->mapWithKeys(fn (Model $record): array => [$record->getKey() => $this->getRecordTitle($record)])
->all();
})
->options(fn (Select $component): array => $this->isRecordSelectPreloaded() ? $getOptions(optionsLimit: $component->getOptionsLimit()) : [])
->hiddenLabel();

Expand Down
9 changes: 9 additions & 0 deletions packages/tables/src/Actions/AttachAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ public function getRecordSelect(): Select

return $this->getRecordTitle($relationshipQuery->find($value));
})
->getOptionLabelsUsing(function (array $values) use ($table): array {
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

$relationshipQuery = app(RelationshipJoiner::class)->prepareQueryForNoConstraints($relationship);

return $relationshipQuery->find($values)
->mapWithKeys(fn (Model $record): array => [$record->getKey() => $this->getRecordTitle($record)])
->all();
})
->options(fn (Select $component): array => $this->isRecordSelectPreloaded() ? $getOptions(optionsLimit: $component->getOptionsLimit()) : [])
->hiddenLabel();

Expand Down

0 comments on commit 11a5adf

Please sign in to comment.