Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Column Filtering and Performance Improvements #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
60 changes: 31 additions & 29 deletions src/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable react/prop-types */

import React from 'react';
import { isEmpty, isEqual, isNil } from 'lodash-es';
import { isEmpty, isEqual, isNil, debounce } from 'lodash-es';
import { useResizeObserver } from 'hooks';
import _ from 'lodash-es';

Expand All @@ -26,6 +26,7 @@ import ManageColumnsPopover from 'pages/Metrics/components/Table/ManageColumnsPo
import HideRowsPopover from 'pages/Metrics/components/Table/HideRowsPopover/HideRowsPopover';
import RowHeightPopover from 'pages/Metrics/components/Table/RowHeightPopover/RowHeightPopover';
import CompareSelectedRunsPopover from 'pages/Metrics/components/Table/CompareSelectedRunsPopover';
import HideColumnsPopover from 'pages/Metrics/components/Table/HideColumnsPopover/HideColumnsPopover';

import { ITableProps } from 'types/components/Table/Table';

Expand All @@ -51,6 +52,7 @@ const Table = React.forwardRef(function Table(
onRowHover = () => {},
onRowClick = () => {},
onTableResizeModeChange,
onDefaultColumnsVisibilityChange,
custom,
data,
columns,
Expand All @@ -71,6 +73,7 @@ const Table = React.forwardRef(function Table(
updateColumnsWidths,
sortFields,
hiddenRows,
unselectedColumnState,
isLoading,
showRowClickBehaviour = true,
showResizeContainerActionBar = true,
Expand Down Expand Up @@ -379,19 +382,21 @@ const Table = React.forwardRef(function Table(
const groupRow = dataRef.current[groupKey];
if (!!groupRow && !!groupRow.data) {
if (colKey === 'value') {
const { min, line, max, stdDevValue, stdErrValue } =
groupRow.data.aggregation.area;
groupHeaderRowCell.children[0].children[0].children[0].textContent =
groupRow.data.aggregation.area.min;
min;
groupHeaderRowCell.children[0].children[0].children[1].textContent =
groupRow.data.aggregation.line;
line;
groupHeaderRowCell.children[0].children[0].children[2].textContent =
groupRow.data.aggregation.area.max;
max;
if (!isNil(groupRow.data.aggregation.area.stdDevValue)) {
groupHeaderRowCell.children[0].children[0].children[3].textContent =
groupRow.data.aggregation.area.stdDevValue;
stdDevValue;
}
if (!isNil(groupRow.data.aggregation.area.stdErrValue)) {
groupHeaderRowCell.children[0].children[0].children[3].textContent =
groupRow.data.aggregation.area.stdErrValue;
stdErrValue;
}
} else {
groupHeaderRowCell.textContent = groupRow.data[colKey];
Expand Down Expand Up @@ -604,22 +609,9 @@ const Table = React.forwardRef(function Table(

React.useEffect(() => {
if (custom && !!tableContainerRef.current) {
const windowEdges = calculateWindow({
scrollTop: tableContainerRef.current.scrollTop,
offsetHeight: tableContainerRef.current.offsetHeight,
scrollHeight: tableContainerRef.current.scrollHeight,
itemHeight: rowHeight,
groupMargin:
ROW_CELL_SIZE_CONFIG[rowHeight]?.groupMargin ??
ROW_CELL_SIZE_CONFIG[RowHeightSize.md].groupMargin,
});

startIndex.current = windowEdges.startIndex;
endIndex.current = windowEdges.endIndex;

virtualizedUpdate();

tableContainerRef.current.onscroll = ({ target }) => {
// Debounce the scroll event to avoid performance issues
const handleScroll = debounce(() => {
const target = tableContainerRef.current;
const windowEdges = calculateWindow({
scrollTop: target.scrollTop,
offsetHeight: target.offsetHeight,
Expand Down Expand Up @@ -651,15 +643,16 @@ const Table = React.forwardRef(function Table(
}
}
setListWindowMeasurements();
}, 30);

tableContainerRef.current.addEventListener('scroll', handleScroll);

return () => {
if (tableContainerRef.current) {
tableContainerRef.current.removeEventListener('scroll', handleScroll);
}
};
}

return () => {
if (custom && tableContainerRef.current) {
// eslint-disable-next-line react-hooks/exhaustive-deps
tableContainerRef.current.onscroll = null;
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [custom, rowData]);

Expand Down Expand Up @@ -803,6 +796,15 @@ const Table = React.forwardRef(function Table(
data={dataRef.current}
/>
)}
{onDefaultColumnsVisibilityChange && (
<HideColumnsPopover
unselectedColumnState={unselectedColumnState}
onDefaultColumnsVisibilityChange={
onDefaultColumnsVisibilityChange
}
appName={appName}
/>
)}
{onSort && (
<ControlPopover
anchorOrigin={{
Expand Down
8 changes: 8 additions & 0 deletions src/src/config/analytics/analyticsKeysMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const ANALYTICS_EVENT_KEYS = {
metricVisibilityChange:
'[MetricsExplorer][Table] Change metric visibility',
compareSelectedRuns: '[MetricsExplorer][Table] Compare selected runs',
changeDefaultColumnsVisibility:
'[MetricsExplorer][Table] Change default columns visibility',
},
chart: {
controls: {
Expand Down Expand Up @@ -97,6 +99,8 @@ export const ANALYTICS_EVENT_KEYS = {
metricVisibilityChange:
'[ParamsExplorer][Table] Change metric visibility',
compareSelectedRuns: '[ParamsExplorer][Table] Compare selected runs',
changeDefaultColumnsVisibility:
'[ParamsExplorer][Table] Change default columns visibility',
},
chart: {
controls: {
Expand Down Expand Up @@ -153,6 +157,8 @@ export const ANALYTICS_EVENT_KEYS = {
changeSorting: '[RunsExplorer][Table] Change sorting',
metricVisibilityChange: '[RunsExplorer][Table] Change metric visibility',
compareSelectedRuns: '[RunsExplorer][Table] Compare selected runs',
changeDefaultColumnsVisibility:
'[RunsExplorer][Table] Change default columns visibility',
},
},
scatters: {
Expand All @@ -177,6 +183,8 @@ export const ANALYTICS_EVENT_KEYS = {
metricVisibilityChange:
'[ScattersExplorer][Table] Change metric visibility',
compareSelectedRuns: '[ScattersExplorer][Table] Compare selected runs',
changeDefaultColumnsVisibility:
'[ScattersExplorer][Table] Change default columns visibility',
},
chart: {
controls: {
Expand Down
10 changes: 10 additions & 0 deletions src/src/config/table/tableConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export enum VisualizationElementEnum {
IMAGE = 'image',
}

export enum UnselectedColumnState {
FORCE_HIDE = 'hide',
FORCE_SHOW = 'show',
DEFAULT = 'default',
}

export const ROW_CELL_SIZE_CONFIG = {
22: {
groupMargin: 2,
Expand All @@ -42,6 +48,7 @@ export const TABLE_DEFAULT_CONFIG: Record<string, any> = {
resizeMode: ResizeModeEnum.Resizable,
rowHeight: RowHeightSize.md,
sortFields: [],
unselectedColumnState: UnselectedColumnState.FORCE_HIDE,
hideSystemMetrics: true,
hiddenMetrics: [],
hiddenColumns: ['hash', 'description'],
Expand All @@ -58,6 +65,7 @@ export const TABLE_DEFAULT_CONFIG: Record<string, any> = {
resizeMode: ResizeModeEnum.Resizable,
rowHeight: RowHeightSize.md,
sortFields: [],
unselectedColumnState: UnselectedColumnState.FORCE_HIDE,
hiddenMetrics: [],
hiddenColumns: ['hash', 'description'],
nonHidableColumns: new Set(['#', 'run', 'actions']),
Expand All @@ -73,6 +81,7 @@ export const TABLE_DEFAULT_CONFIG: Record<string, any> = {
resizeMode: ResizeModeEnum.Resizable,
rowHeight: RowHeightSize.md,
sortFields: [],
unselectedColumnState: UnselectedColumnState.FORCE_HIDE,
hiddenMetrics: [],
hiddenColumns: ['hash', 'description'],
nonHidableColumns: new Set(['#', 'run', 'actions']),
Expand All @@ -89,6 +98,7 @@ export const TABLE_DEFAULT_CONFIG: Record<string, any> = {
resizeMode: ResizeModeEnum.Resizable,
rowHeight: RowHeightSize.md,
sortFields: [],
unselectedColumnState: UnselectedColumnState.FORCE_HIDE,
hiddenMetrics: [],
hiddenColumns: ['hash', 'description'],
nonHidableColumns: new Set(['#', 'run', 'actions']),
Expand Down
4 changes: 4 additions & 0 deletions src/src/pages/Metrics/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ function Metrics(
resizeMode={props.resizeMode}
columnsWidths={props.columnsWidths}
selectedRows={props.selectedRows}
unselectedColumnState={props.unselectedColumnState}
hideSystemMetrics={props.hideSystemMetrics}
appName={AppNameEnum.METRICS}
hiddenChartRows={props.lineChartData?.length === 0}
Expand All @@ -272,6 +273,9 @@ function Metrics(
onColumnsVisibilityChange={
props.onColumnsVisibilityChange
}
onDefaultColumnsVisibilityChange={
props.onDefaultColumnsVisibilityChange
}
onTableDiffShow={props.onTableDiffShow}
onRowHeightChange={props.onRowHeightChange}
onRowsChange={props.onMetricVisibilityChange}
Expand Down
6 changes: 6 additions & 0 deletions src/src/pages/Metrics/MetricsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ function MetricsContainer(): React.FunctionComponentElement<React.ReactNode> {
hiddenMetrics={metricsData?.config?.table?.hiddenMetrics!}
hideSystemMetrics={metricsData?.config?.table?.hideSystemMetrics!}
hiddenColumns={metricsData?.config?.table?.hiddenColumns!}
unselectedColumnState={
metricsData?.config?.table?.unselectedColumnState!
}
chartPanelOffsetHeight={chartPanelOffsetHeight}
selectedRows={metricsData?.selectedRows!}
groupingSelectOptions={metricsData?.groupingSelectOptions!}
Expand Down Expand Up @@ -209,6 +212,9 @@ function MetricsContainer(): React.FunctionComponentElement<React.ReactNode> {
onMetricVisibilityChange={metricAppModel.onMetricVisibilityChange}
onColumnsOrderChange={metricAppModel.onColumnsOrderChange}
onColumnsVisibilityChange={metricAppModel.onColumnsVisibilityChange}
onDefaultColumnsVisibilityChange={
metricAppModel.onDefaultColumnsVisibilityChange
}
onTableDiffShow={metricAppModel.onTableDiffShow}
onTableResizeModeChange={metricAppModel.onTableResizeModeChange}
onRowsVisibilityChange={metricAppModel.onRowsVisibilityChange}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@use 'src/styles/abstracts' as *;

.HideColumnsPopover {
padding: 0.5rem;
width: 16.5rem;
&__item {
text-transform: capitalize;
}
}

.HideColumnsPopover__trigger {
cursor: pointer;
display: flex;
align-items: center;
border: 0.0625rem solid transparent;
transition: all 0.18s ease-out;
border-radius: $radius-main;
padding: 0 0.375rem !important;
margin-right: 0.375rem !important;
i {
margin-right: 0.75rem;
}
&.opened {
border: $border-main-active;
background-color: $primary-color-10;
}
}
Loading
Loading