From de7196ad834d68be56d6ddd79c9e9895fcb3c4e7 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Wed, 1 Nov 2023 13:16:36 -0400 Subject: [PATCH] create useSubscriptionData hook file --- .../notificationTab/UserSubscriptions.tsx | 3 +- .../{Utils.tsx => useSubscriptionData.tsx} | 40 ++----------------- .../preferencesTabs/notificationTab/utils.ts | 35 ++++++++++++++++ 3 files changed, 40 insertions(+), 38 deletions(-) rename src/pages/preferences/preferencesTabs/notificationTab/{Utils.tsx => useSubscriptionData.tsx} (81%) create mode 100644 src/pages/preferences/preferencesTabs/notificationTab/utils.ts diff --git a/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx b/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx index b90e72bb97..b6ecd051e5 100644 --- a/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx +++ b/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx @@ -37,7 +37,8 @@ import { } from "types/subscription"; import { jiraLinkify } from "utils/string/jiraLinkify"; import { ClearSubscriptions } from "./ClearSubscriptions"; -import { getResourceRoute, useSubscriptionData } from "./Utils"; +import { useSubscriptionData } from "./useSubscriptionData"; +import { getResourceRoute } from "./utils"; const { gray } = palette; diff --git a/src/pages/preferences/preferencesTabs/notificationTab/Utils.tsx b/src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx similarity index 81% rename from src/pages/preferences/preferencesTabs/notificationTab/Utils.tsx rename to src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx index 9ca32cff51..f6b81382f4 100644 --- a/src/pages/preferences/preferencesTabs/notificationTab/Utils.tsx +++ b/src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx @@ -2,22 +2,15 @@ import { useMemo } from "react"; import { useQuery } from "@apollo/client"; import styled from "@emotion/styled"; import { LeafyGreenTableRow } from "@leafygreen-ui/table/new"; -import { - getCommitsRoute, - getPatchRoute, - getTaskRoute, - getVersionRoute, -} from "constants/routes"; import { size } from "constants/tokens"; import { convertFamilyTrigger } from "constants/triggers"; import { - GeneralSubscription, - Selector, UserSubscriptionsQuery, UserSubscriptionsQueryVariables, + GeneralSubscription, + Selector, } from "gql/generated/types"; import { USER_SUBSCRIPTIONS } from "gql/queries"; -import { ResourceType } from "types/triggers"; export const useSubscriptionData = () => { const { data } = useQuery< @@ -108,34 +101,7 @@ const ExpandedBlock = styled.pre` padding: ${size.s} ${size.l}; `; -export const getResourceRoute = ( - resourceType: ResourceType, - selector: Selector -) => { - const { data: id, type } = selector; - - if (!id) { - return ""; - } - - switch (resourceType) { - case ResourceType.Build: - case ResourceType.Version: { - if (type === "project") { - return getCommitsRoute(id); - } - return getVersionRoute(id); - } - case ResourceType.Patch: - return getPatchRoute(id, { configure: false }); - case ResourceType.Task: - return getTaskRoute(id); - default: - return ""; - } -}; - -export const formatRegexSelectors = (regexSelectors: Selector[]) => ({ +const formatRegexSelectors = (regexSelectors: Selector[]) => ({ "regex-selectors": regexSelectors.reduce>( (obj, { data, type }) => ({ ...obj, diff --git a/src/pages/preferences/preferencesTabs/notificationTab/utils.ts b/src/pages/preferences/preferencesTabs/notificationTab/utils.ts new file mode 100644 index 0000000000..818e423601 --- /dev/null +++ b/src/pages/preferences/preferencesTabs/notificationTab/utils.ts @@ -0,0 +1,35 @@ +import { + getCommitsRoute, + getPatchRoute, + getTaskRoute, + getVersionRoute, +} from "constants/routes"; +import { Selector } from "gql/generated/types"; +import { ResourceType } from "types/triggers"; + +export const getResourceRoute = ( + resourceType: ResourceType, + selector: Selector +) => { + const { data: id, type } = selector; + + if (!id) { + return ""; + } + + switch (resourceType) { + case ResourceType.Build: + case ResourceType.Version: { + if (type === "project") { + return getCommitsRoute(id); + } + return getVersionRoute(id); + } + case ResourceType.Patch: + return getPatchRoute(id, { configure: false }); + case ResourceType.Task: + return getTaskRoute(id); + default: + return ""; + } +};