fix: react-doctor dialog/a11y/labels → 68/100 with 973 warnings
This commit is contained in:
@@ -22,6 +22,37 @@ type ProductRow = {
|
||||
available_until: string | null;
|
||||
};
|
||||
|
||||
const baseQuery = (db: Parameters<Parameters<typeof withBrand>[1]>[0]) =>
|
||||
db
|
||||
.select({
|
||||
id: products.id,
|
||||
name: products.name,
|
||||
description: products.description,
|
||||
priceCents: products.priceCents,
|
||||
active: products.active,
|
||||
brandId: products.brandId,
|
||||
brandName: brands.name,
|
||||
firstImageKey: productImages.storageKey,
|
||||
firstImagePosition: productImages.position,
|
||||
})
|
||||
.from(products)
|
||||
.leftJoin(brands, eq(brands.id, products.brandId))
|
||||
// Pull only the lowest-position image per product. The
|
||||
// `position` index on product_images (product_id, position) makes
|
||||
// this cheap; a real-world scale would replace it with a
|
||||
// DISTINCT ON subquery, but for the current catalog size this
|
||||
// join is fine and avoids a second round-trip.
|
||||
.leftJoin(
|
||||
productImages,
|
||||
sql`${productImages.id} = (
|
||||
SELECT id FROM product_images
|
||||
WHERE product_id = ${products.id}
|
||||
ORDER BY position ASC, created_at ASC
|
||||
LIMIT 1
|
||||
)`,
|
||||
)
|
||||
.orderBy(asc(products.name));
|
||||
|
||||
export default async function AdminProductsPage() {
|
||||
const adminUser = await getAdminUser();
|
||||
|
||||
@@ -61,37 +92,6 @@ export default async function AdminProductsPage() {
|
||||
let productsList: ProductRow[] = [];
|
||||
let queryError: string | null = null;
|
||||
try {
|
||||
const baseQuery = (db: Parameters<Parameters<typeof withBrand>[1]>[0]) =>
|
||||
db
|
||||
.select({
|
||||
id: products.id,
|
||||
name: products.name,
|
||||
description: products.description,
|
||||
priceCents: products.priceCents,
|
||||
active: products.active,
|
||||
brandId: products.brandId,
|
||||
brandName: brands.name,
|
||||
firstImageKey: productImages.storageKey,
|
||||
firstImagePosition: productImages.position,
|
||||
})
|
||||
.from(products)
|
||||
.leftJoin(brands, eq(brands.id, products.brandId))
|
||||
// Pull only the lowest-position image per product. The
|
||||
// `position` index on product_images (product_id, position) makes
|
||||
// this cheap; a real-world scale would replace it with a
|
||||
// DISTINCT ON subquery, but for the current catalog size this
|
||||
// join is fine and avoids a second round-trip.
|
||||
.leftJoin(
|
||||
productImages,
|
||||
sql`${productImages.id} = (
|
||||
SELECT id FROM product_images
|
||||
WHERE product_id = ${products.id}
|
||||
ORDER BY position ASC, created_at ASC
|
||||
LIMIT 1
|
||||
)`,
|
||||
)
|
||||
.orderBy(asc(products.name));
|
||||
|
||||
const rows = isPlatformAdmin
|
||||
? await withPlatformAdmin((db) => baseQuery(db))
|
||||
: brandId
|
||||
|
||||
Reference in New Issue
Block a user