refactor: optimize RowShareAction component by replacing grouping logic with a Set for product names, simplifying the shareable output format
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (8.3) (push) Waiting to run
tests / ci (8.4) (push) Waiting to run
tests / ci (8.5) (push) Waiting to run

This commit is contained in:
Yoga Pangestu 2026-07-05 22:13:53 +07:00
parent c222be62d3
commit 7c15a39bbd

View File

@ -37,26 +37,17 @@ const whatsappText = computed(() => {
} }
if (c.results?.length) { if (c.results?.length) {
const groups: Record<string, { name: string; items: typeof c.results }> = {}; const productNames = new Set<string>();
c.results.forEach((result) => { c.results.forEach((result) => {
const productName = result.product_variant?.product?.name ?? 'Produk Tidak Diketahui'; const productName = result.product_variant?.product?.name ?? 'Produk Tidak Diketahui';
productNames.add(productName);
if (!groups[productName]) {
groups[productName] = { name: productName, items: [] };
}
groups[productName].items.push(result);
}); });
text += `\n*Hasil Produk:*\n`; text += `\n*Hasil Produk:*\n`;
Object.values(groups).forEach((group, index) => { Array.from(productNames).forEach((name, index) => {
text += `${index + 1}. ${group.name}\n`; text += `${index + 1}. ${name}\n`;
group.items.forEach((item) => {
text += ` - ${item.product_variant?.name ?? '-'}\n`;
});
}); });
} }