Skip to content

Commit

Permalink
use pagination info in response
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkim-det committed Jul 25, 2024
1 parent 5185b78 commit a2a436c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
45 changes: 14 additions & 31 deletions webui/react/src/components/ComparisonView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Pivot, { PivotProps } from 'hew/Pivot';
import Spinner from 'hew/Spinner';
import SplitPane, { Pane } from 'hew/SplitPane';
import { Loadable, NotLoaded } from 'hew/utils/loadable';
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';

import CompareHyperparameters from 'components/CompareHyperparameters';
import { useAsync } from 'hooks/useAsync';
Expand Down Expand Up @@ -33,7 +33,6 @@ interface BaseProps {
onWidthChange: (width: number) => void;
fixedColumnsCount: number;
projectId: number;
total?: number;
}

type Props = XOR<{ experimentSelection: SelectionType }, { runSelection: SelectionType }> &
Expand All @@ -51,38 +50,12 @@ const ComparisonView: React.FC<Props> = ({
projectId,
experimentSelection,
runSelection,
total,
}) => {
const scrollbarWidth = useScrollbarWidth();
const hasPinnedColumns = fixedColumnsCount > 1;
const isMobile = useMobile();

const isSelectionLimitReached = () => {
if (experimentSelection) {
if (
(experimentSelection.type === 'ONLY_IN' &&
experimentSelection.selections.length > SELECTION_LIMIT) ||
(experimentSelection.type === 'ALL_EXCEPT' &&
total &&
total - experimentSelection.exclusions.length > SELECTION_LIMIT)
) {
return true;
}
return false;
}
if (runSelection) {
if (
(runSelection.type === 'ONLY_IN' && runSelection.selections.length > SELECTION_LIMIT) ||
(runSelection.type === 'ALL_EXCEPT' &&
total &&
total - runSelection.exclusions.length > SELECTION_LIMIT)
) {
return true;
}
return false;
}
return false;
};
const [isSelectionLimitReached, setIsSelectionLimitReached] = useState(false);

const loadableSelectedExperiments = useAsync(async () => {
if (experimentSelection) {
Expand All @@ -93,6 +66,11 @@ const ComparisonView: React.FC<Props> = ({
filter: JSON.stringify(filter),
limit: SELECTION_LIMIT,
});
if (response?.pagination?.total && response?.pagination?.total > SELECTION_LIMIT) {
setIsSelectionLimitReached(true);
} else {
setIsSelectionLimitReached(false);
}
return response.experiments;
} catch (e) {
handleError(e, { publicSubject: 'Unable to fetch experiments for comparison' });
Expand All @@ -114,8 +92,13 @@ const ComparisonView: React.FC<Props> = ({
const filter = getRunIdsFilter(filterFormSet, runSelection);
const response = await searchRuns({
filter: JSON.stringify(filter),
limit: 50,
limit: SELECTION_LIMIT,
});
if (response?.pagination?.total && response?.pagination?.total > SELECTION_LIMIT) {
setIsSelectionLimitReached(true);
} else {
setIsSelectionLimitReached(false);
}
return response.runs;
} catch (e) {
handleError(e, { publicSubject: 'Unable to fetch runs for comparison' });
Expand Down Expand Up @@ -220,7 +203,7 @@ const ComparisonView: React.FC<Props> = ({
}
return (
<>
{isSelectionLimitReached() && (
{isSelectionLimitReached && (
<Alert message={`Only up to ${SELECTION_LIMIT} records can be compared`} />
)}
<Pivot items={tabs} />
Expand Down
1 change: 0 additions & 1 deletion webui/react/src/pages/F_ExpList/F_ExperimentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ const F_ExperimentList: React.FC<Props> = ({ project }) => {
initialWidth={comparisonViewTableWidth}
open={settings.compare}
projectId={project.id}
total={Loadable.getOrElse(undefined, total)}
onWidthChange={handleCompareWidthChange}>
<DataGrid<ExperimentWithTrial, ExperimentAction, BulkExperimentItem>
columns={columns}
Expand Down
1 change: 0 additions & 1 deletion webui/react/src/pages/FlatRuns/FlatRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,6 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
open={settings.compare}
projectId={projectId}
runSelection={settings.selection}
total={Loadable.getOrElse(undefined, total)}
onWidthChange={handleCompareWidthChange}>
<DataGrid<FlatRun, FlatRunAction>
columns={columns}
Expand Down

0 comments on commit a2a436c

Please sign in to comment.