Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic/formik #1435

Draft
wants to merge 144 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
9ea7db7
ENG-2811 Rewrite user form to use formik instead of redux-form
raxkaynan Nov 15, 2021
7f5e692
ENG-2811 Move user form validation function to formikValidations module
raxkaynan Nov 15, 2021
97e5aef
Refactor formik SwitchInput by moving unnecessary function into the c…
raxkaynan Nov 16, 2021
65b709e
ENG-2821 user authority form migrate to formik progress
Nov 18, 2021
21757c4
ENG-2821 field array issue resolved
Jan 19, 2022
e6d03af
ENG-2821 unit test updated
Jan 20, 2022
80828fd
ENG-2821 revert change from different base branch
Jan 20, 2022
d437bb6
Revert "ENG-2811 Re-implement user form to use formik instead of redu…
raxkaynan Jan 20, 2022
98f829a
Revert "ENG-2821 convert User Authority Form with Formik"
Jan 20, 2022
279e229
Revert "Revert "ENG-2821 convert User Authority Form with Formik""
Jan 20, 2022
5819412
Revert "Revert "ENG-2811 Re-implement user form to use formik instead…
raxkaynan Jan 20, 2022
8d9ed2e
ENG-2821 amend toast notifications when adding a new user authorization
Jan 21, 2022
c4b9f2e
ENG-3118 integration with formic
Jan 24, 2022
35acf12
ENG-3118 updated unit tests
Jan 25, 2022
4114893
ENG-3118 amended action id for active language list table row for cyp…
Jan 25, 2022
fb6ca59
ENG-3118 removed required validator for language dropdown + reset for…
Jan 25, 2022
201b74e
ENG-3118 formic migration progress for labels form
Jan 21, 2022
39b4a4c
ENG-3124 corrected field handling with formic
Jan 24, 2022
8a415d0
ENG-3124 unit tests for label form updated + amended unmount state to…
Jan 25, 2022
bac135c
ENG-3124 removed unused action
Jan 26, 2022
6d2385c
ENG-2811 Fix user form registration field type checking
raxkaynan Jan 24, 2022
5a137e1
ENG-2824 Re-implement user restrictions form to use formik
raxkaynan Jan 21, 2022
7e98313
ENG-2824 Update restrictions form tests
raxkaynan Jan 24, 2022
2f4a498
ENG-3124 modify error restructurer to accept dot notation + nested fi…
Jan 27, 2022
6b4d71a
refactor Roles screen to formik
gReis89 Jan 25, 2022
0c21e26
renaming function
gReis89 Jan 31, 2022
7208a65
re-implement smtp email config form on formik
gReis89 Feb 1, 2022
768e337
adding success toast
gReis89 Feb 4, 2022
1884eb5
adding number validation to timeout and port
gReis89 Feb 4, 2022
381e4c8
formik/ENG-3121 replace old label search form with formik
chalagashvili Jan 24, 2022
31d1d40
ENG-3121 add correct page handling
chalagashvili Feb 2, 2022
e625e95
ENG-3121 implement correct value sharing
chalagashvili Feb 4, 2022
5d8df70
ENG-3130 Re-implement email sender form to use formik
raxkaynan Jan 28, 2022
3ce9fa0
ENG-3130 Update email sender form tests
raxkaynan Jan 31, 2022
9606dd2
ENG-3130 Pass the onSubmit prop to the email sender formik component
raxkaynan Feb 3, 2022
8b0b72c
ENG-3130 Add email validation to email sender form
raxkaynan Feb 7, 2022
fd4d757
Rebase with develop done
chalagashvili Jan 20, 2023
1d7e0f2
ENG-4557 implement add page form container
ichalagashvili Feb 13, 2023
be9a971
Implement add and clone containers with formik
ichalagashvili Feb 16, 2023
b3988df
ENG-4398 replace redux-form with formik for page form pages
ichalagashvili Feb 20, 2023
5d0ee2e
ENG-4405 replace fragment settings form with formik
ichalagashvili Jan 30, 2023
8b8b05b
ENG-4405 add tests
ichalagashvili Feb 1, 2023
7bb7715
ENG-4402 now with Formik
davdet Feb 15, 2023
fcbe713
ENG-4402 Replaced with Formik
davdet Feb 22, 2023
d33348e
ENG-4402 removes comments
davdet Apr 6, 2023
48da1ce
ENG-4404 implement user search form with formik
ichalagashvili Apr 20, 2023
7752f42
ENG-4401 reimplement fragment search form with formik
ichalagashvili Jul 5, 2023
b83eb65
ENG-4406 reimplement file browser forms with formik
ichalagashvili Apr 27, 2023
c6c556e
amend submit test
DMinnai Jul 4, 2023
e86a68b
removed useless comment
DMinnai Jul 4, 2023
d5b7653
ENG-4408 implement simple widget config form with formik
ichalagashvili Jul 11, 2023
2e82892
formik refactor on accont
DMinnai Jul 6, 2023
91b55dc
ENG-4400 reimplement password change form with formik
ichalagashvili Jul 10, 2023
39ac916
removed unused file bak
DMinnai Jul 27, 2023
324a177
test commit
DMinnai Jul 28, 2023
d9e8506
test commit 2
DMinnai Jul 28, 2023
2470e78
Update package-lock.json
DMinnai Jul 28, 2023
6b56dee
profile section working with updated state
DMinnai Aug 1, 2023
99233f0
redux removed
DMinnai Aug 3, 2023
2513c94
ENG-4399 fix list rendering
Aug 3, 2023
d02eb8d
ENG-4407: fix swap and remove expressions
Aug 4, 2023
3429f3b
ENG-4399 fix profilepicture field in MyProfileEditForm.js
Aug 7, 2023
e3a2762
ENG-4399-fileld required added
DMinnai Aug 8, 2023
76adb78
ENG-4399 add disable button when profile form is not valid
Aug 8, 2023
1cc6e18
ENG-4399 fix lint
Aug 8, 2023
f0cd05e
ENG-4399-revert navbar files
DMinnai Aug 8, 2023
eced803
ENG-4399 fix cancel button behaviour in profile form
Aug 8, 2023
988d560
ENG-4399-revert navbar files
DMinnai Aug 8, 2023
ed0cd15
ENG-4399 removed unused components
DMinnai Sep 6, 2023
63a01b8
ENG-4399 removed redux-form from container
DMinnai Sep 7, 2023
58cdacd
ENG-4399 removed redux-form from container
DMinnai Sep 7, 2023
4120696
ENG-5150 remove redux form and fix the formi bugs in search form
ichalagashvili Sep 14, 2023
457fed3
ENG-5151 remove redux form from clone fragment container
ichalagashvili Sep 14, 2023
d268539
ENG-5154 remove redux form from appsettings container
ichalagashvili Sep 14, 2023
8d50a88
ENG-4407: remove reduxForm
Aug 24, 2023
d094499
ENG-4407: remove reduxForm from NavigationBarConfig
Aug 24, 2023
db34b91
ENG-4407: use shallow copy of expressions to apply changes
Sep 18, 2023
7766398
ENG-5152 remove redux form from find template container
ichalagashvili Sep 22, 2023
e309810
ENG-4402 now with Formik
davdet Feb 15, 2023
a4dbfc3
ENG-4402 Replaced with Formik
davdet Feb 22, 2023
d0a5c08
Update package-lock.json
DMinnai Jul 28, 2023
229c002
ENG-5157 draft edit user profile
Sep 18, 2023
c1b7570
ENG-5157 fix RenderListField for formik
Sep 19, 2023
bcee816
ENG-5157 adapt edit user profile page with formik standards
Sep 22, 2023
9046c75
ENG-5157 remove unuseful changes
Sep 22, 2023
feb0eb3
ENG-5157 remove unused file and add .vscode folder in gitignore
Sep 27, 2023
59897f1
ENG-5161 reimplement single content widget config with formik
ichalagashvili Sep 28, 2023
5e24156
ENG-5148 & ENG-5149: replace redux-form with formik in profile types …
Oct 4, 2023
eb3fb2f
ENG-5153 remove redux-form dependency from MonolistProfilePageContain…
Oct 4, 2023
9651839
ENG-5156 & ENG-5163 replace redux form with formik on add and edit pr…
Oct 4, 2023
e516f56
ENG-5156 & ENG-5163 add validation helper
Oct 4, 2023
82b0153
ENG-5147 remove redux form from bundle group auto complete
Oct 5, 2023
2c9c3f0
ENG-5165 remove unused components and their dependencies
Oct 6, 2023
06f7a4a
ENG-5157 fix component prop
Oct 6, 2023
b85533f
Merge pull request #1551 from entando/ENG-5161
ichalagashvili Oct 9, 2023
7069e24
ENG-5158 replace redux-form RenderListField with formik RenderListField
Oct 9, 2023
113582d
Merge pull request #1550 from entando/ENG-5157_Formik_edit_user_profile
ryanjpburgos Oct 10, 2023
6602fe0
Merge pull request #1553 from entando/ENG-5153_Formik_MonolistProfile…
ryanjpburgos Oct 10, 2023
aba94c7
Merge pull request #1554 from entando/ENG-5156_Formik_ProfileTypesAdd…
ryanjpburgos Oct 10, 2023
4485a16
Merge pull request #1556 from entando/ENG-5165_remove_unused_components
ryanjpburgos Oct 10, 2023
5107bf6
Merge pull request #1558 from entando/ENG-5147_Formik_BundleGroupAuto…
ryanjpburgos Oct 10, 2023
9382e16
ENG-5160 implement multi content widget with config
ichalagashvili Oct 13, 2023
8102060
ENG-5155 remove redux-form func from edit widget page
ichalagashvili Oct 18, 2023
7c0fd0d
ENG-5159 remove redux form on ContentsQueryConfig
Oct 18, 2023
2cbe005
ENG-5159 fix submit form
Oct 19, 2023
cab59f0
Merge branch 'epic/formik' of https://github.com/entando/app-builder …
Oct 19, 2023
86ad80b
Merge pull request #1557 from entando/ENG-5158_formik_myprofileeditform
ryanjpburgos Oct 19, 2023
d3a70de
Merge pull request #1552 from entando/ENG-5148_formik_profile_types
ryanjpburgos Oct 19, 2023
914b4b4
ENG-4834 implement add/edit forms with formik
ichalagashvili Oct 22, 2023
de4735c
ENG-5160 remove reused function
ichalagashvili Oct 22, 2023
95c7608
ENG-5162 implement widget forms with formik
ichalagashvili Oct 10, 2023
f33e59d
ENG-5162 fix the bug with multiple validators
ichalagashvili Oct 13, 2023
0690387
ENG-5162 remove unused func
ichalagashvili Oct 22, 2023
7b5ccef
Merge pull request #1559 from entando/ENG-5162_formik
ichalagashvili Oct 23, 2023
194e04d
Merge pull request #1560 from entando/ENG-5160_formik
ichalagashvili Oct 23, 2023
af4f394
Merge pull request #1562 from entando/ENG-5155
ichalagashvili Oct 23, 2023
111b85b
Merge pull request #1565 from entando/ENG-4834_correct_error
ichalagashvili Oct 23, 2023
e8f816e
ENG-5251 remove redux-form from actions and selectors
Oct 24, 2023
928d374
Merge branch 'epic/formik' of https://github.com/entando/app-builder …
Oct 24, 2023
a329803
ENG-5159 fixes after PR review
Oct 24, 2023
160e303
ENG-5159 fixes after pr review
Oct 31, 2023
2f5cdfb
ENG-5251 remove unused code
Oct 31, 2023
37412e1
ENG-5159 fix save as mode of contentsqueryconfig and ui bug
Nov 2, 2023
bd2a9fa
ENG-5271 fix profile type attribute forms validations
Nov 2, 2023
cbac875
ENG-5159 fix content template loading on save as mode
Nov 6, 2023
d16e377
Merge pull request #1564 from entando/ENG-5159_ContentsQueryConfig
ryanjpburgos Nov 7, 2023
2e710b4
Merge pull request #1567 from entando/ENG-5251_actions_and_selectors
ryanjpburgos Nov 7, 2023
e380a74
Merge pull request #1572 from entando/ENG-5271_FixProfileTypesForm
ryanjpburgos Nov 7, 2023
f804d18
ENG-5185 fix profile type attribute regressions
ichalagashvili Nov 27, 2023
2214312
ENG-5185 fix empty value for selector
ichalagashvili Dec 5, 2023
762b0a2
ENG-5185 reimplement missing profile form formik functionality
ichalagashvili Dec 6, 2023
879f09e
ENG-4362 reimplement the my profile field validations with formik
ichalagashvili Oct 30, 2023
a34eb38
Merge pull request #1570 from entando/ENG-4362_formik
ichalagashvili Dec 6, 2023
3a93316
ENG-5185 inject console logs for remote debugging
ichalagashvili Dec 6, 2023
4c34d1d
ENG-5185 set empty field value when selecting
ichalagashvili Dec 8, 2023
e66d160
ENG-5185 remove unwated values var
ichalagashvili Dec 8, 2023
ac34e50
ENG-5185 final fix
ichalagashvili Dec 12, 2023
440fe19
Merge pull request #1579 from entando/ENG-5185_fix_attributes
ichalagashvili Dec 12, 2023
aa8e46f
ENG-5428 fix the roles ux for formik regression
ichalagashvili Jan 16, 2024
201eb97
Merge pull request #1588 from entando/ENG-5428_roles_fix
ichalagashvili Jan 23, 2024
3497b86
ENG-5437 fix user submit error callback
ichalagashvili Jan 23, 2024
40d71ff
ENG-5447 fix choose content button
ichalagashvili Jan 23, 2024
7bdf381
Merge pull request #1590 from entando/ENG-5437_new_user
ichalagashvili Jan 26, 2024
63f5e65
Merge pull request #1591 from entando/ENG-5447_content_usage
ichalagashvili Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/state/users/actions.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import { setPage } from 'state/pagination/actions';
import { toggleLoading } from 'state/loading/actions';
import { history, ROUTE_USER_LIST, ROUTE_USER_PROFILE } from 'app-init/router';
import { routeConverter } from '@entando/utils';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL } from 'state/users/types';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL, SET_USER_SEARCH_TERM } from 'state/users/types';
import { setVisibleModal } from 'state/modal/actions';


@@ -52,6 +52,11 @@ export const setUsersTotal = usersTotal => ({
},
});

export const setUserSearchTerm = searchTerm => ({
type: SET_USER_SEARCH_TERM,
payload: searchTerm,
});

// thunk
export const fetchUsers = (page = { page: 1, pageSize: 10 }, params = '') => dispatch => (
new Promise((resolve) => {
12 changes: 11 additions & 1 deletion src/state/users/reducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combineReducers } from 'redux';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL } from 'state/users/types';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL, SET_USER_SEARCH_TERM } from 'state/users/types';
import { ACTION_SAVE, ACTION_UPDATE } from 'state/users/const';

const toMap = array => array.reduce((acc, user) => {
@@ -58,10 +58,20 @@ export const total = (state = 0, action = {}) => {
}
};

export const searchTerm = (state = '', action = {}) => {
switch (action.type) {
case SET_USER_SEARCH_TERM: {
return action.payload;
}
default: return state;
}
};

export default combineReducers({
list,
map: userMap,
selected,
authorities,
total,
searchTerm,
});
1 change: 1 addition & 0 deletions src/state/users/selectors.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export const getSelectedUser = state => state.users.selected;
export const getSelectedUserActionAuthorities = state => state.users.authorities.action;
export const getSelectedUserAuthoritiesList = state => state.users.authorities.list;
export const getUsersTotal = state => state.users.total;
export const getUserSearchTerm = state => state.users.searchTerm;

export const getUserList = createSelector(
[getUsersMap, getUsersIdList],
1 change: 1 addition & 0 deletions src/state/users/types.js
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ export const SET_SELECTED_USER = 'users/set-selected-user';
export const SET_SELECTED_USER_AUTHORITIES = 'users/set-selected-user-authorities';
export const TOGGLE_LOADING = 'users/set-toggle-loading';
export const SET_USERS_TOTAL = 'users/set-users-total';
export const SET_USER_SEARCH_TERM = 'users/set-user-search-term';
17 changes: 15 additions & 2 deletions src/ui/users/list/UserListTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Col, Paginator, Alert, Spinner } from 'patternfly-react';
import { convertToQueryString, FILTER_OPERATORS } from '@entando/utils';
import { FormattedMessage, defineMessages, injectIntl, intlShape } from 'react-intl';
import UserListMenuActions from 'ui/users/list/UserListMenuActions';
import UserStatus from 'ui/users/common/UserStatus';
@@ -24,11 +25,21 @@ class UserListTable extends Component {
}

changePage(page) {
this.props.onWillMount({ page, pageSize: this.props.pageSize });
const { onWillMount, userSearchTerm, pageSize } = this.props;
const params = userSearchTerm ? convertToQueryString({
formValues: { username: userSearchTerm },
operators: { key: FILTER_OPERATORS.LIKE },
}) : '';
onWillMount({ page, pageSize }, params);
}

changePageSize(pageSize) {
this.props.onWillMount({ page: 1, pageSize });
const { onWillMount, userSearchTerm } = this.props;
const params = userSearchTerm ? convertToQueryString({
formValues: { username: userSearchTerm },
operators: { key: FILTER_OPERATORS.LIKE },
}) : '';
onWillMount({ page: 1, pageSize }, params);
}

renderTableRows() {
@@ -150,12 +161,14 @@ UserListTable.propTypes = {
page: PropTypes.number.isRequired,
pageSize: PropTypes.number.isRequired,
totalItems: PropTypes.number.isRequired,
userSearchTerm: PropTypes.string,
};

UserListTable.defaultProps = {
onWillMount: () => {},
loading: false,
users: [],
userSearchTerm: '',
};

export default injectIntl(UserListTable);
7 changes: 4 additions & 3 deletions src/ui/users/list/UserListTableContainer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { connect } from 'react-redux';

import { fetchUsers } from 'state/users/actions';
import { getUserList } from 'state/users/selectors';
import { getUserList, getUserSearchTerm } from 'state/users/selectors';
import { getLoading } from 'state/loading/selectors';
import { getCurrentPage, getTotalItems, getPageSize } from 'state/pagination/selectors';
import UserListTable from 'ui/users/list/UserListTable';
@@ -15,11 +15,12 @@ export const mapStateToProps = state => ({
totalItems: getTotalItems(state),
pageSize: getPageSize(state),
loading: getLoading(state).users,
userSearchTerm: getUserSearchTerm(state),
});

export const mapDispatchToProps = dispatch => ({
onWillMount: (page = { page: 1, pageSize: 10 }) => {
dispatch(fetchUsers(page));
onWillMount: (page = { page: 1, pageSize: 10 }, params) => {
dispatch(fetchUsers(page, params));
},
onClickDelete: (user) => {
dispatch(setVisibleModal(MODAL_ID));
51 changes: 34 additions & 17 deletions src/ui/users/list/UserSearchForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { reduxForm, Field } from 'redux-form';
import { FormattedMessage, defineMessages, injectIntl, intlShape } from 'react-intl';
import { Row, Col, FormGroup, Button } from 'patternfly-react';
import { Form, Field, withFormik } from 'formik';
import * as Yup from 'yup';

import { TEST_ID_USER_SEARCH_FORM } from 'ui/test-const/user-test-const';
import RenderTextInput from 'ui/common/formik-field/RenderTextInput';

export const renderSelectOptions = options => (
options.map(option => (
@@ -24,14 +27,13 @@ const msgs = defineMessages({
});

export class UserSearchFormBody extends Component {
componentWillMount() {
this.props.onWillMount();
componentDidMount() {
this.props.onDidMount();
}

onSubmit = (ev) => {
ev.preventDefault();
this.props.handleSubmit();
};
componentWillUnmount() {
this.props.onUnmount();
}

handleClick(handler) {
return (ev) => {
@@ -41,26 +43,28 @@ export class UserSearchFormBody extends Component {
}

render() {
const { intl } = this.props;
const { intl, isValid, isSubmitting } = this.props;
return (
<form onSubmit={this.onSubmit} className="UserSearchForm form-horizontal well" data-testid={TEST_ID_USER_SEARCH_FORM.FORM}>
<Form className="UserSearchForm form-horizontal well" data-testid={TEST_ID_USER_SEARCH_FORM.FORM} aria-label="form">
<h3><FormattedMessage id="app.search" /></h3>
<FormGroup>
<Row>
<div>
<label className="control-label col-sm-2" htmlFor="username">
<FormattedMessage id="user.table.username" />
</label>
<Col sm={9}>
<Field
id="username"
component="input"
inputSize={10}
labelSize={0}
component={RenderTextInput}
className="form-control UserSearchForm__username"
name="username"
placeholder={intl.formatMessage(msgs.username)}
data-testid={TEST_ID_USER_SEARCH_FORM.USERNAME_FIELD}
/>
</Col>
</Row>
</div>
</FormGroup>
{/* Form for user profiletype search */}
{/* insert Advanced Search component when available */}
@@ -73,25 +77,38 @@ export class UserSearchFormBody extends Component {
bsStyle="primary"
className="pull-right"
data-testid={TEST_ID_USER_SEARCH_FORM.SEARCH_BUTTON}
disabled={!isValid || isSubmitting}
>
<FormattedMessage id="app.search" />
</Button>
</Col>
</Row>
</FormGroup>
</form>
</Form>
);
}
}

UserSearchFormBody.propTypes = {
intl: intlShape.isRequired,
handleSubmit: PropTypes.func.isRequired,
onWillMount: PropTypes.func.isRequired,
onDidMount: PropTypes.func.isRequired,
isValid: PropTypes.bool.isRequired,
isSubmitting: PropTypes.bool.isRequired,
onUnmount: PropTypes.func.isRequired,
};

const UserSearchForm = reduxForm({
form: 'userSearch',
const UserSearchForm = withFormik({
enableReinitialize: true,
mapPropsToValues: ({ initialValues }) => initialValues,
validationSchema: () => (
Yup.object().shape({
username: Yup.string().nullable(true),
})
),
handleSubmit: (values, { setSubmitting, props: { onSubmit } }) => {
onSubmit(values).then(() => setSubmitting(false));
},
displayName: 'userSearchFormFormik',
})(UserSearchFormBody);

export default injectIntl(UserSearchForm);
14 changes: 10 additions & 4 deletions src/ui/users/list/UserSearchFormContainer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { connect } from 'react-redux';
import { fetchUsers } from 'state/users/actions';
import { fetchUsers, setUserSearchTerm } from 'state/users/actions';
import { fetchProfileTypes } from 'state/profile-types/actions';
import { getProfileTypesOptions } from 'state/profile-types/selectors';
import UserSearchForm from 'ui/users/list/UserSearchForm';
import { convertToQueryString, FILTER_OPERATORS } from '@entando/utils';
import { PROFILE_FILTER_VALUE_MAP, PROFILE_FILTER_OPTIONS } from 'ui/users/common/const';
import { getUserSearchTerm } from 'state/users/selectors';

const FIELD_OPERATORS = {
username: FILTER_OPERATORS.LIKE,
};

const generateQueryString = (values) => {
export const generateQueryString = (values) => {
const newValues = { ...values };
delete newValues.withProfile;
const withProfile = PROFILE_FILTER_VALUE_MAP[values.withProfile] !== null ?
@@ -28,15 +29,20 @@ export const mapStateToProps = state => ({
profileTypes: getProfileTypesOptions(state),
initialValues: {
withProfile: PROFILE_FILTER_OPTIONS[0].id,
username: getUserSearchTerm(state) || '',
},
});

export const mapDispatchToProps = dispatch => ({
onWillMount: () => {
onDidMount: () => {
dispatch(fetchProfileTypes());
},
onSubmit: (values) => {
dispatch(fetchUsers({ page: 1, pageSize: 10 }, generateQueryString(values)));
dispatch(setUserSearchTerm(values.username));
return dispatch(fetchUsers({ page: 1, pageSize: 10 }, values.username ? generateQueryString(values) : ''));
},
onUnmount: () => {
dispatch(setUserSearchTerm(''));
},
});

11 changes: 10 additions & 1 deletion test/state/users/actions.test.js
Original file line number Diff line number Diff line change
@@ -9,8 +9,9 @@ import {
setSelectedUserDetail, fetchCurrentPageUserDetail, setUsersTotal,
fetchUsersTotal, sendDeleteUser, fetchUserAuthorities, sendPostUserAuthorities,
sendPutUserAuthorities, sendDeleteUserAuthorities, sendPostMyPassword,
setUserSearchTerm,
} from 'state/users/actions';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL } from 'state/users/types';
import { SET_USERS, SET_SELECTED_USER, SET_SELECTED_USER_AUTHORITIES, SET_USERS_TOTAL, SET_USER_SEARCH_TERM } from 'state/users/types';
import { TOGGLE_LOADING } from 'state/loading/types';
import { SET_PAGE } from 'state/pagination/types';
import { SET_VISIBLE_MODAL } from 'state/modal/types';
@@ -63,6 +64,14 @@ describe('state/users/actions', () => {
expect(action).toHaveProperty('payload.usersTotal', 12);
});
});

describe('setUserSearchTerm', () => {
it('test setUserSearchTerm action sets the correct type', () => {
const action = setUserSearchTerm('test');
expect(action).toHaveProperty('type', SET_USER_SEARCH_TERM);
expect(action).toHaveProperty('payload', 'test');
});
});
});

describe('thunk', () => {
13 changes: 12 additions & 1 deletion test/state/users/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import reducer from 'state/users/reducer';
import { setUsers, setSelectedUserDetail, setSelectedUserAuthorities, setUsersTotal } from 'state/users/actions';
import { setUsers, setSelectedUserDetail, setSelectedUserAuthorities, setUsersTotal, setUserSearchTerm } from 'state/users/actions';
import { USERS, AUTHORITIES } from 'test/mocks/users';

const users = USERS;
@@ -40,6 +40,17 @@ describe('state/users/reducer', () => {
});
});

describe('after action SET_USER_SEARCH_TERM', () => {
let newState;
beforeEach(() => {
newState = reducer(state, setUserSearchTerm('test'));
});

it('should define the dataType payload', () => {
expect(newState.searchTerm).toEqual('test');
});
});

describe('after action SET_SELECTED_USERS_AUTHORITIES', () => {
let newState;
beforeEach(() => {
6 changes: 6 additions & 0 deletions test/state/users/selectors.test.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import {
getUsersMap,
getUserList,
getUsersTotal,
getUserSearchTerm,
} from 'state/users/selectors';

jest.mock('state/locale/selectors', () => ({ getLocale: () => ('en') }));
@@ -14,6 +15,7 @@ const TEST_STATE = {
users: {
...USERS_NORMALIZED,
total: 2,
searchTerm: 'test',
},
};

@@ -39,4 +41,8 @@ describe('state/users/selectors', () => {
it('verify getTotalUsers selector', () => {
expect(getUsersTotal(TEST_STATE)).toEqual(2);
});

it('verify getUserSearchTerm selector', () => {
expect(getUserSearchTerm(TEST_STATE)).toEqual('test');
});
});
3 changes: 1 addition & 2 deletions test/ui/email-config/EmailConfigSmtpServer.test.js
Original file line number Diff line number Diff line change
@@ -36,8 +36,7 @@ describe('EmailConfigSmtpServer', () => {
});

it('should render General Settings section', () => {
const { debug } = setupEmailConfigForm();
debug();
setupEmailConfigForm();
expect(getHeadings(screen)[0]).toHaveTextContent('General Settings');
expect(screen.getByLabelText('Active')).toHaveTextContent('ON');
expect(screen.getByLabelText('Debug Mode')).toHaveTextContent('OFF');
4 changes: 3 additions & 1 deletion test/ui/users/list/UserListTableContainer.test.js
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@ import 'test/enzyme-init';

import { mapStateToProps, mapDispatchToProps } from 'ui/users/list/UserListTableContainer';
import { USERS } from 'test/mocks/users';
import { getUserList } from 'state/users/selectors';
import { getUserList, getUserSearchTerm } from 'state/users/selectors';
import { getLoading } from 'state/loading/selectors';

const dispatchMock = jest.fn();

jest.mock('state/users/selectors', () => ({
getUserList: jest.fn(),
getUserSearchTerm: jest.fn(),
}));

jest.mock('state/loading/selectors', () => ({
@@ -23,6 +24,7 @@ jest.mock('state/pagination/selectors', () => ({
const users = USERS;

getUserList.mockReturnValue(users);
getUserSearchTerm.mockReturnValue('');
getLoading.mockReturnValue(false);

describe('UserListTableContainer', () => {
Loading