|
@@ -6,8 +6,11 @@ import EmptyMessage from 'sentry/components/emptyMessage';
|
|
|
import Form from 'sentry/components/forms/form';
|
|
|
import JsonForm from 'sentry/components/forms/jsonForm';
|
|
|
import Pagination from 'sentry/components/pagination';
|
|
|
+import Panel from 'sentry/components/panels/panel';
|
|
|
+import PanelBody from 'sentry/components/panels/panelBody';
|
|
|
+import PanelHeader from 'sentry/components/panels/panelHeader';
|
|
|
import {t} from 'sentry/locale';
|
|
|
-import {Project} from 'sentry/types';
|
|
|
+import {Organization, Project} from 'sentry/types';
|
|
|
import {sortProjects} from 'sentry/utils';
|
|
|
import {
|
|
|
MIN_PROJECTS_FOR_PAGINATION,
|
|
@@ -15,6 +18,7 @@ import {
|
|
|
NotificationSettingsByProviderObject,
|
|
|
NotificationSettingsObject,
|
|
|
} from 'sentry/views/settings/account/notifications/constants';
|
|
|
+import {OrganizationSelectHeader} from 'sentry/views/settings/account/notifications/notificationSettingsByType';
|
|
|
import {
|
|
|
getParentData,
|
|
|
getParentField,
|
|
@@ -25,7 +29,7 @@ import {
|
|
|
SearchWrapper,
|
|
|
} from 'sentry/views/settings/components/defaultSearchBar';
|
|
|
|
|
|
-type Props = {
|
|
|
+export type NotificationSettingsByProjectsBaseProps = {
|
|
|
notificationSettings: NotificationSettingsObject;
|
|
|
notificationType: string;
|
|
|
onChange: (
|
|
@@ -33,7 +37,14 @@ type Props = {
|
|
|
parentId: string
|
|
|
) => NotificationSettingsObject;
|
|
|
onSubmitSuccess: () => void;
|
|
|
-} & DeprecatedAsyncComponent['props'];
|
|
|
+};
|
|
|
+
|
|
|
+export type Props = {
|
|
|
+ handleOrgChange: Function;
|
|
|
+ organizationId: string;
|
|
|
+ organizations: Organization[];
|
|
|
+} & NotificationSettingsByProjectsBaseProps &
|
|
|
+ DeprecatedAsyncComponent['props'];
|
|
|
|
|
|
type State = {
|
|
|
projects: Project[];
|
|
@@ -48,7 +59,15 @@ class NotificationSettingsByProjects extends DeprecatedAsyncComponent<Props, Sta
|
|
|
}
|
|
|
|
|
|
getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
|
|
|
- return [['projects', '/projects/']];
|
|
|
+ return [
|
|
|
+ [
|
|
|
+ 'projects',
|
|
|
+ `/projects/`,
|
|
|
+ {
|
|
|
+ query: {organizationId: this.props.organizationId},
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -74,6 +93,12 @@ class NotificationSettingsByProjects extends DeprecatedAsyncComponent<Props, Sta
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ handleOrgChange = (option: {label: string; value: string}) => {
|
|
|
+ // handleOrgChange(option: {label: string; value: string}) {
|
|
|
+ this.props.handleOrgChange(option);
|
|
|
+ setTimeout(() => this.reloadData(), 0);
|
|
|
+ };
|
|
|
+
|
|
|
renderBody() {
|
|
|
const {notificationType, notificationSettings, onChange, onSubmitSuccess} =
|
|
|
this.props;
|
|
@@ -88,35 +113,50 @@ class NotificationSettingsByProjects extends DeprecatedAsyncComponent<Props, Sta
|
|
|
|
|
|
return (
|
|
|
<Fragment>
|
|
|
- {canSearch &&
|
|
|
- this.renderSearchInput({
|
|
|
- stateKey: 'projects',
|
|
|
- url: '/projects/',
|
|
|
- placeholder: t('Search Projects'),
|
|
|
- children: renderSearch,
|
|
|
- })}
|
|
|
- <Form
|
|
|
- saveOnBlur
|
|
|
- apiMethod="PUT"
|
|
|
- apiEndpoint="/users/me/notification-settings/"
|
|
|
- initialData={getParentData(notificationType, notificationSettings, projects)}
|
|
|
- onSubmitSuccess={onSubmitSuccess}
|
|
|
- >
|
|
|
- {projects.length === 0 ? (
|
|
|
- <EmptyMessage>{t('No projects found')}</EmptyMessage>
|
|
|
- ) : (
|
|
|
- Object.entries(this.getGroupedProjects()).map(([groupTitle, parents]) => (
|
|
|
- <JsonForm
|
|
|
- collapsible
|
|
|
- key={groupTitle}
|
|
|
- title={groupTitle}
|
|
|
- fields={parents.map(parent =>
|
|
|
- getParentField(notificationType, notificationSettings, parent, onChange)
|
|
|
- )}
|
|
|
- />
|
|
|
- ))
|
|
|
- )}
|
|
|
- </Form>
|
|
|
+ <PanelHeader>
|
|
|
+ <OrganizationSelectHeader
|
|
|
+ organizations={this.props.organizations}
|
|
|
+ organizationId={this.props.organizationId}
|
|
|
+ handleOrgChange={this.handleOrgChange}
|
|
|
+ />
|
|
|
+
|
|
|
+ {canSearch &&
|
|
|
+ this.renderSearchInput({
|
|
|
+ stateKey: 'projects',
|
|
|
+ url: `/projects/?organizationId=${this.props.organizationId}`,
|
|
|
+ placeholder: t('Search Projects'),
|
|
|
+ children: renderSearch,
|
|
|
+ })}
|
|
|
+ </PanelHeader>
|
|
|
+ <PanelBody>
|
|
|
+ <Form
|
|
|
+ saveOnBlur
|
|
|
+ apiMethod="PUT"
|
|
|
+ apiEndpoint="/users/me/notification-settings/"
|
|
|
+ initialData={getParentData(notificationType, notificationSettings, projects)}
|
|
|
+ onSubmitSuccess={onSubmitSuccess}
|
|
|
+ >
|
|
|
+ {projects.length === 0 ? (
|
|
|
+ <EmptyMessage>{t('No projects found')}</EmptyMessage>
|
|
|
+ ) : (
|
|
|
+ Object.entries(this.getGroupedProjects()).map(([groupTitle, parents]) => (
|
|
|
+ <StyledJsonForm
|
|
|
+ collapsible
|
|
|
+ key={groupTitle}
|
|
|
+ // title={groupTitle}
|
|
|
+ fields={parents.map(parent =>
|
|
|
+ getParentField(
|
|
|
+ notificationType,
|
|
|
+ notificationSettings,
|
|
|
+ parent,
|
|
|
+ onChange
|
|
|
+ )
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ ))
|
|
|
+ )}
|
|
|
+ </Form>
|
|
|
+ </PanelBody>
|
|
|
{canSearch && shouldPaginate && (
|
|
|
<Pagination pageLinks={projectsPageLinks} {...this.props} />
|
|
|
)}
|
|
@@ -132,3 +172,10 @@ const StyledSearchWrapper = styled(SearchWrapper)`
|
|
|
width: 100%;
|
|
|
}
|
|
|
`;
|
|
|
+
|
|
|
+export const StyledJsonForm = styled(JsonForm)`
|
|
|
+ ${Panel} {
|
|
|
+ border: 0;
|
|
|
+ margin-bottom: 0;
|
|
|
+ }
|
|
|
+`;
|