From 80a7347e0c75bbd33a3083f56814cab9af7041bc Mon Sep 17 00:00:00 2001 From: Jeremy Myers Date: Fri, 6 Oct 2023 10:38:36 -0500 Subject: [PATCH] Talk to vdi service in client --- .../Controllers/UserDatasetListController.tsx | 18 ++++++++++++++++++ .../src/lib/Hooks/user-datasets.ts | 17 +++++++++++++++++ .../libs/user-datasets/src/lib/Service/api.ts | 10 +++++----- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 packages/libs/user-datasets/src/lib/Hooks/user-datasets.ts diff --git a/packages/libs/user-datasets/src/lib/Controllers/UserDatasetListController.tsx b/packages/libs/user-datasets/src/lib/Controllers/UserDatasetListController.tsx index 0183625d99..76c8623249 100644 --- a/packages/libs/user-datasets/src/lib/Controllers/UserDatasetListController.tsx +++ b/packages/libs/user-datasets/src/lib/Controllers/UserDatasetListController.tsx @@ -24,6 +24,10 @@ import { DataNoun, UserDataset } from '../Utils/types'; import '../Components/UserDatasets.scss'; +import { useConfiguredVdiClient } from '../Hooks/user-datasets'; +// const VDI_SERVICE_BASE_URL = 'https://vdi-dev.local.apidb.org:8443' +const VDI_SERVICE_BASE_URL = 'http://localhost:8080'; + const ActionCreators = { showLoginForm, loadUserDatasetList, @@ -175,6 +179,7 @@ class UserDatasetListController extends PageController { ) : ( )} + ); @@ -195,4 +200,17 @@ const enhance = connect( }) ); +type VDIProps = { + baseUrl: string; +}; + +function VDI({ baseUrl }: VDIProps) { + const vdi = useConfiguredVdiClient(baseUrl); + // console.log(vdi); + const uds = vdi.getCurrentUserDatasets(); + // const uds = vdi.getCommunityDatasets(); + console.log(uds); + return <>Working?; +} + export default withRouter(enhance(UserDatasetListController)); diff --git a/packages/libs/user-datasets/src/lib/Hooks/user-datasets.ts b/packages/libs/user-datasets/src/lib/Hooks/user-datasets.ts new file mode 100644 index 0000000000..8f5da93b43 --- /dev/null +++ b/packages/libs/user-datasets/src/lib/Hooks/user-datasets.ts @@ -0,0 +1,17 @@ +import { useNonNullableContext } from '@veupathdb/wdk-client/lib/Hooks/NonNullableContext'; +import { WdkDependenciesContext } from '@veupathdb/wdk-client/lib/Hooks/WdkDependenciesEffect'; +import { useMemo } from 'react'; +import { UserDatasetApi } from '../Service/api'; + +function useWdkServiceContext() { + const { wdkService } = useNonNullableContext(WdkDependenciesContext); + return wdkService; +} + +export function useConfiguredVdiClient(baseUrl: string) { + const wdkService = useWdkServiceContext(); + return useMemo( + () => new UserDatasetApi({ baseUrl }, wdkService), + [baseUrl, wdkService] + ); +} diff --git a/packages/libs/user-datasets/src/lib/Service/api.ts b/packages/libs/user-datasets/src/lib/Service/api.ts index 16d4cf9793..4f7b01e1fd 100644 --- a/packages/libs/user-datasets/src/lib/Service/api.ts +++ b/packages/libs/user-datasets/src/lib/Service/api.ts @@ -2,6 +2,7 @@ import { zipWith } from 'lodash'; import { createJsonRequest, + createPlainTextRequest, FetchClientWithCredentials, ioTransformer, } from '@veupathdb/http-utils'; @@ -17,7 +18,6 @@ import { import { array, type, TypeOf, string } from 'io-ts'; const VDI_SERVICE = '/vdi-datasets'; -const CURRENT_USER_DATASET_PATH = `/users/current/${VDI_SERVICE}`; export class UserDatasetApi extends FetchClientWithCredentials { getCurrentUserDatasets = ( @@ -41,7 +41,7 @@ export class UserDatasetApi extends FetchClientWithCredentials { ); return this.fetch( createJsonRequest({ - path: `${CURRENT_USER_DATASET_PATH}${queryString}`, + path: `${VDI_SERVICE}${queryString}`, method: 'GET', transformResponse: ioTransformer(array(userDataset)), }) @@ -93,7 +93,7 @@ export class UserDatasetApi extends FetchClientWithCredentials { getUserDataset = (id: string) => { return this.fetch( createJsonRequest({ - path: `${CURRENT_USER_DATASET_PATH}/${id}`, + path: `${VDI_SERVICE}/${id}`, method: 'GET', transformResponse: ioTransformer(userDataset), }) @@ -104,7 +104,7 @@ export class UserDatasetApi extends FetchClientWithCredentials { updateUserDataset = (id: string, requestBody: UserDatasetMeta) => { return this.fetch( createJsonRequest({ - path: `${CURRENT_USER_DATASET_PATH}/${id}`, + path: `${VDI_SERVICE}/${id}`, method: 'PATCH', body: requestBody, transformResponse: noContent, @@ -115,7 +115,7 @@ export class UserDatasetApi extends FetchClientWithCredentials { removeUserDataset = (id: string) => { return this.fetch( createJsonRequest({ - path: `${CURRENT_USER_DATASET_PATH}/${id}`, + path: `${VDI_SERVICE}/${id}`, method: 'DELETE', transformResponse: noContent, })