Skip to content

Commit 9958928

Browse files
committed
x
1 parent e2e13f1 commit 9958928

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/components/record/RecordController.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { withRouter } from "react-router-dom";
2626
import { EXTENSIONS } from "../../../config";
2727
import { trackPromise } from "react-promise-tracker";
2828
import PropTypes from "prop-types";
29+
import { loadUsers } from "../../actions/UsersActions.js";
2930

3031
class RecordController extends React.Component {
3132
constructor(props) {
@@ -51,6 +52,8 @@ class RecordController extends React.Component {
5152
this.setState({ showAlert: true });
5253
this.props.unloadSavedRecord();
5354
}
55+
56+
this.props.loadUsers();
5457
}
5558

5659
componentDidUpdate(prevProps, prevState, snapshot) {
@@ -241,6 +244,8 @@ RecordController.propTypes = {
241244
loadFormgen: PropTypes.func.isRequired,
242245
formTemplatesLoaded: PropTypes.object.isRequired,
243246
location: PropTypes.object.isRequired,
247+
loadUsers: PropTypes.func.isRequired,
248+
users: PropTypes.array.isRequired,
244249
};
245250

246251
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(withI18n(withRouter(RecordController))));
@@ -254,6 +259,7 @@ function mapStateToProps(state) {
254259
viewHandlers: state.router.viewHandlers,
255260
formTemplatesLoaded: state.formTemplates.formTemplatesLoaded,
256261
formgen: state.record.formgen,
262+
users: state.users.usersLoaded.users,
257263
};
258264
}
259265

@@ -266,5 +272,6 @@ function mapDispatchToProps(dispatch) {
266272
unloadSavedRecord: bindActionCreators(unloadSavedRecord, dispatch),
267273
loadFormgen: bindActionCreators(loadFormgen, dispatch),
268274
transitionToWithOpts: bindActionCreators(transitionToWithOpts, dispatch),
275+
loadUsers: bindActionCreators(loadUsers, dispatch),
269276
};
270277
}

src/components/record/RecordForm.jsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
import React from "react";
42
import SForms, { Constants } from "@kbss-cvut/s-forms";
53
import PropTypes from "prop-types";
@@ -18,6 +16,7 @@ import PromiseTrackingMask from "../misc/PromiseTrackingMask";
1816
import { trackPromise } from "react-promise-tracker";
1917
import { ROLE } from "../../constants/DefaultConstants.js";
2018
import { hasRole } from "../../utils/RoleUtils.js";
19+
import { connect } from "react-redux";
2120
// import "intelligent-tree-select/lib/styles.css"
2221

2322
// const componentMapping = SmartComponents.getComponentMapping();
@@ -70,15 +69,21 @@ class RecordForm extends React.Component {
7069
const result = await axiosBackend.get(`${FORM_GEN_POSSIBLE_VALUES_URL}?query=${encodeURIComponent(query)}`);
7170
return result.data;
7271
};
72+
_addLabelsToUsers(users) {
73+
return users.map((user) => ({
74+
...user,
75+
id: user.uri,
76+
label: `${user.firstName} ${user.lastName} (${user.username})`,
77+
}));
78+
}
7379

7480
_getUsersOptions() {
75-
const currentUser = this.props.currentUser;
81+
const users = this.props.users || [];
7682
return {
77-
users: [{ id: currentUser.uri, label: currentUser.firstName + " " + currentUser.lastName }],
78-
currentUser: currentUser.uri,
83+
users: this._addLabelsToUsers(users),
84+
currentUser: this.props.currentUser.uri,
7985
};
8086
}
81-
8287
_getIconsOptions() {
8388
if (hasRole(this.props.currentUser, ROLE.COMMENT_RECORD_QUESTIONS)) {
8489
return {
@@ -148,6 +153,13 @@ RecordForm.propTypes = {
148153
isFormValid: PropTypes.func,
149154
form: PropTypes.object,
150155
updateForm: PropTypes.func,
156+
users: PropTypes.array.isRequired,
151157
};
152158

153-
export default injectIntl(withI18n(RecordForm, { forwardRef: true }), { forwardRef: true });
159+
export default connect(mapStateToProps)(injectIntl(withI18n(RecordForm, { forwardRef: true }), { forwardRef: true }));
160+
161+
function mapStateToProps(state) {
162+
return {
163+
users: state.users.usersLoaded.users,
164+
};
165+
}

0 commit comments

Comments
 (0)