Skip to content

Commit bc839b6

Browse files
authored
Migration of the remaining components (#530)
* Add useLazyLoadQuery to ViewerProfile * Add useFragment to UserProfile * Add useLazyLoadQuery to Home * Add useLazyLoadQuery to TaskCommandLogs * Add useLazyLoadQuery to ViewerTopRepositories * Add useFragment to LastDefaultBranchBuildRow * Add useSubscription to LastDefaultBranchBuildRow * Add useFragment to AccountInformation * Add useFragment to HookNameChip * Add useFragment to AccountsSwitch
1 parent 533eae3 commit bc839b6

File tree

11 files changed

+175
-216
lines changed

11 files changed

+175
-216
lines changed

src/AllRoutes.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ function AllRoutes() {
165165
<ChevronLeftIcon />
166166
</IconButton>
167167
</div>
168-
<ViewerTopRepositories className={classes.topRepositories} />
168+
<Suspense fallback={<CirrusLinearProgress />}>
169+
<ViewerTopRepositories className={classes.topRepositories} />
170+
</Suspense>
169171
</Drawer>
170172
</nav>
171173
);

src/components/account/AccountInformation.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { createFragmentContainer } from 'react-relay';
2+
import { useFragment } from 'react-relay';
33
import { graphql } from 'babel-plugin-relay/macro';
44

55
import Avatar from '@mui/material/Avatar';
@@ -10,7 +10,7 @@ import ListItemIcon from '@mui/material/ListItemIcon';
1010
import ListItemText from '@mui/material/ListItemText';
1111
import { navigateHelper } from '../../utils/navigateHelper';
1212
import { useNavigate } from 'react-router-dom';
13-
import { AccountInformation_viewer } from './__generated__/AccountInformation_viewer.graphql';
13+
import { AccountInformation_viewer$key } from './__generated__/AccountInformation_viewer.graphql';
1414
import ManageAccountsIcon from '@mui/icons-material/ManageAccounts';
1515
import DirectionsRun from '@mui/icons-material/DirectionsRun';
1616
import Button from '@mui/material/Button';
@@ -27,10 +27,18 @@ const useStyles = makeStyles(theme => {
2727
});
2828

2929
interface Props {
30-
viewer: AccountInformation_viewer;
30+
viewer: AccountInformation_viewer$key;
3131
}
3232

33-
function AccountInformation(props: Props) {
33+
export default function AccountInformation(props: Props) {
34+
let viewer = useFragment(
35+
graphql`
36+
fragment AccountInformation_viewer on User {
37+
avatarURL
38+
}
39+
`,
40+
props.viewer,
41+
);
3442
let navigate = useNavigate();
3543
const [anchorEl, setAnchorEl] = React.useState(null);
3644

@@ -42,7 +50,6 @@ function AccountInformation(props: Props) {
4250
setAnchorEl(null);
4351
};
4452

45-
let { viewer } = props;
4653
let classes = useStyles();
4754

4855
if (!viewer) {
@@ -94,11 +101,3 @@ function AccountInformation(props: Props) {
94101
</div>
95102
);
96103
}
97-
98-
export default createFragmentContainer(AccountInformation, {
99-
viewer: graphql`
100-
fragment AccountInformation_viewer on User {
101-
avatarURL
102-
}
103-
`,
104-
});

src/components/account/UserProfile.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { useEffect } from 'react';
22
import { useNavigate } from 'react-router-dom';
3-
import { createFragmentContainer } from 'react-relay';
3+
import { useFragment } from 'react-relay';
44
import { graphql } from 'babel-plugin-relay/macro';
55
import Tooltip from '@mui/material/Tooltip';
66
import { makeStyles } from '@mui/styles';
77
import Card from '@mui/material/Card';
88
import CardHeader from '@mui/material/CardHeader';
99
import { navigateHelper } from '../../utils/navigateHelper';
1010
import IconButton from '@mui/material/IconButton';
11-
import { UserProfile_user } from './__generated__/UserProfile_user.graphql';
11+
import { UserProfile_user$key } from './__generated__/UserProfile_user.graphql';
1212
import { Helmet as Head } from 'react-helmet';
1313
import Settings from '@mui/icons-material/Settings';
1414
import OwnerPlatformIcon from '../icons/OwnerPlatformIcon';
@@ -30,13 +30,25 @@ const useStyles = makeStyles(theme => {
3030
});
3131

3232
interface Props {
33-
user: UserProfile_user;
33+
user: UserProfile_user$key;
3434
}
3535

36-
function UserProfile(props: Props) {
36+
export default function UserProfile(props: Props) {
37+
let user = useFragment(
38+
graphql`
39+
fragment UserProfile_user on User {
40+
relatedOwners {
41+
platform
42+
name
43+
uid
44+
}
45+
}
46+
`,
47+
props.user,
48+
);
49+
3750
const navigate = useNavigate();
3851

39-
let { user } = props;
4052
let classes = useStyles();
4153

4254
useEffect(() => {
@@ -84,15 +96,3 @@ function UserProfile(props: Props) {
8496
</div>
8597
);
8698
}
87-
88-
export default createFragmentContainer(UserProfile, {
89-
user: graphql`
90-
fragment UserProfile_user on User {
91-
relatedOwners {
92-
platform
93-
name
94-
uid
95-
}
96-
}
97-
`,
98-
});

src/components/builds/LastDefaultBranchBuildMiniRow.tsx

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import React, { useEffect } from 'react';
2-
import { createFragmentContainer, requestSubscription } from 'react-relay';
1+
import React, { useMemo } from 'react';
2+
import { useFragment, useSubscription } from 'react-relay';
33
import { graphql } from 'babel-plugin-relay/macro';
4-
import environment from '../../createRelayEnvironment';
54
import TableCell from '@mui/material/TableCell';
65
import TableRow from '@mui/material/TableRow';
76
import { makeStyles } from '@mui/styles';
87
import { navigateBuildHelper } from '../../utils/navigateHelper';
98
import RepositoryNameChip from '../chips/RepositoryNameChip';
109
import BuildStatusChip from '../chips/BuildStatusChip';
11-
import { LastDefaultBranchBuildMiniRow_repository } from './__generated__/LastDefaultBranchBuildMiniRow_repository.graphql';
10+
import { LastDefaultBranchBuildMiniRow_repository$key } from './__generated__/LastDefaultBranchBuildMiniRow_repository.graphql';
1211
import { useNavigate } from 'react-router-dom';
1312
import MarkdownTypography from '../common/MarkdownTypography';
1413

@@ -33,25 +32,36 @@ const useStyles = makeStyles(theme => {
3332
});
3433

3534
interface Props {
36-
repository: LastDefaultBranchBuildMiniRow_repository;
35+
repository: LastDefaultBranchBuildMiniRow_repository$key;
3736
}
3837

39-
function LastDefaultBranchBuildRow(props: Props) {
40-
useEffect(() => {
41-
let variables = { repositoryID: props.repository.id };
38+
export default function LastDefaultBranchBuildRow(props: Props) {
39+
let repository = useFragment(
40+
graphql`
41+
fragment LastDefaultBranchBuildMiniRow_repository on Repository {
42+
id
43+
lastDefaultBranchBuild {
44+
id
45+
changeMessageTitle
46+
...BuildStatusChip_build
47+
}
48+
...RepositoryNameChip_repository
49+
}
50+
`,
51+
props.repository,
52+
);
4253

43-
const subscription = requestSubscription(environment, {
54+
const buildSubscriptionConfig = useMemo(
55+
() => ({
56+
variables: { repositoryID: repository.id },
4457
subscription: buildSubscription,
45-
variables: variables,
46-
});
47-
return () => {
48-
subscription.dispose();
49-
};
50-
}, [props.repository.id]);
58+
}),
59+
[repository.id],
60+
);
61+
useSubscription(buildSubscriptionConfig);
5162

5263
let navigate = useNavigate();
5364

54-
let { repository } = props;
5565
let classes = useStyles();
5666
let build = repository.lastDefaultBranchBuild;
5767
if (!build) {
@@ -76,17 +86,3 @@ function LastDefaultBranchBuildRow(props: Props) {
7686
</TableRow>
7787
);
7888
}
79-
80-
export default createFragmentContainer(LastDefaultBranchBuildRow, {
81-
repository: graphql`
82-
fragment LastDefaultBranchBuildMiniRow_repository on Repository {
83-
id
84-
lastDefaultBranchBuild {
85-
id
86-
changeMessageTitle
87-
...BuildStatusChip_build
88-
}
89-
...RepositoryNameChip_repository
90-
}
91-
`,
92-
});

src/components/chips/HookNameChip.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import React from 'react';
33
import Avatar from '@mui/material/Avatar';
44
import Chip from '@mui/material/Chip';
55
import Functions from '@mui/icons-material/Functions';
6-
import { createFragmentContainer } from 'react-relay';
6+
import { useFragment } from 'react-relay';
77
import { graphql } from 'babel-plugin-relay/macro';
88
import { makeStyles } from '@mui/styles';
99
import { navigateHookHelper } from '../../utils/navigateHelper';
1010
import { useNavigate } from 'react-router-dom';
11-
import { HookNameChip_hook } from './__generated__/HookNameChip_hook.graphql';
11+
import { HookNameChip_hook$key } from './__generated__/HookNameChip_hook.graphql';
1212

1313
const useStyles = makeStyles(theme => {
1414
return {
@@ -22,12 +22,21 @@ const useStyles = makeStyles(theme => {
2222
});
2323

2424
interface Props {
25-
hook: HookNameChip_hook;
25+
hook: HookNameChip_hook$key;
2626
className?: string;
2727
}
2828

29-
let HookNameChip = (props: Props) => {
30-
const { hook, className } = props;
29+
export default function HookNameChip(props: Props) {
30+
let hook = useFragment(
31+
graphql`
32+
fragment HookNameChip_hook on Hook {
33+
id
34+
name
35+
}
36+
`,
37+
props.hook,
38+
);
39+
const { className } = props;
3140
let classes = useStyles();
3241
let navigate = useNavigate();
3342

@@ -44,13 +53,4 @@ let HookNameChip = (props: Props) => {
4453
}
4554
/>
4655
);
47-
};
48-
49-
export default createFragmentContainer(HookNameChip, {
50-
hook: graphql`
51-
fragment HookNameChip_hook on Hook {
52-
id
53-
name
54-
}
55-
`,
56-
});
56+
}

src/components/common/AccountSwitch.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { useNavigate } from 'react-router-dom';
3-
import { createFragmentContainer } from 'react-relay';
3+
import { useFragment } from 'react-relay';
44
import { graphql } from 'babel-plugin-relay/macro';
55

66
import Menu from '@mui/material/Menu';
@@ -10,13 +10,25 @@ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
1010

1111
import { navigateHelper } from '../../utils/navigateHelper';
1212

13-
import { AccountSwitch_viewer } from './__generated__/AccountSwitch_viewer.graphql';
13+
import { AccountSwitch_viewer$key } from './__generated__/AccountSwitch_viewer.graphql';
1414

1515
interface AccountSwitchProps {
16-
viewer?: AccountSwitch_viewer;
16+
viewer?: AccountSwitch_viewer$key;
1717
}
1818

19-
const AccountsSwitch = ({ viewer }: AccountSwitchProps) => {
19+
export default function AccountsSwitch(props: AccountSwitchProps) {
20+
let viewer = useFragment(
21+
graphql`
22+
fragment AccountSwitch_viewer on User {
23+
relatedOwners {
24+
platform
25+
name
26+
}
27+
}
28+
`,
29+
props.viewer,
30+
);
31+
2032
const navigate = useNavigate();
2133

2234
const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(null);
@@ -53,15 +65,4 @@ const AccountsSwitch = ({ viewer }: AccountSwitchProps) => {
5365
</Menu>
5466
</>
5567
);
56-
};
57-
58-
export default createFragmentContainer(AccountsSwitch, {
59-
viewer: graphql`
60-
fragment AccountSwitch_viewer on User {
61-
relatedOwners {
62-
platform
63-
name
64-
}
65-
}
66-
`,
67-
});
68+
}

src/components/tasks/TaskCommandList.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { Suspense } from 'react';
22

33
import { useCommandStatusColorMapping } from '../../utils/colors';
44
import TaskCommandLogs from './TaskCommandLogs';
@@ -20,6 +20,7 @@ import { makeStyles } from '@mui/styles';
2020
import { Box, useTheme } from '@mui/material';
2121
import { useRecoilValue } from 'recoil';
2222
import { prefersDarkModeState } from '../../cirrusTheme';
23+
import CirrusCircularProgress from '../common/CirrusCircularProgress';
2324

2425
const useStyles = makeStyles(theme => {
2526
return {
@@ -123,7 +124,9 @@ export default function TaskCommandList(props: Props) {
123124
</div>
124125
</AccordionSummary>
125126
<AccordionDetails className={classes.details}>
126-
<TaskCommandLogs taskId={task.id} command={command} />
127+
<Suspense fallback={<CirrusCircularProgress />}>
128+
<TaskCommandLogs taskId={task.id} command={command} />
129+
</Suspense>
127130
</AccordionDetails>
128131
</Accordion>
129132
</Box>

0 commit comments

Comments
 (0)