Skip to content

Commit

Permalink
👻 Add kind support for task api objects
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Jun 20, 2024
1 parent 5b2352d commit 94cc4d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
9 changes: 5 additions & 4 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ export interface Task {
createTime?: string;

name: string;
kind: string;
addon: string;
kind?: string;
addon?: string;
extensions: string[];
state?: TaskState;
locator?: string;
Expand Down Expand Up @@ -408,7 +408,8 @@ export interface TaskgroupTask {
export interface Taskgroup {
id?: number;
name: string;
addon: string;
kind?: string;
addon?: string;
data: TaskData;
tasks: TaskgroupTask[];
}
Expand Down Expand Up @@ -469,7 +470,7 @@ export interface Target {
labels?: TargetLabel[];
image?: RulesetImage;
ruleset: Ruleset;
provider?: string;
provider?: string[];
}

export interface Metadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const defaultTaskData: TaskData = {

export const defaultTaskgroup: 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
12 changes: 11 additions & 1 deletion client/src/app/queries/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

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

export const TasksQueryKey = "tasks";
Expand All @@ -38,7 +39,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 94cc4d7

Please sign in to comment.