diff --git a/src/common/api/narrativeService.ts b/src/common/api/narrativeService.ts new file mode 100644 index 00000000..f4186636 --- /dev/null +++ b/src/common/api/narrativeService.ts @@ -0,0 +1,33 @@ +/* narrativeService */ +import { baseApi } from './index'; +import { jsonRpcService } from './utils/serviceHelpers'; + +const narrativeService = jsonRpcService({ + name: 'NarrativeService', + release: 'release', +}); + +export interface NarrativeServiceParams { + getStatus: void; +} + +interface NarrativeServiceResults { + getStatus: unknown; +} + +export const narrativeServiceApi = baseApi.injectEndpoints({ + endpoints: (builder) => ({ + getStatus: builder.query< + NarrativeServiceResults['getStatus'], + NarrativeServiceParams['getStatus'] + >({ + query: () => + narrativeService({ + method: 'NarrativeService.status', + params: [], + }), + }), + }), +}); + +export const { getStatus } = narrativeServiceApi.endpoints; diff --git a/src/common/api/serviceWizardApi.ts b/src/common/api/serviceWizardApi.ts index 5110059a..54ba8fb3 100644 --- a/src/common/api/serviceWizardApi.ts +++ b/src/common/api/serviceWizardApi.ts @@ -1,34 +1,35 @@ +/* serviceWizardApi */ import { baseApi } from './index'; import { setConsumedService } from './utils/kbaseBaseQuery'; import { jsonRpcService } from './utils/serviceHelpers'; const serviceWizard = jsonRpcService({ url: 'services/service_wizard' }); -interface ServiceWizardParams { - serviceStatus: { module_name: string; version: string }; +export interface ServiceStatus { + git_commit_hash: string; + status: string; + version: string; + hash: string; + release_tags: string[]; + url: string; + module_name: string; + health: string; + up: number; +} + +export interface ServiceWizardParams { + getServiceStatus: { module_name: string; version: string }; } interface ServiceWizardResults { - serviceStatus: [ - { - git_commit_hash: string; - status: string; - version: string; - hash: string; - release_tags: string[]; - url: string; - module_name: string; - health: string; - up: number; - } - ]; + getServiceStatus: ServiceStatus[]; } export const serviceWizardApi = baseApi.injectEndpoints({ endpoints: (builder) => ({ - serviceStatus: builder.query< - ServiceWizardResults['serviceStatus'], - ServiceWizardParams['serviceStatus'] + getServiceStatus: builder.query< + ServiceWizardResults['getServiceStatus'], + ServiceWizardParams['getServiceStatus'] >({ query: ({ module_name, version }) => serviceWizard({ @@ -40,6 +41,10 @@ export const serviceWizardApi = baseApi.injectEndpoints({ }), }); -setConsumedService('serviceWizardApi', serviceWizardApi); +const setConsumed = () => + setConsumedService('serviceWizardApi', serviceWizardApi); + +setConsumed(); -export const { serviceStatus } = serviceWizardApi.endpoints; +export { setConsumed }; +export const { getServiceStatus } = serviceWizardApi.endpoints; diff --git a/src/common/api/utils/kbaseBaseQuery.ts b/src/common/api/utils/kbaseBaseQuery.ts index c1f8b30d..eecc7f9b 100644 --- a/src/common/api/utils/kbaseBaseQuery.ts +++ b/src/common/api/utils/kbaseBaseQuery.ts @@ -132,7 +132,7 @@ const getServiceUrl = async ( // get serviceWizardApi while avoiding circular imports // (as serviceWizardApi imports this file) const serviceStatusQuery = - getConsumedService('serviceWizardApi').endpoints.serviceStatus; + getConsumedService('serviceWizardApi').endpoints.getServiceStatus; const wizardQueryArgs = { module_name: name, diff --git a/src/features/navigator/Navigator.tsx b/src/features/navigator/Navigator.tsx index 6ce6a1ac..876d45e1 100644 --- a/src/features/navigator/Navigator.tsx +++ b/src/features/navigator/Navigator.tsx @@ -25,7 +25,7 @@ import { normalizeVersion, searchParams, } from './common'; -import { useNarratives } from './hooks'; +import { useNarratives, useServices } from './hooks'; import { loading, navigatorSelected, @@ -210,6 +210,7 @@ const Navigator: FC = () => { term: search, username, }); + useServices(); const items = useAppSelector(narrativeDocs); const narrativeSelected = getNarrativeSelected({ id, obj, verRaw, items }); // hooks that update state diff --git a/src/features/navigator/fixtures.ts b/src/features/navigator/fixtures.ts index 5882d31c..eac43e32 100644 --- a/src/features/navigator/fixtures.ts +++ b/src/features/navigator/fixtures.ts @@ -298,6 +298,7 @@ export const initialTestStateFactory = ({ narrativeDocsLookup: testNarrativeDocsLookup, search_time: 0, selected: null, + services: {}, users: {}, wsObjects: [], cells, diff --git a/src/features/navigator/hooks.ts b/src/features/navigator/hooks.ts index 18cae76c..271a095e 100644 --- a/src/features/navigator/hooks.ts +++ b/src/features/navigator/hooks.ts @@ -2,6 +2,15 @@ import { useEffect, useMemo } from 'react'; import { useAppDispatch, useAppSelector } from '../../common/hooks'; import { getUsers } from '../../common/api/authService'; import { getNarratives, SearchParams } from '../../common/api/searchApi'; +import { setConsumed } from '../../common/api/serviceWizardApi'; +// import { setConsumedService } from '../../common/api/utils/kbaseBaseQuery'; +/* +import { + ServiceStatus, + ServiceWizardParams, +} from '../../common/api/serviceWizardApi'; +*/ +import { getStatus } from '../../common/api/narrativeService'; import { getwsNarrative } from '../../common/api/workspaceApi'; import { Cell } from '../../common/types/NarrativeDoc'; import { authToken } from '../auth/authSlice'; @@ -12,6 +21,7 @@ import { setCells, setCellsLoaded, setNarrativeDocs, + //setServices, synchronized, updateUsers, users, @@ -140,6 +150,40 @@ export const useNarratives = (params: getNarrativesParams) => { }, [dispatch, narrativesPrevious, searchAPIQuery, searchAPIParams, syncd]); }; +export const useServices = () => { + /* + const dispatch = useAppDispatch(); + // const serviceState = useAppSelector(services); + const servicesRequired: ServiceWizardParams['getServiceStatus'][] = useMemo( + () => [ + { + module_name: 'NarrativeService', + version: 'release', + }, + ], + [] + ); + const servicesQuerys = servicesRequired.map((serviceVersion) => + getServiceStatus.useQuery(serviceVersion) + ); + const servicesAvailable: Record = {}; + servicesRequired.forEach((serviceVersion, ix) => { + const currQuery = servicesQuerys[ix]; + servicesAvailable[serviceVersion.module_name] = data; + //dispatch(setServices(servicesAvailable)); + }); + setConsumedService('serviceWizardApi', serviceWizardApi); + */ + setConsumed(); + const nsQuery = getStatus.useQuery(); + useEffect(() => { + if (nsQuery.isSuccess && nsQuery.data) { + const data = nsQuery.data; + console.log({ data }); // eslint-disable-line no-console + } + }, [nsQuery.data, nsQuery.isSuccess]); +}; + export const useUsers = (params: { users: string[] }) => { const dispatch = useAppDispatch(); const token = useAppSelector(authToken); diff --git a/src/features/navigator/navigatorSlice.ts b/src/features/navigator/navigatorSlice.ts index 15bb2bf6..02baa1f9 100644 --- a/src/features/navigator/navigatorSlice.ts +++ b/src/features/navigator/navigatorSlice.ts @@ -6,11 +6,12 @@ import { NarrativeDoc, } from '../../common/types/NarrativeDoc'; import { SearchResults } from '../../common/api/searchApi'; +import { ServiceStatus } from '../../common/api/serviceWizardApi'; import { OrgInfo } from '../../common/api/orgsApi'; import { Category, UserPermission } from './common'; // Define a type for the slice state -interface NavigatorState { +export interface NavigatorState { category: Category; cells: Cell[]; cellsLoaded: boolean; @@ -25,6 +26,7 @@ interface NavigatorState { narrativeDocsLookup: Record; search_time: number; selected: string | null; + services: Record; synchronized: boolean; synchronizedLast: number; users: Record; @@ -47,6 +49,7 @@ const initialState: NavigatorState = { narrativeDocsLookup: {}, search_time: 0, selected: null, + services: {}, synchronized: true, synchronizedLast: Date.now(), users: {}, @@ -168,6 +171,9 @@ export const navigatorSlice = createSlice({ state.synchronized = true; state.synchronizedLast = Date.now(); }, + setServices: (state, action: PayloadAction) => { + state.services = action.payload; + }, setSynchronized: ( state, action: PayloadAction @@ -222,6 +228,7 @@ export const { setLoading, setNarrativeDocs, setShares, + setServices, setSynchronized, setUserPermission, updateUsers, @@ -239,6 +246,7 @@ export const narrativeDocsCount = (state: RootState) => state.navigator.count; export const narrativeLinkedOrgs = (state: RootState) => state.navigator.controlMenu.linkedOrgs; export const navigatorSelected = (state: RootState) => state.navigator.selected; +export const services = (state: RootState) => state.navigator.services; export const shares = (state: RootState) => state.navigator.controlMenu.shares; export const sharesCount = (state: RootState) => state.navigator.controlMenu.sharesCount;