-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: manage source datasets ui (#277) * refactor: use generic usefetchdata hook (#294) * fix: remove unused source datasets tab (#294) --------- Co-authored-by: Fran McDade <[email protected]>
- Loading branch information
Showing
11 changed files
with
71 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,17 @@ | ||
import { useAsync } from "@databiosphere/findable-ui/lib/hooks/useAsync"; | ||
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication"; | ||
import { useCallback, useEffect } from "react"; | ||
import { API } from "../apis/catalog/hca-atlas-tracker/common/api"; | ||
import { HCAAtlasTrackerAtlas } from "../apis/catalog/hca-atlas-tracker/common/entities"; | ||
import { METHOD, PathParameter } from "../common/entities"; | ||
import { | ||
getFetchOptions, | ||
getRequestURL, | ||
isFetchStatusOk, | ||
} from "../common/utils"; | ||
import { getRequestURL } from "../common/utils"; | ||
import { useFetchData } from "./useFetchData"; | ||
|
||
interface UseFetchAtlas { | ||
atlas?: HCAAtlasTrackerAtlas; | ||
} | ||
|
||
export const useFetchAtlas = (pathParameter: PathParameter): UseFetchAtlas => { | ||
const { token } = useAuthentication(); | ||
const { data: atlas, run } = useAsync<HCAAtlasTrackerAtlas | undefined>(); | ||
|
||
const fetchAtlas = useCallback( | ||
async (accessToken: string): Promise<HCAAtlasTrackerAtlas | undefined> => { | ||
const res = await fetch( | ||
getRequestURL(API.ATLAS, pathParameter), | ||
getFetchOptions(METHOD.GET, accessToken) | ||
); | ||
if (isFetchStatusOk(res.status)) { | ||
return await res.json(); | ||
} | ||
throw new Error( | ||
await res | ||
.json() | ||
.then(({ message }) => message) | ||
.catch(() => `Received ${res.status} response`) | ||
); | ||
}, | ||
[pathParameter] | ||
const { data: atlas } = useFetchData<HCAAtlasTrackerAtlas | undefined>( | ||
getRequestURL(API.ATLAS, pathParameter), | ||
METHOD.GET | ||
); | ||
|
||
useEffect(() => { | ||
if (!token) return; | ||
run(fetchAtlas(token)); | ||
}, [fetchAtlas, run, token]); | ||
|
||
return { atlas }; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,13 @@ | ||
import { useAsync } from "@databiosphere/findable-ui/lib/hooks/useAsync"; | ||
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication"; | ||
import { useCallback, useEffect } from "react"; | ||
import { API } from "../apis/catalog/hca-atlas-tracker/common/api"; | ||
import { HCAAtlasTrackerActiveUser } from "../apis/catalog/hca-atlas-tracker/common/entities"; | ||
import { METHOD } from "../common/entities"; | ||
import { getFetchOptions, isFetchStatusOk } from "../common/utils"; | ||
import { useFetchData } from "./useFetchData"; | ||
|
||
export const useFetchUser = (): HCAAtlasTrackerActiveUser | undefined => { | ||
const { token } = useAuthentication(); | ||
const { data: user, run } = useAsync<HCAAtlasTrackerActiveUser | undefined>(); | ||
|
||
const fetchUser = useCallback( | ||
async ( | ||
accessToken: string | ||
): Promise<HCAAtlasTrackerActiveUser | undefined> => { | ||
const res = await fetch( | ||
API.USER, | ||
getFetchOptions(METHOD.GET, accessToken) | ||
); | ||
if (isFetchStatusOk(res.status)) { | ||
return await res.json(); | ||
} | ||
throw new Error( | ||
await res | ||
.json() | ||
.then(({ message }) => message) | ||
.catch(() => `Received ${res.status} response`) | ||
); | ||
}, | ||
[] | ||
const { data: user } = useFetchData<HCAAtlasTrackerActiveUser | undefined>( | ||
API.USER, | ||
METHOD.GET | ||
); | ||
|
||
useEffect(() => { | ||
if (!token) return; | ||
run(fetchUser(token)); | ||
}, [fetchUser, run, token]); | ||
|
||
return user; | ||
}; |
2 changes: 1 addition & 1 deletion
2
app/views/ComponentAtlasView/hooks/useEditComponentAtlasForm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/views/ComponentAtlasView/hooks/useFetchComponentAtlas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { API } from "../../../apis/catalog/hca-atlas-tracker/common/api"; | ||
import { HCAAtlasTrackerComponentAtlas } from "../../../apis/catalog/hca-atlas-tracker/common/entities"; | ||
import { METHOD, PathParameter } from "../../../common/entities"; | ||
import { getRequestURL } from "../../../common/utils"; | ||
import { useFetchData } from "../../../hooks/useFetchData"; | ||
|
||
interface UseFetchComponentAtlas { | ||
componentAtlas?: HCAAtlasTrackerComponentAtlas; | ||
} | ||
|
||
export const useFetchComponentAtlas = ( | ||
pathParameter: PathParameter | ||
): UseFetchComponentAtlas => { | ||
const { data: componentAtlas } = useFetchData< | ||
HCAAtlasTrackerComponentAtlas | undefined | ||
>(getRequestURL(API.ATLAS_COMPONENT_ATLAS, pathParameter), METHOD.GET); | ||
|
||
return { | ||
componentAtlas, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/views/ComponentAtlasesView/hooks/useFetchComponentAtlases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { API } from "../../../apis/catalog/hca-atlas-tracker/common/api"; | ||
import { HCAAtlasTrackerComponentAtlas } from "../../../apis/catalog/hca-atlas-tracker/common/entities"; | ||
import { METHOD, PathParameter } from "../../../common/entities"; | ||
import { getRequestURL } from "../../../common/utils"; | ||
import { useFetchData } from "../../../hooks/useFetchData"; | ||
|
||
interface UseFetchComponentAtlases { | ||
componentAtlases?: HCAAtlasTrackerComponentAtlas[]; | ||
} | ||
|
||
export const useFetchComponentAtlases = ( | ||
pathParameter: PathParameter | ||
): UseFetchComponentAtlases => { | ||
const { data: componentAtlases } = useFetchData< | ||
HCAAtlasTrackerComponentAtlas[] | undefined | ||
>(getRequestURL(API.ATLAS_COMPONENT_ATLASES, pathParameter), METHOD.GET); | ||
|
||
return { componentAtlases }; | ||
}; |
19 changes: 19 additions & 0 deletions
19
app/views/SourceStudiesView/hooks/useFetchSourceStudies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { API } from "../../../apis/catalog/hca-atlas-tracker/common/api"; | ||
import { HCAAtlasTrackerSourceStudy } from "../../../apis/catalog/hca-atlas-tracker/common/entities"; | ||
import { METHOD, PathParameter } from "../../../common/entities"; | ||
import { getRequestURL } from "../../../common/utils"; | ||
import { useFetchData } from "../../../hooks/useFetchData"; | ||
|
||
interface UseFetchSourceStudies { | ||
sourceStudies?: HCAAtlasTrackerSourceStudy[]; | ||
} | ||
|
||
export const useFetchSourceStudies = ( | ||
pathParameter: PathParameter | ||
): UseFetchSourceStudies => { | ||
const { data: sourceStudies } = useFetchData< | ||
HCAAtlasTrackerSourceStudy[] | undefined | ||
>(getRequestURL(API.ATLAS_SOURCE_STUDIES, pathParameter), METHOD.GET); | ||
|
||
return { sourceStudies }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters