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

Commit

Permalink
normalize application
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Petrovich committed Mar 22, 2021
1 parent e912505 commit 1ad0e42
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 109 deletions.
13 changes: 8 additions & 5 deletions client/src/App.jsx
Expand Up @@ -95,7 +95,7 @@ const App = ({ coreConfig, fetchConfig, typeConfig }) => {
await loadSettings();
});

if (!localStorage.getItem('router')) {
if (!localStorage.getItem('router') && path) {
dispatch(createTab(routeParser({ path })));
}
} catch (error) {
Expand All @@ -115,6 +115,10 @@ const App = ({ coreConfig, fetchConfig, typeConfig }) => {
return;
}

if (udata && Object.keys(udata).length) {
return;
}

const rest = new context.Request();

try {
Expand All @@ -135,8 +139,7 @@ const App = ({ coreConfig, fetchConfig, typeConfig }) => {
const defaultModule = menu ? menu.find((item) => item?.SIGN === 'default') : null;
if (defaultModule) path = defaultModule?.EUID;

const activeTabsCopy = [...activeTabs];
const isFind = activeTabsCopy.findIndex((tab) => tab === path) !== -1;
const isFind = activeTabs.findIndex((tab) => tab === path) !== -1;

const { data = {} } = response;
const { user = {} } = data;
Expand All @@ -150,7 +153,7 @@ const App = ({ coreConfig, fetchConfig, typeConfig }) => {
: acc || {};
}, {});

if (!isFind && tabsLimit && tabsLimit <= activeTabsCopy.length) {
if (!isFind && tabsLimit && tabsLimit <= activeTabs.length) {
message.error(`Максимальное количество вкладок: ${tabsLimit}`);
return;
}
Expand All @@ -174,7 +177,7 @@ const App = ({ coreConfig, fetchConfig, typeConfig }) => {

setAuth(true);
setLoadApp(true);
}, [appActive, context.Request, dispatch, initialSession, menu, router, tabsLimit]);
}, [udata, appActive, context.Request, dispatch, initialSession, menu, router, tabsLimit]);

const bootstrapApplication = useCallback(
async (forceUpdate) => {
Expand Down
3 changes: 3 additions & 0 deletions client/src/Components/ContentView/ContentView.jsx
Expand Up @@ -116,6 +116,9 @@ const ContentView = memo(

let childrensExistInEntrypointTypeTab = false;

if (!path?.includes) {
}

if (Array.isArray(activeTabs) && path && path?.includes(moduleName)) {
childrensExistInEntrypointTypeTab = !!activeTabs.some(
(tabItem) => tabItem !== tabKey && tabItem && tabItem.includes(moduleName),
Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/ContentView/ContentView.types.js
Expand Up @@ -11,5 +11,5 @@ export const contentViewType = {
onChangeVisibleAction: func.isRequired,
isToolbarActive: bool,
visibilityPortal: bool,
activeTabs: oneOfType([oneOf([null]), arrayOf(string.isRequired)]).isRequired,
activeTabs: oneOfType([oneOf([null]), arrayOf(string)]).isRequired,
};
4 changes: 2 additions & 2 deletions client/src/Components/HeaderView/HeaderView.types.jsx
@@ -1,12 +1,12 @@
import PropTypes from 'prop-types';
const { object, func, string, array, bool, oneOfType, number } = PropTypes;
const { object, func, string, arrayOf, oneOf, bool, oneOfType, number } = PropTypes;

export const headerViewType = {
dashboardStream: object.isRequired,
cbMenuTabHandler: func.isRequired,
activeTabEUID: string.isRequired,
logout: PropTypes.func.isRequired,
tabs: array.isRequired,
tabs: oneOfType([oneOf([null]), arrayOf(string)]),
goCabinet: func,
webSocket: object,
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/Helpers/PrivateRoute.jsx
Expand Up @@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { Route } from 'react-router-dom';
import Loader from 'Components/Loader';
import modelsContext from 'Models/context';
import { array, object } from 'prop-types';
import { array, func } from 'prop-types';
import { APP_STATUS } from 'App.constant';
import { setAppStatus } from 'Redux/reducers/publicReducer.slice';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -79,7 +79,7 @@ const PrivateRoute = ({ component: Component, ...routeProps }) => {
};

PrivateRoute.propTypes = {
component: object.isRequired,
component: func.isRequired,
routeProps: array,
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/ModalWindow/ModalWindow.jsx
Expand Up @@ -51,7 +51,7 @@ const ModalWindow = memo((props) => {
const [state, dispatch] = useReducer(reducer, modalState);
const context = useContext(ModelContext);

const { key: keyActiveRoute, _id: id, name: nameActive } = routeDataActive;
const { key: keyActiveRoute = null, _id: id = null, name: nameActive = null } = routeDataActive || {};

const { type: typeView = '' } = state;
const {
Expand Down
53 changes: 30 additions & 23 deletions client/src/Components/Output/Output.jsx
Expand Up @@ -106,7 +106,7 @@ const Output = memo(
if (typeOutput && typeOutput !== 'default') {
return (
<Button
onKeyDown={createHandleOpenLink(id, 'cabinet')}
onClick={createHandleOpenLink(id || displayValue, 'cabinet')}
type="link"
key={`${id}-editor`}
className="editor"
Expand Down Expand Up @@ -235,28 +235,35 @@ const Output = memo(
const shouldBeRunRenderLinks =
shouldRenderList && isChildrenList && links && typeof children === 'string';

const value = useMemo(
() =>
shouldBeRunRenderLinks
? null
: renderLinks(
!isStaticList && Array.isArray(links)
? links
.reduce((links, link) => {
if (Array.isArray(children) && children.some((child) => child === link?._id)) {
return [...links, { displayValue: link?.displayName, id: link?._id }];
}
return links;
}, [])
.sort((a, b) => a?.displayName - b?.displayName)
: isChildrenList
? children.map((link) => {
return { displayValue: link?.displayName, id: link?._id };
})
: children,
),
[children, isChildrenList, isStaticList, links, renderLinks, shouldBeRunRenderLinks],
);
const value = useMemo(() => {
if (shouldBeRunRenderLinks) {
return null;
}

let isSingleLink = false;
let val = children;

if (!isStaticList && Array.isArray(links)) {
val = links.reduce((links, link) => {
if (Array.isArray(children) && children.some((child) => child === link?._id)) {
return [...links, { displayValue: link?.displayName, id: link?._id }];
}
return links;
}, []);
} else if (isChildrenList) {
val = children.map((link) => {
return { displayValue: link?.displayName, id: link?._id };
});
} else if (typeOutput === 'link' && Array.isArray(links)) {
val = links.find(({ _id }) => _id === children) || children;
isSingleLink = true;
}

if (isSingleLink) {
}

return renderLinks(val, isSingleLink ? 'single' : undefined);
}, [typeOutput, children, isChildrenList, isStaticList, links, renderLinks, shouldBeRunRenderLinks]);

const output = useMemo(
() => (
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/TableView/Table/Table.jsx
Expand Up @@ -78,8 +78,8 @@ class Table extends PureComponent {

getTaskConfigColumns = () => {
const { routerData, t } = this.props;
const { saveData = {} } = routerData;
const { sortedInfo = [] } = saveData;
const { saveData = {} } = routerData || {};
const { sortedInfo = [] } = saveData || {};

const columns = [
{
Expand Down
6 changes: 3 additions & 3 deletions client/src/Models/TreeBuilder/TreeBuilder.js
Expand Up @@ -28,10 +28,10 @@ class TreeBuilder {
buildTree(root, indexRoot = 0) {
if (!root.length || !root[indexRoot]) return root;

const currentNode = root[indexRoot];
const childNodes = this.childrens.filter((child) => child.parentId === currentNode._id);
const item = { ...root[indexRoot] };
const childNodes = this.childrens.filter((child) => child.parentId === item._id);

currentNode.children = this.buildTree(childNodes);
item.children = this.buildTree(childNodes);
return this.buildTree(root, indexRoot + 1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/Modules/ContactModule/ContactModule.types.jsx
Expand Up @@ -8,7 +8,7 @@ export const contactModuleType = {
activeTabs: arrayOf(string.isRequired).isRequired,
statusApp: string.isRequired,
visibilityPortal: bool,
clientDB: func.isRequired,
clientDB: func,
webSocket: object,
onChangeVisibleAction: func,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/Modules/WikiModule/WikiPage/WikiPage.jsx
Expand Up @@ -164,7 +164,7 @@ const WikiPage = ({ selectedNode, metadata, onChangeWikiPage }) => {
editor={true}
onChange={onChangeContent}
editorKey={pageId}
readOnly={readOnly}
readOnly={!!readOnly}
contentState={content}
shouldDisplayButton={true}
onPublish={!readOnly ? onSubmitChanges : content && readOnly ? onChangeStateEditor : null}
Expand Down
22 changes: 15 additions & 7 deletions client/src/Pages/Dashboard/Dashboard.jsx
Expand Up @@ -4,7 +4,7 @@ import { Redirect } from 'react-router-dom';
import { EventEmitter } from 'events';
import io from 'socket.io-client';
import { Layout, message, Modal, Button } from 'antd';
import { useDispatch, useSelector } from 'react-redux';
import { batch, useDispatch, useSelector } from 'react-redux';
import { getAvailableTabNameKey, routeParser, saveAndNormalizeRoute, showSystemMessage } from 'Utils';
import FixedToolbar from 'Components/FixedToolbar';
import Loader from 'Components/Loader';
Expand Down Expand Up @@ -238,7 +238,7 @@ const Dashboard = () => {

const activeTabsData = useMemo(() => {
const { menu } = appConfig;
const activeTabsData = [];
let activeTabsData = null;

if (!menu || !activeTabs) {
return null;
Expand All @@ -248,13 +248,22 @@ const Dashboard = () => {
const tabItem = menu.find((menuItem) => menuItem.EUID === tab);

if (tabItem) {
if (!activeTabsData) {
activeTabsData = [];
}

activeTabsData.push({ ...tabItem });
continue;
}

const { page, path, pageChild } = routeParser({ pageType: 'page', path: tab });
const DATAKEY = pageChild || page || '';
const VALUE = getAvailableTabNameKey(DATAKEY, routeData[DATAKEY]);

if (!activeTabsData) {
activeTabsData = [];
}

activeTabsData.push({
EUID: path || tab,
PARENT_CODE: page,
Expand Down Expand Up @@ -310,11 +319,10 @@ const Dashboard = () => {
const path = event['key'] ? event['key'] : key;
const { tabsLimit = 50 } = appConfig;

const activeTabsCopy = [...activeTabs];
const isFind = activeTabsCopy.findIndex((tab) => tab === path) !== -1;
const isFind = activeTabs.findIndex((tab) => tab === path) !== -1;

if (mode === 'open') {
if (!isFind && tabsLimit <= activeTabsCopy.length) {
if (!isFind && tabsLimit <= activeTabs.length) {
message.error(`Максимальное количество вкладок: ${tabsLimit}`);
return;
}
Expand All @@ -334,10 +342,10 @@ const Dashboard = () => {
return;
}

if (entityId) {
batch(() => {
dispatch(removeTab({ path: path, type: type }));
dispatch(clearAppCache({ path, type: type, currentActionTab }));
}
});
}
},
[activeTabs, appConfig, currentActionTab, dispatch, routeData],
Expand Down
4 changes: 2 additions & 2 deletions client/src/Redux/core/core.utils.js
Expand Up @@ -55,9 +55,9 @@ const runLocalUpdate = async (dispatch, depAction, depParser, multiple) => {

const { data, shoudClearError = false, shouldUpdateState = true } = dataParser(depParser);
if (shoudClearError) await dispatch(setRequestError(null));
if (shouldUpdateState && !multiple)
if (shouldUpdateState && !multiple) {
await dispatch(refreshRouterData({ ...data, loading: false, add, params }));
else if (multiple) return data;
} else if (multiple) return data;
};

const coreUtils = { runLocalUpdate, runBadNetworkMode, runRefreshIndexedDb, runNoCorsSave };
Expand Down
6 changes: 1 addition & 5 deletions client/src/Redux/middleware/routerReducer.thunk.js
Expand Up @@ -6,7 +6,7 @@ import _ from 'lodash';
import { makeApiAction, getActionStore } from 'Utils/Api';
import { APP_STATUS } from 'App.constant';
import { setSystemMessage } from 'Redux/reducers/systemReducer.slice';
import { setAppStatus, setRequestError } from 'Redux/reducers/publicReducer.slice';
import { setAppStatus } from 'Redux/reducers/publicReducer.slice';
import {
openPageWithData,
refreshRouterData,
Expand Down Expand Up @@ -123,8 +123,6 @@ const loadCurrentData = (params) => async (dispatch, getState, { schema, Request
pathValid,
requestError,
uuid: 'uuid',
refreshRouterData,
setRequestError,
};

dispatch(setAppStatus({ params, path: pagePath }));
Expand Down Expand Up @@ -191,8 +189,6 @@ const multipleLoadData = (params) => async (dispatch, getState, { schema, Reques
clientDB,
methodQuery: body?.params?.query,
uuid: 'uuid',
refreshRouterData,
setRequestError,
isLocalUpdate,
};

Expand Down

0 comments on commit 1ad0e42

Please sign in to comment.