Skip to content

Commit

Permalink
GUI S3 Objects lifecycle (#2759): History modal - change filter selec…
Browse files Browse the repository at this point in the history
…t to multiselect. Refactoring
  • Loading branch information
AleksandrGorodetskii committed Aug 25, 2022
1 parent 12062d2 commit 174e5be
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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 @@ -52,6 +54,8 @@ const fullWidthLayout = {
}
};

@inject('usersInfo')
@observer
class NotificationForm extends React.Component {
state = {
previewMode: false,
Expand All @@ -65,6 +69,21 @@ class NotificationForm extends React.Component {
return form.getFieldValue('notification.disabled');
}

@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 [];
}

setPreviewMode = (preview) => {
this.setState({previewMode: preview});
};
Expand Down Expand Up @@ -118,8 +137,8 @@ class NotificationForm extends React.Component {
{getFieldDecorator('notification.informedUserIds', {
type: 'array',
initialValue: rule.notification
? rule.notification.informedUserIds
: undefined
? this.informedUsers
: []
})(
<UsersRolesSelect
adGroups={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import React from 'react';
import PropTypes from 'prop-types';
import {computed} from 'mobx';
import {inject, observer} from 'mobx-react';
import {
Button,
Input,
Expand All @@ -25,11 +27,9 @@ import {
Col,
Select,
Collapse,
message,
Spin
} from 'antd';
import moment from 'moment-timezone';
import UsersInfoFilter from '../../../../../../../models/user/UsersInfoFilter';
import {NotificationForm, TransitionsForm} from '../../forms';
import styles from './life-cycle-edit-modal.css';

Expand Down Expand Up @@ -81,11 +81,22 @@ function FormSection ({
);
}

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

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

get showMatches () {
const {form} = this.props;
const criteriaType = form.getFieldValue('transitionCriterion.type');
Expand Down Expand Up @@ -119,7 +130,7 @@ class LifeCycleEditModal extends React.Component {
delete payload.notification.disabled;
}
if (notification && notification.informedUserIds) {
const recipientsIds = await this.fetchRecipientsInfo(notification.informedUserIds);
const recipientsIds = this.getIdsFromUsers(notification.informedUserIds);
payload.notification.informedUserIds = recipientsIds;
}
if (transitions && transitions.length) {
Expand Down Expand Up @@ -147,24 +158,14 @@ class LifeCycleEditModal extends React.Component {
});
};

fetchRecipientsInfo = async (recipients) => {
if (!recipients || !recipients.length > 0) {
return undefined;
}
const names = recipients
.map(recipient => recipient.name)
.filter(Boolean);
if (names && names.length) {
const request = new UsersInfoFilter(names);
await request.fetch();
if (request.error) {
message.error(request.error, 5);
getIdsFromUsers = (users = []) => {
return users.map(user => {
const userInfo = this.usersInfo.find(info => info.name === user.name);
if (userInfo) {
return userInfo.id;
}
return request.loaded && request.value && request.value.length > 0
? request.value.map(user => user.id)
: undefined;
}
return undefined;
return undefined;
}).filter(Boolean);
};

onCancel = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class LifeCycleHistoryModal extends React.Component {
const {executions} = this.state;
const executionsData = executions.map(execution => ({
date: moment.utc(execution.updated).format(FULL_FORMAT),
action: ACTION_TYPES.transition,
action: DESTINATIONS[execution.storageClass] === DESTINATIONS.DELETION
? ACTION_TYPES.deletion
: ACTION_TYPES.transition,
user: 'System',
file: execution.path,
prolongation: undefined,
Expand All @@ -120,8 +122,9 @@ class LifeCycleHistoryModal extends React.Component {

get filteredHistory () {
const {actionFilter} = this.state;
if (actionFilter) {
return this.history.filter(entry => entry.action === actionFilter);
if (actionFilter && actionFilter.length > 0) {
return this.history
.filter(entry => actionFilter.includes(entry.action));
}
return this.history;
}
Expand All @@ -142,8 +145,8 @@ class LifeCycleHistoryModal extends React.Component {
}
};

onSelectActionFilter = (key) => {
this.setState({actionFilter: key});
onSelectActionFilter = (keys) => {
this.setState({actionFilter: keys});
};

renderHeader = () => {
Expand Down Expand Up @@ -172,14 +175,10 @@ class LifeCycleHistoryModal extends React.Component {
Action type:
</span>
<Select
mode="multiple"
onChange={this.onSelectActionFilter}
style={{marginLeft: 5, width: 150}}
className={styles.historyFilter}
>
<Select.Option
style={{height: 32}}
value={undefined}
key="empty"
/>
{Object.values(ACTION_TYPES).map((description) => (
<Select.Option
value={description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@
flex-direction: column;
width: fit-content;
}

.history-filter {
min-width: 150px;
max-width: 350px;
margin-left: 5px;
}
1 change: 1 addition & 0 deletions client/src/components/special/users-roles-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class UsersRolesSelect extends React.Component {
@computed
get users () {
const {users} = this.props;
console.log('users', users)
if (users && users.loaded) {
return (users.value || [])
.map(user => ({
Expand Down

0 comments on commit 174e5be

Please sign in to comment.