Skip to content

Commit

Permalink
WIP001
Browse files Browse the repository at this point in the history
  • Loading branch information
dakotablair committed Sep 11, 2023
1 parent 5f69af7 commit e94ed78
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 23 deletions.
33 changes: 33 additions & 0 deletions src/common/api/narrativeService.ts
Original file line number Diff line number Diff line change
@@ -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;
45 changes: 25 additions & 20 deletions src/common/api/serviceWizardApi.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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;
2 changes: 1 addition & 1 deletion src/common/api/utils/kbaseBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/features/navigator/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
normalizeVersion,
searchParams,
} from './common';
import { useNarratives } from './hooks';
import { useNarratives, useServices } from './hooks';
import {
loading,
navigatorSelected,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/features/navigator/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const initialTestStateFactory = ({
narrativeDocsLookup: testNarrativeDocsLookup,
search_time: 0,
selected: null,
services: {},
users: {},
wsObjects: [],
cells,
Expand Down
44 changes: 44 additions & 0 deletions src/features/navigator/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -12,6 +21,7 @@ import {
setCells,
setCellsLoaded,
setNarrativeDocs,
//setServices,
synchronized,
updateUsers,
users,
Expand Down Expand Up @@ -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<string, ServiceStatus> = {};
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);
Expand Down
10 changes: 9 additions & 1 deletion src/features/navigator/navigatorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ interface NavigatorState {
narrativeDocsLookup: Record<number, NarrativeDoc>;
search_time: number;
selected: string | null;
services: Record<string, ServiceStatus>;
synchronized: boolean;
synchronizedLast: number;
users: Record<string, string>;
Expand All @@ -47,6 +49,7 @@ const initialState: NavigatorState = {
narrativeDocsLookup: {},
search_time: 0,
selected: null,
services: {},
synchronized: true,
synchronizedLast: Date.now(),
users: {},
Expand Down Expand Up @@ -168,6 +171,9 @@ export const navigatorSlice = createSlice({
state.synchronized = true;
state.synchronizedLast = Date.now();
},
setServices: (state, action: PayloadAction<NavigatorState['services']>) => {
state.services = action.payload;
},
setSynchronized: (
state,
action: PayloadAction<NavigatorState['synchronized']>
Expand Down Expand Up @@ -222,6 +228,7 @@ export const {
setLoading,
setNarrativeDocs,
setShares,
setServices,
setSynchronized,
setUserPermission,
updateUsers,
Expand All @@ -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;
Expand Down

0 comments on commit e94ed78

Please sign in to comment.