Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@ export const TableCheckpointSubmissions: FC<Props> = (props: Props) => {
)

const aiReviewsColumn = useMemo<TableColumn<Screening> | undefined>(
() => {
if (!props.aiReviewers?.length) {
return undefined
}

return {
() => ({
columnId: 'ai-reviews-table',
isExpand: true,
label: '',
Expand All @@ -187,15 +182,14 @@ export const TableCheckpointSubmissions: FC<Props> = (props: Props) => {
return (
<CollapsibleAiReviewsRow
className={styles.aiReviews}
aiReviewers={props.aiReviewers!}
aiReviewers={props.aiReviewers ?? []}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using the nullish coalescing operator (??) to default aiReviewers to an empty array is a good practice. However, ensure that the rest of the codebase correctly handles an empty array for aiReviewers to avoid unintended behavior.

submission={submissionPayload}
defaultOpen={allRows ? !allRows.indexOf(data) : false}
/>
)
},
type: 'element',
} as TableColumn<Screening>
},
} as TableColumn<Screening>),
[props.aiReviewers],
)

Expand Down Expand Up @@ -733,7 +727,7 @@ export const TableCheckpointSubmissions: FC<Props> = (props: Props) => {
const columnsMobile = useMemo<MobileTableColumn<Screening>[][]>(
() => columns.map(
column => [
{
column.label && {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 maintainability]
The conditional check column.label && { ... } can lead to a potential issue where undefined is included in the array, which is then filtered out. Consider restructuring this logic to avoid adding undefined in the first place, which can improve readability and maintainability.

...column,
className: '',
label: `${column.label as string} label`,
Expand All @@ -748,9 +742,10 @@ export const TableCheckpointSubmissions: FC<Props> = (props: Props) => {
},
{
...column,
colSpan: column.label ? 1 : 2,
mobileType: 'last-value',
},
] as MobileTableColumn<Screening>[],
].filter(Boolean) as MobileTableColumn<Screening>[],
),
[columns],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,24 +1337,20 @@ export const TableIterativeReview: FC<Props> = (props: Props) => {
baseColumns.push(reviewerColumn)
}

if (props.aiReviewers) {
baseColumns.push({
columnId: 'ai-reviews-table',
isExpand: true,
label: '',
renderer: (submission: SubmissionInfo, allRows: SubmissionInfo[]) => (
props.aiReviewers && (
<CollapsibleAiReviewsRow
className={styles.aiReviews}
aiReviewers={props.aiReviewers}
submission={submission as any}
defaultOpen={allRows ? !allRows.indexOf(submission) : false}
/>
)
),
type: 'element',
})
}
baseColumns.push({
columnId: 'ai-reviews-table',
isExpand: true,
label: '',
renderer: (submission: SubmissionInfo, allRows: SubmissionInfo[]) => (
<CollapsibleAiReviewsRow
className={styles.aiReviews}
aiReviewers={props.aiReviewers ?? []}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using the nullish coalescing operator (??) to default props.aiReviewers to an empty array is a good practice for avoiding undefined values. However, ensure that the rest of the codebase is prepared to handle an empty array as a valid input, as this might change the behavior if previously undefined was expected to be handled differently.

submission={submission as any}
defaultOpen={allRows ? !allRows.indexOf(submission) : false}
/>
),
type: 'element',
})

return baseColumns
}, [
Expand All @@ -1375,7 +1371,7 @@ export const TableIterativeReview: FC<Props> = (props: Props) => {

const columnsMobile = useMemo<MobileTableColumn<SubmissionInfo>[][]>(() => (
(actionColumn ? [...columns, actionColumn] : columns).map(column => ([
{
column.label && {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of column.label && in the map function could lead to unexpected behavior if column.label is falsy but not undefined or null. Consider explicitly checking for undefined or null if those are the only cases you want to handle.

...column,
className: '',
label: `${column.label as string} label`,
Expand All @@ -1390,9 +1386,10 @@ export const TableIterativeReview: FC<Props> = (props: Props) => {
},
{
...column,
colSpan: column.label ? 1 : 2,
mobileType: 'last-value',
},
] as MobileTableColumn<SubmissionInfo>[]))
].filter(Boolean) as MobileTableColumn<SubmissionInfo>[]))
), [actionColumn, columns])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,7 @@ export const TableSubmissionScreening: FC<Props> = (props: Props) => {
}, [filteredChallengeSubmissions, props.screenings])

const aiReviewersColumn = useMemo<TableColumn<Screening> | undefined>(
() => {
if (!props.aiReviewers?.length) {
return undefined
}

return {
() => ({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The useMemo hook is used to memoize the aiReviewersColumn even when props.aiReviewers is undefined or empty. This could lead to unnecessary computations and memory usage. Consider adding a condition to return undefined when props.aiReviewers is not present or empty.

columnId: 'ai-reviews-table',
isExpand: true,
label: '',
Expand All @@ -821,8 +816,7 @@ export const TableSubmissionScreening: FC<Props> = (props: Props) => {
)
},
type: 'element',
} as TableColumn<Screening>
},
} as TableColumn<Screening>),
[props.aiReviewers, submissionMetaById],
)

Expand Down Expand Up @@ -1191,7 +1185,7 @@ export const TableSubmissionScreening: FC<Props> = (props: Props) => {
const columnsMobile = useMemo<MobileTableColumn<Screening>[][]>(
() => columns.map(
column => [
{
column.label && {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 performance]
The use of column.label && in the map function could lead to a false value being pushed into the array, which is then filtered out. This pattern is not optimal. Consider using a conditional (ternary) operator to directly return the object or null to avoid unnecessary filtering.

...column,
className: '',
label: `${column.label as string} label`,
Expand All @@ -1206,9 +1200,10 @@ export const TableSubmissionScreening: FC<Props> = (props: Props) => {
},
{
...column,
colSpan: column.label ? 1 : 2,
mobileType: 'last-value',
},
] as MobileTableColumn<Screening>[],
].filter(Boolean) as MobileTableColumn<Screening>[],
),
[columns],
)
Expand Down
Loading