Skip to content

Commit

Permalink
GUI S3 Objects lifecycle (#2759): Use default template for 'body' and…
Browse files Browse the repository at this point in the history
… 'subject' from settings
  • Loading branch information
AleksandrGorodetskii committed Sep 8, 2022
1 parent 1e9d769 commit c168adc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {observer} from 'mobx-react';
import {observable, computed} from 'mobx';
import {
Button,
Input,
Form,
Row,
Col,
Icon,
Checkbox
Checkbox,
message
} from 'antd';
import UsersRolesSelect from '../../../../../special/users-roles-select';
import CodeEditor from '../../../../../special/CodeEditor';
import EmailPreview from '../../../../../../components/settings/forms/EmailPreview';
import NotificationTemplates from '../../../../../../models/settings/NotificationTemplates';
import styles from './life-cycle-forms.css';

const columnLayout = {
Expand All @@ -52,20 +56,70 @@ const fullWidthLayout = {
}
};

const TEMPLATE_KEY = 'DATASTORAGE_LIFECYCLE_ACTION';

@observer
class NotificationForm extends React.Component {
state = {
previewMode: false,
pending: false
}

@observable systemTemplate;

notifyFormContainer;

componentDidMount () {
this.fetchEmailSettings();
}

componentDidUpdate (prevProps) {
if (this.props.notificationsDisabled !== prevProps.notificationsDisabled) {
this.checkRequiredFields();
}
if (this.props.rule.id !== prevProps.rule.id) {
this.fetchEmailSettings();
}
}

@computed
get initialBody () {
const {rule} = this.props;
if (rule.notification && rule.notification.body) {
return rule.notification.body;
}
if (this.systemTemplate) {
return this.systemTemplate.body;
}
return undefined;
}

@computed
get initialSubject () {
const {rule} = this.props;
if (rule.notification && rule.notification.subject) {
return rule.notification.subject;
}
if (this.systemTemplate) {
return this.systemTemplate.subject;
}
return undefined;
}

fetchEmailSettings = () => {
this.setState({pending: true}, async () => {
const request = new NotificationTemplates();
await request.fetch();
this.setState({pending: false}, () => {
if (request.error) {
message.error(request.error, 5);
}
this.systemTemplate = (request.value || [])
.find(template => template.name === TEMPLATE_KEY);
});
});
};

checkRequiredFields = () => {
const {form} = this.props;
form.validateFields(
Expand All @@ -90,7 +144,6 @@ class NotificationForm extends React.Component {
renderNotificationTemplate = () => {
const {
form,
rule,
notificationsDisabled,
useDefaultNotify
} = this.props;
Expand Down Expand Up @@ -131,9 +184,7 @@ class NotificationForm extends React.Component {
style={{display: previewMode ? 'none' : 'inherit'}}
>
{getFieldDecorator('notification.subject', {
initialValue: rule.notification
? rule.notification.subject
: undefined,
initialValue: this.initialSubject,
rules: [{
required: !notificationsDisabled,
message: ' '
Expand Down Expand Up @@ -178,9 +229,7 @@ class NotificationForm extends React.Component {
>
{getFieldDecorator('notification.body', {
valuePropName: 'code',
initialValue: rule.notification
? rule.notification.body
: undefined,
initialValue: this.initialBody,
rules: [{
required: !notificationsDisabled,
message: ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,9 @@ import {
Icon
} from 'antd';
import moment from 'moment-timezone';
import {DESTINATIONS} from '../modals';
import styles from './life-cycle-forms.css';

const DESTINATIONS = {
GLACIER_IR: 'S3 Glacier Instant Retrieval',
GLACIER: 'S3 Glacier Flexible Retrieval (formerly Glacier)',
DEEP_ARCHIVE: 'S3 Glacier Deep Archive',
DELETION: 'Deletion'
};

const TRANSITION_PERIOD = {
after: 'after',
at: 'at'
Expand Down

0 comments on commit c168adc

Please sign in to comment.