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

fix(projects): Show join a team if person doesn't have a team #55499

Merged
merged 5 commits into from
Aug 30, 2023
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
52 changes: 52 additions & 0 deletions static/app/components/noProjectMessage.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';

import {Label} from 'sentry/components/editableText';
import NoProjectMessage from 'sentry/components/noProjectMessage';
import ConfigStore from 'sentry/stores/configStore';
import ProjectsStore from 'sentry/stores/projectsStore';
Expand All @@ -26,6 +27,41 @@ describe('NoProjectMessage', function () {
expect(screen.getByText('Remain Calm')).toBeInTheDocument();
});

it('shows "Join a Team" when member has no teams', function () {
const organization = TestStubs.Organization({
slug: 'org-slug',
access: ['org:read', 'team:read'],
});
const childrenMock = jest.fn().mockReturnValue(null);
ProjectsStore.loadInitialData([]);

render(
<NoProjectMessage organization={organization}>{childrenMock}</NoProjectMessage>
);

expect(childrenMock).not.toHaveBeenCalled();
expect(screen.getByRole('button', {name: 'Join a Team'})).toBeInTheDocument();
});

it('does not show up when user has at least a project and a team', function () {
const organization = TestStubs.Organization({slug: 'org-slug'});
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
const project = TestStubs.Project({slug: 'project1', teams: [team]});
ProjectsStore.loadInitialData([{...project, hasAccess: true}]);
TeamStore.loadInitialData([{...team, access: ['team:read']}]);

render(
<NoProjectMessage organization={organization}>
<Label data-test-id="project-row" isDisabled>
Some Project
</Label>
</NoProjectMessage>
);

expect(screen.getByTestId('project-row')).toBeInTheDocument();
expect(screen.queryByText('Remain Calm')).not.toBeInTheDocument();
});

it('shows "Create Project" button when there are no projects', function () {
ProjectsStore.loadInitialData([]);

Expand Down Expand Up @@ -96,4 +132,20 @@ describe('NoProjectMessage', function () {
screen.getByText('You need at least one project to use this view')
).toBeInTheDocument();
});

it('shows projects to superusers if membership is not required', function () {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the test that would have failed on the previous PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the test 👏

ProjectsStore.loadInitialData([TestStubs.Project({isMember: false})]);

ConfigStore.set('user', {...ConfigStore.get('user'), isSuperuser: true});

render(
<NoProjectMessage organization={org}>
<Label data-test-id="project-row" isDisabled>
Some Project
</Label>
</NoProjectMessage>
);

expect(screen.getByTestId('project-row')).toBeInTheDocument();
});
});
8 changes: 6 additions & 2 deletions static/app/components/noProjectMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function NoProjectMessage({
}: Props) {
const {projects, initiallyLoaded: projectsLoaded} = useProjects();
const {teams, initiallyLoaded: teamsLoaded} = useTeams();
const isTeamMember = teams.some(team => team.isMember);

const orgSlug = organization.slug;
const {canCreateProject} = useProjectCreationAccess({organization, teams});
Expand All @@ -39,7 +40,10 @@ function NoProjectMessage({
? !!projects?.some(p => p.hasAccess)
: !!projects?.some(p => p.isMember && p.hasAccess);

if (hasProjectAccess || !projectsLoaded || !teamsLoaded) {
if (
(isTeamMember || isSuperuser) &&
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only change from previous PR

(hasProjectAccess || !projectsLoaded || !teamsLoaded)
) {
return <Fragment>{children}</Fragment>;
}

Expand Down Expand Up @@ -81,7 +85,7 @@ function NoProjectMessage({
<Layout.Title>{t('Remain Calm')}</Layout.Title>
<HelpMessage>{t('You need at least one project to use this view')}</HelpMessage>
<Actions gap={1}>
{!orgHasProjects ? (
{!orgHasProjects && canCreateProject ? (
createProjectAction
) : (
<Fragment>
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/alerts/create.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ describe('ProjectAlertsCreate', function () {
const createWrapper = (props = {}, location = {}) => {
const {organization, project, router, routerContext} = initializeOrg(props);
ProjectsStore.loadInitialData([project]);
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
const params = {orgId: organization.slug, projectId: project.slug};
const wrapper = render(
<AlertsContainer>
Expand Down
6 changes: 6 additions & 0 deletions static/app/views/alerts/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';

import TeamStore from 'sentry/stores/teamStore';
import AlertsContainer from 'sentry/views/alerts';

describe('AlertsContainer', function () {
beforeEach(() => {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
});

function SubView({hasMetricAlerts}: {hasMetricAlerts?: boolean}) {
return <div>{hasMetricAlerts ? 'access' : 'no access'}</div>;
}
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/alerts/list/incidents/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ describe('IncidentsList', () => {
};

beforeEach(() => {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
MockApiClient.addMockResponse({
url: '/organizations/org-slug/incidents/',
body: [
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/dashboards/detail.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {

import * as modals from 'sentry/actionCreators/modal';
import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import CreateDashboard from 'sentry/views/dashboards/create';
import * as types from 'sentry/views/dashboards/types';
import ViewEditDashboard from 'sentry/views/dashboards/view';
Expand All @@ -27,6 +28,8 @@ describe('Dashboards > Detail', function () {
let initialData;

beforeEach(function () {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
act(() => ProjectsStore.loadInitialData(projects));
initialData = initializeOrg({organization});

Expand Down
3 changes: 3 additions & 0 deletions static/app/views/dashboards/manage/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import selectEvent from 'react-select-event';
import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import ManageDashboards from 'sentry/views/dashboards/manage';

const FEATURES = [
Expand All @@ -22,6 +23,8 @@ describe('Dashboards > Detail', function () {
features: FEATURES,
});
beforeEach(function () {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
act(() => ProjectsStore.loadInitialData([TestStubs.Project()]));

MockApiClient.addMockResponse({
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/discover/eventDetails/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
import {act, render, screen} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import EventView from 'sentry/utils/discover/eventView';
import {ALL_VIEWS, DEFAULT_EVENT_VIEW} from 'sentry/views/discover/data';
import EventDetails from 'sentry/views/discover/eventDetails';
Expand All @@ -13,6 +14,8 @@ describe('Discover > EventDetails', function () {
);

beforeEach(function () {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
act(() => ProjectsStore.loadInitialData([TestStubs.Project()]));

MockApiClient.addMockResponse({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import TeamInsightsContainer from 'sentry/views/organizationStats/teamInsights';

describe('TeamInsightsContainer', () => {
Expand All @@ -22,6 +23,8 @@ describe('TeamInsightsContainer', () => {
});
it('allows access for orgs with flag', () => {
ProjectsStore.loadInitialData([TestStubs.Project()]);
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
const organization = TestStubs.Organization({features: ['team-insights']});
const context = TestStubs.routerContext([{organization}]);
render(
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/projectDetail/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {textWithMarkupMatcher} from 'sentry-test/utils';

import PageFiltersStore from 'sentry/stores/pageFiltersStore';
import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import ProjectDetails from 'sentry/views/projectDetail/projectDetail';

describe('ProjectDetail', function () {
Expand All @@ -13,6 +14,8 @@ describe('ProjectDetail', function () {
beforeEach(() => {
PageFiltersStore.reset();
ProjectsStore.reset();
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
// eslint-disable-next-line no-console
jest.spyOn(console, 'error').mockImplementation(jest.fn());

Expand Down
3 changes: 3 additions & 0 deletions static/app/views/releases/list/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import ReleasesList from 'sentry/views/releases/list/';
import {ReleasesDisplayOption} from 'sentry/views/releases/list/releasesDisplayOptions';
import {ReleasesSortOption} from 'sentry/views/releases/list/releasesSortOptions';
Expand Down Expand Up @@ -57,6 +58,8 @@ describe('ReleasesList', () => {
let endpointMock, sessionApiMock;

beforeEach(() => {
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);
act(() => ProjectsStore.loadInitialData(organization.projects));
endpointMock = MockApiClient.addMockResponse({
url: '/organizations/org-slug/releases/',
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/userFeedback/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import ProjectsStore from 'sentry/stores/projectsStore';
import TeamStore from 'sentry/stores/teamStore';
import UserFeedback from 'sentry/views/userFeedback';

describe('UserFeedback', function () {
Expand All @@ -22,6 +23,8 @@ describe('UserFeedback', function () {

beforeEach(function () {
ProjectsStore.loadInitialData([project]);
const team = TestStubs.Team({slug: 'team-slug', isMember: true});
TeamStore.loadInitialData([{...team, access: ['team:read']}]);

MockApiClient.addMockResponse({
url: '/organizations/org-slug/user-feedback/',
Expand Down