Skip to content

Commit

Permalink
GUI S3 Objects lifecycle (#2759): notifications recipients: move from…
Browse files Browse the repository at this point in the history
… informedUserIds to recipients API field
  • Loading branch information
AleksandrGorodetskii committed Sep 2, 2022
1 parent da5865a commit 2163e14
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import React from 'react';
import PropTypes from 'prop-types';
import {computed} from 'mobx';
import {inject, observer} from 'mobx-react';
import classNames from 'classnames';
import {
Button,
Expand Down Expand Up @@ -54,37 +52,20 @@ const fullWidthLayout = {
}
};

@inject('usersInfo')
@observer
class NotificationForm extends React.Component {
state = {
previewMode: false,
pending: false
}

notifyFormContainer;

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

notifyFormContainer;

@computed
get informedUsers () {
const {usersInfo, rule} = this.props;
if (usersInfo.loaded &&
rule.notification &&
rule.notification.informedUserIds
) {
return (rule.notification.informedUserIds || []).map(id => {
const user = (usersInfo.value || []).find(info => info.id === id);
return user || undefined;
}).filter(Boolean);
}
return [];
}

checkRequiredFields = () => {
const {form} = this.props;
form.validateFields(
Expand Down Expand Up @@ -120,10 +101,7 @@ class NotificationForm extends React.Component {
valuePropName: 'checked',
initialValue: rule.notification && rule.notification.enabled !== undefined
? !rule.notification.enabled
: false,
rules: [{
required: false
}]
: false
})(
<Checkbox
disabled={pending}
Expand All @@ -139,15 +117,13 @@ class NotificationForm extends React.Component {
className={styles.formItem}
label="Recipients"
>
{getFieldDecorator('notification.informedUserIds', {
{getFieldDecorator('notification.recipients', {
type: 'array',
initialValue: rule.notification
? this.informedUsers
initialValue: rule.notification && rule.notification.recipients
? rule.notification.recipients
: []
})(
<UsersRolesSelect
adGroups={false}
showRoles={false}
disabled={notificationsDisabled || pending}
style={{flex: 1}}
dropdownStyle={{maxHeight: '80%'}}
Expand Down Expand Up @@ -280,7 +256,10 @@ class NotificationForm extends React.Component {
: undefined
})(
<CodeEditor
className={classNames(styles.codeEditor, 'cp-code-editor')}
className={classNames(
styles.codeEditor,
'cp-code-editor'
)}
language="application/x-jsp"
lineWrapping
readOnly={notificationsDisabled || pending}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import {computed} from 'mobx';
import {inject, observer} from 'mobx-react';
import {observer} from 'mobx-react';
import {
Button,
Input,
Expand Down Expand Up @@ -94,7 +93,6 @@ function FormSection ({
);
}

@inject('usersInfo')
@observer
class LifeCycleEditModal extends React.Component {
state={
Expand All @@ -115,15 +113,6 @@ class LifeCycleEditModal extends React.Component {
}
}

@computed
get usersInfo () {
const {usersInfo} = this.props;
if (usersInfo.loaded) {
return usersInfo.value;
}
return [];
}

get modified () {
const {initialRule} = this.state;
const {form, createNewRule} = this.props;
Expand Down Expand Up @@ -155,7 +144,6 @@ class LifeCycleEditModal extends React.Component {
const fieldValue = form.getFieldValue(formPath);
return !compareArrays(initialValue, fieldValue, comparerFn);
};
// TODO: add informedIserIds check when API change ids to user\group objects
return stringFieldModified('notification.body', notification.body) ||
stringFieldModified('notification.disabled', !notification.enabled) ||
stringFieldModified('notification.notifyBeforeDays', notification.notifyBeforeDays) ||
Expand All @@ -170,6 +158,11 @@ class LifeCycleEditModal extends React.Component {
initialRule.transitions,
(a, b) => (a.storageClass === b.storageClass &&
a.transitionAfterDays === b.transitionAfterDays)
) ||
arrayFieldModified(
'notification.recipients',
(initialRule.notification || {}).recipients,
(a, b) => (a.name === b.name && a.principal === b.principal)
);
}

Expand Down Expand Up @@ -226,10 +219,6 @@ class LifeCycleEditModal extends React.Component {
payload.notification.enabled = !notification.disabled;
delete payload.notification.disabled;
}
if (notification && notification.informedUserIds) {
const recipientsIds = this.getIdsFromUsers(notification.informedUserIds);
payload.notification.informedUserIds = recipientsIds;
}
if (METHODS[method] === METHODS.ONE_BY_ONE) {
if (!payload.notification) {
payload.notification = {};
Expand Down Expand Up @@ -264,16 +253,6 @@ class LifeCycleEditModal extends React.Component {
this.setState({initialRule: rule});
};

getIdsFromUsers = (users = []) => {
return users.map(user => {
const userInfo = this.usersInfo.find(info => info.name === user.name);
if (userInfo) {
return userInfo.id;
}
return undefined;
}).filter(Boolean);
};

onCancel = () => {
const {onCancel, form} = this.props;
form.resetFields();
Expand Down Expand Up @@ -301,9 +280,25 @@ class LifeCycleEditModal extends React.Component {
};

onChangeMethod = (key) => {
const {form} = this.props;
const {initialRule} = this.state;
if (METHODS[key] === METHODS.ONE_BY_ONE) {
this.collapsePanel(PANELS.notify);
form.setFields({
'notification.disabled': {
value: true,
errors: undefined
}
});
return this.collapsePanel(PANELS.notify);
}
return form.setFields({
'notification.disabled': {
value: (initialRule.notification || {}).enabled !== undefined
? !initialRule.notification.enabled
: false,
errors: undefined
}
});
};

render () {
Expand Down

0 comments on commit 2163e14

Please sign in to comment.