From ba247c5ba8855367442b22aa493f95ffdc0975d7 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Apr 2025 22:47:42 -0400 Subject: [PATCH] wip --- app/models/oauth/OAuthClient.ts | 4 ++++ .../OAuthAuthenticationListItem.tsx | 18 ++++++++++++++++-- .../components/OAuthClientListItem.tsx | 8 +------- app/stores/RootStore.ts | 19 +++++++++++++++++-- shared/i18n/locales/en_US/translation.json | 5 ++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/models/oauth/OAuthClient.ts b/app/models/oauth/OAuthClient.ts index fe22707ea8..656824c4e1 100644 --- a/app/models/oauth/OAuthClient.ts +++ b/app/models/oauth/OAuthClient.ts @@ -73,6 +73,10 @@ class OAuthClient extends ParanoidModel { }); } + public get initial() { + return this.name[0]; + } + public get authorizationUrl(): string { const params = { client_id: this.clientId, diff --git a/app/scenes/Settings/components/OAuthAuthenticationListItem.tsx b/app/scenes/Settings/components/OAuthAuthenticationListItem.tsx index 85c3684033..61b1bea510 100644 --- a/app/scenes/Settings/components/OAuthAuthenticationListItem.tsx +++ b/app/scenes/Settings/components/OAuthAuthenticationListItem.tsx @@ -2,6 +2,9 @@ import { observer } from "mobx-react"; import * as React from "react"; import { useTranslation } from "react-i18next"; import OAuthAuthentication from "~/models/oauth/OAuthAuthentication"; +import { OAuthScopeHelper } from "~/scenes/Login/OAuthScopeHelper"; +import { Avatar, AvatarSize } from "~/components/Avatar"; +import { AvatarVariant } from "~/components/Avatar/Avatar"; import ListItem from "~/components/List/Item"; import Text from "~/components/Text"; import Time from "~/components/Time"; @@ -18,18 +21,29 @@ const OAuthAuthenticationListItem = ({ oauthAuthentication }: Props) => { <> {oauthAuthentication.lastActiveAt && ( - {t("Last accessed")}{" "} + {t("Accessed data")}{" "} )} - {oauthAuthentication.scope.join(", ")} + + {OAuthScopeHelper.normalizeScopes(oauthAuthentication.scope, t).join( + ", " + )} + ); return ( + } title={oauthAuthentication.oauthClient.name} subtitle={subtitle} /> diff --git a/app/scenes/Settings/components/OAuthClientListItem.tsx b/app/scenes/Settings/components/OAuthClientListItem.tsx index 825a357cbe..910bbbca34 100644 --- a/app/scenes/Settings/components/OAuthClientListItem.tsx +++ b/app/scenes/Settings/components/OAuthClientListItem.tsx @@ -31,18 +31,12 @@ const OAuthClientListItem = ({ oauthClient }: Props) => { ); - const avatarModel = { - id: oauthClient.id, - initial: oauthClient.name[0], - avatarUrl: oauthClient.avatarUrl, - }; - return ( diff --git a/app/stores/RootStore.ts b/app/stores/RootStore.ts index eeef2dfac3..046de46725 100644 --- a/app/stores/RootStore.ts +++ b/app/stores/RootStore.ts @@ -113,8 +113,9 @@ export default class RootStore { */ public getStoreForModelName(modelName: string) { const storeName = this.getStoreNameForModelName(modelName); + invariant(storeName, `No store found for model name "${modelName}"`); + const store = this[storeName]; - invariant(store, `No store found for model name "${modelName}"`); return store as RootStore[K]; } @@ -142,10 +143,24 @@ export default class RootStore { // @ts-expect-error TS thinks we are instantiating an abstract class. const store = new StoreClass(this); const storeName = name ?? this.getStoreNameForModelName(store.modelName); + invariant(storeName, `No store found for model name "${store.modelName}"`); + this[storeName] = store; } private getStoreNameForModelName(modelName: string) { - return pluralize(lowerFirst(modelName)) as keyof RootStore; + for (const key of Object.keys(this)) { + const store = this[key as keyof RootStore]; + if ("modelName" in store && store.modelName === modelName) { + return key as keyof RootStore; + } + } + + const storeName = pluralize(lowerFirst(modelName)) as keyof RootStore; + if (storeName) { + return storeName; + } + + return undefined; } } diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 383d56e123..5ba61e355e 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -517,12 +517,13 @@ "Unsubscribed from document": "Unsubscribed from document", "Unsubscribed from collection": "Unsubscribed from collection", "Account": "Account", - "API Keys": "API Keys", + "Authorizations": "Authorizations", "Details": "Details", "Security": "Security", "Features": "Features", "Members": "Members", "Groups": "Groups", + "API Keys": "API Keys", "Applications": "Applications", "Shared Links": "Shared Links", "Import": "Import", @@ -959,6 +960,7 @@ "Drag and drop the zip file from the Markdown export option in {{appName}}, or click to upload": "Drag and drop the zip file from the Markdown export option in {{appName}}, or click to upload", "Last active": "Last active", "Guest": "Guest", + "Accessed data": "Accessed data", "Are you sure you want to delete the {{ appName }} application? This cannot be undone.": "Are you sure you want to delete the {{ appName }} application? This cannot be undone.", "Shared by": "Shared by", "Date shared": "Date shared", @@ -1046,6 +1048,7 @@ "The email integration is currently disabled. Please set the associated environment variables and restart the server to enable notifications.": "The email integration is currently disabled. Please set the associated environment variables and restart the server to enable notifications.", "Create personal API keys to authenticate with the API and programatically control\n your workspace's data. API keys have the same permissions as your user account.\n For more details see the developer documentation.": "Create personal API keys to authenticate with the API and programatically control\n your workspace's data. API keys have the same permissions as your user account.\n For more details see the developer documentation.", "Personal keys": "Personal keys", + "Authentications": "Authentications", "Preferences saved": "Preferences saved", "Delete account": "Delete account", "Manage settings that affect your personal experience.": "Manage settings that affect your personal experience.",