-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
154 additions
and
25 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
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,31 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {createContext} from 'react' | ||
|
||
export type PluginSlot={ | ||
name: string, | ||
icon: JSX.Element, | ||
href: string, | ||
title: string, | ||
subtitle: string | null | ||
} | ||
|
||
export type RsdPluginProps = { | ||
pluginSlots: PluginSlot[] | ||
} | ||
|
||
export const RsdPluginContext = createContext<RsdPluginProps>({ | ||
pluginSlots: [] | ||
}) | ||
|
||
export default function PluginSettingsProvider(props: any) { | ||
const {pluginSlots} = props | ||
|
||
return <RsdPluginContext.Provider | ||
value={{pluginSlots}} | ||
{...props} | ||
/> | ||
} |
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,4 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
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,7 +1,7 @@ | ||
// SPDX-FileCopyrightText: 2021 - 2022 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2021 - 2023 dv4all | ||
// SPDX-FileCopyrightText: 2022 - 2023 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2022 - 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all) | ||
|
@@ -21,7 +21,7 @@ import Diversity3Icon from '@mui/icons-material/Diversity3' | |
import {RsdModule} from './rsdSettingsReducer' | ||
|
||
export type MenuItemType = { | ||
type?: 'link' | 'function' |'divider' | ||
type?: 'link' | 'function' |'divider' | 'pluginSlot' | ||
label: string, | ||
// used as url link | ||
path?: string, | ||
|
@@ -120,6 +120,10 @@ export const userMenuItems: MenuItemType[] = [ | |
}, | ||
path: '/user/communities', | ||
icon: <Diversity3Icon />, | ||
}, { | ||
module: 'user', | ||
type: 'pluginSlot', | ||
label: 'Unused label for plugin slot', | ||
}, { | ||
module: 'user', | ||
type: 'divider', | ||
|
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,10 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Defines the possible names for plugin slots, referred by the individual components | ||
export enum PluginSlotNames { | ||
userMenu = 'userMenu', | ||
softwareEditSidebar = 'softwareEditSidebar', | ||
} |
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
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,21 +1,41 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {userMenuItems} from './menuItems' | ||
import {MenuItemType, userMenuItems} from './menuItems' | ||
import {useSession} from '~/auth' | ||
import useRsdSettings from './useRsdSettings' | ||
import {useContext} from 'react' | ||
import {RsdPluginContext} from './RsdPluginContext' | ||
|
||
export default function useUserMenuItems(){ | ||
const {user} = useSession() | ||
const {host} = useRsdSettings() | ||
const {pluginSlots} = useContext(RsdPluginContext) | ||
|
||
const items = userMenuItems.filter(item=>{ | ||
if (item.active){ | ||
return item.active({role: user?.role, modules: host.modules}) | ||
const items: MenuItemType[] = [] | ||
|
||
userMenuItems.forEach( (item) => { | ||
if (item.active && item.active({role: user?.role, modules: host.modules})){ | ||
items.push(item) | ||
} else if (item.type == 'pluginSlot') { | ||
pluginSlots.forEach( | ||
(pluginSlot) => { | ||
if (pluginSlot.name == 'userMenuItem') { | ||
items.push({ | ||
module: 'user', | ||
type: 'link', | ||
label: pluginSlot.title, | ||
path: pluginSlot.href, | ||
icon: typeof pluginSlot.icon === 'string' ? <span dangerouslySetInnerHTML={{__html: pluginSlot.icon}} /> : pluginSlot.icon as JSX.Element | ||
}) | ||
} | ||
} | ||
) | ||
} | ||
return true | ||
}) | ||
|
||
return items | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
// SPDX-FileCopyrightText: 2022 dv4all | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -47,6 +49,10 @@ if (process.env.NODE_ENV === 'docker') { | |
{ | ||
source: '/documentation/:path*', | ||
destination: 'http://localhost/documentation/:path*', | ||
}, | ||
{ | ||
source: '/modules/:path*', | ||
destination: 'http://localhost/modules/:path*' | ||
} | ||
] | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
// SPDX-FileCopyrightText: 2021 - 2023 dv4all | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 Jesús García Gonzalez (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2023 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -41,14 +41,17 @@ import Announcement from '~/components/Announcement/Announcement' | |
// user settings (from cookies) | ||
import {getUserSettings} from '~/utils/userSettings' | ||
import {UserSettingsProps, UserSettingsProvider} from '~/config/UserSettingsContext' | ||
import getUserPlugins from '~/utils/userPlugins' | ||
import PluginSettingsProvider, {PluginSlot} from '~/config/RsdPluginContext' | ||
|
||
// extend Next app props interface with emotion cache | ||
export interface MuiAppProps extends AppProps { | ||
emotionCache: EmotionCache | ||
session: Session, | ||
settings: RsdSettingsState, | ||
matomo: Matomo, | ||
userSettings?:UserSettingsProps | ||
userSettings?: UserSettingsProps, | ||
pluginSlots?: PluginSlot[] | ||
} | ||
|
||
// define npgrogres setup, no spinner | ||
|
@@ -77,7 +80,7 @@ Router.events.on('routeChangeError', ()=>{ | |
function RsdApp(props: MuiAppProps) { | ||
const { | ||
Component, emotionCache = clientSideEmotionCache, | ||
pageProps, session, settings, matomo, userSettings | ||
pageProps, session, settings, matomo, userSettings, pluginSlots | ||
} = props | ||
|
||
//currently we support only default (light) and dark RSD theme for MUI | ||
|
@@ -94,6 +97,7 @@ function RsdApp(props: MuiAppProps) { | |
const [rsdSession] = useState(session) | ||
const [rsdSettings] = useState(settings) | ||
const [rsdUserSettings] = useState(userSettings) | ||
const [rsdPluginSlots] = useState(pluginSlots) | ||
// request theme when options changed | ||
const {muiTheme, cssVariables} = useMemo(() => { | ||
return loadMuiTheme(rsdSettings.theme) | ||
|
@@ -136,13 +140,16 @@ function RsdApp(props: MuiAppProps) { | |
<AuthProvider session={rsdSession}> | ||
{/* RSD settings/config */} | ||
<RsdSettingsProvider settings={rsdSettings}> | ||
{/* MUI snackbar service */} | ||
<MuiSnackbarProvider> | ||
{/* User settings rows, page layout etc. */} | ||
<UserSettingsProvider user={rsdUserSettings}> | ||
<Component {...pageProps} /> | ||
</UserSettingsProvider> | ||
</MuiSnackbarProvider> | ||
{/* Plugin slots context */} | ||
<PluginSettingsProvider pluginSlots={rsdPluginSlots}> | ||
{/* MUI snackbar service */} | ||
<MuiSnackbarProvider> | ||
{/* User settings rows, page layout etc. */} | ||
<UserSettingsProvider user={rsdUserSettings}> | ||
<Component {...pageProps} /> | ||
</UserSettingsProvider> | ||
</MuiSnackbarProvider> | ||
</PluginSettingsProvider> | ||
</RsdSettingsProvider> | ||
</AuthProvider> | ||
{/* Matomo cookie consent dialog */} | ||
|
@@ -190,6 +197,8 @@ RsdApp.getInitialProps = async(appContext:AppContext) => { | |
let session: Session | null = null | ||
// user settings variable to extract from cookies | ||
let userSettings:UserSettingsProps|null = null | ||
// List of all plugins that can be used by the user | ||
let pluginSlots: PluginSlot[] = [] | ||
// Matomo cached settings passed via getInitialProps | ||
// Note! getInitialProps does not always run server side | ||
// so we keep the last obtained values in this object | ||
|
@@ -198,6 +207,8 @@ RsdApp.getInitialProps = async(appContext:AppContext) => { | |
id: process.env.MATOMO_ID || null, | ||
consent: null | ||
} | ||
// extract rsd settings | ||
const settings = await getSettingsServerSide(req, appContext.router.query) | ||
// extract user session from cookies and | ||
// matomo consent if matomo is used (id) | ||
// only in SSR mode (req && res present) | ||
|
@@ -209,11 +220,10 @@ RsdApp.getInitialProps = async(appContext:AppContext) => { | |
} | ||
// get user settings from cookies | ||
userSettings = getUserSettings(req) | ||
pluginSlots = await getUserPlugins(session?.token, settings.host.plugins) | ||
// set content security header | ||
setContentSecurityPolicyHeader(res) | ||
} | ||
// extract rsd settings | ||
const settings = await getSettingsServerSide(req, appContext.router.query) | ||
|
||
// console.group('RsdApp.getInitialProps') | ||
// console.log('session...', session) | ||
|
@@ -227,7 +237,8 @@ RsdApp.getInitialProps = async(appContext:AppContext) => { | |
session, | ||
settings, | ||
matomo, | ||
userSettings | ||
userSettings, | ||
pluginSlots | ||
} | ||
} | ||
|
||
|
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
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,33 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {PluginSlot} from '~/config/RsdPluginContext' | ||
import {createJsonHeaders} from './fetchHelpers' | ||
|
||
export default async function getUserPlugins( | ||
token?: string, plugins?: string[] | ||
) { | ||
if (!token || !plugins) { | ||
return [] | ||
} | ||
|
||
const promises = plugins?.map(async pluginPath => { | ||
const url = `/modules/${pluginPath}/config` | ||
try { | ||
const response = await fetch(url, { | ||
headers: { | ||
...createJsonHeaders(token) | ||
}, | ||
signal: AbortSignal.timeout(200) | ||
}) | ||
return response.json() as Promise<PluginSlot> | ||
} catch (e) { | ||
console.log(`Failed to load plugin config for plugin ${pluginPath}`, e) | ||
return [] | ||
} | ||
}) | ||
const pluginSlots = await Promise.all(promises ?? []) as PluginSlot[] | ||
return pluginSlots.flat() | ||
} |
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