From 5ead5167b6cb6ce99a2de879d97aea1b27fbea7a Mon Sep 17 00:00:00 2001 From: Marius Tobiassen Bungum Date: Tue, 20 Aug 2024 08:18:42 +0200 Subject: [PATCH] :sparkles: Expose query keys --- package.json | 2 +- src/constants/index.ts | 1 + src/constants/queryKeys.ts | 9 +++++++++ src/index.ts | 2 ++ src/providers/FeatureToggleProvider.tsx | 3 ++- src/providers/TutorialProvider/TutorialProvider.const.ts | 3 --- src/providers/TutorialProvider/TutorialProvider.hooks.ts | 4 ++-- .../TutorialProvider/TutorialProvider.stories.tsx | 4 ++-- src/providers/TutorialProvider/TutorialProvider.test.tsx | 6 ++++-- 9 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 src/constants/index.ts create mode 100644 src/constants/queryKeys.ts diff --git a/package.json b/package.json index 156733a..b52e896 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@equinor/subsurface-app-management", - "version": "1.1.7", + "version": "1.1.8", "description": "React Typescript components/hooks to communicate with equinor/sam", "types": "dist/index.d.ts", "type": "module", diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..e08035c --- /dev/null +++ b/src/constants/index.ts @@ -0,0 +1 @@ +export * from './queryKeys'; diff --git a/src/constants/queryKeys.ts b/src/constants/queryKeys.ts new file mode 100644 index 0000000..f5ca6e0 --- /dev/null +++ b/src/constants/queryKeys.ts @@ -0,0 +1,9 @@ +export const GET_FEATURE_TOGGLES_FOR_APP = 'getFeatureToggleFromAppName'; +export const GET_TUTORIALS_FOR_APP = 'getTutorialsForApp'; +export const GET_TUTORIALS_SAS_TOKEN = 'getTutorialsSasToken'; + +export const SAM_QUERIES = [ + GET_FEATURE_TOGGLES_FOR_APP, + GET_TUTORIALS_FOR_APP, + GET_TUTORIALS_SAS_TOKEN, +]; diff --git a/src/index.ts b/src/index.ts index 293dba9..56d7367 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,3 +9,5 @@ export * from './types'; export * from './utils'; export * from './api'; + +export * from './constants'; diff --git a/src/providers/FeatureToggleProvider.tsx b/src/providers/FeatureToggleProvider.tsx index 91e3d17..7fe260c 100644 --- a/src/providers/FeatureToggleProvider.tsx +++ b/src/providers/FeatureToggleProvider.tsx @@ -5,6 +5,7 @@ import { useQuery } from '@tanstack/react-query'; // These 2 api imports need to be separated to be able to use vi.mock in tests import { FeatureAPIType, GraphUser } from 'src/api'; import { FeatureToggleService } from 'src/api/services/FeatureToggleService'; +import { GET_FEATURE_TOGGLES_FOR_APP } from 'src/constants/queryKeys'; import { EnvironmentType } from 'src/types'; import { environment } from 'src/utils'; import { getEnvironmentName } from 'src/utils/environment'; @@ -66,7 +67,7 @@ export const FeatureToggleProvider: FC = ({ isLoading, isError, } = useQuery({ - queryKey: ['getFeatureToggleFromAppName'], + queryKey: [GET_FEATURE_TOGGLES_FOR_APP], queryFn: async () => FeatureToggleService.getFeatureToggleFromApplicationName(applicationName), }); diff --git a/src/providers/TutorialProvider/TutorialProvider.const.ts b/src/providers/TutorialProvider/TutorialProvider.const.ts index 1bc485b..29a57e5 100644 --- a/src/providers/TutorialProvider/TutorialProvider.const.ts +++ b/src/providers/TutorialProvider/TutorialProvider.const.ts @@ -3,6 +3,3 @@ export const DIALOG_EDGE_MARGIN = 24; export const TUTORIAL_SEARCH_PARAM_KEY = 'tutorial'; export const TUTORIAL_LOCALSTORAGE_VALUE_STRING = 'hasCompletedTutorial'; export const TUTORIAL_HIGHLIGHTER_DATATEST_ID = 'tutorial-highlighter'; - -export const GET_TUTORIALS_FOR_APP = 'getTutorialsForApp'; -export const GET_TUTORIALS_SAS_TOKEN = 'getTutorialsSasToken'; diff --git a/src/providers/TutorialProvider/TutorialProvider.hooks.ts b/src/providers/TutorialProvider/TutorialProvider.hooks.ts index 501b92a..a179e20 100644 --- a/src/providers/TutorialProvider/TutorialProvider.hooks.ts +++ b/src/providers/TutorialProvider/TutorialProvider.hooks.ts @@ -2,11 +2,11 @@ import { useContext } from 'react'; import { useQuery } from '@tanstack/react-query'; +import { TutorialService } from 'src/api/services/TutorialService'; import { GET_TUTORIALS_FOR_APP, GET_TUTORIALS_SAS_TOKEN, -} from './TutorialProvider.const'; -import { TutorialService } from 'src/api/services/TutorialService'; +} from 'src/constants/queryKeys'; import { TutorialContext } from 'src/providers/TutorialProvider/TutorialProvider'; export const useGetTutorialsForApp = (appName: string) => { diff --git a/src/providers/TutorialProvider/TutorialProvider.stories.tsx b/src/providers/TutorialProvider/TutorialProvider.stories.tsx index 53befcd..51e95ca 100644 --- a/src/providers/TutorialProvider/TutorialProvider.stories.tsx +++ b/src/providers/TutorialProvider/TutorialProvider.stories.tsx @@ -7,11 +7,11 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { CustomTutorialComponent } from './TutorialProvider.types'; import { Tutorial } from 'src/api'; -import { TutorialProvider } from 'src/providers'; import { GET_TUTORIALS_FOR_APP, GET_TUTORIALS_SAS_TOKEN, -} from 'src/providers/TutorialProvider/TutorialProvider.const'; +} from 'src/constants/queryKeys'; +import { TutorialProvider } from 'src/providers'; import styled, { keyframes } from 'styled-components'; diff --git a/src/providers/TutorialProvider/TutorialProvider.test.tsx b/src/providers/TutorialProvider/TutorialProvider.test.tsx index 04b66a5..dc310b7 100644 --- a/src/providers/TutorialProvider/TutorialProvider.test.tsx +++ b/src/providers/TutorialProvider/TutorialProvider.test.tsx @@ -7,12 +7,14 @@ import { waitFor } from '@testing-library/react'; import { render, renderHook, screen, userEvent } from '../../tests/test-utils'; import { DIALOG_EDGE_MARGIN, - GET_TUTORIALS_FOR_APP, - GET_TUTORIALS_SAS_TOKEN, TUTORIAL_HIGHLIGHTER_DATATEST_ID, TUTORIAL_LOCALSTORAGE_VALUE_STRING, } from './TutorialProvider.const'; import { CancelablePromise, Step, Tutorial, TutorialPosition } from 'src/api'; +import { + GET_TUTORIALS_FOR_APP, + GET_TUTORIALS_SAS_TOKEN, +} from 'src/constants/queryKeys'; import { TutorialProvider } from 'src/providers'; import { useTutorial } from 'src/providers/TutorialProvider/TutorialProvider.hooks'; import { EnvironmentType } from 'src/types';