Skip to content

Commit

Permalink
[optional ML refactor] Use renderCellValue.isDetails to customize n…
Browse files Browse the repository at this point in the history
…umeric popover content instead of `renderCellPopover`

 - since no especially custom popover rendering is occuring, just conditional content
  • Loading branch information
cee-chen committed Mar 4, 2022
1 parent 7a5e5a2 commit 46f433e
Showing 1 changed file with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import {
EuiButtonEmpty,
EuiDataGrid,
EuiDataGridProps,
EuiDataGridCellValueElementProps,
EuiDataGridCellPopoverElementProps,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
Expand Down Expand Up @@ -115,8 +113,6 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
const [columns, setColumns] = useState<ConfusionMatrixColumn[]>([]);
const [columnsData, setColumnsData] = useState<ConfusionMatrixColumnData[]>([]);
const [showFullColumns, setShowFullColumns] = useState<boolean>(false);
const [renderCellPopover, setRenderCellPopover] =
useState<EuiDataGridProps['renderCellPopover']>();
const [dataSubsetTitle, setDataSubsetTitle] = useState<SUBSET_TITLE>(SUBSET_TITLE.ENTIRE);
// Column visibility
const [visibleColumns, setVisibleColumns] = useState<string[]>(() =>
Expand Down Expand Up @@ -153,21 +149,6 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
setVisibleColumns(() => derivedColumns.map(({ id }: { id: string }) => id));
setColumns(derivedColumns);
setColumnsData(columnData);
setRenderCellPopover((props: EuiDataGridCellPopoverElementProps) => {
const { rowIndex, columnId, schema, cellContentsElement, DefaultCellPopover } = props;
if (schema === 'numeric') {
const gridItem = columnData[rowIndex];

if (gridItem !== undefined && columnId !== ACTUAL_CLASS_ID) {
const count = gridItem.predicted_classes_count[columnId];
return `${count} / ${gridItem.actual_class_doc_count} * 100 = ${cellContentsElement.textContent}`;
}

return cellContentsElement.textContent;
} else {
return <DefaultCellPopover {...props} />;
}
});
}
}, [confusionMatrixData]);

Expand All @@ -186,11 +167,9 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
rowIndex,
columnId,
setCellProps,
}: {
rowIndex: number;
columnId: string;
setCellProps: EuiDataGridCellValueElementProps['setCellProps'];
}) => {
schema,
isDetails,
}: EuiDataGridCellValueElementProps) => {
const cellValue =
columnId === ACTUAL_CLASS_ID
? columnsData[rowIndex][columnId]
Expand All @@ -204,6 +183,7 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
accuracyNumber = Math.round(accuracyNumber * 100) / 100;
accuracy = `${Math.round(accuracyNumber * 100)}%`;
}

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (columnId !== ACTUAL_CLASS_ID) {
Expand All @@ -214,7 +194,19 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
});
}
}, [rowIndex, columnId, setCellProps]);
return <span>{columnId === ACTUAL_CLASS_ID ? cellValue : accuracy}</span>;

let cellContent = columnId === ACTUAL_CLASS_ID ? cellValue : accuracy;

// Custom popover content for numeric schemas
if (isDetails && schema === 'numeric') {
const gridItem = columnsData[rowIndex];
if (gridItem !== undefined && columnId !== ACTUAL_CLASS_ID) {
const count = gridItem.predicted_classes_count[columnId];
cellContent = `${count} / ${gridItem.actual_class_doc_count} * 100 = ${cellContent}`;
}
}

return <span>{cellContent}</span>;
};

const docLink = docLinks.links.ml.classificationEvaluation;
Expand Down Expand Up @@ -341,7 +333,6 @@ export const EvaluatePanel: FC<EvaluatePanelProps> = ({ jobConfig, jobStatus, se
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={rowCount}
renderCellValue={renderCellValue}
renderCellPopover={renderCellPopover}
inMemory={{ level: 'sorting' }}
toolbarVisibility={{
showColumnSelector: true,
Expand Down

0 comments on commit 46f433e

Please sign in to comment.