Skip to content
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
17 changes: 10 additions & 7 deletions static/app/views/teamInsights/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {cloneElement, isValidElement} from 'react';

import Feature from 'app/components/acl/feature';
import NoProjectMessage from 'app/components/noProjectMessage';
import SentryDocumentTitle from 'app/components/sentryDocumentTitle';
import {t} from 'app/locale';
import {Organization} from 'app/types';
Expand All @@ -14,13 +15,15 @@ type Props = {
function TeamInsightsContainer({children, organization}: Props) {
return (
<Feature organization={organization} features={['team-insights']}>
<SentryDocumentTitle title={t('Project Reports')} orgSlug={organization.slug}>
{children && isValidElement(children)
? cloneElement(children, {
organization,
})
: children}
</SentryDocumentTitle>
<NoProjectMessage organization={organization}>
<SentryDocumentTitle title={t('Project Reports')} orgSlug={organization.slug}>
{children && isValidElement(children)
? cloneElement(children, {
organization,
})
: children}
</SentryDocumentTitle>
</NoProjectMessage>
</Feature>
);
}
Expand Down
26 changes: 25 additions & 1 deletion static/app/views/teamInsights/teamMisery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Fragment} from 'react';
import {css} from '@emotion/react';
import styled from '@emotion/styled';
import {Location} from 'history';

Expand Down Expand Up @@ -67,6 +68,7 @@ function TeamMisery({

return (
<StyledPanelTable
isEmpty={projects.length === 0 || periodTableData?.data.length === 0}
headers={[
t('Key transaction'),
t('Project'),
Expand Down Expand Up @@ -135,6 +137,20 @@ function TeamMiseryWrapper({
start,
end,
}: Props) {
if (projects.length === 0) {
return (
<TeamMisery
isLoading={false}
organization={organization}
location={location}
projects={[]}
period={period}
periodTableData={{data: []}}
weekTableData={{data: []}}
/>
);
}

const commonEventView = {
id: undefined,
query: 'transaction.duration:<15m team_key_transaction:true',
Expand Down Expand Up @@ -195,7 +211,7 @@ function TeamMiseryWrapper({

export default TeamMiseryWrapper;

const StyledPanelTable = styled(PanelTable)`
const StyledPanelTable = styled(PanelTable)<{isEmpty: boolean}>`
grid-template-columns: 1fr 0.5fr 112px 112px 0.25fr;
font-size: ${p => p.theme.fontSizeMedium};
white-space: nowrap;
Expand All @@ -206,6 +222,14 @@ const StyledPanelTable = styled(PanelTable)`
& > div {
padding: ${space(1)} ${space(2)};
}

${p =>
p.isEmpty &&
css`
& > div:last-child {
padding: 48px ${space(2)};
}
`}
`;

const ProjectBadgeContainer = styled('div')`
Expand Down
1 change: 1 addition & 0 deletions static/app/views/teamInsights/teamStability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class TeamStability extends AsyncComponent<Props, State> {

return (
<StyledPanelTable
isEmpty={projects.length === 0}
headers={[
t('Project'),
<RightAligned key="last">{tct('Last [period]', {period})}</RightAligned>,
Expand Down
24 changes: 24 additions & 0 deletions tests/js/spec/views/teamInsights/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {mountWithTheme} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'app/stores/projectsStore';
import TeamInsightsContainer from 'app/views/teamInsights';

describe('TeamInsightsContainer', () => {
afterEach(() => {
ProjectsStore.reset();
});

it('blocks access if org is missing flag', () => {
// @ts-expect-error
const organization = TestStubs.Organization();
Expand All @@ -18,6 +23,10 @@ describe('TeamInsightsContainer', () => {
expect(wrapper.queryByText('test')).toBeNull();
});
it('allows access for orgs with flag', () => {
ProjectsStore.loadInitialData([
// @ts-expect-error
TestStubs.Project(),
]);
// @ts-expect-error
const organization = TestStubs.Organization({features: ['team-insights']});
// @ts-expect-error
Expand All @@ -31,4 +40,19 @@ describe('TeamInsightsContainer', () => {

expect(wrapper.getByText('test')).toBeTruthy();
});
it('shows message for users with no teams', () => {
ProjectsStore.loadInitialData([]);
// @ts-expect-error
const organization = TestStubs.Organization({features: ['team-insights']});
// @ts-expect-error
const context = TestStubs.routerContext([{organization}]);
const wrapper = mountWithTheme(
<TeamInsightsContainer organization={organization} />,
{context}
);

expect(
wrapper.getByText('You need at least one project to use this view')
).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions tests/js/spec/views/teamInsights/teamMisery.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,23 @@ describe('TeamMisery', () => {
expect(wrapper.getAllByText(project.slug)).toHaveLength(2);
expect(wrapper.getAllByText('0% change')).toHaveLength(2);
});

it('should render empty state', async () => {
const routerContext = TestStubs.routerContext();
const wrapper = mountWithTheme(
<TeamMisery
organization={TestStubs.Organization()}
projects={[]}
period="14d"
location={routerContext.context}
/>,
{context: routerContext}
);

await waitFor(() => {
expect(wrapper.queryByTestId('loading-indicator')).not.toBeInTheDocument();
});

expect(wrapper.getByText('There are no items to display')).toBeTruthy();
});
});
8 changes: 8 additions & 0 deletions tests/js/spec/views/teamInsights/teamStability.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ describe('TeamStability', () => {

expect(wrapper.getAllByText('\u2014')).toHaveLength(3);
});

it('should render no projects', async () => {
const wrapper = mountWithTheme(
<TeamStability projects={[]} organization={TestStubs.Organization()} period="7d" />
);

expect(wrapper.getByText('There are no items to display')).toBeTruthy();
});
});