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

ref(js): Remove usage of organization.projects from SidebarOrgSummary #28705

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
9 changes: 6 additions & 3 deletions static/app/components/sidebar/sidebarDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {IconChevron, IconSentry} from 'app/icons';
import {t} from 'app/locale';
import ConfigStore from 'app/stores/configStore';
import space from 'app/styles/space';
import {Config, Organization, User} from 'app/types';
import {Config, Organization, Project, User} from 'app/types';
import withApi from 'app/utils/withApi';
import withProjects from 'app/utils/withProjects';

import SidebarMenuItemLink from '../sidebarMenuItemLink';
import {CommonSidebarProps} from '../types';
Expand All @@ -30,6 +31,7 @@ import SwitchOrganization from './switchOrganization';
type Props = Pick<CommonSidebarProps, 'orientation' | 'collapsed'> & {
api: Client;
org: Organization;
projects: Project[];
user: User;
config: Config;
/**
Expand All @@ -41,6 +43,7 @@ type Props = Pick<CommonSidebarProps, 'orientation' | 'collapsed'> & {
const SidebarDropdown = ({
api,
org,
projects,
orientation,
collapsed,
config,
Expand Down Expand Up @@ -105,7 +108,7 @@ const SidebarDropdown = ({
<OrgAndUserMenu {...getMenuProps({})}>
{hasOrganization && (
<Fragment>
<SidebarOrgSummary organization={org} />
<SidebarOrgSummary organization={org} projectCount={projects.length} />
{!hideOrgLinks && (
<Fragment>
{hasOrgRead && (
Expand Down Expand Up @@ -180,7 +183,7 @@ const SidebarDropdown = ({
);
};

export default withApi(SidebarDropdown);
export default withApi(withProjects(SidebarDropdown));

const SentryLink = styled(Link)`
color: ${p => p.theme.white};
Expand Down
4 changes: 2 additions & 2 deletions static/app/components/sidebar/sidebarMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const MenuItemLabel = styled('span')<{hasMenu?: boolean}>`
${p =>
p.hasMenu
? css`
margin: 0 -15px;
padding: 0 15px;
margin: 0 -${p.theme.sidebar.menuSpacing};
padding: 0 ${p.theme.sidebar.menuSpacing};
`
: css`
overflow: hidden;
Expand Down
68 changes: 32 additions & 36 deletions static/app/components/sidebar/sidebarOrgSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,57 @@ import styled from '@emotion/styled';
import OrganizationAvatar from 'app/components/avatar/organizationAvatar';
import {tn} from 'app/locale';
import overflowEllipsis from 'app/styles/overflowEllipsis';
import {Organization, OrganizationSummary} from 'app/types';
import space from 'app/styles/space';
import {OrganizationSummary} from 'app/types';

type Props = {
organization: OrganizationSummary;
/**
* Show the project count under the organization name.
*/
projectCount?: number;
};

const SidebarOrgSummary = ({organization}: Props) => {
const fullOrg = organization as Organization;
const projects = fullOrg.projects && fullOrg.projects.length;
const extra: string[] = [];

if (projects) {
extra.push(tn('%s project', '%s projects', projects));
}

return (
<OrgSummary>
<OrganizationAvatar organization={organization} size={36} />

<Details>
<SummaryOrgName>{organization.name}</SummaryOrgName>
{!!extra.length && <SummaryOrgDetails>{extra.join(', ')}</SummaryOrgDetails>}
</Details>
</OrgSummary>
);
};
const SidebarOrgSummary = ({organization, projectCount}: Props) => (
<OrgSummary>
<OrganizationAvatar organization={organization} size={36} />
<Details>
<Name>{organization.name}</Name>
{!!projectCount && <Extra>{tn('%s project', '%s projects', projectCount)}</Extra>}
</Details>
</OrgSummary>
);

const OrgSummary = styled('div')`
display: flex;
padding: 10px 15px;
display: grid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh nice clean up here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah basically just rewrote it all lol

grid-template-columns: max-content 1fr;
grid-gap: ${space(1)};
align-items: center;
padding: ${space(1)} ${p => p.theme.sidebar.menuSpacing};
overflow: hidden;
`;

const Details = styled('div')`
overflow: hidden;
`;
const SummaryOrgName = styled('div')`

const Name = styled('div')`
color: ${p => p.theme.textColor};
font-size: 16px;
font-size: ${p => p.theme.fontSizeLarge};
line-height: 1.1;
font-weight: bold;
margin-bottom: 4px;
${overflowEllipsis};
`;
const SummaryOrgDetails = styled('div')`

const Extra = styled('div')`
color: ${p => p.theme.subText};
font-size: 14px;
font-size: ${p => p.theme.fontSizeMedium};
line-height: 1;
margin-top: ${space(0.5)};
${overflowEllipsis};
`;
const Details = styled('div')`
display: flex;
flex-direction: column;
justify-content: center;

padding-left: 10px;
overflow: hidden;
`;

// Needed for styling in SidebarMenuItem
export {OrgSummary};

export default SidebarOrgSummary;