Skip to content

Commit ef7d6ee

Browse files
authored
Merge branch 'master' into filter-complimentary-credits
2 parents c3cf653 + 0b031be commit ef7d6ee

35 files changed

+1087
-1061
lines changed

frontend/javascripts/admin/statistic/available_tasks_report_view.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,26 @@ import AdminPage from "admin/admin_page";
33
import { getAvailableTasksReport } from "admin/rest_api";
44
import { Spin, Table, Tag, Tooltip } from "antd";
55
import TeamSelectionComponent from "dashboard/dataset/team_selection_component";
6-
import { handleGenericError } from "libs/error_handling";
6+
import { useQueryWithErrorHandling } from "libs/react_hooks";
77
import { compareBy, localeCompareBy } from "libs/utils";
88
import { useState } from "react";
99
import type { APIAvailableTasksReport } from "types/api_types";
1010

1111
const { Column } = Table;
1212

1313
/*
14-
* Note that the phrasing available tasks is chosen here over pending to
14+
* Note that the phrasing "available" tasks is chosen here over "pending" to
1515
* emphasize that tasks are still available for individual users.
1616
* From the project viewpoint they are tasks with pending instances.
1717
*/
1818
function AvailableTasksReportView() {
19-
const [data, setData] = useState<APIAvailableTasksReport[]>([]);
20-
const [isLoading, setIsLoading] = useState(false);
19+
const [selectedTeamId, setSelectedTeamId] = useState<string | null>(null);
2120

22-
async function fetchData(teamId: string | null | undefined) {
23-
if (teamId == null) {
24-
setData([]);
25-
} else {
26-
try {
27-
setIsLoading(true);
28-
const progressData = await getAvailableTasksReport(teamId);
29-
setData(progressData);
30-
} catch (error) {
31-
handleGenericError(error as Error);
32-
} finally {
33-
setIsLoading(false);
34-
}
35-
}
36-
}
21+
const { data = [], isLoading } = useQueryWithErrorHandling({
22+
queryKey: ["availableTasksReport", selectedTeamId],
23+
enabled: selectedTeamId != null,
24+
queryFn: () => getAvailableTasksReport(selectedTeamId!),
25+
});
3726

3827
return (
3928
<AdminPage
@@ -47,7 +36,7 @@ function AvailableTasksReportView() {
4736
<TeamSelectionComponent
4837
onChange={(selectedTeam) => {
4938
if (!Array.isArray(selectedTeam) && selectedTeam != null) {
50-
fetchData(selectedTeam.id);
39+
setSelectedTeamId(selectedTeam.id);
5140
}
5241
}}
5342
prefix={<FilterOutlined />}

frontend/javascripts/admin/statistic/project_and_annotation_type_dropdown.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { FilterOutlined } from "@ant-design/icons";
22
import { getProjects } from "admin/rest_api";
33
import { Select } from "antd";
4-
import { useFetch } from "libs/react_helpers";
5-
import { useWkSelector } from "libs/react_hooks";
4+
import { useQueryWithErrorHandling, useWkSelector } from "libs/react_hooks";
65
import { isUserAdminOrTeamManager } from "libs/utils";
76
import type React from "react";
87
import { useEffect, useState } from "react";
@@ -55,17 +54,15 @@ function ProjectAndAnnotationTypeDropdown({
5554
}: ProjectAndTypeDropdownProps) {
5655
// This state property is derived from selectedProjectIds and selectedAnnotationType.
5756
// It is mainly used to determine the selected items in the multiselect form item.
58-
const [selectedFilters, setSelectedFilters] = useState(Array<string>);
57+
const [selectedFilters, setSelectedFilters] = useState<string[]>([]);
5958
const [filterOptions, setFilterOptions] = useState<Array<NestedSelectOptions>>([]);
6059
const activeUser = useWkSelector((state) => state.activeUser);
61-
const allProjects = useFetch(
62-
async () => {
63-
if (activeUser == null || !isUserAdminOrTeamManager(activeUser)) return [];
64-
return await getProjects();
65-
},
66-
[],
67-
[],
68-
);
60+
61+
const { data: allProjects = [] } = useQueryWithErrorHandling({
62+
queryKey: ["projects"],
63+
enabled: activeUser != null && isUserAdminOrTeamManager(activeUser),
64+
queryFn: getProjects,
65+
});
6966

7067
useEffect(() => {
7168
const selectedKeys =
@@ -84,7 +81,10 @@ function ProjectAndAnnotationTypeDropdown({
8481
value: project.id,
8582
};
8683
});
87-
let allOptions = [ANNOTATION_TYPE_FILTERS, ANNOTATION_STATE_FILTERS];
84+
const allOptions: Array<NestedSelectOptions> = [
85+
ANNOTATION_TYPE_FILTERS,
86+
ANNOTATION_STATE_FILTERS,
87+
];
8888
if (projectOptions.length > 0) {
8989
allOptions.push({ label: "Filter projects (only tasks)", options: projectOptions });
9090
}

0 commit comments

Comments
 (0)