Skip to content

Commit d9b7d9d

Browse files
authored
DT-1152: Migrate Components from @mui/styles (#1751)
1 parent dd2784e commit d9b7d9d

10 files changed

+256
-331
lines changed

src/components/common/AddUserAccess.tsx

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useState } from 'react';
22
import _ from 'lodash';
3-
import { CustomTheme } from '@mui/material/styles';
4-
import { createStyles, WithStyles, withStyles } from '@mui/styles';
3+
import { styled } from '@mui/material/styles';
54
import {
65
Typography,
76
Autocomplete,
@@ -10,63 +9,31 @@ import {
109
SelectChangeEvent,
1110
MenuItem,
1211
Button,
12+
Box,
1313
} from '@mui/material';
14-
import clsx from 'clsx';
1514
import isEmail from 'validator/lib/isEmail';
1615

17-
const styles = (theme: CustomTheme) =>
18-
createStyles({
19-
sharingArea: {
20-
display: 'flex',
21-
'flex-direction': 'row',
22-
justifyContent: 'space-between',
23-
alignItems: 'center',
24-
},
25-
emailEntryArea: {
26-
display: 'flex',
27-
},
28-
sharingCol: {
29-
flexGrow: 1,
30-
marginRight: '1rem',
31-
},
32-
permissionsCol: {
33-
flexGrow: 'unset',
34-
width: 150,
35-
},
36-
input: {
37-
backgroundColor: theme.palette.common.white,
38-
borderRadius: theme.spacing(0.5),
39-
},
40-
sharingButtonContainer: {
41-
paddingTop: 22,
42-
},
43-
button: {
44-
backgroundColor: theme.palette.common.link,
45-
color: theme.palette.common.white,
46-
'&:hover': {
47-
backgroundColor: theme.palette.common.link,
48-
},
49-
},
50-
section: {
51-
margin: `${theme.spacing(1)} 0px`,
52-
overflowX: 'hidden',
53-
},
54-
errMessage: {
55-
color: theme.palette.error.main,
56-
},
57-
});
16+
// Styled components (>3 styles)
17+
const SharingArea = styled(Box)({
18+
display: 'flex',
19+
flexDirection: 'row',
20+
justifyContent: 'space-between',
21+
alignItems: 'center',
22+
});
5823

5924
export interface AccessPermission {
6025
policy: string;
6126
disabled: boolean;
6227
}
6328

64-
interface AddUserAccessProps extends WithStyles<typeof styles> {
65-
permissions: AccessPermission[];
66-
onAdd: (policyName: string, usersToAdd: string[]) => void;
29+
interface AddUserAccessProps {
30+
readonly permissions: AccessPermission[];
31+
readonly onAdd: (policyName: string, usersToAdd: string[]) => void;
6732
}
6833

69-
function AddUserAccess({ classes, permissions, onAdd }: AddUserAccessProps) {
34+
// The rest can use sx prop as they have ≤3 styles
35+
function AddUserAccess(props: AddUserAccessProps) {
36+
const { permissions, onAdd } = props;
7037
const [policyName, setPolicyName] = useState(permissions[0].policy);
7138
const permissionDisplays = permissions.map((perm) =>
7239
perm.policy
@@ -123,8 +90,8 @@ function AddUserAccess({ classes, permissions, onAdd }: AddUserAccessProps) {
12390

12491
return (
12592
<>
126-
<div className={classes.sharingArea} data-cy="manageAccessContainer">
127-
<div className={classes.sharingCol}>
93+
<SharingArea data-cy="manageAccessContainer">
94+
<Box sx={{ flexGrow: 1, marginRight: '1rem' }}>
12895
<Typography variant="subtitle2">People</Typography>
12996
<Autocomplete
13097
multiple
@@ -134,7 +101,10 @@ function AddUserAccess({ classes, permissions, onAdd }: AddUserAccessProps) {
134101
{...params}
135102
variant="outlined"
136103
fullWidth
137-
className={classes.input}
104+
sx={{
105+
backgroundColor: 'common.white',
106+
borderRadius: 0.5,
107+
}}
138108
placeholder="enter email addresses"
139109
onChange={parseEmail}
140110
data-cy="enterEmailBox"
@@ -145,14 +115,23 @@ function AddUserAccess({ classes, permissions, onAdd }: AddUserAccessProps) {
145115
inputValue={addEmailInput}
146116
options={[]}
147117
/>
148-
</div>
149-
<div className={clsx(classes.sharingCol, classes.permissionsCol)}>
118+
</Box>
119+
<Box
120+
sx={{
121+
flexGrow: 'unset',
122+
width: '150px',
123+
marginRight: '1rem',
124+
}}
125+
>
150126
<Typography variant="subtitle2">Permissions</Typography>
151127
<Select
152128
value={policyName}
153129
variant="outlined"
154-
className={classes.input}
155130
fullWidth
131+
sx={{
132+
backgroundColor: 'common.white',
133+
borderRadius: 0.5,
134+
}}
156135
onChange={(event: SelectChangeEvent) => setPolicyName(event.target.value)}
157136
data-cy="roleSelect"
158137
>
@@ -167,24 +146,31 @@ function AddUserAccess({ classes, permissions, onAdd }: AddUserAccessProps) {
167146
</MenuItem>
168147
))}
169148
</Select>
170-
</div>
171-
<div className={classes.sharingButtonContainer}>
149+
</Box>
150+
<Box sx={{ paddingTop: '22px' }}>
172151
<Button
173152
variant="contained"
174153
color="primary"
175154
disableElevation
176155
disabled={!isEmail(addEmailInput) && !_.some(usersToAdd, (user) => isEmail(user))}
177-
className={clsx(classes.button, classes.section)}
156+
sx={{
157+
backgroundColor: 'common.link',
158+
color: 'common.white',
159+
margin: '8px 0px',
160+
'&:hover': {
161+
backgroundColor: 'common.link',
162+
},
163+
}}
178164
onClick={invite}
179165
data-cy="inviteButton"
180166
>
181167
Add
182168
</Button>
183-
</div>
184-
</div>
185-
{err && <div className={classes.errMessage}>{err}</div>}
169+
</Box>
170+
</SharingArea>
171+
{err && <Box sx={{ color: 'error.main' }}>{err}</Box>}
186172
</>
187173
);
188174
}
189175

190-
export default withStyles(styles)(AddUserAccess);
176+
export default AddUserAccess;

src/components/common/Failure.jsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { withStyles } from '@mui/styles';
3+
import { Box } from '@mui/material';
4+
import { styled } from '@mui/material/styles';
45

56
import ErrorIcon from 'media/icons/warning-standard-solid.svg?react';
67

7-
const styles = (theme) => ({
8-
text: {
9-
alignSelf: 'center',
10-
fontFamily: theme.typography.fontFamily,
11-
fontSize: 12,
12-
fontWeight: 600,
13-
padding: `0 0 0 ${theme.spacing(2)}px`,
14-
},
15-
icon: {
16-
fill: theme.palette.primary.contrastText,
17-
height: theme.spacing(4),
18-
},
19-
});
8+
// Use styled component for text since it has >3 styles
9+
const StyledText = styled(Box)(({ theme }) => ({
10+
alignSelf: 'center',
11+
fontFamily: theme.typography.fontFamily,
12+
fontSize: '12px',
13+
fontWeight: 600,
14+
padding: `0 0 0 ${theme.spacing(2)}`,
15+
}));
2016

21-
function Failure({ errString, classes }) {
17+
function Failure({ errString }) {
18+
// Use sx prop for icon since it has ≤3 styles
2219
return (
23-
<div>
24-
<ErrorIcon className={classes.icon} alt="logo" />
25-
<div className={classes.text}>{errString}</div>
26-
</div>
20+
<Box>
21+
<ErrorIcon
22+
sx={{
23+
fill: (theme) => theme.palette.primary.contrastText,
24+
height: (theme) => theme.spacing(4),
25+
}}
26+
alt="logo"
27+
/>
28+
<StyledText>{errString}</StyledText>
29+
</Box>
2730
);
2831
}
2932

3033
Failure.propTypes = {
31-
classes: PropTypes.object.isRequired,
3234
errString: PropTypes.string,
3335
};
3436

35-
export default withStyles(styles)(Failure);
37+
export default Failure;

src/components/common/FullViewSnapshotButton.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mount } from 'cypress/react';
22
import { Router } from 'react-router-dom';
3-
import { ThemeProvider } from '@mui/styles';
3+
import { ThemeProvider } from '@mui/material/styles';
44
import { Provider } from 'react-redux';
55
import React from 'react';
66
import createMockStore from 'redux-mock-store';

src/components/common/FullViewSnapshotButton.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import {
1414
FormLabel,
1515
Link,
1616
TextField,
17+
Box,
1718
CustomTheme,
19+
useTheme,
1820
} from '@mui/material';
21+
import { styled } from '@mui/material/styles';
1922
import React, { Dispatch } from 'react';
2023
import {
2124
BillingProfileModel,
@@ -25,28 +28,23 @@ import {
2528
import { Action } from 'redux';
2629
import { connect } from 'react-redux';
2730
import { isEmpty, now, uniq } from 'lodash';
28-
import { createStyles, withStyles, WithStyles } from '@mui/styles';
2931
import { ManagedGroupMembershipEntry } from 'models/group';
3032
import TerraTooltip from './TerraTooltip';
3133
import JadeDropdown from '../dataset/data/JadeDropdown';
3234
import { useOnMount } from '../../libs/utils';
3335

34-
const styles = (theme: CustomTheme) =>
35-
createStyles({
36-
jadeLink: {
37-
...theme.mixins.jadeLink,
38-
},
39-
});
36+
const StyledLink = styled('span')(({ theme }: { theme: CustomTheme }) => ({
37+
...theme.mixins.jadeLink,
38+
}));
4039

41-
interface FullViewSnapshotButtonProps extends WithStyles<typeof styles> {
40+
interface FullViewSnapshotButtonProps {
4241
dispatch: Dispatch<Action>;
4342
dataset: DatasetModel;
4443
billingProfiles: Array<BillingProfileModel>;
4544
userGroups: Array<ManagedGroupMembershipEntry>;
4645
}
4746

4847
function FullViewSnapshotButton({
49-
classes,
5048
dataset,
5149
dispatch,
5250
billingProfiles,
@@ -120,7 +118,7 @@ function FullViewSnapshotButton({
120118
<DialogTitle id="customized-dialog-title" sx={{ fontSize: '1rem' }}>
121119
Creating snapshot - select a billing project
122120
</DialogTitle>
123-
<div style={{ padding: '0px 24px 16px 24px' }}>
121+
<Box sx={{ padding: '0px 24px 16px 24px' }}>
124122
<FormLabel sx={{ fontWeight: 600, color: 'black' }} htmlFor="snapshot-name" required>
125123
Snapshot Name
126124
</FormLabel>
@@ -151,15 +149,15 @@ function FullViewSnapshotButton({
151149
Do you want to use the Google Billing Project associated with this dataset or would you
152150
like to select a different one?
153151
</Typography>
154-
<div style={{ marginTop: 8 }}>
152+
<Box sx={{ marginTop: '8px' }}>
155153
<FormLabel
156154
sx={{ fontWeight: 600, color: 'black' }}
157155
htmlFor="billing-profile-select"
158156
required
159157
>
160158
Google Billing Project
161159
</FormLabel>
162-
</div>
160+
</Box>
163161
<JadeDropdown
164162
sx={{ height: '2.5rem' }}
165163
disabled={billingProfiles.length <= 1}
@@ -178,15 +176,18 @@ function FullViewSnapshotButton({
178176
}
179177
value={selectedBillingProfile?.profileName || ''}
180178
/>
181-
<div style={{ marginTop: 8 }}>
179+
<Box sx={{ marginTop: '8px' }}>
182180
<FormLabel
183181
sx={{ fontWeight: 600, color: 'black' }}
184182
htmlFor="select-authorization-domain-select"
185183
>
186184
Authorization Domain
187-
<span style={{ fontWeight: 400, color: 'black' }}> - (optional)</span>
185+
<Box component="span" sx={{ fontWeight: 400, color: 'black' }}>
186+
{' '}
187+
- (optional)
188+
</Box>
188189
</FormLabel>
189-
</div>
190+
</Box>
190191
<JadeDropdown
191192
sx={{ height: '2.5rem' }}
192193
disabled={userGroups ? userGroups.length <= 1 : true}
@@ -196,7 +197,7 @@ function FullViewSnapshotButton({
196197
value={selectedAuthDomain || ''}
197198
includeNoneOption={true}
198199
/>
199-
<div>
200+
<Box>
200201
Authorization Domains restrict data access to only specified individuals in a group and
201202
are intended to fulfill requirements you may have for data governed by a compliance
202203
standard, such as federal controlled-access data or HIPAA protected data. They follow
@@ -205,10 +206,10 @@ function FullViewSnapshotButton({
205206
href="https://support.terra.bio/hc/en-us/articles/360026775691-Overview-Managing-access-to-controlled-data-with-Authorization-Domains#h_01J94P49XS1NE5KE4B3NA3A413"
206207
target="_blank"
207208
>
208-
<span className={classes.jadeLink}>When to use an Authorization Domain</span>
209+
<StyledLink theme={useTheme()}>When to use an Authorization Domain</StyledLink>
209210
</Link>
210211
.
211-
</div>
212+
</Box>
212213
<DialogActions sx={{ display: 'flex', justifyContent: 'flex-end' }}>
213214
<Button onClick={onDismiss} variant="outlined">
214215
Cancel
@@ -226,7 +227,7 @@ function FullViewSnapshotButton({
226227
Create
227228
</Button>
228229
</DialogActions>
229-
</div>
230+
</Box>
230231
</Dialog>
231232
</>
232233
);
@@ -240,4 +241,4 @@ function mapStateToProps(state: TdrState) {
240241
};
241242
}
242243

243-
export default connect(mapStateToProps)(withStyles(styles)(FullViewSnapshotButton));
244+
export default connect(mapStateToProps)(FullViewSnapshotButton);

0 commit comments

Comments
 (0)