Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public function getDefaultTable(Table $table): Table
->getSearchResultsUsing(static function (string $search): array {
return get_search_builder(Collection::modelClass(), $search)
->get()
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->attr('name')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => static::getCollectionOptionLabel($record)])
->all();
})
->getOptionLabelUsing(function ($value): string {
return Collection::modelClass()::find($value)?->attr('name') ?? $value;
$record = Collection::modelClass()::find($value);

return $record ? static::getCollectionOptionLabel($record) : $value;
}),
Forms\Components\Hidden::make('discountable_type')
->default(Collection::morphName()),
Expand All @@ -76,11 +78,26 @@ public function getDefaultTable(Table $table): Table
)
->formatStateUsing(
fn (Model $record) => $record->discountable?->attr('name')
)
->description(
fn (Model $record) => $record->discountable ? static::getCollectionPath($record->discountable) : null
),
])->recordActions([
DeleteAction::make(),
])->toolbarActions([
DeleteBulkAction::make(),
]);
}

protected static function getCollectionPath(CollectionContract $record): string
{
return collect([$record->group->name])
->merge($record->breadcrumb)
->implode(' > ');
}

protected static function getCollectionOptionLabel(CollectionContract $record): string
{
return $record->attr('name').' ('.static::getCollectionPath($record).')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function getDefaultTable(Table $table): Table
'exclusion' => __('lunarpanel::discount.relationmanagers.collections.form.type.options.exclusion.label'),
]
)->default('limitation'),
])->recordTitle(function ($record) {
return $record->attr('name');
])->recordTitle(function (Collection $record) {
return $record->attr('name').' ('.static::getCollectionPath($record).')';
})->recordSelectSearchColumns(['attribute_data->name'])
->preloadRecordSelect()
->label(
Expand All @@ -62,7 +62,7 @@ public function getDefaultTable(Table $table): Table
->label(
__('lunarpanel::discount.relationmanagers.collections.table.name.label')
)
->description(fn (Collection $record): string => $record->breadcrumb->implode(' > '))
->description(fn (Collection $record): string => static::getCollectionPath($record))
->formatStateUsing(
fn (Model $record) => $record->attr('name')
),
Expand All @@ -78,4 +78,11 @@ public function getDefaultTable(Table $table): Table
DetachBulkAction::make(),
]);
}

protected static function getCollectionPath(Collection $record): string
{
return collect([$record->group->name])
->merge($record->breadcrumb)
->implode(' > ');
}
}