-
Notifications
You must be signed in to change notification settings - Fork 17
/
UserListMenuActions.js
110 lines (98 loc) · 3.19 KB
/
UserListMenuActions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { DropdownKebab, MenuItem } from 'patternfly-react';
import { LinkMenuItem } from '@entando/menu';
import { routeConverter } from '@entando/utils';
import {
history,
ROUTE_USER_AUTHORITY, ROUTE_USER_DETAIL,
ROUTE_USER_EDIT, ROUTE_USER_PROFILE,
} from 'app-init/router';
class UserListMenuActions extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
this.handleClickView = this.handleClickView.bind(this);
this.onClickEdit = this.onClickEdit.bind(this);
}
onClickEdit() {
history.push(routeConverter(ROUTE_USER_EDIT, { username: this.props.username }));
}
handleClick(handler) {
return (ev) => {
ev.preventDefault();
if (handler) { handler(this.props); }
};
}
handleClickView = (ev) => {
ev.preventDefault();
this.props.onClickView(this.props.username);
}
render() {
const { onClickDelete } = this.props;
const manageAuthLabel = (
<FormattedMessage id="user.action.manageAuth" values={{ username: this.props.username }} />
);
const editUserProfileLabel = (
<FormattedMessage id="user.action.editProfile" values={{ username: this.props.username }} />
);
const renderViewProfile = () => {
if (this.props.hasProfile) {
return (
<MenuItem
className="UserListMenuAction__menu-item-view-profile"
onClick={() => history.push(routeConverter(
ROUTE_USER_DETAIL,
{ username: this.props.username },
))}
>
<FormattedMessage id="user.action.viewProfile" values={{ username: this.props.username }} />
</MenuItem>
);
}
return null;
};
return (
<DropdownKebab pullRight id={`${this.props.username}-actions`}>
<MenuItem
className="UserListMenuAction__menu-item-edit"
onClick={this.onClickEdit}
>
<FormattedMessage id="app.edit" />
</MenuItem>
<LinkMenuItem
id={`manageAuth-${this.props.username}`}
to={routeConverter(ROUTE_USER_AUTHORITY, { username: this.props.username })}
label={manageAuthLabel}
className="UserListMenuAction__menu-item-auth"
/>
<LinkMenuItem
id={`editProfile-${this.props.username}`}
to={routeConverter(ROUTE_USER_PROFILE, { username: this.props.username })}
label={editUserProfileLabel}
className="UserListMenuAction__menu-item-edit-profile"
/>
{renderViewProfile()}
<MenuItem
className="UserListMenuAction__menu-item-delete"
onClick={this.handleClick(onClickDelete)}
>
<FormattedMessage id="app.delete" />
</MenuItem>
</DropdownKebab>
);
}
}
UserListMenuActions.propTypes = {
onClickDelete: PropTypes.func,
onClickView: PropTypes.func,
username: PropTypes.string.isRequired,
hasProfile: PropTypes.bool,
};
UserListMenuActions.defaultProps = {
onClickDelete: () => {},
onClickView: () => {},
hasProfile: false,
};
export default UserListMenuActions;