Skip to content

Commit

Permalink
Migrate makeStyles to MUI v5 (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel authored Feb 2, 2024
1 parent 17379a7 commit 58e02d6
Show file tree
Hide file tree
Showing 7 changed files with 2,350 additions and 2,957 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@emotion/styled": "^11.10.6",
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.8",
"@mui/styles": "5.14.10",
"papaparse": "^5.4.1",
"prop-types": "^15.8.1",
"ra-language-chinese": "^2.0.10",
Expand Down
21 changes: 1 addition & 20 deletions src/components/ImportFeature.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import React, { useState } from "react";
import {
Button as ReactAdminButton,
useDataProvider,
useNotify,
Title,
} from "react-admin";
import { useDataProvider, useNotify, Title } from "react-admin";
import { parse as parseCsv, unparse as unparseCsv } from "papaparse";
import GetAppIcon from "@mui/icons-material/GetApp";
import {
Button,
Card,
Expand All @@ -23,19 +17,6 @@ import { generateRandomUser } from "./users";

const LOGGING = true;

export const ImportButton = ({ label, variant = "text" }) => {
return (
<ReactAdminButton
color="primary"
component="span"
variant={variant}
label={label}
>
<GetAppIcon style={{ transform: "rotate(180deg)", fontSize: "20" }} />
</ReactAdminButton>
);
};

const expectedFields = ["id", "displayname"].sort();
const optionalFields = [
"user_type",
Expand Down
2 changes: 0 additions & 2 deletions src/components/LoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ const LoginPage = ({ theme }) => {
type="submit"
color="primary"
disabled={loading || !supportPassAuth}
className={classes.button}
fullWidth
>
{loading && <CircularProgress size={25} thickness={2} />}
Expand All @@ -359,7 +358,6 @@ const LoginPage = ({ theme }) => {
color="secondary"
onClick={handleSSO}
disabled={loading || ssoBaseUrl === ""}
className={classes.button}
fullWidth
>
{loading && <CircularProgress size={25} thickness={2} />}
Expand Down
17 changes: 4 additions & 13 deletions src/components/RoomDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Fragment } from "react";
import { Avatar, Chip } from "@mui/material";
import { connect } from "react-redux";
import FolderSharedIcon from "@mui/icons-material/FolderShared";
import { makeStyles } from "@material-ui/core/styles";
import {
BooleanField,
BulkDeleteButton,
Expand All @@ -23,13 +22,6 @@ import {
useUnselectAll,
} from "react-admin";

const useStyles = makeStyles({
small: {
height: "40px",
width: "40px",
},
});

const RoomDirectoryPagination = props => (
<Pagination {...props} rowsPerPageOptions={[100, 500, 1000, 2000]} />
);
Expand Down Expand Up @@ -158,19 +150,19 @@ const RoomDirectoryFilter = ({ ...props }) => {
label={translate("resources.rooms.fields.room_id")}
source="room_id"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
<Chip
label={translate("resources.rooms.fields.topic")}
source="topic"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
<Chip
label={translate("resources.rooms.fields.canonical_alias")}
source="canonical_alias"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
</Filter>
);
Expand All @@ -181,7 +173,6 @@ export const FilterableRoomDirectoryList = ({
dispatch,
...props
}) => {
const classes = useStyles();
const filter = roomDirectoryFilters;
const roomIdFilter = filter && filter.room_id ? true : false;
const topicFilter = filter && filter.topic ? true : false;
Expand All @@ -199,7 +190,7 @@ export const FilterableRoomDirectoryList = ({
<AvatarField
source="avatar_src"
sortable={false}
className={classes.small}
sx={{ height: "40px", width: "40px" }}
label="resources.rooms.fields.avatar"
/>
<TextField
Expand Down
27 changes: 12 additions & 15 deletions src/components/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
} from "react-admin";
import get from "lodash/get";
import PropTypes from "prop-types";
import { makeStyles } from "@material-ui/core/styles";
import { Tooltip, Typography, Chip } from "@mui/material";
import Box from "@mui/material/Box";
import FastForwardIcon from "@mui/icons-material/FastForward";
import HttpsIcon from "@mui/icons-material/Https";
import NoEncryptionIcon from "@mui/icons-material/NoEncryption";
Expand All @@ -50,13 +50,6 @@ const date_format = {
second: "2-digit",
};

const useStyles = makeStyles(theme => ({
helper_forward_extremities: {
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
margin: "0.5em",
},
}));

const RoomPagination = props => (
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
);
Expand Down Expand Up @@ -129,7 +122,6 @@ const RoomShowActions = ({ basePath, data, resource }) => {
};

export const RoomShow = props => {
const classes = useStyles({ props });
const translate = useTranslate();
return (
<Show {...props} actions={<RoomShowActions />} title={<RoomTitle />}>
Expand Down Expand Up @@ -281,9 +273,14 @@ export const RoomShow = props => {
icon={<FastForwardIcon />}
path="forward_extremities"
>
<div className={classes.helper_forward_extremities}>
<Box
sx={{
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
margin: "0.5em",
}}
>
{translate("resources.rooms.helper.forward_extremities")}
</div>
</Box>
<ReferenceManyField
reference="forward_extremities"
target="room_id"
Expand Down Expand Up @@ -329,25 +326,25 @@ const RoomFilter = ({ ...props }) => {
label={translate("resources.rooms.fields.joined_local_members")}
source="joined_local_members"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
<Chip
label={translate("resources.rooms.fields.state_events")}
source="state_events"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
<Chip
label={translate("resources.rooms.fields.version")}
source="version"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
<Chip
label={translate("resources.rooms.fields.federatable")}
source="federatable"
defaultValue={false}
style={{ marginBottom: 8 }}
sx={{ marginBottom: "8px" }}
/>
</Filter>
);
Expand Down
25 changes: 5 additions & 20 deletions src/components/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,13 @@ import { Link } from "react-router-dom";
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
import { DeviceRemoveButton } from "./devices";
import { ProtectMediaButton, QuarantineMediaButton } from "./media";
import { makeStyles } from "@material-ui/core/styles";

const redirect = () => {
return {
pathname: "/import_users",
};
};

const useStyles = makeStyles({
small: {
height: "40px",
width: "40px",
},
large: {
height: "120px",
width: "120px",
float: "right",
},
});

const choices_medium = [
{ id: "email", name: "resources.users.email" },
{ id: "msisdn", name: "resources.users.msisdn" },
Expand Down Expand Up @@ -130,7 +117,7 @@ const UserListActions = ({
/>
{/* Add your custom actions */}
<Button component={Link} to={redirect} label="CSV Import">
<GetAppIcon style={{ transform: "rotate(180deg)", fontSize: "20" }} />
<GetAppIcon sx={{ transform: "rotate(180deg)", fontSize: "20px" }} />
</Button>
</TopToolbar>
);
Expand Down Expand Up @@ -169,12 +156,11 @@ const UserBulkActionButtons = props => (
</Fragment>
);

const AvatarField = ({ source, className, record = {} }) => (
<Avatar src={record[source]} className={className} />
const AvatarField = ({ source, record = {}, sx }) => (
<Avatar src={record[source]} sx={sx} />
);

export const UserList = props => {
const classes = useStyles();
return (
<List
{...props}
Expand All @@ -188,7 +174,7 @@ export const UserList = props => {
<Datagrid rowClick="edit">
<AvatarField
source="avatar_src"
className={classes.small}
sx={{ height: "40px", width: "40px" }}
sortBy="avatar_url"
/>
<TextField source="id" sortBy="name" />
Expand Down Expand Up @@ -344,7 +330,6 @@ const UserTitle = props => {
};

export const UserEdit = props => {
const classes = useStyles();
const translate = useTranslate();
return (
<Edit {...props} title={<UserTitle />} actions={<UserEditActions />}>
Expand All @@ -356,7 +341,7 @@ export const UserEdit = props => {
<AvatarField
source="avatar_src"
sortable={false}
className={classes.large}
sx={{ height: "120px", width: "120px", float: "right" }}
/>
<TextInput source="id" disabled />
<TextInput source="displayname" />
Expand Down
Loading

0 comments on commit 58e02d6

Please sign in to comment.