diff --git a/client/src/components/Preferences/PreferencesContentRoute.js b/client/src/components/Preferences/PreferencesContentRoute.js
index d619171dd..3ed99820a 100644
--- a/client/src/components/Preferences/PreferencesContentRoute.js
+++ b/client/src/components/Preferences/PreferencesContentRoute.js
@@ -3,15 +3,13 @@ import { Route, Switch, useRouteMatch } from 'react-router-dom';
import preferencesRoutes from 'routes/preferences'
export default function DashboardContentRoute() {
- const { path } = useRouteMatch();
-
return (
{ preferencesRoutes.map((route, index) => (
diff --git a/client/src/components/Preferences/PreferencesSidebar.js b/client/src/components/Preferences/PreferencesSidebar.js
index 763ad31a0..c1987de94 100644
--- a/client/src/components/Preferences/PreferencesSidebar.js
+++ b/client/src/components/Preferences/PreferencesSidebar.js
@@ -18,13 +18,15 @@ export default function PreferencesSidebar() {
return (
);
}
\ No newline at end of file
diff --git a/client/src/components/Views/ViewForm.js b/client/src/components/Views/ViewForm.js
index 20d8c5283..0caca61e4 100644
--- a/client/src/components/Views/ViewForm.js
+++ b/client/src/components/Views/ViewForm.js
@@ -1,4 +1,4 @@
-import React, {useState, useEffect} from 'react';
+import React, {useState, useEffect, useCallback, useMemo} from 'react';
import {Formik, useFormik, ErrorMessage} from "formik";
import {useIntl} from 'react-intl';
import {
@@ -34,12 +34,13 @@ function ViewForm({
const [draggedColumns, setDraggedColumn] = useState([]);
const [availableColumns, setAvailableColumns] = useState(columns);
- const defaultViewRole = {
+ const defaultViewRole = useMemo(() => ({
field_key: '',
comparator: 'AND',
value: '',
index: 1,
- };
+ }), []);
+
const validationSchema = Yup.object().shape({
resource_name: Yup.string().required(),
name: Yup.string().required(),
@@ -86,7 +87,6 @@ function ViewForm({
],
},
onSubmit: (values) => {
-
if (viewForm && viewForm.id) {
editView(viewForm.id, values).then((response) => {
@@ -100,10 +100,11 @@ function ViewForm({
});
useEffect(() => {
- formik.setFieldValue('columns', draggedColumns.map((column, index) => ({
+ formik.setFieldValue('columns',
+ draggedColumns.map((column, index) => ({
index, key: column.key,
})));
- }, [draggedColumns]);
+ }, [draggedColumns, formik]);
const conditionalsItems = [
{ value: 'and', label: 'AND' },
@@ -123,16 +124,16 @@ function ViewForm({
];
// Resource fields.
- const resourceFields = [
+ const resourceFields = useMemo(() => ([
{value: '', label: 'Select a field'},
...fields.map((field) => ({ value: field.key, label: field.labelName, })),
- ];
+ ]), []);
// Account item of select accounts field.
const selectItem = (item, { handleClick, modifiers, query }) => {
return ()
};
// Handle click new condition button.
- const onClickNewRole = () => {
+ const onClickNewRole = useCallback(() => {
formik.setFieldValue('roles', [
...formik.values.roles,
{
@@ -140,9 +141,10 @@ function ViewForm({
index: formik.values.roles.length + 1,
}
]);
- };
+ }, [formik, defaultViewRole]);
+
// Handle click remove view role button.
- const onClickRemoveRole = (viewRole, index) => () => {
+ const onClickRemoveRole = useCallback((viewRole, index) => () => {
const viewRoles = [...formik.values.roles];
viewRoles.splice(index, 1);
viewRoles.map((role, i) => {
@@ -150,9 +152,12 @@ function ViewForm({
return role;
});
formik.setFieldValue('roles', viewRoles);
- };
+ }, [formik]);
+
+ const onClickDeleteView = useCallback(() => {
+ onDelete && onDelete(viewForm);
+ }, [onDelete, viewForm]);
- const onClickDeleteView = () => { onDelete(viewForm); };
return (