Skip to content

Commit

Permalink
Revert reuse as it requires adding dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Nov 28, 2023
1 parent dfaf4e1 commit c05f02e
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions packages/dashboard/src/components/tasks/tasks-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,6 @@ export const TasksApp = React.memo(
};
}, [autoRefresh]);

const getAllTaskRequests = async (tasks: TaskState[]) => {
if (!rmf) {
return {};
}

const taskIds: string[] = tasks.map((task) => task.booking.id);
const taskIdsQuery = taskIds.join(',');
const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery))
.data;

const taskRequestMap: Record<string, TaskRequest> = {};
let requestIndex = 0;
for (const id of taskIds) {
if (requestIndex < taskRequests.length && taskRequests[requestIndex]) {
taskRequestMap[id] = taskRequests[requestIndex];
}
++requestIndex;
}
return taskRequestMap;
};

// TODO: parameterize this variable
const GET_LIMIT = 10;
React.useEffect(() => {
Expand Down Expand Up @@ -203,7 +182,20 @@ export const TasksApp = React.memo(
);
const results = resp.data as TaskState[];
const newTasks = results.slice(0, GET_LIMIT);
const taskRequestMap = await getAllTaskRequests(newTasks);

const taskIds: string[] = newTasks.map((task) => task.booking.id);
const taskIdsQuery = taskIds.join(',');
const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery))
.data;

const taskRequestMap: Record<string, TaskRequest> = {};
let requestIndex = 0;
for (const id of taskIds) {
if (requestIndex < taskRequests.length && taskRequests[requestIndex]) {
taskRequestMap[id] = taskRequests[requestIndex];
}
++requestIndex;
}

setTasksState((old) => ({
...old,
Expand Down Expand Up @@ -250,6 +242,27 @@ export const TasksApp = React.memo(
return allTasks;
};

const getAllTaskRequests = async (tasks: TaskState[]) => {
if (!rmf) {
return {};
}

const taskIds: string[] = tasks.map((task) => task.booking.id);
const taskIdsQuery = taskIds.join(',');
const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery))
.data;

const taskRequestMap: Record<string, TaskRequest> = {};
let requestIndex = 0;
for (const id of taskIds) {
if (requestIndex < taskRequests.length && taskRequests[requestIndex]) {
taskRequestMap[id] = taskRequests[requestIndex];
}
++requestIndex;
}
return taskRequestMap;
};

const exportTasksToCsv = async (minimal: boolean) => {
const now = new Date();
const allTasks = await getAllTasks(now);
Expand Down

0 comments on commit c05f02e

Please sign in to comment.