Skip to content

Commit

Permalink
fix: update label picker when labels change [DET-5254] (#2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Hoyoul Kang authored Apr 16, 2021
1 parent 6ab2268 commit eb61693
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 53 deletions.
43 changes: 0 additions & 43 deletions webui/react/src/components/LabelSelectFilter.tsx

This file was deleted.

33 changes: 23 additions & 10 deletions webui/react/src/pages/ExperimentList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { Button, Input, Modal } from 'antd';
import { Button, Input, Modal, Select } from 'antd';
import { SelectValue } from 'antd/es/select';
import { SorterResult } from 'antd/es/table/interface';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import Icon from 'components/Icon';
import LabelSelectFilter from 'components/LabelSelectFilter';
import MultiSelect from 'components/MultiSelect';
import Page from 'components/Page';
import ResponsiveFilters from 'components/ResponsiveFilters';
import ResponsiveTable from 'components/ResponsiveTable';
Expand All @@ -27,7 +27,7 @@ import usePolling from 'hooks/usePolling';
import useStorage from 'hooks/useStorage';
import { parseUrl } from 'routes/utils';
import {
activateExperiment, archiveExperiment, cancelExperiment, getExperiments,
activateExperiment, archiveExperiment, cancelExperiment, getExperimentLabels, getExperiments,
killExperiment, openOrCreateTensorboard, pauseExperiment, unarchiveExperiment,
} from 'services/api';
import { V1GetExperimentsRequestSortBy } from 'services/api-ts-sdk';
Expand All @@ -38,6 +38,7 @@ import {
ALL_VALUE, CommandTask, ExperimentFilters, ExperimentItem, Pagination, RunState,
} from 'types';
import { isEqual } from 'utils/data';
import { alphanumericSorter } from 'utils/sort';
import {
cancellableRunStates, experimentToTask, isTaskKillable, terminalRunStates,
} from 'utils/types';
Expand All @@ -46,6 +47,8 @@ import { openCommand } from 'wait';
import css from './ExperimentList.module.scss';
import { columns as defaultColumns, idRenderer } from './ExperimentList.table';

const { Option } = Select;

enum Action {
Activate = 'Activate',
Archive = 'Archive',
Expand Down Expand Up @@ -88,6 +91,7 @@ const ExperimentList: React.FC = () => {
const initSorter = storage.getWithDefault(STORAGE_SORTER_KEY, { ...defaultSorter });
const [ canceler ] = useState(new AbortController());
const [ experiments, setExperiments ] = useState<ExperimentItem[]>();
const [ labels, setLabels ] = useState<string[]>([]);
const [ isLoading, setIsLoading ] = useState(true);
const [ isUrlParsed, setIsUrlParsed ] = useState(false);
const [ filters, setFilters ] = useState<ExperimentFilters>(initFilters);
Expand All @@ -97,8 +101,6 @@ const ExperimentList: React.FC = () => {
const [ sorter, setSorter ] = useState(initSorter);
const [ total, setTotal ] = useState(0);

const fetchUsers = useFetchUsers(canceler);

/*
* When filters changes update the page URL.
*/
Expand Down Expand Up @@ -269,6 +271,8 @@ const ExperimentList: React.FC = () => {
return tracker;
}, [ selectedExperiments ]);

const fetchUsers = useFetchUsers(canceler);

const fetchExperiments = useCallback(async (): Promise<void> => {
try {
const states = filters.states.includes(ALL_VALUE) ? undefined : filters.states.map(state => {
Expand Down Expand Up @@ -301,14 +305,23 @@ const ExperimentList: React.FC = () => {
}
}, [ canceler, filters, pagination, search, sorter ]);

const fetchLabels = useCallback(async () => {
try {
const labels = await getExperimentLabels({ signal: canceler.signal });
labels.sort((a, b) => alphanumericSorter(a, b));
setLabels(labels);
} catch (e) {}
}, [ canceler.signal ]);

const fetchAll = useCallback(() => {
fetchExperiments();
fetchLabels();
fetchUsers();
}, [ fetchExperiments, fetchUsers ]);
}, [ fetchExperiments, fetchLabels, fetchUsers ]);

usePolling(fetchAll);

const experimentTags = useExperimentTags(fetchExperiments);
const experimentTags = useExperimentTags(fetchAll);

const handleActionComplete = useCallback(() => fetchExperiments(), [ fetchExperiments ]);

Expand Down Expand Up @@ -496,9 +509,9 @@ const ExperimentList: React.FC = () => {
checked={filters.showArchived}
prefixLabel="Show Archived"
onChange={handleArchiveChange} />
<LabelSelectFilter
value={filters.labels}
onChange={handleLabelsChange} />
<MultiSelect label="Labels" value={filters.labels} onChange={handleLabelsChange}>
{labels.map((label) => <Option key={label} value={label}>{label}</Option>)}
</MultiSelect>
<StateSelectFilter
showCommandStates={false}
value={filters.states}
Expand Down

0 comments on commit eb61693

Please sign in to comment.