Skip to content

Commit

Permalink
chore: updated findable-ui to latest v20.0.0 (#511) (#515)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Fran McDade <[email protected]>
  • Loading branch information
frano-m and Fran McDade authored Jan 6, 2025
1 parent 9d2a0a9 commit 4d719f4
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { ButtonPrimary } from "@databiosphere/findable-ui/lib/components/common/Button/components/ButtonPrimary/buttonPrimary";
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { TextField } from "@mui/material";
import { useCallback, useRef, useState } from "react";
import {
TASK_STATUS,
TaskStatusesUpdatedByDOIResult,
} from "../../../../../app/apis/catalog/hca-atlas-tracker/common/entities";
import { METHOD } from "../../../../../app/common/entities";
import {
fetchResource,
isFetchStatusOk,
} from "../../../../../app/common/utils";
import { FormResponseErrors } from "../../../../../app/hooks/useForm/common/entities";
} from "../../../../apis/catalog/hca-atlas-tracker/common/entities";
import { METHOD } from "../../../../common/entities";
import { fetchResource, isFetchStatusOk } from "../../../../common/utils";
import { FormResponseErrors } from "../../../../hooks/useForm/common/entities";

export const CellxGeneInProgressForm = (): JSX.Element => {
const [isDisabled, setIsDisabled] = useState(false);
Expand All @@ -21,7 +18,7 @@ export const CellxGeneInProgressForm = (): JSX.Element => {

const textareaRef = useRef<HTMLTextAreaElement>();

const { token } = useAuthentication();
const { token } = useToken();

const onSave = useCallback(() => {
(async (): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { ButtonPrimary } from "@databiosphere/findable-ui/lib/components/common/Button/components/ButtonPrimary/buttonPrimary";
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { useCallback, useState } from "react";
import { METHOD } from "../../../../../app/common/entities";
import {
fetchResource,
isFetchStatusOk,
} from "../../../../../app/common/utils";
import { FormResponseErrors } from "../../../../../app/hooks/useForm/common/entities";
import { METHOD } from "../../../../common/entities";
import { fetchResource, isFetchStatusOk } from "../../../../common/utils";
import { FormResponseErrors } from "../../../../hooks/useForm/common/entities";

export const IntegrationLeadsFromAtlasesForm = (): JSX.Element => {
const [isDisabled, setIsDisabled] = useState(false);
const [responseErrors, setResponseErrors] = useState<FormResponseErrors>();
const [didUpdate, setDidUpdate] = useState(false);

const { token } = useAuthentication();
const { token } = useToken();

const onSave = useCallback(() => {
(async (): Promise<void> => {
Expand Down
12 changes: 6 additions & 6 deletions app/components/Forms/components/Refresh/refresh.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ButtonPrimary } from "@databiosphere/findable-ui/lib/components/common/Button/components/ButtonPrimary/buttonPrimary";
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { useCallback, useEffect, useState } from "react";
import { METHOD } from "../../../../../app/common/entities";
import { fetchResource } from "../../../../../app/common/utils";
import { FormResponseErrors } from "../../../../../app/hooks/useForm/common/entities";
import { METHOD } from "../../../../common/entities";
import { fetchResource } from "../../../../common/utils";
import { FormResponseErrors } from "../../../../hooks/useForm/common/entities";
import {
REFRESH_ACTIVITY,
REFRESH_OUTCOME,
RefreshServicesStatuses,
RefreshStatus,
} from "../../../../../app/services/common/entities";
} from "../../../../services/common/entities";

export const RefreshForm = (): JSX.Element => {
const [statusIsDisabled, setStatusIsDisabled] = useState(false);
Expand All @@ -22,7 +22,7 @@ export const RefreshForm = (): JSX.Element => {
useState<FormResponseErrors>();
const [refreshStarted, setRefreshStarted] = useState(false);

const { token } = useAuthentication();
const { token } = useToken();

const onReloadStatus = useCallback(() => {
doApiRequest(
Expand Down
4 changes: 2 additions & 2 deletions app/hooks/useDeleteData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { useCallback } from "react";
import { METHOD } from "../common/entities";
import { fetchResource, isFetchStatusOk } from "../common/utils";
Expand All @@ -13,7 +13,7 @@ export const useDeleteData = <T>(
method = METHOD.DELETE,
options?: OnDeleteOptions
): UseDeleteData<T> => {
const { token } = useAuthentication();
const { token } = useToken();

const onDelete = useCallback(
async (payload?: T): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions app/hooks/useFetchData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
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 { METHOD } from "../common/entities";
import { fetchResource, isFetchStatusOk } from "../common/utils";
Expand All @@ -14,7 +14,7 @@ export const useFetchData = <D>(
method: METHOD,
shouldFetch = true
): UseFetchData<D> => {
const { token } = useAuthentication();
const { token } = useToken();
const { data, isSuccess, run } = useAsync<D>();

const fetchData = useCallback(async (): Promise<D> => {
Expand Down
4 changes: 2 additions & 2 deletions app/hooks/useFetchSourceStudiesSourceDatasets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { useCallback, useEffect, useState } from "react";
import { API } from "../apis/catalog/hca-atlas-tracker/common/api";
import {
Expand All @@ -13,7 +13,7 @@ import { useFetchData } from "./useFetchData";
export const useFetchSourceStudiesSourceDatasets = (
pathParameter: PathParameter
): HCAAtlasTrackerSourceDataset[] | undefined => {
const { token } = useAuthentication();
const { token } = useToken();
const [sourceStudiesSourceDatasets, setSourceStudiesSourceDatasets] =
useState<HCAAtlasTrackerSourceDataset[]>();
const { data: sourceStudies } = useFetchData<
Expand Down
4 changes: 2 additions & 2 deletions app/hooks/useForm/useForm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { yupResolver } from "@hookform/resolvers/yup";
import { useCallback, useEffect, useMemo, useState } from "react";
import {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const useForm = <T extends FieldValues, R = undefined>(
mapApiValues: MapApiValuesFn<T> = (p): unknown => p,
options: CustomUseFormOptions<T> = {}
): UseForm<T, R> => {
const { token } = useAuthentication();
const { token } = useToken();
const values = useMemo(
() => schema.cast(mapSchemaValues?.(apiData)),
[apiData, mapSchemaValues, schema]
Expand Down
6 changes: 4 additions & 2 deletions app/hooks/useFormManager/useFormManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useAuth } from "@databiosphere/findable-ui/lib/providers/authentication/auth/hook";
import Router from "next/router";
import { useCallback, useEffect, useState } from "react";
import { FieldValues } from "react-hook-form";
Expand Down Expand Up @@ -34,7 +34,9 @@ export const useFormManager = <T extends FieldValues, R = undefined>(
} = {},
isDirty = formMethod?.formState.isDirty ?? false
): UseFormManager => {
const { isAuthenticated } = useAuthentication();
const {
authState: { isAuthenticated },
} = useAuth();
const { user } = useAuthorization();
const { canEdit } = useUserHasEditAuthorization();
const [pathRoute, setPathRoute] =
Expand Down
10 changes: 7 additions & 3 deletions app/providers/authorization.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Main as DXMain } from "@databiosphere/findable-ui/lib/components/Layout/components/Main/main";
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useAuth } from "@databiosphere/findable-ui/lib/providers/authentication/auth/hook";
import { createContext, ReactNode, useEffect } from "react";
import {
HCAAtlasTrackerActiveUser,
Expand All @@ -21,7 +21,9 @@ interface Props {
}

export function AuthorizationProvider({ children }: Props): JSX.Element {
const { isAuthenticated } = useAuthentication();
const {
authState: { isAuthenticated },
} = useAuth();
const user = useFetchActiveUser();
const { disabled, role } = user || {};
const isAuthorized = isUserAuthorized(role, disabled);
Expand All @@ -33,7 +35,9 @@ export function AuthorizationProvider({ children }: Props): JSX.Element {
}, [role, disabled]);

return (
<AuthorizationContext.Provider value={{ user }}>
<AuthorizationContext.Provider
value={{ user: isAuthenticated ? user : undefined }} // TODO(cc) - we should reset / clear user when not authenticated see useFetchActiveUser.
>
{shouldRenderComponents(isAuthenticated, isAuthorized) ? (
children
) : (
Expand Down
23 changes: 0 additions & 23 deletions app/services/__mocks__/user-profile.ts

This file was deleted.

6 changes: 4 additions & 2 deletions app/services/user-profile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getAuthenticationRequestOptions } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/common/utils";
import { UserProfile } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useFetchGoogleProfile";
import { UserProfile as BaseUserProfile } from "@databiosphere/findable-ui/lib/providers/authentication/authentication/types";
import { getAuthenticationRequestOptions } from "@databiosphere/findable-ui/lib/providers/authentication/terra/hooks/common/utils";
import ky from "ky";

const ENDPOINT = "https://www.googleapis.com/oauth2/v3/userinfo";

const userProfilesCache = new Map<string, UserProfile>();

export type UserProfile = BaseUserProfile & { email_verified: boolean };

export async function getProvidedUserProfile(
authorization: string | undefined
): Promise<UserProfile | null> {
Expand Down
16 changes: 9 additions & 7 deletions app/views/CellxGeneInProgressView/cellxgeneInProgressView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useAuth } from "@databiosphere/findable-ui/lib/providers/authentication/auth/hook";
import { ContentView } from "@databiosphere/findable-ui/lib/views/ContentView/contentView";
import { AccessPrompt } from "../../../app/components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../../app/components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { CellxGeneInProgressForm } from "../../../app/components/Forms/components/CellxGeneInProgress/cellxgeneInProgress";
import { Content } from "../../../app/components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../../app/content/common/constants";
import { AccessPrompt } from "../../components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { CellxGeneInProgressForm } from "../../components/Forms/components/CellxGeneInProgress/cellxgeneInProgress";
import { Content } from "../../components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../content/common/constants";

export const CellxGeneInProgressView = (): JSX.Element => {
const { isAuthenticated } = useAuthentication();
const {
authState: { isAuthenticated },
} = useAuth();
return (
<ContentView
content={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useAuth } from "@databiosphere/findable-ui/lib/providers/authentication/auth/hook";
import { ContentView } from "@databiosphere/findable-ui/lib/views/ContentView/contentView";
import { AccessPrompt } from "../../../app/components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../../app/components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { IntegrationLeadsFromAtlasesForm } from "../../../app/components/Forms/components/IntegrationLeadsFromAtlases/integrationLeadsFromAtlases";
import { Content } from "../../../app/components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../../app/content/common/constants";
import { AccessPrompt } from "../../components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { IntegrationLeadsFromAtlasesForm } from "../../components/Forms/components/IntegrationLeadsFromAtlases/integrationLeadsFromAtlases";
import { Content } from "../../components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../content/common/constants";

export const IntegrationLeadsFromAtlasesView = (): JSX.Element => {
const { isAuthenticated } = useAuthentication();
const {
authState: { isAuthenticated },
} = useAuth();
return (
<ContentView
content={
Expand Down
16 changes: 9 additions & 7 deletions app/views/RefreshView/refreshView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useAuth } from "@databiosphere/findable-ui/lib/providers/authentication/auth/hook";
import { ContentView } from "@databiosphere/findable-ui/lib/views/ContentView/contentView";
import { AccessPrompt } from "../../../app/components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../../app/components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { RefreshForm } from "../../../app/components/Forms/components/Refresh/refresh";
import { Content } from "../../../app/components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../../app/content/common/constants";
import { AccessPrompt } from "../../components/common/Form/components/FormManager/components/AccessPrompt/accessPrompt";
import { Divider } from "../../components/Detail/components/TrackerForm/components/Divider/divider.styles";
import { RefreshForm } from "../../components/Forms/components/Refresh/refresh";
import { Content } from "../../components/Layout/components/Content/content";
import { LAYOUT_STYLE_NO_CONTRAST_DEFAULT } from "../../content/common/constants";

export const RefreshView = (): JSX.Element => {
const { isAuthenticated } = useAuthentication();
const {
authState: { isAuthenticated },
} = useAuth();
return (
<ContentView
content={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import { useCallback } from "react";
import { API } from "../../../apis/catalog/hca-atlas-tracker/common/api";
import { METHOD, PathParameter } from "../../../common/entities";
Expand All @@ -16,7 +16,7 @@ export interface UseSetLinkedAtlasSourceDatasets {
export const useSetLinkedAtlasSourceDatasets = (
pathParameter: PathParameter
): UseSetLinkedAtlasSourceDatasets => {
const { token } = useAuthentication();
const { token } = useToken();

const onSetLinked = useCallback(
async (sourceDatasetId: string, linked: boolean): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions app/views/SourceStudyView/hooks/useDeleteSourceStudy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAuthentication } from "@databiosphere/findable-ui/lib/hooks/useAuthentication/useAuthentication";
import { useToken } from "@databiosphere/findable-ui/lib/hooks/authentication/token/useToken";
import Router from "next/router";
import { useCallback } from "react";
import { API } from "../../../apis/catalog/hca-atlas-tracker/common/api";
Expand All @@ -18,7 +18,7 @@ export interface UseDeleteSourceStudy {
export const useDeleteSourceStudy = (
pathParameter: PathParameter
): UseDeleteSourceStudy => {
const { token } = useAuthentication();
const { token } = useToken();

const onDelete = useCallback(async (): Promise<void> => {
const res = await fetchResource(
Expand Down
Loading

0 comments on commit 4d719f4

Please sign in to comment.