Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 20, 2023
1 parent d336426 commit 0e9c31b
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 57 deletions.
23 changes: 13 additions & 10 deletions dashboard/client/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import uploaderImg from './images/uploader.png';
import exposeImg from './images/expose.png';
import notifyImg from './images/notify.png';
import DashboardBar from "./DashboardBar";
import {useKeycloakUser} from '@alchemy/react-auth'
import AdminPanelSettingsIcon from "@mui/icons-material/AdminPanelSettings";

type Props = {};

export default function Dashboard({}: Props) {
const theme = useTheme();
const isLarge = useMediaQuery(theme.breakpoints.up('sm'));
const {user} = useKeycloakUser();

const {
DATABOX_API_URL,
EXPOSE_API_URL,
Expand All @@ -29,9 +35,6 @@ export default function Dashboard({}: Props) {

console.debug('config', config);

const theme = useTheme();
const isLarge = useMediaQuery(theme.breakpoints.up('sm'));

return (
<Container>
{isLarge && (
Expand All @@ -45,16 +48,16 @@ export default function Dashboard({}: Props) {
}}
>
{STACK_NAME}
<Chip
{user && <Chip
icon={<SellIcon/>}
label={STACK_VERSION}
color={'info'}
/>
/>}
</Typography>
</DashboardBar>
)}

{isLarge && DEV_MODE && (
{user && isLarge && DEV_MODE && (
<Alert
sx={{
mt: 2,
Expand All @@ -73,15 +76,15 @@ export default function Dashboard({}: Props) {
spacing={2}
>
<Service
mainUrl={config.keycloakUrl}
mainUrl={`${config.keycloakUrl}/admin/${config.realmName}/console`}
title={`Identity Manager`}
description={`Keycloak IAM`}
logo={keycloakImg}
links={[
{
icon: <ApiIcon/>,
href: config.keycloakUrl,
title: `Keycloak Home`,
icon: <AdminPanelSettingsIcon />,
href: `${config.keycloakUrl}/admin/master/console`,
title: `Master Admin`,
},
]}
/>
Expand Down
14 changes: 13 additions & 1 deletion dashboard/client/src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {oauthClient} from './lib/apiClient';
import {AuthenticationProvider, SessionExpireContainer, useAuthorizationCode} from '@alchemy/react-auth';
import {FullPageLoader} from '@alchemy/phrasea-ui';
import Dashboard from "./Dashboard.tsx";

type Props = {};

export default function Root({}: Props) {
useAuthorizationCode({
const {
error,
hasCode,
} = useAuthorizationCode({
oauthClient,
allowNoCode: true,
navigate: (path, {replace} = {}) => {
if (replace) {
document.location.replace(path);
Expand All @@ -17,8 +22,15 @@ export default function Root({}: Props) {
successUri: '/'
});

if (error) {
return <div>
{error.toString()}
</div>
}

return (
<AuthenticationProvider oauthClient={oauthClient}>
{hasCode && <FullPageLoader/>}
<SessionExpireContainer/>
<Dashboard />
</AuthenticationProvider>
Expand Down
8 changes: 5 additions & 3 deletions databox/client/src/components/Layout/MainAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ export default function MainAppBar({onToggleLeftPanel}: Props) {
username={username}
accountUrl={getAccountUrl()}
onLogout={logout}
actions={({closeMenu}) => <>
actions={({closeMenu}) => [
<MenuItem
key={'change_theme'}
onClick={() => {
openModal(ChangeTheme);
closeMenu();
Expand All @@ -152,8 +153,9 @@ export default function MainAppBar({onToggleLeftPanel}: Props) {
'Change theme'
)}
/>
</MenuItem>
</MenuItem>,
<MenuItem
key={'theme_editor'}
onClick={() => {
openModal(
ThemeEditor,
Expand Down Expand Up @@ -181,7 +183,7 @@ export default function MainAppBar({onToggleLeftPanel}: Props) {
)}
/>
</MenuItem>
</>}
]}
/>
)}
</Box>
Expand Down
6 changes: 5 additions & 1 deletion lib/js/auth/src/client/OAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ export default class OAuthClient {

const t = this.storage.getItem(this.tokenStorageKey);
if (t) {
return this.tokensCache = JSON.parse(t) as AuthTokens;
const tokens = JSON.parse(t) as AuthTokens;

this.handleSessionTimeout(tokens)

return this.tokensCache = tokens;
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/js/phrasea-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import NotFoundPage from "./src/components/Error/NotFoundPage";
import ErrorPage from "./src/components/Error/ErrorPage";
import ErrorLayout from "./src/components/Error/ErrorLayout";
import UserMenu from "./src/components/UserMenu";
import FullPageLoader from "./src/components/FullPageLoader";

export {
NotFoundPage,
ErrorPage,
ErrorLayout,
UserMenu,
FullPageLoader,
};
17 changes: 17 additions & 0 deletions lib/js/phrasea-ui/src/components/FullPageLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {CircularProgress} from "@mui/material";

type Props = {};

export default function FullPageLoader({}: Props) {
return <div style={{
background: 'rgba(0,0,0,0.3)',
position: 'absolute',
height: '100vh',
width: '100vw',
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}>
<CircularProgress/>
</div>
}
80 changes: 44 additions & 36 deletions lib/js/phrasea-ui/src/components/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {useTranslation} from 'react-i18next';
type Props = {
actions?: (props: {
closeMenu: () => void,
}) => ReactNode;
}) => ReactNode[];
accountUrl?: string;
onLogout?: () => void;
menuHeight: number;
Expand All @@ -39,6 +39,48 @@ export default function UserMenu({
setAnchorElUser(null);
};

let menuItems: ReactNode[] = [];
if (accountUrl) {
menuItems.push(<MenuItem
component={'a'}
href={accountUrl}
key={'account'}
>
<ListItemIcon>
<AccountBoxIcon/>
</ListItemIcon>
<ListItemText
primary={t(
'ui:menu.account',
'My account'
)}
secondary={username}
/>
</MenuItem>)
}
if (actions) {
menuItems = menuItems.concat(actions({
closeMenu: handleCloseUserMenu,
}));
}
if (onLogout) {
menuItems.push(<Divider key={'logout_div'} light/>);
menuItems.push(<MenuItem
key={'logout'}
onClick={onLogout}
>
<ListItemIcon>
<LogoutIcon/>
</ListItemIcon>
<ListItemText
primary={t(
'ui:menu.logout',
'Logout'
)}
/>
</MenuItem>);
}

return <>
<Tooltip title="Open settings">
<IconButton
Expand Down Expand Up @@ -75,41 +117,7 @@ export default function UserMenu({
open={Boolean(anchorElUser)}
onClose={handleCloseUserMenu}
>
{accountUrl && <MenuItem
component={'a'}
href={accountUrl}
>
<ListItemIcon>
<AccountBoxIcon/>
</ListItemIcon>
<ListItemText
primary={t(
'ui:menu.account',
'My account'
)}
secondary={username}
/>
</MenuItem>}
{actions && actions({
closeMenu: handleCloseUserMenu,
})}
{onLogout && <>
<Divider light/>
<MenuItem
key={'logout'}
onClick={onLogout}
>
<ListItemIcon>
<LogoutIcon/>
</ListItemIcon>
<ListItemText
primary={t(
'ui:menu.logout',
'Logout'
)}
/>
</MenuItem>
</>}
{menuItems}
</Menu>
</>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function AuthenticationProvider({
setTokens(undefined);
}
};

const refreshTokenListener: AuthEventHandler<RefreshTokenEvent> = async (event) => {
if (!event.preventDefault) {
setTokens(event.tokens);
Expand Down
11 changes: 9 additions & 2 deletions lib/js/react-auth/src/hooks/useAuthorizationCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ export function useAuthorizationCode({
successUri,
errorHandler,
navigate,
}: Props) {
allowNoCode,
}: {
allowNoCode?: boolean;
} & Props) {
const {setTokens} = useAuth();
const [error, setError] = React.useState<any>();
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');

useEffectOnce(() => {
const code = urlParams.get('code');
if (!code) {
setError(new Error(`Missing authorization code.`));
if (!allowNoCode) {
setError(new Error(`Missing authorization code.`));
}

return;
}
Expand Down Expand Up @@ -84,5 +90,6 @@ export function useAuthorizationCode({

return {
error,
hasCode: Boolean(code),
}
}
1 change: 0 additions & 1 deletion lib/js/react-hooks/src/useTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function useTimeout(handler: () => void | undefined, delay: number | unde
}

if (undefined !== delay && handler) {
console.log('setTimeout delay', delay);
timeoutRef.current = setTimeout(handler, delay);
}

Expand Down
1 change: 0 additions & 1 deletion lib/js/visual-workflow/src/stories/Updates.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Story = StoryObj<typeof WorkflowUpdater>;

const rerun = async (jobId: string): Promise<void> => {
return new Promise<void>((resolve) => {
console.log(`Rerunning job ${jobId}`);
setTimeout(() => {
resolve();
}, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Story = StoryObj<typeof VisualWorkflow>;

const rerun = async (jobId: string): Promise<void> => {
return new Promise<void>((resolve) => {
console.log(`Rerunning job ${jobId}`);
setTimeout(() => {
resolve();
}, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Story = StoryObj<typeof WorkflowHeader>;

const refresh = async (): Promise<void> => {
return new Promise<void>((resolve) => {
console.log(`Refreshing workflow`);
setTimeout(() => {
resolve();
}, 1000);
Expand Down

0 comments on commit 0e9c31b

Please sign in to comment.