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

✨ Implement the Task Manager drawer #1955

Merged
merged 10 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions client/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { BrowserRouter } from "react-router-dom";
import { AppRoutes } from "./Routes";
import { DefaultLayout } from "./layout";
import { NotificationsProvider } from "./components/NotificationsContext";
import { TaskManagerProvider } from "./components/task-manager/TaskManagerContext";

import "./app.css";

const App: React.FC = () => {
return (
<BrowserRouter>
<NotificationsProvider>
<DefaultLayout>
<AppRoutes />
</DefaultLayout>
<TaskManagerProvider>
<DefaultLayout>
<AppRoutes />
</DefaultLayout>
</TaskManagerProvider>
</NotificationsProvider>
</BrowserRouter>
);
Expand Down
13 changes: 13 additions & 0 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ export interface Taskgroup {
tasks: TaskgroupTask[];
}

export interface TaskQueue {
/** Total number of tasks scheduled */
total: number;
/** number of tasks ready to run */
ready: number;
/** number of postponed tasks */
postponed: number;
/** number of tasks with pods created awaiting node scheduler */
pending: number;
/** number of tasks with running pods */
running: number;
}

export interface Cache {
path: string;
capacity: string;
Expand Down
44 changes: 25 additions & 19 deletions client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
import axios, { AxiosPromise, RawAxiosRequestHeaders } from "axios";

import {
AnalysisAppDependency,
AnalysisAppReport,
AnalysisDependency,
BaseAnalysisRuleReport,
BaseAnalysisIssueReport,
AnalysisIssue,
AnalysisFileReport,
AnalysisIncident,
AnalysisIssue,
Application,
ApplicationAdoptionPlan,
ApplicationDependency,
ApplicationImport,
ApplicationImportSummary,
Archetype,
Assessment,
BaseAnalysisIssueReport,
BaseAnalysisRuleReport,
BusinessService,
Cache,
HubFile,
HubPaginatedResult,
HubRequestParams,
Identity,
InitialAssessment,
IReadFile,
Tracker,
JobFunction,
MigrationWave,
MimeType,
New,
Proxy,
Questionnaire,
Ref,
Review,
Setting,
SettingTypes,
Stakeholder,
StakeholderGroup,
Tag,
TagCategory,
Target,
Task,
Taskgroup,
MigrationWave,
TaskQueue,
Ticket,
New,
Ref,
Tracker,
TrackerProject,
TrackerProjectIssuetype,
UnstructuredFact,
AnalysisAppDependency,
AnalysisAppReport,
Target,
HubFile,
Questionnaire,
Archetype,
InitialAssessment,
MimeType,
} from "./models";
import { serializeRequestParamsForHub } from "@app/hooks/table-controls";

Expand Down Expand Up @@ -332,7 +333,7 @@ export function getTaskById(id: number): Promise<Task> {

export function getTaskByIdAndFormat(
id: number,
format: string,
format: "json" | "yaml",
merged: boolean = false
): Promise<string> {
const isYaml = format === "yaml";
Expand All @@ -345,7 +346,7 @@ export function getTaskByIdAndFormat(
}

return axios
.get(url, {
.get<Task | string>(url, {
headers: headers,
responseType: responseType,
})
Expand All @@ -362,10 +363,15 @@ export const getTasks = () =>
export const getServerTasks = (params: HubRequestParams = {}) =>
getHubPaginatedResult<Task>(TASKS, params);

export const deleteTask = (id: number) => axios.delete<Task>(`${TASKS}/${id}`);
export const deleteTask = (id: number) => axios.delete<void>(`${TASKS}/${id}`);

export const cancelTask = (id: number) =>
axios.put<Task>(`${TASKS}/${id}/cancel`);
axios.put<void>(`${TASKS}/${id}/cancel`);

export const getTaskQueue = (addon?: string): Promise<TaskQueue> =>
axios
.get<TaskQueue>(`${TASKS}/report/queue`, { params: { addon } })
.then(({ data }) => data);

export const createTaskgroup = (obj: Taskgroup) =>
axios.post<Taskgroup>(TASKGROUPS, obj).then((response) => response.data);
Expand Down
48 changes: 48 additions & 0 deletions client/src/app/components/task-manager/TaskManagerContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useFetchTaskQueue } from "@app/queries/tasks";
import React, { useContext, useMemo, useState } from "react";

interface TaskManagerContextProps {
/** Count of the currently "queued" Tasks */
queuedCount: number;

/** Is the task manager drawer currently visible? */
isExpanded: boolean;

/** Control if the task manager drawer is visible */
setIsExpanded: (value: boolean) => void;
}

const TaskManagerContext = React.createContext<TaskManagerContextProps>({
queuedCount: 0,

isExpanded: false,
setIsExpanded: () => undefined,
});

export const useTaskManagerContext = () => {
const values = useContext(TaskManagerContext);

return values;
};

export const TaskManagerProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const { taskQueue } = useFetchTaskQueue();
const [isExpanded, setIsExpanded] = useState(false);

const contextValue = useMemo(
() => ({
queuedCount: taskQueue.total,
isExpanded,
setIsExpanded,
}),
[taskQueue.total, isExpanded, setIsExpanded]
);

return (
<TaskManagerContext.Provider value={contextValue}>
{children}
</TaskManagerContext.Provider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.task-manager-item-collapsed .pf-v5-c-notification-drawer__list-item-header {
margin-bottom: 0;
}
Loading
Loading