From 4b07fe0f466061b0498cd154bfd547dad355381b Mon Sep 17 00:00:00 2001 From: Luke Pereira Date: Thu, 21 Mar 2024 15:44:57 +0000 Subject: [PATCH] fix(website): show NeedToLogin component instead of redirecting --- .../DatasetCitations/DatasetItem.tsx | 9 +- website/src/pages/datasets/index.astro | 139 ++++++++++-------- .../src/utils/shouldMiddlewareEnforceLogin.ts | 6 +- 3 files changed, 85 insertions(+), 69 deletions(-) diff --git a/website/src/components/DatasetCitations/DatasetItem.tsx b/website/src/components/DatasetCitations/DatasetItem.tsx index a3ac67b19b..5e0d02ae5f 100644 --- a/website/src/components/DatasetCitations/DatasetItem.tsx +++ b/website/src/components/DatasetCitations/DatasetItem.tsx @@ -157,8 +157,13 @@ const DatasetItemInner: FC = ({ )}
-

- +

+
+ +

+ Number of times this dataset has been cited by a publication +

+
diff --git a/website/src/pages/datasets/index.astro b/website/src/pages/datasets/index.astro index 73e48bef64..0747141afc 100644 --- a/website/src/pages/datasets/index.astro +++ b/website/src/pages/datasets/index.astro @@ -4,89 +4,104 @@ import { CitationPlot } from '../../components/DatasetCitations/CitationPlot'; import { DatasetList } from '../../components/DatasetCitations/DatasetList'; import { DatasetListActions } from '../../components/DatasetCitations/DatasetListActions'; import { ErrorFeedback } from '../../components/ErrorFeedback'; -import { getRuntimeConfig } from '../../config'; +import NeedToLogin from '../../components/common/NeedToLogin.astro'; +import { getRuntimeConfig, getWebsiteConfig } from '../../config'; import BaseLayout from '../../layouts/BaseLayout.astro'; import { DatasetCitationClient } from '../../services/datasetCitationClient.ts'; import { KeycloakClientManager } from '../../utils/KeycloakClientManager'; import { getAccessToken } from '../../utils/getAccessToken'; import { urlForKeycloakAccountPage } from '../../utils/urlForKeycloakAccountPage'; -const clientConfig = getRuntimeConfig().public; const session = Astro.locals.session!; const accessToken = getAccessToken(session)!; -const username = session.user!.username!; +const username = session.user?.username ?? ''; +const websiteConfig = getWebsiteConfig(); +const websiteName = websiteConfig.name; +const clientConfig = getRuntimeConfig().public; const datasetClient = DatasetCitationClient.create(); +const keycloakClient = await KeycloakClientManager.getClient(); const datasetsResponse = await datasetClient.getDatasetsOfUser(accessToken); const userCitedByResponse = await datasetClient.getUserCitedBy(username, accessToken); const authorResponse = await datasetClient.getAuthor(username); - -const keycloakClient = await KeycloakClientManager.getClient(); const editAccountUrl = (await urlForKeycloakAccountPage(keycloakClient!)) + '/#/personal-info'; ---
-
-
- { - authorResponse.match( - (authorProfile) => ( - - ), - (error) => ( - - ), - ) - } -
-
-
-
-

Datasets

- -
-
- { - datasetsResponse.match( - (datasets) => , - (error) => ( - - ), - ) - } + { + !accessToken ? ( + + ) : ( +
+
+ {authorResponse.match( + (authorProfile) => ( + + ), + (error) => ( + + ), + )} +
+
+
+
+

Datasets

+ +
+
+ {datasetsResponse.match( + (datasets) => ( + + ), + (error) => ( + + ), + )} +
+
+
+ Cited By + {userCitedByResponse.match( + (citedByData) => ( +
+ +

+ Number of times your sequences appear in {websiteName} datasets +

+
+ ), + (error) => ( + + ), + )} +
-
-
- Cited By - { - userCitedByResponse.match( - (citedByData) => , - (error) => ( - - ), - ) - } -
-
+ ) + }
diff --git a/website/src/utils/shouldMiddlewareEnforceLogin.ts b/website/src/utils/shouldMiddlewareEnforceLogin.ts index 38d28605b4..b8b5a523e4 100644 --- a/website/src/utils/shouldMiddlewareEnforceLogin.ts +++ b/website/src/utils/shouldMiddlewareEnforceLogin.ts @@ -8,11 +8,7 @@ function getEnforcedLoginRoutes(configuredOrganisms: string[]) { new RegExp(`^/${organism}/my_sequences`), ]); - enforcedLoginRoutesCache[cacheKey] = [ - new RegExp('^/user/?'), - new RegExp(`^/datasets\/?$`), - ...organismSpecificRoutes, - ]; + enforcedLoginRoutesCache[cacheKey] = [new RegExp('^/user/?'), ...organismSpecificRoutes]; } return enforcedLoginRoutesCache[cacheKey]; }