Skip to content

Commit

Permalink
refactor: use lodash for value
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaKorevo committed Oct 25, 2023
1 parent 735a9b7 commit 640794f
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions client/src/modules/Score/components/ScoreTable/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Table } from 'antd';
import { ColumnType } from 'antd/lib/table';
import { ScoreStudentDto } from 'api';
import get from 'lodash/get';

type SummaryProps = {
visibleColumns: ColumnType<ScoreStudentDto>[];
Expand All @@ -13,14 +14,7 @@ export const Summary = ({ visibleColumns, studentScore }: SummaryProps) => {
{/* the table has a hidden first column */}
<Table.Summary.Cell index={0} />
{visibleColumns.map(({ dataIndex, render }, index) => {
const value: any = Array.isArray(dataIndex)
? dataIndex.reduce((result: any, property) => {
return Object.prototype.hasOwnProperty.call(result ?? {}, property as string)
? result[property as string]
: null;
}, studentScore)
: studentScore[dataIndex as keyof ScoreStudentDto];

const value = get(studentScore, dataIndex as string | string[], null);
return (
<Table.Summary.Cell key={index} index={index + 1}>
{render ? render(value, studentScore, index + 1) : value}
Expand Down

0 comments on commit 640794f

Please sign in to comment.