Skip to content

Commit

Permalink
fix: reset InteractiveTable pagination when filters applied [ET-183] [E…
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyBonar authored May 23, 2024
1 parent 3cbe805 commit ba31f03
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
10 changes: 5 additions & 5 deletions webui/react/src/components/ModelRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
);

const handleUserFilterReset = useCallback(() => {
updateSettings({ users: undefined });
updateSettings({ tableOffset: 0, users: undefined });
}, [updateSettings]);

const userFilterDropdown = useCallback(
Expand All @@ -255,7 +255,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
);

const handleNameSearchReset = useCallback(() => {
updateSettings({ name: undefined });
updateSettings({ name: undefined, tableOffset: 0 });
}, [updateSettings]);

const nameFilterSearch = useCallback(
Expand All @@ -278,7 +278,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
);

const handleDescriptionSearchReset = useCallback(() => {
updateSettings({ description: undefined });
updateSettings({ description: undefined, tableOffset: 0 });
}, [updateSettings]);

const descriptionFilterSearch = useCallback(
Expand All @@ -301,7 +301,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
);

const handleLabelFilterReset = useCallback(() => {
updateSettings({ tags: undefined });
updateSettings({ tableOffset: 0, tags: undefined });
}, [updateSettings]);

const handleWorkspaceFilterApply = useCallback(
Expand All @@ -317,7 +317,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
);

const handleWorkspaceFilterReset = useCallback(() => {
updateSettings({ row: undefined, workspace: undefined });
updateSettings({ row: undefined, tableOffset: 0, workspace: undefined });
}, [updateSettings]);

const workspaceFilterDropdown = useCallback(
Expand Down
27 changes: 20 additions & 7 deletions webui/react/src/components/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {
users,
settings.search,
);
}, [loadedTasks, settings, users]);
}, [
loadedTasks,
settings.search,
settings.state,
settings.tableLimit,
settings.type,
settings.user,
settings.workspace,
users,
]);

const taskMap = useMemo(() => {
return (loadedTasks || []).reduce(
Expand Down Expand Up @@ -190,13 +199,13 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {

const handleNameSearchApply = useCallback(
(newSearch: string) => {
updateSettings({ row: undefined, search: newSearch || undefined });
updateSettings({ row: undefined, search: newSearch || undefined, tableOffset: 0 });
},
[updateSettings],
);

const handleNameSearchReset = useCallback(() => {
updateSettings({ row: undefined, search: undefined });
updateSettings({ row: undefined, search: undefined, tableOffset: 0 });
}, [updateSettings]);

const nameFilterSearch = useCallback(
Expand All @@ -215,6 +224,7 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {
(types: string[]) => {
updateSettings({
row: undefined,
tableOffset: 0,
type: types.length !== 0 ? (types as CommandType[]) : undefined,
});
},
Expand All @@ -225,18 +235,19 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {
(workspaces: string[]) => {
updateSettings({
row: undefined,
tableOffset: 0,
workspace: workspaces.length !== 0 ? workspaces : undefined,
});
},
[updateSettings],
);

const handleWorkspaceFilterReset = useCallback(() => {
updateSettings({ row: undefined, workspace: undefined });
updateSettings({ row: undefined, tableOffset: 0, workspace: undefined });
}, [updateSettings]);

const handleTypeFilterReset = useCallback(() => {
updateSettings({ row: undefined, type: undefined });
updateSettings({ row: undefined, tableOffset: 0, type: undefined });
}, [updateSettings]);

const typeFilterDropdown = useCallback(
Expand Down Expand Up @@ -271,13 +282,14 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {
updateSettings({
row: undefined,
state: states.length !== 0 ? (states as CommandState[]) : undefined,
tableOffset: 0,
});
},
[updateSettings],
);

const handleStateFilterReset = useCallback(() => {
updateSettings({ row: undefined, state: undefined });
updateSettings({ row: undefined, state: undefined, tableOffset: 0 });
}, [updateSettings]);

const stateFilterDropdown = useCallback(
Expand All @@ -297,14 +309,15 @@ const TaskList: React.FC<Props> = ({ workspace }: Props) => {
(users: string[]) => {
updateSettings({
row: undefined,
tableOffset: 0,
user: users.length !== 0 ? users : undefined,
});
},
[updateSettings],
);

const handleUserFilterReset = useCallback(() => {
updateSettings({ row: undefined, user: undefined });
updateSettings({ row: undefined, tableOffset: 0, user: undefined });
}, [updateSettings]);

const userFilterDropdown = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/pages/Admin/UserManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ const UserManagement: React.FC = () => {
const [selectedUserIds, setSelectedUserIds] = useState<React.Key[]>([]);
const [refresh, setRefresh] = useState<Record<string, never>>({});
const [nameFilter, setNameFilter] = useState<string>('');
const [roleFilter, setRoleFilter] = useState<UserRole | number[] | ''>('');
const [statusFilter, setStatusFilter] = useState<UserStatus | ''>('');
const [roleFilter, setRoleFilter] = useState<UserRole | number[]>();
const [statusFilter, setStatusFilter] = useState<UserStatus>();
const pageRef = useRef<HTMLElement>(null);
const currentUser = Loadable.getOrElse(undefined, useObservable(userStore.currentUser));
const loadableSettings = useObservable(userManagementSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ const ExperimentCheckpoints: React.FC<Props> = ({ experiment, pageRef }: Props)
updateSettings({
row: undefined,
state: states.length !== 0 ? (states as CheckpointState[]) : undefined,
tableOffset: 0,
});
},
[updateSettings],
);

const handleStateFilterReset = useCallback(() => {
updateSettings({ row: undefined, state: undefined });
updateSettings({ row: undefined, state: undefined, tableOffset: 0 });
}, [updateSettings]);

const stateFilterDropdown = useCallback(
Expand Down Expand Up @@ -263,13 +264,11 @@ const ExperimentCheckpoints: React.FC<Props> = ({ experiment, pageRef }: Props)
stateFilterDropdown,
]);

const stateString = settings.state?.join('.');
const fetchExperimentCheckpoints = useCallback(async () => {
if (!settings) return;

const states = settings.state?.map((state) => encodeCheckpointState(state as CheckpointState));
try {
const states = stateString
?.split('.')
.map((state) => encodeCheckpointState(state as CheckpointState));
const response = await getExperimentCheckpoints(
{
id: experiment.id,
Expand All @@ -294,7 +293,7 @@ const ExperimentCheckpoints: React.FC<Props> = ({ experiment, pageRef }: Props)
} finally {
setIsLoading(false);
}
}, [experiment.id, canceler, settings, stateString, checkpoints]);
}, [settings, experiment.id, canceler.signal, checkpoints]);

const submitBatchAction = useCallback(
async (action: CheckpointAction) => {
Expand Down
10 changes: 4 additions & 6 deletions webui/react/src/pages/ExperimentDetails/ExperimentTrials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ const ExperimentTrials: React.FC<Props> = ({ experiment, pageRef }: Props) => {
updateSettings({
row: undefined,
state: states.length !== 0 ? (states as RunState[]) : undefined,
tableOffset: 0,
});
},
[updateSettings],
);

const handleStateFilterReset = useCallback(() => {
updateSettings({ row: undefined, state: undefined });
updateSettings({ row: undefined, state: undefined, tableOffset: 0 });
}, [updateSettings]);

const stateFilterDropdown = useCallback(
Expand Down Expand Up @@ -312,14 +313,11 @@ const ExperimentTrials: React.FC<Props> = ({ experiment, pageRef }: Props) => {
[columns, settings, updateSettings],
);

const stateString = useMemo(() => settings.state?.join('.'), [settings.state]);
const fetchExperimentTrials = useCallback(async () => {
if (!settings) return;
const states = settings.state?.map((state) => encodeExperimentState(state as RunState));

try {
const states = stateString
?.split('.')
.map((state) => encodeExperimentState(state as RunState));
const { trials: experimentTrials, pagination: responsePagination } = await getExpTrials(
{
id: experiment.id,
Expand Down Expand Up @@ -348,7 +346,7 @@ const ExperimentTrials: React.FC<Props> = ({ experiment, pageRef }: Props) => {
} finally {
setIsLoading(false);
}
}, [experiment.id, canceler, settings, stateString]);
}, [settings, experiment.id, canceler.signal]);

const sendBatchActions = useCallback(
async (action: Action) => {
Expand Down
14 changes: 9 additions & 5 deletions webui/react/src/pages/ExperimentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ const ExperimentList: React.FC<Props> = ({ project }) => {

const handleNameSearchApply = useCallback(
(newSearch: string) => {
updateSettings({ row: undefined, search: newSearch || undefined });
updateSettings({ row: undefined, search: newSearch || undefined, tableOffset: 0 });
},
[updateSettings],
);

const handleNameSearchReset = useCallback(() => {
updateSettings({ row: undefined, search: undefined });
updateSettings({ row: undefined, search: undefined, tableOffset: 0 });
}, [updateSettings]);

const nameFilterSearch = useCallback(
Expand All @@ -312,13 +312,14 @@ const ExperimentList: React.FC<Props> = ({ project }) => {
updateSettings({
label: labels.length !== 0 ? labels : undefined,
row: undefined,
tableOffset: 0,
});
},
[updateSettings],
);

const handleLabelFilterReset = useCallback(() => {
updateSettings({ label: undefined, row: undefined });
updateSettings({ label: undefined, row: undefined, tableOffset: 0 });
}, [updateSettings]);

const labelFilterDropdown = useCallback(
Expand All @@ -340,13 +341,14 @@ const ExperimentList: React.FC<Props> = ({ project }) => {
updateSettings({
row: undefined,
state: states.length !== 0 ? (states as RunState[]) : undefined,
tableOffset: 0,
});
},
[updateSettings],
);

const handleStateFilterReset = useCallback(() => {
updateSettings({ row: undefined, state: undefined });
updateSettings({ row: undefined, state: undefined, tableOffset: 0 });
}, [updateSettings]);

const stateFilterDropdown = useCallback(
Expand All @@ -366,14 +368,15 @@ const ExperimentList: React.FC<Props> = ({ project }) => {
(users: string[]) => {
updateSettings({
row: undefined,
tableOffset: 0,
user: users.length !== 0 ? users : undefined,
});
},
[updateSettings],
);

const handleUserFilterReset = useCallback(() => {
updateSettings({ row: undefined, user: undefined });
updateSettings({ row: undefined, tableOffset: 0, user: undefined });
}, [updateSettings]);

const userFilterDropdown = useCallback(
Expand Down Expand Up @@ -922,6 +925,7 @@ const ExperimentList: React.FC<Props> = ({ project }) => {
columns: newColumns,
columnWidths: newColumnWidths,
row: undefined,
tableOffset: 0,
});
},
[settings, updateSettings],
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/pages/Templates/TemplatesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const TemplateList: React.FC<Props> = ({ workspaceId }) => {
);

const handleWorkspaceFilterReset = useCallback(() => {
updateSettings({ workspace: undefined });
updateSettings({ tableOffset: 0, workspace: undefined });
}, [updateSettings]);

const workspaceFilterDropdown = useCallback(
Expand Down Expand Up @@ -154,7 +154,7 @@ const TemplateList: React.FC<Props> = ({ workspaceId }) => {
);

const handleNameSearchReset = useCallback(() => {
updateSettings({ name: undefined });
updateSettings({ name: undefined, tableOffset: 0 });
}, [updateSettings]);

const handleNameSearchApply = useCallback(
Expand Down

0 comments on commit ba31f03

Please sign in to comment.