From 44c425e197d1157e17d54e437e137ed7aed87d8f Mon Sep 17 00:00:00 2001 From: Mohamed Khelif Date: Fri, 1 Dec 2023 11:55:16 -0500 Subject: [PATCH] DEVPROD-1969 Refactor BuildBaronTable and remove antd table dependency (#2163) --- src/analytics/task/useAnnotationAnalytics.ts | 20 +-- src/gql/mocks/getSpruceConfig.ts | 48 ++++++- src/pages/task/metadata/Metadata.stories.tsx | 1 - .../taskTabs/ExecutionTasksTable.stories.tsx | 1 - .../GroupedFileTable.stories.tsx | 1 - .../AnnotationNote.tsx | 6 +- .../AnnotationTicketRow.stories.tsx | 1 - .../buildBaronAndAnnotations/BBComponents.tsx | 85 +---------- .../BuildBaron.test.tsx | 133 ++++++++++++++++-- .../CreatedTicketsTable/BBCreatedTickets.tsx | 14 +- .../CreatedTicketsTable/BuildBaronTable.tsx | 30 ---- .../CustomCreatedTickets.tsx | 14 +- .../CreatedTicketsTable/index.ts | 3 +- .../Issues/AnnotationTickets.tsx | 38 +++-- .../JiraIssueTable/index.tsx | 21 ++- .../JiraTicketRow/JiraTicketRow.stories.tsx | 24 ++++ .../JiraTicketList/JiraTicketRow/index.tsx | 72 ++++++++++ .../JiraTicketList/index.tsx | 16 +++ .../TaskDurationTable.stories.tsx | 1 - src/test_utils/graphql.tsx | 14 ++ 20 files changed, 344 insertions(+), 199 deletions(-) delete mode 100644 src/pages/task/taskTabs/buildBaronAndAnnotations/CreatedTicketsTable/BuildBaronTable.tsx create mode 100644 src/pages/task/taskTabs/buildBaronAndAnnotations/JiraTicketList/JiraTicketRow/JiraTicketRow.stories.tsx create mode 100644 src/pages/task/taskTabs/buildBaronAndAnnotations/JiraTicketList/JiraTicketRow/index.tsx create mode 100644 src/pages/task/taskTabs/buildBaronAndAnnotations/JiraTicketList/index.tsx create mode 100644 src/test_utils/graphql.tsx diff --git a/src/analytics/task/useAnnotationAnalytics.ts b/src/analytics/task/useAnnotationAnalytics.ts index fce458b23c..589d4c22f4 100644 --- a/src/analytics/task/useAnnotationAnalytics.ts +++ b/src/analytics/task/useAnnotationAnalytics.ts @@ -1,6 +1,5 @@ import { useQuery } from "@apollo/client"; -import get from "lodash/get"; -import { useParams, useLocation } from "react-router-dom"; +import { useParams } from "react-router-dom"; import { useAnalyticsRoot } from "analytics/useAnalyticsRoot"; import { BuildBaronQuery, @@ -9,10 +8,9 @@ import { AnnotationEventDataQueryVariables, } from "gql/generated/types"; import { ANNOTATION_EVENT_DATA, BUILD_BARON } from "gql/queries"; +import { useQueryParam } from "hooks/useQueryParam"; import { RequiredQueryParams } from "types/task"; -import { queryString } from "utils"; -const { parseQueryString } = queryString; type Action = | { name: "Click Jira Summary Link" } | { name: "Build Baron File Ticket" } @@ -29,10 +27,8 @@ type Action = export const useAnnotationAnalytics = () => { const { id } = useParams<{ id: string }>(); + const [execution] = useQueryParam(RequiredQueryParams.Execution, 0); - const location = useLocation(); - const parsed = parseQueryString(location.search); - const execution = Number(parsed[RequiredQueryParams.Execution]); const { data: eventData } = useQuery< AnnotationEventDataQuery, AnnotationEventDataQueryVariables @@ -49,16 +45,12 @@ export const useAnnotationAnalytics = () => { } ); - const annotation = get(eventData, "task.annotation", undefined); - const bbConfigured = get( - bbData, - "buildBaron.buildBaronConfigured", - undefined - ); + const { annotation } = eventData?.task || {}; + const { buildBaronConfigured } = bbData?.buildBaron || {}; return useAnalyticsRoot("Annotations", { taskId: id, annotation, - bbConfigured, + bbConfigured: buildBaronConfigured, }); }; diff --git a/src/gql/mocks/getSpruceConfig.ts b/src/gql/mocks/getSpruceConfig.ts index 7acce0a624..a30e9e3245 100644 --- a/src/gql/mocks/getSpruceConfig.ts +++ b/src/gql/mocks/getSpruceConfig.ts @@ -1,6 +1,8 @@ import { SpruceConfigQuery, SpruceConfigQueryVariables, + UserSettingsQuery, + UserSettingsQueryVariables, } from "gql/generated/types"; import { SPRUCE_CONFIG } from "gql/queries"; import { ApolloMock } from "types/gql"; @@ -38,7 +40,11 @@ export const getSpruceConfigMock: ApolloMock< location: "/path/to/key", }, ], - jira: { host: "jira.mongodb.org", __typename: "JiraConfig" }, + jira: { + host: "jira.mongodb.org", + __typename: "JiraConfig", + email: "test@example.com", + }, providers: { aws: { maxVolumeSizePerUser: 1500, @@ -61,3 +67,43 @@ export const getSpruceConfigMock: ApolloMock< }, }, }; + +export const getUserSettingsMock: ApolloMock< + UserSettingsQuery, + UserSettingsQueryVariables +> = { + request: { + query: SPRUCE_CONFIG, + variables: null, + }, + result: { + data: { + userSettings: { + __typename: "UserSettings", + dateFormat: "MM/DD/YYYY", + githubUser: { + lastKnownAs: "user", + __typename: "GithubUser", + }, + notifications: { + __typename: "Notifications", + buildBreak: "", + patchFinish: "", + patchFirstFailure: "", + spawnHostExpiration: "", + spawnHostOutcome: "", + }, + region: "us-east-1", + slackMemberId: "1234", + slackUsername: "user", + timezone: "America/New_York", + useSpruceOptions: { + __typename: "UseSpruceOptions", + hasUsedMainlineCommitsBefore: true, + spruceV1: true, + hasUsedSpruceBefore: true, + }, + }, + }, + }, +}; diff --git a/src/pages/task/metadata/Metadata.stories.tsx b/src/pages/task/metadata/Metadata.stories.tsx index 2957ffadd3..455cd36ff1 100644 --- a/src/pages/task/metadata/Metadata.stories.tsx +++ b/src/pages/task/metadata/Metadata.stories.tsx @@ -5,7 +5,6 @@ import { CustomStoryObj, CustomMeta } from "test_utils/types"; import { Metadata } from "./index"; export default { - title: "Pages/Task/Metadata", component: Metadata, } satisfies CustomMeta; diff --git a/src/pages/task/taskTabs/ExecutionTasksTable.stories.tsx b/src/pages/task/taskTabs/ExecutionTasksTable.stories.tsx index 8af0489035..4746957948 100644 --- a/src/pages/task/taskTabs/ExecutionTasksTable.stories.tsx +++ b/src/pages/task/taskTabs/ExecutionTasksTable.stories.tsx @@ -3,7 +3,6 @@ import { CustomStoryObj, CustomMeta } from "test_utils/types"; import { ExecutionTasksTable } from "./ExecutionTasksTable"; export default { - title: "Pages/Task/Table/Execution Tasks Table", component: ExecutionTasksTable, } satisfies CustomMeta; diff --git a/src/pages/task/taskTabs/FileTable/GroupedFileTable/GroupedFileTable.stories.tsx b/src/pages/task/taskTabs/FileTable/GroupedFileTable/GroupedFileTable.stories.tsx index 2f692b8237..b8a6627cca 100644 --- a/src/pages/task/taskTabs/FileTable/GroupedFileTable/GroupedFileTable.stories.tsx +++ b/src/pages/task/taskTabs/FileTable/GroupedFileTable/GroupedFileTable.stories.tsx @@ -13,7 +13,6 @@ const files = [ ]; export default { - title: "Pages/Task/table/GroupedFileTable", component: GroupedFileTable, } satisfies CustomMeta; diff --git a/src/pages/task/taskTabs/buildBaronAndAnnotations/AnnotationNote.tsx b/src/pages/task/taskTabs/buildBaronAndAnnotations/AnnotationNote.tsx index 7fb2481394..3469be072b 100644 --- a/src/pages/task/taskTabs/buildBaronAndAnnotations/AnnotationNote.tsx +++ b/src/pages/task/taskTabs/buildBaronAndAnnotations/AnnotationNote.tsx @@ -12,7 +12,7 @@ import { } from "gql/generated/types"; import { EDIT_ANNOTATION_NOTE } from "gql/mutations"; import { useDateFormat } from "hooks"; -import { ButtonWrapper, NonTableWrapper } from "./BBComponents"; +import { ButtonWrapper } from "./BBComponents"; interface Props { note: Note; @@ -63,7 +63,7 @@ const AnnotationNote: React.FC = ({ }; return ( - + <>