diff --git a/apps/web/src/components/navbar/navbar.tsx b/apps/web/src/components/navbar/navbar.tsx index ecd864a3885b1c79c3f3f6b0c60a234db9f70b94..5cb0e428ea05fafe99248032c3ece755f6676cc0 100644 --- a/apps/web/src/components/navbar/navbar.tsx +++ b/apps/web/src/components/navbar/navbar.tsx @@ -13,9 +13,8 @@ import { useAuthCache, useAuthentication } from '@graphpolaris/shared/lib/data-a import { DropdownItem } from '@graphpolaris/shared/lib/components/dropdowns'; import GpLogo from './gp-logo'; import { Popover, PopoverContent, PopoverTrigger } from '@graphpolaris/shared/lib/components/layout/Popover'; -import { useDispatch } from 'react-redux'; -import { getEnvVariable, showManagePermissions, showSharableExploration } from 'config'; -import { Button, Dialog, DialogContent, DialogTrigger, useActiveSaveStateAuthorization, useSessionCache } from '@graphpolaris/shared'; +import { showSharableExploration } from 'config'; +import { Button, useActiveSaveStateAuthorization } from '@graphpolaris/shared'; import { ManagementTrigger, ManagementViews } from '@graphpolaris/shared/lib/management'; const AuthURL = import.meta.env.GP_AUTH_URL; @@ -26,7 +25,7 @@ export const Navbar = () => { const authCache = useAuthCache(); const authorization = useActiveSaveStateAuthorization(); const [menuOpen, setMenuOpen] = useState(false); - const buildInfo = getEnvVariable('GRAPHPOLARIS_VERSION'); + const buildInfo = import.meta.env.GRAPHPOLARIS_VERSION; const [managementOpen, setManagementOpen] = useState<boolean>(false); const [current, setCurrent] = useState<ManagementViews>('overview'); @@ -89,7 +88,7 @@ export const Navbar = () => { <DropdownItem value="Log out" onClick={() => { - location.replace(`${getEnvVariable('GP_AUTH_URL')}/outpost.goauthentik.io/sign_out`); + location.replace(`${AuthURL}/outpost.goauthentik.io/sign_out`); }} /> </> diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx index f7029e4d6bc435c67ac1c20f5070f08fc3cb9fec..e25807e6dcf9c82c0ac44379a39e99babad3712b 100644 --- a/apps/web/src/main.tsx +++ b/apps/web/src/main.tsx @@ -5,13 +5,12 @@ import * as Sentry from '@sentry/react'; import { store } from '@graphpolaris/shared/lib/data-access/store'; import App from './app/App'; import { createRoot } from 'react-dom/client'; -import { getEnvVariable } from 'config'; import './main.css'; import { ErrorBoundary } from '@graphpolaris/shared/lib/components/errorBoundary'; -if (getEnvVariable('SENTRY_ENABLED')) { +if (import.meta.env.SENTRY_ENABLED) { Sentry.init({ - dsn: getEnvVariable('SENTRY_URL'), + dsn: import.meta.env.SENTRY_URL, integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()], tracesSampleRate: 1.0, replaysSessionSampleRate: 0.1, diff --git a/libs/config/src/featureFlags.ts b/libs/config/src/featureFlags.ts index 21d94384fe9c60b135140fddc9b3341d82c4a7cc..b6364d037ede7d1d7677ba42c2c43c626a632356 100644 --- a/libs/config/src/featureFlags.ts +++ b/libs/config/src/featureFlags.ts @@ -1,49 +1,32 @@ -const envFallbacks: Record<string, any> = { - SENTRY_ENABLED: false, - SENTRY_URL: '', - GRAPHPOLARIS_VERSION: 'prod', - GP_AUTH_URL: '', - BACKEND_WSS_URL: '', - BACKEND_URL: '', - BACKEND_USER: '', - WIP_TABLEVIS: true, - WIP_NODELINKVIS: true, - WIP_RAWJSONVIS: true, - WIP_PAOHVIS: true, - WIP_MATRIXVIS: true, - WIP_SEMANTICSUBSTRATESVIS: true, - WIP_MAPVIS: true, - WIP_INSIGHT_SHARING: true, - WIP_VIEWER_PERMISSIONS: true, - WIP_SHARABLE_EXPLORATION: true, -}; - -type EnvFallbackKey = keyof typeof envFallbacks; - // Safely retrieve environment variable values with a default fallback -const getEnvVariable = (key: EnvFallbackKey): any => { - const value = import.meta.env[key]; - if (value === undefined) { - console.error(`Environment variable ${key} is missing, using fallback value.`); - return envFallbacks[key]; - } - return value; +const getEnvVariable = (key: string, defaultValue: string = 'false'): string => { + return import.meta.env[key] ?? defaultValue; }; // Check if the environment is production const isProduction = (): boolean => { - return getEnvVariable('GRAPHPOLARIS_VERSION') === 'prod'; + return getEnvVariable('GRAPHPOLARIS_VERSION', 'dev') === 'prod'; +}; + +// Check if the Manage Permissions feature is enabled +const showManagePermissions = (): boolean => { + return !isProduction() || (isProduction() && getEnvVariable('WIP_VIEWER_PERMISSIONS') === 'false'); +}; + +// Check if the Insight Sharing feature is enabled +const showInsightSharing = (): boolean => { + return !isProduction() || (isProduction() && getEnvVariable('WIP_INSIGHT_SHARING') === 'false'); }; -// Utility to check if a WIP feature is enabled -const isWIPFeatureEnabled = (featureKey: string): boolean => { - return getEnvVariable(`WIP_${featureKey.toUpperCase()}`) === 'false'; +// Check if the Insight Sharing feature is enabled +const showSharableExploration = (): boolean => { + return !isProduction() || (isProduction() && getEnvVariable('WIP_SHARABLE_EXPLORATION') === 'false'); }; -// Feature flags with checks for production and WIP feature flags -const showManagePermissions = (): boolean => !isProduction() || isWIPFeatureEnabled('viewer_permissions'); -const showInsightSharing = (): boolean => !isProduction() || isWIPFeatureEnabled('insight_sharing'); -const showSharableExploration = (): boolean => !isProduction() || isWIPFeatureEnabled('sharable_exploration'); -const isVisualizationReleased = (visualizationName: string): boolean => !isProduction() || isWIPFeatureEnabled(visualizationName); +// Utility to check if a specific visualization is released based on environment variables +const isVisualizationReleased = (visualizationName: string): boolean => { + const visualizationFlag = getEnvVariable(`WIP_${visualizationName.toUpperCase()}`, 'false'); + return !isProduction() || (isProduction() && visualizationFlag === 'false'); +}; -export { getEnvVariable, isProduction, showManagePermissions, showInsightSharing, showSharableExploration, isVisualizationReleased }; +export { isProduction, showManagePermissions, showInsightSharing, showSharableExploration, isVisualizationReleased }; diff --git a/libs/shared/lib/data-access/broker/broker.tsx b/libs/shared/lib/data-access/broker/broker.tsx index 3614348423c9054d01ba9264a98382232903c3e9..f915a2f241faec948ebecc2ecf8ff1bc788db470 100644 --- a/libs/shared/lib/data-access/broker/broker.tsx +++ b/libs/shared/lib/data-access/broker/broker.tsx @@ -4,7 +4,6 @@ * © Copyright Utrecht University (Department of Information and Computing Sciences) */ -import { getEnvVariable } from 'config'; import { UseIsAuthorizedState } from '../store/authSlice'; import { ReceiveMessageI, SendMessageI, SendMessageWithSessionI } from './types'; @@ -39,7 +38,7 @@ export class Broker { /** Get the singleton instance of the Broker. */ public static instance(): Broker { - if (!this.singletonInstance) this.singletonInstance = new Broker(getEnvVariable('BACKEND_WSS_URL')); + if (!this.singletonInstance) this.singletonInstance = new Broker(import.meta.env.BACKEND_WSS_URL); return this.singletonInstance; } diff --git a/libs/shared/lib/data-access/security/useAuthentication.tsx b/libs/shared/lib/data-access/security/useAuthentication.tsx index 18310f7381486a97df250c1eee63399a6fd8f79e..fcb507b868c3effc43464d9049899e9ec33be6ce 100644 --- a/libs/shared/lib/data-access/security/useAuthentication.tsx +++ b/libs/shared/lib/data-access/security/useAuthentication.tsx @@ -1,9 +1,8 @@ -import { getEnvVariable } from 'config'; import { useAppDispatch, useAuthCache } from '../store'; import { authenticated, changeRoom, UserAuthenticationHeader } from '../store/authSlice'; -const domain = getEnvVariable('BACKEND_URL'); -const userURI = getEnvVariable('BACKEND_USER'); +const domain = import.meta.env.BACKEND_URL; +const userURI = import.meta.env.BACKEND_USER; export const fetchSettings: RequestInit = { method: 'GET', diff --git a/libs/shared/lib/inspector/InspectorPanel.tsx b/libs/shared/lib/inspector/InspectorPanel.tsx index 6efabffa94b1fe994b8eab2fea119723672a7e11..cbc35aefc3191b55141d062f965daacd8b25695d 100644 --- a/libs/shared/lib/inspector/InspectorPanel.tsx +++ b/libs/shared/lib/inspector/InspectorPanel.tsx @@ -9,10 +9,9 @@ import { SelectionConfig } from '../vis/components/config/SelectionConfig'; import { SchemaSettings } from '../schema/panel/SchemaSettings'; import { QuerySettings } from '../querybuilder/panel/querysidepanel/QuerySettings'; import { useActiveVisualization } from '@graphpolaris/shared/lib/data-access'; -import { getEnvVariable } from 'config'; export function InspectorPanel(props: { children?: React.ReactNode }) { - const buildInfo = getEnvVariable('GRAPHPOLARIS_VERSION'); + const buildInfo = import.meta.env.GRAPHPOLARIS_VERSION; const selection = useSelection(); const focus = useFocus(); const dispatch = useDispatch(); diff --git a/libs/shared/lib/sidebar/index.tsx b/libs/shared/lib/sidebar/index.tsx index 8307fea0328a1402cfe369b67fa6ed92b30dbbbb..7c2f424192cc6deaa7350748873198edb2440207 100644 --- a/libs/shared/lib/sidebar/index.tsx +++ b/libs/shared/lib/sidebar/index.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { Button, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../components'; import ColorMode from '../components/color-mode'; -import { getEnvVariable } from 'config'; export type SideNavTab = 'Schema' | 'Search' | undefined; @@ -30,8 +29,8 @@ export function Sidebar({ tab: SideNavTab; openMonitoringDialog: () => void; }) { - const isProd = getEnvVariable('GRAPHPOLARIS_VERSION') === 'prod'; - const isInsightSharingWIP = getEnvVariable('WIP_INSIGHT_SHARING') === true; + const isProd = import.meta.env.GRAPHPOLARIS_VERSION === 'prod'; + const isInsightSharingWIP = import.meta.env.WIP_INSIGHT_SHARING === 'true'; return ( <div className="side-bar w-fit h-full flex shrink">