Skip to content

Commit a9208c2

Browse files
committed
fix icon, refactor table
1 parent 90baeaa commit a9208c2

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

apps/dashboard/components/analytics/components/table-content.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ export function TableContent<TData extends { name: string | number }>({
6060
}: TableContentProps<TData>) {
6161
const [expandedRow, setExpandedRow] = useState<string | null>(null);
6262
const { getRowPercentage, getRowGradient, hasPercentageColumn } =
63-
useTableRowPercentage(table);
63+
useTableRowPercentage();
6464

6565
const toggleRowExpansion = useCallback((rowId: string) => {
6666
setExpandedRow((prev) => (prev === rowId ? null : rowId));
6767
}, []);
6868

6969
const displayData = table.getRowModel().rows;
70+
const tableData = displayData.map((row) => row.original);
71+
const hasPercentageData = hasPercentageColumn(tableData);
7072

7173
if (!displayData.length) {
7274
return (
@@ -197,10 +199,10 @@ export function TableContent<TData extends { name: string | number }>({
197199
expandable && getSubRows ? getSubRows(row.original) : undefined;
198200
const hasSubRows = subRows && subRows.length > 0;
199201
const isExpanded = expandedRow === row.id;
200-
const percentage = hasPercentageColumn
202+
const percentage = hasPercentageData
201203
? getRowPercentage(row.original)
202204
: 0;
203-
const gradient = hasPercentageColumn
205+
const gradient = hasPercentageData
204206
? getRowGradient(row.original)
205207
: null;
206208

@@ -215,8 +217,8 @@ export function TableContent<TData extends { name: string | number }>({
215217
onRowAction
216218
? 'cursor-pointer'
217219
: '',
218-
219-
rowIndex % 2 === 0 ? 'bg-background/50' : 'bg-muted/10'
220+
!(percentage > 0 && gradient) &&
221+
(rowIndex % 2 === 0 ? 'bg-background/50' : 'bg-muted/10')
220222
)}
221223
onClick={() => {
222224
if (hasSubRows) {

apps/dashboard/components/analytics/hooks/use-table-row-percentage.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import type { Table } from '@tanstack/react-table';
2-
import { useMemo } from 'react';
3-
4-
declare module '@tanstack/react-table' {
5-
interface ColumnMeta<TData, TValue> {
6-
isPercentageColumn?: boolean;
7-
}
8-
}
9-
101
const PERCENTAGE_THRESHOLDS = {
112
HIGH: 50,
123
MEDIUM: 25,
@@ -113,29 +104,28 @@ function getPercentageGradient(percentage: number) {
113104
);
114105
}
115106

116-
export function useTableRowPercentage<TData>(table: Table<TData>) {
117-
const percentageColumnId = useMemo(() => {
118-
return table
119-
.getAllColumns()
120-
.find((column) => column.columnDef.meta?.isPercentageColumn)?.id;
121-
}, [table]);
122-
107+
export function useTableRowPercentage<TData>() {
123108
const getRowPercentage = (row: TData): number => {
124-
if (!percentageColumnId) {
125-
return 0;
126-
}
127-
const value = (row as any)[percentageColumnId];
128-
return Number.parseFloat(String(value)) || 0;
109+
const value = (row as any).percentage;
110+
return value !== undefined ? Number.parseFloat(String(value)) || 0 : 0;
129111
};
130112

131113
const getRowGradient = (row: TData) => {
132114
const percentage = getRowPercentage(row);
133115
return getPercentageGradient(percentage);
134116
};
135117

118+
const hasPercentageColumn = (data: TData[]): boolean => {
119+
if (!data || data.length === 0) {
120+
return false;
121+
}
122+
const firstRow = data[0] as any;
123+
return firstRow.percentage !== undefined;
124+
};
125+
136126
return {
137127
getRowPercentage,
138128
getRowGradient,
139-
hasPercentageColumn: Boolean(percentageColumnId),
129+
hasPercentageColumn,
140130
};
141131
}

apps/dashboard/components/icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function getOSMappedName(normalizedName: string): string {
121121
}
122122

123123
function getIconSrc(iconName: string, folder: string): string {
124-
if (iconName === 'Brave' && folder === 'browsers') {
124+
if ((iconName === 'Brave' || iconName === 'QQ') && folder === 'browsers') {
125125
return `/${folder}/${iconName}.webp`;
126126
}
127127
return `/${folder}/${iconName}.svg`;

0 commit comments

Comments
 (0)