Skip to content

Commit

Permalink
Talk to vdi service in client
Browse files Browse the repository at this point in the history
  • Loading branch information
jernestmyers committed Oct 6, 2023
1 parent 9af6ee7 commit 80a7347
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -175,6 +179,7 @@ class UserDatasetListController extends PageController<Props> {
) : (
<UserDatasetList {...listProps} />
)}
<VDI baseUrl={VDI_SERVICE_BASE_URL} />
</div>
</div>
);
Expand All @@ -195,4 +200,17 @@ const enhance = connect<StateProps, DispatchProps, OwnProps, Props, StateSlice>(
})
);

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));
17 changes: 17 additions & 0 deletions packages/libs/user-datasets/src/lib/Hooks/user-datasets.ts
Original file line number Diff line number Diff line change
@@ -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]
);
}
10 changes: 5 additions & 5 deletions packages/libs/user-datasets/src/lib/Service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { zipWith } from 'lodash';

import {
createJsonRequest,
createPlainTextRequest,
FetchClientWithCredentials,
ioTransformer,
} from '@veupathdb/http-utils';
Expand All @@ -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 = (
Expand All @@ -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)),
})
Expand Down Expand Up @@ -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),
})
Expand All @@ -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,
Expand All @@ -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,
})
Expand Down

0 comments on commit 80a7347

Please sign in to comment.