Skip to content

Commit 61277b2

Browse files
committed
fix: 리뷰 요약 라벨 중복 렌더링 제거
1 parent b3613d5 commit 61277b2

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

src/components/product/review/analysis-content.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
SelectTrigger,
88
SelectValue,
99
} from '@/components/ui/select';
10-
import { ReviewCategorySummary } from '@/types/domain/review';
10+
import {
11+
COLOR_ANSWER_OPTIONS,
12+
MATERIAL_ANSWER_OPTIONS,
13+
ReviewCategorySummary,
14+
SIZE_ANSWER_OPTIONS,
15+
} from '@/types/domain/review';
1116
import { EVALUATION_MAP } from './review-constants';
1217

1318
interface AnalysisContentProps {
@@ -28,6 +33,19 @@ function getStatLabel(item: { label?: string; answer?: string }) {
2833
return EVALUATION_MAP[raw] ?? raw;
2934
}
3035

36+
function getDefaultAnswers(category: string) {
37+
if (category === '사이즈') {
38+
return [...SIZE_ANSWER_OPTIONS];
39+
}
40+
if (category === '색감') {
41+
return [...COLOR_ANSWER_OPTIONS];
42+
}
43+
if (category === '소재') {
44+
return [...MATERIAL_ANSWER_OPTIONS];
45+
}
46+
return [];
47+
}
48+
3149
function getEmptyMessage(
3250
variant: 'size' | 'color' | 'default',
3351
selectedOption: string,
@@ -56,12 +74,17 @@ export default function AnalysisContent({
5674
const sorted = [...(stat.answerStats ?? [])].sort(
5775
(a, b) => b.count - a.count,
5876
);
59-
const limitedDetails = [...sorted.slice(0, maxItems)];
60-
while (limitedDetails.length < maxItems) {
61-
limitedDetails.push({ answer: '정보 없음', count: 0, percentage: 0 });
62-
}
77+
const defaultAnswers = getDefaultAnswers(category);
78+
const existingLabels = new Set(sorted.map((item) => getStatLabel(item)));
79+
const enumFallbackDetails = defaultAnswers
80+
.filter((answer) => !existingLabels.has(getStatLabel({ answer })))
81+
.map((answer) => ({ answer, count: 0, percentage: 0 }));
82+
const limitedDetails = [...sorted, ...enumFallbackDetails].slice(0, maxItems);
6383

64-
const totalCount = limitedDetails.reduce((sum, item) => sum + item.count, 0);
84+
const totalCount = (stat.answerStats ?? []).reduce(
85+
(sum, item) => sum + item.count,
86+
0,
87+
);
6588
const isFiltered = selectedOption !== 'all';
6689
const isEmpty = totalCount === 0;
6790

0 commit comments

Comments
 (0)