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
|
public function getNames(): Collection
|
||||||
{
|
{
|
||||||
return Product::select(['id', 'name'])
|
return Product::select('name')
|
||||||
->get();
|
->distinct()
|
||||||
|
->pluck('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
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>
|
</ComboboxEmpty>
|
||||||
<ComboboxList>
|
<ComboboxList>
|
||||||
{(name) => (
|
{(name) => (
|
||||||
<ComboboxItem value={name}>{name}</ComboboxItem>
|
<ComboboxItem key={name} value={name}>{name}</ComboboxItem>
|
||||||
)}
|
)}
|
||||||
</ComboboxList>
|
</ComboboxList>
|
||||||
</ComboboxContent>
|
</ComboboxContent>
|
||||||
@ -224,6 +224,7 @@ export default function ProductIndex({ products, categories, productNames, filte
|
|||||||
<Combobox
|
<Combobox
|
||||||
items={categories}
|
items={categories}
|
||||||
itemToStringLabel={(cat) => cat.name}
|
itemToStringLabel={(cat) => cat.name}
|
||||||
|
getOptionAsValue={(cat) => String(cat.id)}
|
||||||
value={selectedCategory}
|
value={selectedCategory}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
applyFilter('category', value ? String(value.id) : '')
|
applyFilter('category', value ? String(value.id) : '')
|
||||||
@ -239,7 +240,7 @@ export default function ProductIndex({ products, categories, productNames, filte
|
|||||||
</ComboboxEmpty>
|
</ComboboxEmpty>
|
||||||
<ComboboxList>
|
<ComboboxList>
|
||||||
{(cat) => (
|
{(cat) => (
|
||||||
<ComboboxItem value={cat}>
|
<ComboboxItem key={cat.id} value={cat}>
|
||||||
{cat.name}
|
{cat.name}
|
||||||
</ComboboxItem>
|
</ComboboxItem>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user