Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5978 convert DrawerNavigation to relay modern #2250

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 51 additions & 47 deletions src/app/components/drawer/DrawerNavigation.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import React from 'react';
import Relay from 'react-relay/classic';
import { QueryRenderer, graphql } from 'react-relay/compat';
import Drawer from '@material-ui/core/Drawer';
import DrawerRail from './DrawerRail';
import DrawerNavigationComponent from './DrawerNavigationComponent';
import FindPublicTeamRoute from '../../relay/FindPublicTeamRoute';
import teamPublicFragment from '../../relay/teamPublicFragment';

const DrawerNavigationContainer = Relay.createContainer(DrawerNavigationComponent, {
fragments: {
team: () => teamPublicFragment,
},
});

const DrawerRailContainer = Relay.createContainer(DrawerRail, {
fragments: {
team: () => teamPublicFragment,
},
});
import ErrorBoundary from '../error/ErrorBoundary';
import DrawerContent from './index.js';
import styles from './Drawer.module.css';

const getBooleanPref = (key, fallback) => {
const inStore = window.storage.getValue(key);
if (inStore === null) return fallback;
return (inStore === 'true'); // we are testing against the string value of 'true' because `localStorage` only stores string values, and casts `true` as `'true'`
};

const DrawerNavigation = (props) => {
const DrawerNavigation = (parentProps) => {
const [drawerOpen, setDrawerOpen] = React.useState(getBooleanPref('drawer.isOpen', true));
const [drawerType, setDrawerType] = React.useState('tipline');

Expand All @@ -33,44 +23,58 @@ const DrawerNavigation = (props) => {
}
}, [drawerType]);

if (props.teamSlug) {
const { teamSlug } = props;

const route = new FindPublicTeamRoute({ teamSlug });
if (parentProps.teamSlug) {
const { teamSlug } = parentProps;

return (
<>
<Relay.RootContainer
Component={DrawerRailContainer}
renderFetched={
data => (<DrawerRailContainer
drawerOpen={drawerOpen}
drawerType={drawerType}
onDrawerOpenChange={setDrawerOpen}
onDrawerTypeChange={setDrawerType}
{...props}
{...data}
/>)
}
route={route}
/>
<Relay.RootContainer
Component={DrawerNavigationContainer}
renderFetched={
data => (<DrawerNavigationContainer
drawerOpen={drawerOpen}
drawerType={drawerType}
{...props}
{...data}
/>)
}
route={route}
/>
<ErrorBoundary component="DrawerNavigation">
<QueryRenderer
environment={Relay.Store}
query={graphql`
query DrawerNavigationQuery($teamSlug: String!) {
find_public_team(slug: $teamSlug) {
...DrawerRail_team
}
}
`}
render={({ error, props }) => {
if (!error && props) {
return (
<>
<DrawerRail
currentUserIsMember={parentProps.currentUserIsMember}
drawerOpen={drawerOpen}
drawerType={drawerType}
team={props.find_public_team}
onDrawerOpenChange={setDrawerOpen}
onDrawerTypeChange={setDrawerType}
/>
<Drawer
anchor="left"
className={[styles.drawer, drawerOpen ? styles.drawerOpen : styles.drawerClosed].join(' ')}
open={Boolean(drawerOpen)}
variant="persistent"
>
{parentProps.currentUserIsMember ? (
<DrawerContent drawerType={drawerType} />
) : null }
</Drawer>
</>
);
}
return null;
}}
variables={{
teamSlug,
}}
/>
</ErrorBoundary>
</>
);
}

return <><DrawerRail {...props} /><DrawerNavigationComponent {...props} /></>;
return <><DrawerRail {...parentProps} /></>;
};

export default DrawerNavigation;
111 changes: 0 additions & 111 deletions src/app/components/drawer/DrawerNavigationComponent.js

This file was deleted.

76 changes: 0 additions & 76 deletions src/app/components/drawer/DrawerNavigationComponent.test.js

This file was deleted.

11 changes: 9 additions & 2 deletions src/app/components/drawer/DrawerRail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import { injectIntl, defineMessages } from 'react-intl';
import { createFragmentContainer, graphql } from 'react-relay/compat';
import cx from 'classnames/bind';
import Tooltip from '../cds/alerts-and-prompts/Tooltip';
import TeamAvatar from '../team/TeamAvatar';
Expand Down Expand Up @@ -147,7 +148,7 @@ const DrawerRail = ({
<div className={styles.railIconLink}>
<ChevronLeftIcon />
</div>
<TeamAvatar className={styles.teamLogo} size="44px" team={team} />
<TeamAvatar className={styles.teamLogo} size="44px" team={{ avatar: team.avatar }} />
</button>
</Tooltip>
<ContentFilterControls />
Expand Down Expand Up @@ -303,4 +304,10 @@ DrawerRail.propTypes = {
onDrawerTypeChange: PropTypes.func.isRequired,
};

export default injectIntl(DrawerRail);
export default createFragmentContainer(injectIntl(DrawerRail), graphql`
fragment DrawerRail_team on PublicTeam {
slug
private
avatar
}
`);
13 changes: 0 additions & 13 deletions src/app/relay/FindPublicTeamRoute.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/app/relay/teamPublicFragment.js

This file was deleted.

Loading