[WIP] add ids

This commit is contained in:
Sina Blattmann 2023-04-06 09:49:15 +02:00
parent 68720b32ab
commit c9f84a04c5
11 changed files with 79 additions and 26 deletions

View File

@ -28,6 +28,7 @@
color: #61dafb; color: #61dafb;
} }
@keyframes App-logo-spin { @keyframes App-logo-spin {
from { from {
transform: rotate(0deg); transform: rotate(0deg);

View File

@ -35,18 +35,12 @@ const App = () => {
locale={language} locale={language}
defaultLocale="EN" defaultLocale="EN"
> >
<Container maxWidth="xl" sx={{ marginTop: 2 }}> <Container maxWidth="xl" sx={{ marginTop: 2, height: "100vh" }}>
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid item xs={3}> <Grid item xs={3}>
<NavigationButtons /> <NavigationButtons />
</Grid> </Grid>
<Grid <Grid item xs={9} container justifyContent="flex-end">
item
xs={9}
container
justifyContent="flex-end"
sx={{ px: 1, pt: 1 }}
>
<LanguageSelect language={language} setLanguage={setLanguage} /> <LanguageSelect language={language} setLanguage={setLanguage} />
<LogoutButton removeToken={removeToken} /> <LogoutButton removeToken={removeToken} />
</Grid> </Grid>

View File

@ -0,0 +1,24 @@
import { createContext, ReactNode, useState } from "react";
import { I_User } from "../../util/user.util";
interface InstallationContextProviderProps {
currentUser?: I_User;
setCurrentUser: (value: I_User) => void;
}
export const UserContext = createContext<InstallationContextProviderProps>({
currentUser: {} as I_User,
setCurrentUser: () => {},
});
const UserContextProvider = ({ children }: { children: ReactNode }) => {
const [currentUser, setCurrentUser] = useState<I_User>();
return (
<UserContext.Provider value={{ currentUser, setCurrentUser }}>
{children}
</UserContext.Provider>
);
};
export default UserContextProvider;

View File

@ -11,7 +11,7 @@ const AccessManagement = () => {
<Grid container sx={{ mt: 1 }}> <Grid container sx={{ mt: 1 }}>
<Grid item xs={6}> <Grid item xs={6}>
<AvailableUserDialog /> <AvailableUserDialog />
<InnovenergyList> <InnovenergyList id="access-management-list">
<UsersWithDirectAccess /> <UsersWithDirectAccess />
<UsersWithInheritedAccess /> <UsersWithInheritedAccess />
</InnovenergyList> </InnovenergyList>

View File

@ -48,6 +48,7 @@ const AvailableUserDialog = () => {
return ( return (
<> <>
<Dialog <Dialog
id="available-user-dialog"
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
aria-labelledby="customized-dialog-title" aria-labelledby="customized-dialog-title"
open={open} open={open}
@ -57,12 +58,14 @@ const AvailableUserDialog = () => {
}} }}
scroll="paper" scroll="paper"
> >
<DialogTitle>Create new folder</DialogTitle> <DialogTitle id="available-user-dialog-title">
<DialogContent> Create new folder
</DialogTitle>
<DialogContent id="available-user-dialog-content">
<Autocomplete <Autocomplete
sx={{ width: "500px" }} sx={{ width: "500px" }}
multiple multiple
id="tags-standard" id="available-user-dialog-autocomplete"
options={getAvailableUsersForResource()} options={getAvailableUsersForResource()}
getOptionLabel={(option) => option.name} getOptionLabel={(option) => option.name}
renderInput={(params) => ( renderInput={(params) => (
@ -76,8 +79,9 @@ const AvailableUserDialog = () => {
onChange={(event, values) => setSelectedUsers(values)} onChange={(event, values) => setSelectedUsers(values)}
/> />
</DialogContent> </DialogContent>
<DialogActions> <DialogActions id="available-user-dialog-actions">
<InnovenergyButton <InnovenergyButton
id="available-user-dialog-grant-access-button"
type="submit" type="submit"
sx={{ height: 40, ml: 2 }} sx={{ height: 40, ml: 2 }}
onClick={handleGrant} onClick={handleGrant}
@ -86,7 +90,11 @@ const AvailableUserDialog = () => {
</InnovenergyButton> </InnovenergyButton>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
<InnovenergyButton type="submit" onClick={() => setOpen(true)}> <InnovenergyButton
id="available-user-dialog-submit-button"
type="submit"
onClick={() => setOpen(true)}
>
<FormattedMessage id="grantAccess" defaultMessage="Grant access" /> <FormattedMessage id="grantAccess" defaultMessage="Grant access" />
</InnovenergyButton> </InnovenergyButton>
</> </>

View File

@ -1,7 +1,12 @@
import { List } from "@mui/material"; import { List } from "@mui/material";
import { ReactNode } from "react"; import { ReactNode } from "react";
const InnovenergyList = ({ children }: { children: ReactNode }) => { interface InnovenergyListProps {
id: string;
children: ReactNode;
}
const InnovenergyList = (props: InnovenergyListProps) => {
return ( return (
<List <List
sx={{ sx={{
@ -14,7 +19,7 @@ const InnovenergyList = ({ children }: { children: ReactNode }) => {
component="nav" component="nav"
aria-labelledby="nested-list-subheader" aria-labelledby="nested-list-subheader"
> >
{children} {props.children}
</List> </List>
); );
}; };

View File

@ -43,21 +43,30 @@ const UsersWithDirectAccess = () => {
return ( return (
<Fragment key={user.id}> <Fragment key={user.id}>
<ListItem <ListItem
id={"direct-access-user-" + user.id}
secondaryAction={ secondaryAction={
<IconButton <IconButton
id={"direct-access-user-icon-button" + user.id}
onClick={() => handleIconClick(user.id)} onClick={() => handleIconClick(user.id)}
edge="end" edge="end"
> >
<PersonRemoveIcon id={user.id.toString()} /> <PersonRemoveIcon
id={"direct-access-user-icon" + user.id}
/>
</IconButton> </IconButton>
} }
> >
<ListItemAvatar> <ListItemAvatar id={"direct-access-user-item-avatar" + user.id}>
<Avatar> <Avatar id={"direct-access-user-avatar" + user.id}>
<PersonIcon /> <PersonIcon
id={"direct-access-user-person-icon" + user.id}
/>
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText primary={user.name} /> <ListItemText
id={"direct-access-user-list-text-" + user.id}
primary={user.name}
/>
</ListItem> </ListItem>
<Divider /> <Divider />
</Fragment> </Fragment>

View File

@ -30,18 +30,24 @@ const UsersWithInheritedAccess = () => {
({ user, folderName }: UserWithInheritedAccess) => { ({ user, folderName }: UserWithInheritedAccess) => {
return ( return (
<Fragment key={user.id}> <Fragment key={user.id}>
<ListItem> <ListItem id={"inherited-access-user-list-item" + user.id}>
<ListItemAvatar> <ListItemAvatar
<Avatar> id={"inherited-access-user-list-item-avatar-" + user.id}
<PersonIcon /> >
<Avatar id={"inherited-access-user-avatar-" + user.id}>
<PersonIcon
id={"inherited-access-user-person-icon-" + user.id}
/>
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
<ListItemText <ListItemText
id={"inherited-access-user-list-item-text-" + user.id}
primary={user.name} primary={user.name}
secondary={ secondary={
<> <>
Inherited access from{" "} Inherited access from{" "}
<Link <Link
id={"inherited-access-user-link-" + user.id}
to={ to={
routes.groups + routes.manageAccess + user.parentId routes.groups + routes.manageAccess + user.parentId
} }

View File

@ -6,11 +6,13 @@ interface I_InnovenergyButtonProps {
type?: "button" | "submit" | "reset" | undefined; type?: "button" | "submit" | "reset" | undefined;
onClick?: React.MouseEventHandler<HTMLButtonElement>; onClick?: React.MouseEventHandler<HTMLButtonElement>;
sx?: SxProps<Theme> | undefined; sx?: SxProps<Theme> | undefined;
id?: string;
} }
const InnovenergyButton = (props: I_InnovenergyButtonProps) => { const InnovenergyButton = (props: I_InnovenergyButtonProps) => {
return ( return (
<Button <Button
id={props.id}
variant="contained" variant="contained"
type={props.type} type={props.type}
onClick={props.onClick} onClick={props.onClick}

View File

@ -30,6 +30,7 @@ const UserForm = (props: I_UserFormProps) => {
handleSubmit(formikValues) handleSubmit(formikValues)
.then(() => { .then(() => {
setOpen(true); setOpen(true);
setLoading(false);
}) })
.catch((err: AxiosError) => { .catch((err: AxiosError) => {
setOpen(true); setOpen(true);

View File

@ -4,6 +4,7 @@ import "./index.css";
import App from "./App"; import App from "./App";
import reportWebVitals from "./reportWebVitals"; import reportWebVitals from "./reportWebVitals";
import { createTheme, ThemeProvider } from "@mui/material"; import { createTheme, ThemeProvider } from "@mui/material";
import UserContextProvider from "./components/Context/UserContextProvider";
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement document.getElementById("root") as HTMLElement
@ -20,7 +21,9 @@ const theme = createTheme({
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<UserContextProvider>
<App /> <App />
</UserContextProvider>
</ThemeProvider> </ThemeProvider>
</React.StrictMode> </React.StrictMode>
); );