Skip to content

Commit

Permalink
🐛 Prefer Task field kind over addon (konveyor#1971)
Browse files Browse the repository at this point in the history
Resolves: konveyor#1970

  - When creating a new `Taskgroup`, specify `kind` instead of `addon`

  - Process Tasks where `kind` may be missing and `addon` is given instead
    (i.e. tasks created before this change)

  - Make `Task.id` and `Taskgroup.id` required, `New<>` as needed

---------

Signed-off-by: Ian Bolton <[email protected]>
Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 authored Jun 20, 2024
1 parent cf87201 commit 2bd0d6f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
19 changes: 10 additions & 9 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,16 @@ export interface Task {
updateUser?: string;
createTime?: string;

name: string;
kind: string;
addon: string;
extensions: string[];
name?: string;
kind?: string;
addon?: string;
extensions?: string[];
state?: TaskState;
locator?: string;
priority?: number;
policy: TaskPolicy;
ttl: TTL;
data: TaskData;
policy?: TaskPolicy;
ttl?: TTL;
data?: TaskData;
application: Ref;
bucket?: Ref;
pod?: string;
Expand Down Expand Up @@ -407,9 +407,10 @@ export interface TaskgroupTask {
}

export interface Taskgroup {
id?: number;
id: number;
name: string;
addon: string;
kind?: string;
addon?: string;
data: TaskData;
tasks: TaskgroupTask[];
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export const getTaskQueue = (addon?: string): Promise<TaskQueue> =>
export const updateTask = (task: Partial<Task> & { id: number }) =>
axios.patch<Task>(`${TASKS}/${task.id}`, task);

export const createTaskgroup = (obj: Taskgroup) =>
export const createTaskgroup = (obj: New<Taskgroup>) =>
axios.post<Taskgroup>(TASKGROUPS, obj).then((response) => response.data);

export const submitTaskgroup = (obj: Taskgroup) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useTranslation } from "react-i18next";

import {
Application,
New,
TaskData,
Taskgroup,
TaskgroupTask,
Expand Down Expand Up @@ -70,9 +71,9 @@ const defaultTaskData: TaskData = {
},
};

export const defaultTaskgroup: Taskgroup = {
export const defaultTaskgroup: New<Taskgroup> = {
name: `taskgroup.analyzer`,
addon: "analyzer",
kind: "analyzer",
data: {
...defaultTaskData,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const ApplicationsTable: React.FC = () => {
tasks.find((task: Task) => task.application?.id === application.id);

const { tasks, hasActiveTasks } = useFetchTasks(
{ addon: "analyzer" },
{ kind: "analyzer", addon: "analyzer" },
isAnalyzeModalOpen
);

Expand Down
3 changes: 1 addition & 2 deletions client/src/app/pages/tasks/tasks-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ export const TasksPage: React.FC = () => {

const tableControls = useTableControlProps({
...tableControlState,
// task.id is defined as optional
idProperty: "name",
idProperty: "id",
currentPageItems,
totalItemCount,
isLoading: isFetching,
Expand Down
12 changes: 11 additions & 1 deletion client/src/app/queries/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

interface FetchTasksFilters {
addon?: string;
kind?: string;
}

export const TasksQueryKey = "tasks";
Expand All @@ -39,7 +40,16 @@ export const useFetchTasks = (
select: (allTasks) => {
const uniqSorted = allTasks
.filter((task) =>
filters?.addon ? filters.addon === task.addon : true
// If there are any tasks with the addon field, we will still need to consider those older
// tasks that do not have the kind field. This is because the kind field was added later and is
// preferred over the addon field.

// The task manager will determine and assign the addon field when the addon is specified and addon isnt
// which will result in both being set.

filters?.kind || filters?.addon
? filters.kind === task.kind || filters.addon === task.addon
: true
)
// sort by application.id (ascending) then createTime (newest to oldest)
.sort((a, b) =>
Expand Down

0 comments on commit 2bd0d6f

Please sign in to comment.