|
@@ -7,13 +7,17 @@ import {OrganizationIntegration} from 'sentry/types/integrations';
|
|
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
|
|
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
|
|
import withOrganizations from 'sentry/utils/withOrganizations';
|
|
import withOrganizations from 'sentry/utils/withOrganizations';
|
|
import {
|
|
import {
|
|
|
|
+ ALL_PROVIDER_NAMES,
|
|
CONFIRMATION_MESSAGE,
|
|
CONFIRMATION_MESSAGE,
|
|
NotificationSettingsByProviderObject,
|
|
NotificationSettingsByProviderObject,
|
|
NotificationSettingsObject,
|
|
NotificationSettingsObject,
|
|
} from 'sentry/views/settings/account/notifications/constants';
|
|
} from 'sentry/views/settings/account/notifications/constants';
|
|
import FeedbackAlert from 'sentry/views/settings/account/notifications/feedbackAlert';
|
|
import FeedbackAlert from 'sentry/views/settings/account/notifications/feedbackAlert';
|
|
import {ACCOUNT_NOTIFICATION_FIELDS} from 'sentry/views/settings/account/notifications/fields';
|
|
import {ACCOUNT_NOTIFICATION_FIELDS} from 'sentry/views/settings/account/notifications/fields';
|
|
-import {NOTIFICATION_SETTING_FIELDS} from 'sentry/views/settings/account/notifications/fields2';
|
|
|
|
|
|
+import {
|
|
|
|
+ NOTIFICATION_SETTING_FIELDS,
|
|
|
|
+ QUOTA_FIELDS,
|
|
|
|
+} from 'sentry/views/settings/account/notifications/fields2';
|
|
import NotificationSettingsByOrganization from 'sentry/views/settings/account/notifications/notificationSettingsByOrganization';
|
|
import NotificationSettingsByOrganization from 'sentry/views/settings/account/notifications/notificationSettingsByOrganization';
|
|
import NotificationSettingsByProjects from 'sentry/views/settings/account/notifications/notificationSettingsByProjects';
|
|
import NotificationSettingsByProjects from 'sentry/views/settings/account/notifications/notificationSettingsByProjects';
|
|
import {Identity} from 'sentry/views/settings/account/notifications/types';
|
|
import {Identity} from 'sentry/views/settings/account/notifications/types';
|
|
@@ -33,7 +37,7 @@ import {
|
|
} from 'sentry/views/settings/account/notifications/utils';
|
|
} from 'sentry/views/settings/account/notifications/utils';
|
|
import Form from 'sentry/views/settings/components/forms/form';
|
|
import Form from 'sentry/views/settings/components/forms/form';
|
|
import JsonForm from 'sentry/views/settings/components/forms/jsonForm';
|
|
import JsonForm from 'sentry/views/settings/components/forms/jsonForm';
|
|
-import {FieldObject} from 'sentry/views/settings/components/forms/type';
|
|
|
|
|
|
+import {Field} from 'sentry/views/settings/components/forms/type';
|
|
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
|
|
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
|
|
import TextBlock from 'sentry/views/settings/components/text/textBlock';
|
|
import TextBlock from 'sentry/views/settings/components/text/textBlock';
|
|
|
|
|
|
@@ -48,6 +52,19 @@ type State = {
|
|
organizationIntegrations: OrganizationIntegration[];
|
|
organizationIntegrations: OrganizationIntegration[];
|
|
} & AsyncComponent['state'];
|
|
} & AsyncComponent['state'];
|
|
|
|
|
|
|
|
+const typeMappedChildren = {
|
|
|
|
+ quota: ['quotaErrors', 'quotaTransactions', 'quotaAttachments', 'quotaWarnings'],
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const getQueryParams = (notificationType: string) => {
|
|
|
|
+ // if we need multiple settings on this page
|
|
|
|
+ // then omit the type so we can load all settings
|
|
|
|
+ if (notificationType in typeMappedChildren) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return {type: notificationType};
|
|
|
|
+};
|
|
|
|
+
|
|
class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
getDefaultState(): State {
|
|
getDefaultState(): State {
|
|
return {
|
|
return {
|
|
@@ -64,7 +81,7 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
[
|
|
[
|
|
'notificationSettings',
|
|
'notificationSettings',
|
|
`/users/me/notification-settings/`,
|
|
`/users/me/notification-settings/`,
|
|
- {query: {type: notificationType}},
|
|
|
|
|
|
+ {query: getQueryParams(notificationType)},
|
|
],
|
|
],
|
|
['identities', `/users/me/identities/`, {query: {provider: 'slack'}}],
|
|
['identities', `/users/me/identities/`, {query: {provider: 'slack'}}],
|
|
[
|
|
[
|
|
@@ -114,6 +131,39 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
return updatedNotificationSettings;
|
|
return updatedNotificationSettings;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ getStateToPutForDependentSetting = (
|
|
|
|
+ changedData: NotificationSettingsByProviderObject,
|
|
|
|
+ notificationType: string
|
|
|
|
+ ) => {
|
|
|
|
+ const value = changedData[notificationType];
|
|
|
|
+ const {notificationSettings} = this.state;
|
|
|
|
+
|
|
|
|
+ // parent setting will control the which providers we send to
|
|
|
|
+ // just set every provider to the same value for the child/dependent setting
|
|
|
|
+ const userSettings = ALL_PROVIDER_NAMES.reduce((accum, provider) => {
|
|
|
|
+ accum[provider] = value;
|
|
|
|
+ return accum;
|
|
|
|
+ }, {});
|
|
|
|
+
|
|
|
|
+ // setting is a user-only setting
|
|
|
|
+ const updatedNotificationSettings = {
|
|
|
|
+ [notificationType]: {
|
|
|
|
+ user: {
|
|
|
|
+ me: userSettings,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ this.setState({
|
|
|
|
+ notificationSettings: mergeNotificationSettings(
|
|
|
|
+ notificationSettings,
|
|
|
|
+ updatedNotificationSettings
|
|
|
|
+ ),
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return updatedNotificationSettings;
|
|
|
|
+ };
|
|
|
|
+
|
|
getStateToPutForDefault = (
|
|
getStateToPutForDefault = (
|
|
changedData: NotificationSettingsByProviderObject
|
|
changedData: NotificationSettingsByProviderObject
|
|
): NotificationSettingsObject => {
|
|
): NotificationSettingsObject => {
|
|
@@ -174,10 +224,14 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
getCurrentProviders(notificationType, notificationSettings)
|
|
getCurrentProviders(notificationType, notificationSettings)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+ const childTypes: string[] = typeMappedChildren[notificationType] || [];
|
|
|
|
+ childTypes.forEach(childType => {
|
|
|
|
+ initialData[childType] = getCurrentDefault(childType, notificationSettings);
|
|
|
|
+ });
|
|
return initialData;
|
|
return initialData;
|
|
}
|
|
}
|
|
|
|
|
|
- getFields(): FieldObject[] {
|
|
|
|
|
|
+ getFields(): Field[] {
|
|
const {notificationType} = this.props;
|
|
const {notificationType} = this.props;
|
|
const {notificationSettings} = this.state;
|
|
const {notificationSettings} = this.state;
|
|
|
|
|
|
@@ -185,7 +239,7 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
? t('This is the default for all projects.')
|
|
? t('This is the default for all projects.')
|
|
: t('This is the default for all organizations.');
|
|
: t('This is the default for all organizations.');
|
|
|
|
|
|
- const defaultField = Object.assign(
|
|
|
|
|
|
+ const defaultField: Field = Object.assign(
|
|
{},
|
|
{},
|
|
NOTIFICATION_SETTING_FIELDS[notificationType],
|
|
NOTIFICATION_SETTING_FIELDS[notificationType],
|
|
{
|
|
{
|
|
@@ -197,7 +251,7 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
defaultField.confirm = {never: CONFIRMATION_MESSAGE};
|
|
defaultField.confirm = {never: CONFIRMATION_MESSAGE};
|
|
}
|
|
}
|
|
|
|
|
|
- const fields = [defaultField];
|
|
|
|
|
|
+ const fields: Field[] = [defaultField];
|
|
if (!isEverythingDisabled(notificationType, notificationSettings)) {
|
|
if (!isEverythingDisabled(notificationType, notificationSettings)) {
|
|
fields.push(
|
|
fields.push(
|
|
Object.assign(
|
|
Object.assign(
|
|
@@ -209,7 +263,26 @@ class NotificationSettingsByType extends AsyncComponent<Props, State> {
|
|
)
|
|
)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
- return fields as FieldObject[];
|
|
|
|
|
|
+
|
|
|
|
+ // if a quota notification is not disabled, add in our dependent fields
|
|
|
|
+ if (
|
|
|
|
+ notificationType === 'quota' &&
|
|
|
|
+ !isEverythingDisabled(notificationType, notificationSettings)
|
|
|
|
+ ) {
|
|
|
|
+ fields.push(
|
|
|
|
+ ...QUOTA_FIELDS.map(field => ({
|
|
|
|
+ ...field,
|
|
|
|
+ type: 'select' as const,
|
|
|
|
+ getData: data =>
|
|
|
|
+ this.getStateToPutForDependentSetting(
|
|
|
|
+ data as NotificationSettingsByProviderObject,
|
|
|
|
+ field.name
|
|
|
|
+ ),
|
|
|
|
+ }))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fields;
|
|
}
|
|
}
|
|
|
|
|
|
getUnlinkedOrgs = (): OrganizationSummary[] => {
|
|
getUnlinkedOrgs = (): OrganizationSummary[] => {
|