refactor: optimize product name retrieval and enhance category selection in ProductIndex component
This commit is contained in:
parent
ff8dc64a27
commit
278493b4c6
@ -27,8 +27,9 @@ public function __construct(
|
||||
|
||||
public function getNames(): Collection
|
||||
{
|
||||
return Product::select(['id', 'name'])
|
||||
->get();
|
||||
return Product::select('name')
|
||||
->distinct()
|
||||
->pluck('name');
|
||||
}
|
||||
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
|
||||
@ -168,7 +168,7 @@ export default function ProductIndex({ products, categories, productNames, filte
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(name) => (
|
||||
<ComboboxItem value={name}>{name}</ComboboxItem>
|
||||
<ComboboxItem key={name} value={name}>{name}</ComboboxItem>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
@ -224,6 +224,7 @@ export default function ProductIndex({ products, categories, productNames, filte
|
||||
<Combobox
|
||||
items={categories}
|
||||
itemToStringLabel={(cat) => cat.name}
|
||||
getOptionAsValue={(cat) => String(cat.id)}
|
||||
value={selectedCategory}
|
||||
onValueChange={(value) =>
|
||||
applyFilter('category', value ? String(value.id) : '')
|
||||
@ -239,7 +240,7 @@ export default function ProductIndex({ products, categories, productNames, filte
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(cat) => (
|
||||
<ComboboxItem value={cat}>
|
||||
<ComboboxItem key={cat.id} value={cat}>
|
||||
{cat.name}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user