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

chore: migrate experiment list api [DET-3696, DET-3697, DET-3698] #1228

Merged
merged 15 commits into from
Sep 2, 2020
Merged
2 changes: 1 addition & 1 deletion webui/react/src/components/TaskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import css from './TaskCard.module.scss';
const TaskCard: React.FC<RecentTask> = (props: RecentTask) => {
let [ hasProgress, isComplete ] = [ false, false ];
if (isExperimentTask(props)) {
hasProgress = props.progress != null;
hasProgress = !!props.progress;
justin-determined-ai marked this conversation as resolved.
Show resolved Hide resolved
isComplete = props.progress === 1;
}
const classes = [ css.base ];
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/contexts/AppContexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Users from 'contexts/Users';
import usePolling from 'hooks/usePolling';
import useRestApi from 'hooks/useRestApi';
import {
getAgents, getCommands, getExperimentSummaries, getNotebooks, getShells,
getTensorboards, getUsers,
getAgents, getCommands, getExperimentSummaries, getNotebooks,
hkang1 marked this conversation as resolved.
Show resolved Hide resolved
getShells, getTensorboards, getUsers,
} from 'services/api';
import { EmptyParams, ExperimentsParams } from 'services/types';
import { Agent, Command, DetailedUser, Experiment } from 'types';
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/contexts/Experiments.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { generateContext } from 'contexts';
import { RestApiState } from 'hooks/useRestApi';
import { Experiment } from 'types';
import { ExperimentX } from 'types';

const contextProvider = generateContext<RestApiState<Experiment[]>>({
const contextProvider = generateContext<RestApiState<ExperimentX[]>>({
initialState: {
errorCount: 0,
hasLoaded: false,
Expand Down
26 changes: 20 additions & 6 deletions webui/react/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import ActiveExperiments from 'contexts/ActiveExperiments';
import Auth from 'contexts/Auth';
import ClusterOverview from 'contexts/ClusterOverview';
import { Commands, Notebooks, Shells, Tensorboards } from 'contexts/Commands';
import Experiments from 'contexts/Experiments';
import Users from 'contexts/Users';
import usePolling from 'hooks/usePolling';
import useStorage from 'hooks/useStorage';
import { getExperimentList } from 'services/api';
import { decodeExperimentList } from 'services/decoder';
import { ShirtSize } from 'themes';
import {
ALL_VALUE, Command, CommandType, RecentTask, ResourceType,
TaskFilters, TaskType,
ALL_VALUE, Command, CommandType, ExperimentX, RecentTask,
ResourceType, TaskFilters, TaskType,
} from 'types';
import { getPath } from 'utils/data';
import { filterTasks } from 'utils/task';
Expand All @@ -44,11 +46,11 @@ const Dashboard: React.FC = () => {
const users = Users.useStateContext();
const overview = ClusterOverview.useStateContext();
const activeExperiments = ActiveExperiments.useStateContext();
const experiments = Experiments.useStateContext();
const commands = Commands.useStateContext();
const notebooks = Notebooks.useStateContext();
const shells = Shells.useStateContext();
const tensorboards = Tensorboards.useStateContext();
const [ experiments, setExperiments ] = useState<ExperimentX[]>();

const storage = useStorage('dashboard/tasks');
const initFilters = storage.getWithDefault('filters', {
Expand All @@ -57,6 +59,18 @@ const Dashboard: React.FC = () => {
});
const [ filters, setFilters ] = useState<TaskFilters>(initFilters);

const fetchExperiments = useCallback(async (): Promise<void> => {
const response = await getExperimentList(
{ descend: true, key: 'startTime' },
hamidzr marked this conversation as resolved.
Show resolved Hide resolved
{ limit: 100, offset: 0 },
{ showArchived: false, states: filters.states, username: filters.username },
);
const experiments = decodeExperimentList(response.experiments || []);
setExperiments(experiments);
}, [ filters, setExperiments ]);

usePolling(fetchExperiments);

/* Overview */

const countActiveCommand = (commands: Command[]): number => {
Expand All @@ -74,7 +88,7 @@ const Dashboard: React.FC = () => {
/* Recent Tasks */

const showTasksSpinner = (
!experiments.hasLoaded ||
!experiments ||
hkang1 marked this conversation as resolved.
Show resolved Hide resolved
!commands.hasLoaded ||
!notebooks.hasLoaded ||
!shells.hasLoaded ||
Expand All @@ -89,7 +103,7 @@ const Dashboard: React.FC = () => {
];

const loadedTasks = [
...(experiments.data || []).map(experimentToTask),
...(experiments || []).map(experimentToTask),
...genericCommands.map(commandToTask),
];

Expand Down
2 changes: 1 addition & 1 deletion webui/react/src/pages/ExperimentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const ExperimentList: React.FC = () => {
}, [ selectedExperiments ]);

const fetchExperiments = useCallback(async (): Promise<void> => {
const response = await getExperimentList(sorter, pagination, search, filters);
const response = await getExperimentList(sorter, pagination, filters, search);
const experiments = decodeExperimentList(response.experiments || []);
setTotal(response.pagination?.total || 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the api is going to have pagination (both the request and the response) be the same format we might want to abstract and reuse that for other places (maybe with the current useRestApi)

actually the current userRestApi hook allows you to update the request parameters whenever needed could that still let us keep using it?

setExperiments(experiments);
Expand Down
2 changes: 1 addition & 1 deletion webui/react/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ type ExperimentListState =
export const getExperimentList = async (
sorter: TableSorter,
hamidzr marked this conversation as resolved.
Show resolved Hide resolved
pagination: TablePagination,
search: string,
filters: ExperimentFilters,
search?: string,
): Promise<V1GetExperimentsResponse> => {
try {
const response = await detExperimentApi.determinedGetExperiments(
Expand Down