Skip to content

Commit

Permalink
fix: Searches view fixes (ET-297) (#9487)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkim-det authored Jun 11, 2024
1 parent aa6521b commit e138267
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 51 deletions.
8 changes: 4 additions & 4 deletions webui/react/src/components/Searches/Searches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ const Searches: React.FC<Props> = ({ project }) => {
const filters = JSON.parse(filtersString);
const existingFilterGroup = { ...filters.filterGroup };
const singleTrialFilter = {
columnName: 'numTrials',
columnName: 'searcherType',
kind: 'field',
location: 'LOCATION_TYPE_EXPERIMENT',
operator: '>',
type: 'COLUMN_TYPE_NUMBER',
value: 1,
operator: '!=',
type: 'COLUMN_TYPE_TEXT',
value: 'single',
};
filters.filterGroup = {
children: [existingFilterGroup, singleTrialFilter],
Expand Down
3 changes: 2 additions & 1 deletion webui/react/src/pages/FlatRuns/FlatRuns.settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export const ProjectUrlSettings = t.partial({
page: t.number,
});

export const settingsPathForProject = (id: number): string => `flatRunsForProject${id}`;
export const settingsPathForProject = (projectId: number, searchId?: number): string =>
`flatRunsForProject${projectId}-${searchId}`;
67 changes: 28 additions & 39 deletions webui/react/src/pages/FlatRuns/FlatRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { Loadable, Loaded, NotLoaded } from 'hew/utils/loadable';
import { isUndefined } from 'lodash';
import { useObservable } from 'micro-observables';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { v4 as uuidv4 } from 'uuid';

import ColumnPickerMenu from 'components/ColumnPickerMenu';
Expand All @@ -59,6 +58,7 @@ import { useGlasbey } from 'hooks/useGlasbey';
import useMobile from 'hooks/useMobile';
import usePolling from 'hooks/usePolling';
import { useSettings } from 'hooks/useSettings';
import useTypedParams from 'hooks/useTypedParams';
import {
DEFAULT_SELECTION,
SelectionType as SelectionState,
Expand All @@ -76,6 +76,7 @@ import { pluralizer } from 'utils/string';
import {
defaultColumnWidths,
defaultRunColumns,
defaultSearchRunColumns,
getColumnDefs,
RunColumn,
runColumns,
Expand All @@ -85,6 +86,7 @@ import css from './FlatRuns.module.scss';
import {
defaultFlatRunsSettings,
FlatRunsSettings,
ProjectUrlSettings,
settingsPathForProject,
} from './FlatRuns.settings';

Expand Down Expand Up @@ -120,9 +122,17 @@ const parseSortString = (sortString: string): Sort[] => {
const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
const dataGridRef = useRef<DataGridHandle>(null);
const contentRef = useRef<HTMLDivElement>(null);
const [searchParams, setSearchParams] = useSearchParams();
const { params, updateParams } = useTypedParams(ProjectUrlSettings, {});
const page = params.page || 0;
const setPage = useCallback(
(p: number) => updateParams({ page: p || undefined }),
[updateParams],
);

const settingsPath = useMemo(() => settingsPathForProject(projectId), [projectId]);
const settingsPath = useMemo(
() => settingsPathForProject(projectId, searchId),
[projectId, searchId],
);
const flatRunsSettingsObs = useMemo(
() => userSettings.get(FlatRunsSettings, settingsPath),
[settingsPath],
Expand All @@ -133,23 +143,20 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
(p: Partial<FlatRunsSettings>) => userSettings.setPartial(FlatRunsSettings, settingsPath, p),
[settingsPath],
);
const settings = useMemo(
() =>
flatRunsSettings
.map((s) => ({ ...defaultFlatRunsSettings, ...s }))
.getOrElse(defaultFlatRunsSettings),
[flatRunsSettings],
);
const settings = useMemo(() => {
const defaultSettings = { ...defaultFlatRunsSettings };
if (searchId) {
defaultSettings.columns = defaultSearchRunColumns;
}
return flatRunsSettings.map((s) => ({ ...defaultSettings, ...s })).getOrElse(defaultSettings);
}, [flatRunsSettings, searchId]);

const { settings: globalSettings, updateSettings: updateGlobalSettings } =
useSettings<DataGridGlobalSettings>(settingsConfigGlobal);

const [isOpenFilter, setIsOpenFilter] = useState<boolean>(false);
const [runs, setRuns] = useState<Loadable<FlatRun>[]>(INITIAL_LOADING_RUNS);
const isPagedView = true;
const [page, setPage] = useState(() =>
isFinite(Number(searchParams.get('page'))) ? Math.max(Number(searchParams.get('page')), 0) : 0,
);

const [sorts, setSorts] = useState<Sort[]>(() => {
if (!isLoadingSettings) {
Expand Down Expand Up @@ -428,14 +435,12 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
(cPage: number, cPageSize: number) => {
updateSettings({ pageLimit: cPageSize });
// Pagination component is assuming starting index of 1.
setPage((prevPage) => {
if (cPage - 1 !== prevPage) {
setRuns(Array(cPageSize).fill(NotLoaded));
}
return cPage - 1;
});
if (cPage - 1 !== page) {
setRuns(Array(cPageSize).fill(NotLoaded));
}
setPage(cPage - 1);
},
[updateSettings],
[page, updateSettings, setPage],
);

const fetchRuns = useCallback(async (): Promise<void> => {
Expand Down Expand Up @@ -507,17 +512,13 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {

const { stopPolling } = usePolling(fetchRuns, { rerunOnNewFn: true });

const handlePageUpdate = useCallback((page: number) => {
setPage(page);
}, []);

const numFilters = 0;

const resetPagination = useCallback(() => {
setIsLoading(true);
setPage(0);
setRuns(INITIAL_LOADING_RUNS);
}, []);
}, [setPage]);

useEffect(() => {
if (!isLoadingSettings && settings.sortString) {
Expand All @@ -526,18 +527,6 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoadingSettings]);

useEffect(() => {
setSearchParams((params) => {
if (page) {
params.set('page', page.toString());
} else {
params.delete('page');
}
return params;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page]);

useEffect(() => {
let cleanup: () => void;
// eagerSubscribe is like subscribe but it runs once before the observed value changes.
Expand Down Expand Up @@ -913,7 +902,7 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
onChange={handleSortChange}
/>
<ColumnPickerMenu
defaultVisibleColumns={defaultRunColumns}
defaultVisibleColumns={searchId ? defaultSearchRunColumns : defaultRunColumns}
initialVisibleColumns={columnsIfLoaded}
isMobile={isMobile}
pinnedColumnsCount={settings.pinnedColumnsCount}
Expand Down Expand Up @@ -982,7 +971,7 @@ const FlatRuns: React.FC<Props> = ({ projectId, searchId }) => {
onColumnResize={handleColumnWidthChange}
onColumnsOrderChange={handleColumnsOrderChange}
onContextMenuComplete={handleContextMenuComplete}
onPageUpdate={handlePageUpdate}
onPageUpdate={setPage}
onPinnedColumnsCountChange={handlePinnedColumnsCountChange}
onSelectionChange={handleSelectionChange}
/>
Expand Down
10 changes: 10 additions & 0 deletions webui/react/src/pages/FlatRuns/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ export const runColumns = [
'parentArchived',
] as const;

const EXCLUDED_SEARCH_DEFAULT_COLUMNS: RunColumn[] = [
'searcherType',
'searcherMetric',
'searcherMetricsVal',
];

export type RunColumn = (typeof runColumns)[number];

export const defaultRunColumns: RunColumn[] = [...runColumns];

export const defaultSearchRunColumns: RunColumn[] = runColumns.filter(
(c) => !EXCLUDED_SEARCH_DEFAULT_COLUMNS?.includes(c),
);

function getCellStateFromExperimentState(expState: RunState) {
switch (expState) {
case RunState.Queued: {
Expand Down
17 changes: 10 additions & 7 deletions webui/react/src/pages/SearchDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import FlatRuns from './FlatRuns/FlatRuns';
const TabType = {
Code: 'code',
Notes: 'notes',
Trials: 'trials',
Runs: 'runs',
} as const;

type TabType = ValueOf<typeof TabType>;

type Params = {
searchId: string;
tab?: ValueOf<typeof TabType>;
tab?: TabType;
};

const TAB_KEYS = Object.values(TabType);
const INITIAL_TAB_KEY = TabType.Trials;
const INITIAL_TAB_KEY = TabType.Runs;

const SearchDetails: React.FC = () => {
const { tab, searchId } = useParams<Params>();
Expand All @@ -46,7 +47,9 @@ const SearchDetails: React.FC = () => {

const navigate = useNavigate();
const location = useLocation();
const [tabKey, setTabKey] = useState(tab && TAB_KEYS.includes(tab) ? tab : INITIAL_TAB_KEY);
const [tabKey, setTabKey] = useState<TabType>(
tab && TAB_KEYS.includes(tab) ? tab : INITIAL_TAB_KEY,
);
const basePath = paths.searchDetails(id);

const configForExperiment = (experimentId: number): SettingsConfig<{ filePath: string }> => ({
Expand Down Expand Up @@ -140,8 +143,8 @@ const SearchDetails: React.FC = () => {
children: experiment?.projectId && (
<FlatRuns projectId={experiment.projectId} searchId={id} />
),
key: TabType.Trials,
label: 'Trials',
key: TabType.Runs,
label: 'Runs',
},
];

Expand Down

0 comments on commit e138267

Please sign in to comment.