Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
save entity fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Petrovich committed Jun 29, 2020
1 parent fd47175 commit 6b32f2b
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 43 deletions.
26 changes: 22 additions & 4 deletions client/src/Components/Comments/Comments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Button, Empty, message, notification } from 'antd';

import Textarea from 'Components/Textarea';
import Comment from './Comment';
import actionsTypes from 'actions.types';
import { routeParser } from 'Utils';

class Comments extends React.PureComponent {
state = {
Expand All @@ -29,6 +31,7 @@ class Comments extends React.PureComponent {
onUpdate,
data: { key = '', comments = [], _id: id = '' } = {},
data = {},
path,
udata: { displayName = '', _id: uId = '' } = {},
} = this.props;

Expand All @@ -50,10 +53,17 @@ class Comments extends React.PureComponent {

this.setState({ ...this.state, onUpdateDisabled: true, value: '' });

const parsedRoutePath = routeParser({
pageType: 'moduleItem',
path,
});

await onUpdate({
actionType: actionsTypes.$UPDATE_SINGLE,
parsedRoutePath,
key,
id,
updateBy: 'key',
updateBy: '_id',
updateItem: [...comments, comment],
updateField: 'comments',
store: 'tasks',
Expand Down Expand Up @@ -84,15 +94,22 @@ class Comments extends React.PureComponent {
};

onDelete = async (event, idComment) => {
const { onUpdate, data: { _id: id = '', key = '', comments = [] } = {}, data = {} } = this.props;
const { path, onUpdate, data: { _id: id = '', key = '', comments = [] } = {}, data = {} } = this.props;
const filterComments = comments.filter((it) => it.id !== idComment);
try {
const parsedRoutePath = routeParser({
pageType: 'moduleItem',
path,
});

await onUpdate({
actionType: actionsTypes.$UPDATE_SINGLE,
parsedRoutePath,
id,
key,
item: data,
store: 'tasks',
updateBy: 'key',
updateBy: '_id',
updateItem: filterComments,
updateField: 'comments',
});
Expand Down Expand Up @@ -122,11 +139,12 @@ class Comments extends React.PureComponent {

try {
await onUpdate({
actionType: actionsTypes.$UPDATE_SINGLE,
id,
key,
item: data,
store: 'tasks',
updateBy: 'key',
updateBy: '_id',
updateItem: newCommentsArray,
updateField: 'comments',
});
Expand Down
31 changes: 24 additions & 7 deletions client/src/Components/ModalWindow/ModalWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';
import moment from 'moment';
import { Modal, Button, message, Select } from 'antd';
import { TASK_CONTROLL_JURNAL_SCHEMA } from 'Models/Schema/const';
import { createNotification, isTimeLostValue } from 'Utils';
import { createNotification, isTimeLostValue, routeParser } from 'Utils';
import SimpleEditableModal from './SimpleEditableModal';
import RegistrationModal from './RegistrationModal';
import ActionList from 'Components/ActionList';
Expand Down Expand Up @@ -154,10 +154,19 @@ class ModalWindow extends React.PureComponent {
routeDataActive = {},
routeDataActive: { key = null } = {},
onCancelEditModeContent,
path,
} = this.props;

const parsedRoutePath = routeParser({
pageType: 'moduleItem',
path,
});

onUpdate({
actionType: actionsTypes.$UPDATE_MANY,
parsedRoutePath,
key,
updateBy: 'key',
updateBy: '_id',
id: routeDataActive?._id,
updateItem: valueDescription,
updateField: 'description',
Expand Down Expand Up @@ -248,11 +257,18 @@ class ModalWindow extends React.PureComponent {
});

try {
const parsedRoutePath = routeParser({
pageType: 'moduleItem',
path,
});

await onUpdate({
actionType: actionsTypes.$UPDATE_SINGLE,
parsedRoutePath,
path,
id: routeDataActive?._id,
key,
updateBy: 'key',
updateBy: '_id',
updateItem: _.isString(customStatus) ? customStatus : taskStatus,
updateField: 'status',
item: { ...routeDataActive },
Expand Down Expand Up @@ -416,6 +432,7 @@ class ModalWindow extends React.PureComponent {
const { statusTaskValue, accessStatus } = this.props;
const { type = '' } = this.state;
const { [type]: visible = false } = this.state;

return (
<div className="dropDownWrapper">
<ActionList {...actionProps} />
Expand All @@ -427,13 +444,13 @@ class ModalWindow extends React.PureComponent {
title="Смена статуса"
>
<Select onChange={this.onChangeSelect} defaultValue={statusTaskValue}>
{accessStatus.map((status, i) =>
i === 0 ? (
<Option key={i + status} value={statusTaskValue}>
{accessStatus.map((status, index) =>
index === 0 ? (
<Option key={index + status} value={statusTaskValue}>
{statusTaskValue}
</Option>
) : (
<Option key={i + status} value={status}>
<Option key={status} value={status}>
{status}
</Option>
),
Expand Down
2 changes: 2 additions & 0 deletions client/src/Modules/TaskModule/TaskView/DescriptionTask.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DescriptionTask = forwardRef(
onUpdate,
udata,
rest,
path,
},
ref,
) => {
Expand Down Expand Up @@ -55,6 +56,7 @@ const DescriptionTask = forwardRef(
<Comments
commentProps={commentProps}
udata={udata}
path={path}
rules={true}
onUpdate={onUpdate}
data={routeDataActive}
Expand Down
9 changes: 6 additions & 3 deletions client/src/Modules/TaskModule/TaskView/TaskView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import TitleModule from 'Components/TitleModule';
import modelContext from 'Models/context';
import DescriptionTask from './DescriptionTask';
import renderDescription from './renderDescription';
import actionsTypes from 'actions.types';

class TaskView extends React.PureComponent {
state = {
Expand Down Expand Up @@ -416,11 +417,11 @@ class TaskView extends React.PureComponent {
const { _id: id = '', key = '' } = modeControllEdit || {};
try {
await onUpdate({
actionType: actionsTypes.$UPDATE_MANY,
id,
key,
path,
updateBy: '_id',
actionType: 'update_many',
updateItem: { ...validHash },
item: { ...routeDataActive },
store: 'tasks',
Expand Down Expand Up @@ -619,6 +620,7 @@ class TaskView extends React.PureComponent {
setCurrentTab,
router = {},
columnStyleConfig = {},
currentActionTab: path = '',
} = this.props;

const {
Expand Down Expand Up @@ -685,7 +687,7 @@ class TaskView extends React.PureComponent {
router,
udata,
};

console.log(path);
const descriptionTaskProps = {
...commonProps,
routeDataActive,
Expand All @@ -694,6 +696,7 @@ class TaskView extends React.PureComponent {
filesArray,
onUpdate,
udata,
path,
rest,
};

Expand Down Expand Up @@ -763,7 +766,7 @@ const mapDispatchToProps = (dispatch) => {
return {
onCaching: async (props) => await dispatch(middlewareCaching(props)),
onSaveCache: (props) => dispatch(сachingAction(props)),
onUpdate: (props) => dispatch(middlewareUpdate({ ...props })),
onUpdate: (props) => dispatch(middlewareUpdate(props)),
};
};

Expand Down
4 changes: 4 additions & 0 deletions client/src/Redux/actions/publicActions/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ const middlewareUpdate = (props = {}) => async (dispatch, getState, { schema, Re
store = {},
actionType = 'default',
updateBy = '_id',
parsedRoutePath,
} = props;
const rest = new Request();
/**
* update by @property {string} id more prioritized than @property {string} key
*/

try {
const path =
actionType === actionsTypes.$UPDATE_MANY
Expand All @@ -201,6 +203,7 @@ const middlewareUpdate = (props = {}) => async (dispatch, getState, { schema, Re

if (error) throw new Error(error);
const dep = {
parsedRoutePath,
updateBy,
store,
schema,
Expand All @@ -213,6 +216,7 @@ const middlewareUpdate = (props = {}) => async (dispatch, getState, { schema, Re
await updateEntityHook(dispatch, dep);
} catch (error) {
const depError = {
parsedRoutePath,
store,
actionType,
clientDB,
Expand Down
53 changes: 36 additions & 17 deletions client/src/Redux/reducers/routerStateReducer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,32 @@ export default handleActions(
} else return state;
},
[UPDATE_ITEM]: (state, { payload }) => {
const { routeDataActive, currentActionTab = '', routeData = {}, path = '' } = state;
const { id, updateBy = '_id', updaterItem = {}, store = path.split('__')[0] } = payload;
const { routeDataActive, routeData = {}, path: currentPath = '' } = state;
const {
id,
updateBy = '_id',
updaterItem = {},
store = currentPath.split('__')[0],
parsedRoutePath = {},
} = payload;
const { itemId = '', path = '' } = parsedRoutePath || {};

const isExist = routeDataActive && routeDataActive[updateBy];
const currentModule = currentActionTab.split('__')[0];
const currentModule = path.split('__');

const [moduleName = '', entityId = ''] = currentModule || [];
const itemName = moduleName && entityId ? entityId : moduleName;

const isExistModule = !!routeData[currentModule];
const isExistStore = isExistModule ? !!routeData[currentModule][store] : null;
const { [store]: dataArray = [], ...data } =
!itemId && routeData[currentModule[0]]
? routeData[itemName]
: currentModule[1] && itemId && routeData[itemId]
? routeData[itemId]
: {};

const dataList = Array.isArray(dataArray) && dataArray?.length ? dataArray : data;

const updateCurrent = isExist && routeDataActive[updateBy] === id ? true : false;
const dataList = isExistStore && isExistModule ? routeData[currentModule][store] : [];

const newStore =
Array.isArray(dataList) && dataList?.length
Expand All @@ -400,17 +415,21 @@ export default handleActions(
}
: updaterItem;
})
: null;

const updateCurrentModule =
newStore && newStore.length
? {
[currentModule]: {
...routeData[currentModule],
[store]: newStore,
},
}
: {};
: dataList;

const updateCurrentModule = dataList
? {
[itemName]: {
...routeData[itemName],
[store]:
Array.isArray(newStore) && newStore?.length
? newStore
: !!routeData[itemName][store]
? [...Array.from(routeData[currentModule][store]), newStore]
: [newStore],
},
}
: {};

return {
...state,
Expand Down
3 changes: 2 additions & 1 deletion client/src/Utils/Hooks/coreHook/coreHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const coreUpdaterDataHook = async (dispatch, dep = {}, multiple = false, badNetw
};

const updateEntityHook = async (dispatch, dep = {}) => {
const { store, schema, dataItems, id, updateItemStateAction, updateBy = '' } = dep;
const { parsedRoutePath = null, store, schema, dataItems, id, updateItemStateAction, updateBy = '' } = dep;

const schemaTemplate = getStoreSchema(store);

Expand All @@ -81,6 +81,7 @@ const updateEntityHook = async (dispatch, dep = {}) => {
updaterItem: dataItems,
type: 'UPDATE',
updateBy,
parsedRoutePath,
store,
id,
}),
Expand Down
17 changes: 6 additions & 11 deletions logger.error-audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
"auditLog": "logger.error-audit.json",
"files": [
{
"date": 1593258193859,
"name": "logs\\logs-error-2020-06-27-14.log",
"hash": "e13e7a5f93099201e4885c5218632dbc"
"date": 1593466609490,
"name": "logs\\logs-error-2020-06-30-00.log",
"hash": "08f41f0f2f00f31bb65b58f6081244f4"
},
{
"date": 1593304175219,
"name": "logs\\logs-error-2020-06-28-03.log",
"hash": "61fed90d49ca704c4e56d01130e1206a"
},
{
"date": 1593306800794,
"name": "logs\\logs-error-2020-06-28-04.log",
"hash": "3ae1dc0d79fcdc43628ee8b606b5e764"
"date": 1593468118442,
"name": "logs\\logs-error-2020-06-30-01.log",
"hash": "11e91c590cba98806569d8c70518370d"
}
]
}

0 comments on commit 6b32f2b

Please sign in to comment.