From ceaf64323958e2e32f4805940b9cd025da955e7d Mon Sep 17 00:00:00 2001 From: Christopher Berge Hove Date: Thu, 17 Oct 2024 08:53:38 +0200 Subject: [PATCH] chore: refactor selector --- .../components/src/components/task/hooks/use-assignment.ts | 3 ++- .../src/components/task/queries/fusion-meetings-queries.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/packages/components/src/components/task/hooks/use-assignment.ts b/client/packages/components/src/components/task/hooks/use-assignment.ts index 8f698bfe2..306218790 100644 --- a/client/packages/components/src/components/task/hooks/use-assignment.ts +++ b/client/packages/components/src/components/task/hooks/use-assignment.ts @@ -1,7 +1,7 @@ import { useFramework } from '@equinor/fusion-framework-react'; import { useQuery } from 'react-query'; import { getPimsTasks } from '../work-assigned/assignment-queries'; -import { getMyMeetingsActions, getMyReviewActions } from '../queries/fusion-meetings-queries'; +import { getMyMeetingsActions, getMyReviewActions, myMeetingsActionSelector } from '../queries/fusion-meetings-queries'; import { getQueryAndNCRequest } from '../queries/query-ncr-request-queries'; import { Task } from '../types/task'; import { getFusionTasks, getProCoSysAssignments } from '../queries/fusion-task-queries'; @@ -95,6 +95,7 @@ export function useMeetingsActionsQuery() { return useQuery({ queryKey: ['Assignment', 'Meetings', 'Meetings-Actions'], queryFn: async ({ signal }) => getMyMeetingsActions(await client, signal), + select: myMeetingsActionSelector, cacheTime: 5000 * 60, refetchInterval: 5000 * 60, staleTime: 2000 * 60, diff --git a/client/packages/components/src/components/task/queries/fusion-meetings-queries.ts b/client/packages/components/src/components/task/queries/fusion-meetings-queries.ts index 8357063a7..071aaf026 100644 --- a/client/packages/components/src/components/task/queries/fusion-meetings-queries.ts +++ b/client/packages/components/src/components/task/queries/fusion-meetings-queries.ts @@ -2,7 +2,7 @@ import { IHttpClient } from '@equinor/fusion-framework-module-http'; import { Task } from '../types/task'; import { verifyDate } from '../utils/time'; -import { ActionState, MeetingAction } from '../types/meetings-task'; +import { ActionState, MeetingAction, MeetingType } from '../types/meetings-task'; import { isTaskOverdue } from './query-ncr-request-queries'; function stripHtml(html?: string) { @@ -11,11 +11,14 @@ function stripHtml(html?: string) { return tmp.textContent || tmp.innerText || ''; } -export async function getMyMeetingsActions(client: IHttpClient, signal?: AbortSignal): Promise { +export async function getMyMeetingsActions(client: IHttpClient, signal?: AbortSignal): Promise { const response = await client.fetch('/persons/me/actions?api-version=4.0', { signal }); const tasks: MeetingAction[] = await response.json(); + return tasks; +} +export function myMeetingsActionSelector(tasks: MeetingAction[]): Task[] { return tasks .filter((a) => a.state !== ActionState.Completed && a.state !== ActionState.NotCompleted) .map((task) => ({