Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed May 11, 2021
1 parent 04f948c commit 2134aa7
Showing 1 changed file with 9 additions and 87 deletions.
96 changes: 9 additions & 87 deletions src/components/manage/Blocks/NavigationBlock/View.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* REACT */
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { compose } from 'redux';
import { connect } from 'react-redux';
Expand All @@ -9,17 +9,14 @@ import { Menu } from 'semantic-ui-react';
import cx from 'classnames';
import { isActive, getNavigationByParent, getBasePath } from '~/helpers';
import { deleteQueryParam, setQueryParam } from 'volto-datablocks/actions';
import { useEffect } from 'react';
import qs from 'querystring';

const View = ({ content, ...props }) => {
const history = useHistory();
const { data } = props;
const [state, setState] = useState({
activeItem: '',
});
const [navigationItems, setNavigationItems] = useState([]);
const [pages, setPages] = useState([]);
const parent = data.parent?.value;
const history = useHistory();

useEffect(() => {
const pagesProperties = data.pages?.value
Expand All @@ -46,66 +43,15 @@ const View = ({ content, ...props }) => {
{navigationItems.map((item, index) => {
const url = getBasePath(item.url);
const name = item.title;
if (
props.navigation?.items?.filter(
(navItem) => navItem.title === item.title,
).length
) {
if (isActive(url, props.pathname) && url !== state.activeItem) {
setState({
...state,
activeItem: url,
});
} else if (
!isActive(url, props.pathname) &&
url === state.activeItem
) {
setState({
...state,
activeItem: '',
});
}
}
if (
props.discodata_query.search.siteInspireId &&
props.flags.items.sites?.[
props.discodata_query.search.siteInspireId
] &&
item.title === 'Regulatory information' &&
!props.flags.items.sites?.[
props.discodata_query.search.siteInspireId
]?.has_installations
) {
return '';
}
if (
props.discodata_query.search.siteInspireId &&
props.flags.items.sites?.[
props.discodata_query.search.siteInspireId
] &&
item.title === 'Large-scale fuel combustion' &&
!props.flags.items.sites?.[
props.discodata_query.search.siteInspireId
]?.has_lcps
) {
return '';
}

return (
<Menu.Item
className={cx(
index > 0 ? 'sibling-on-left' : '',
index < navigationItems.length - 1 ? 'sibling-on-right' : '',
)}
name={name}
key={url}
active={
state.activeItem
? state.activeItem === url
: !url
? isActive(url, props.pathname)
: false
}
active={isActive(url, props.path)}
onClick={() => {
if (
props.discodata_query.search.facilityInspireId ||
Expand All @@ -120,30 +66,11 @@ const View = ({ content, ...props }) => {
],
});
}
if (item.title === 'Large-scale fuel combustion') {
const lcp =
props.discodata_resources.data.site_details_4?.[
props.discodata_query.search.siteInspireId
] || {};
if (Object.keys(lcp).length) {
history.push(
`/industrial-site/large-scale-fuel-combustion/site-overview/lcp-overview/${props.query}`,
);
props.setQueryParam({
queryParam: {
facilityInspireId: lcp.facilityInspireId,
installationInspireId: lcp.installationInspireId,
lcpInspireId: lcp.lcpInspireId,
},
});
} else {
history.push(`${url}${props.query}`);
}
} else {
history.push(`${url}${props.query}`);
}
history.push(`${url}?${qs.stringify(props.query)}`);
}}
/>
>
{name}
</Menu.Item>
);
})}
</Menu>
Expand All @@ -161,14 +88,9 @@ const View = ({ content, ...props }) => {
export default compose(
connect(
(state, props) => ({
query: state.router.location.search,
content:
state.prefetch?.[state.router.location.pathname] || state.content.data,
pathname: state.router.location.pathname,
query: qs.parse(state.router.location.search.replace('?', '')),
discodata_query: state.discodata_query,
discodata_resources: state.discodata_resources,
navItems: state.navigation.items,
flags: state.flags,
navigation: getNavigationByParent(
state.navigation.items,
props.data?.parent?.value,
Expand Down

0 comments on commit 2134aa7

Please sign in to comment.