Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 9, 2020
1 parent 2c87a6c commit adbb7f7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.discodata-list {
margin-left: -5px;
}

.discodata-list a {
display: inline-block;
margin: 0.3em;
margin: 5px
}
66 changes: 43 additions & 23 deletions src/components/manage/Blocks/NavigationBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,62 @@ import {
getBasePath,
} from 'volto-tabsview/helpers';
import { deleteQueryParam } from 'volto-datablocks/actions';
import { useEffect } from 'react';

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

try {
const pagesProperties = JSON.parse(data.pages?.value)?.properties || {};
Object.keys(pagesProperties).forEach((page) => {
pages.push(pagesProperties[page]);
});
} catch {}

const navigationItems = [...(props.navigation?.items || []), ...pages];
useEffect(() => {
const pagesProperties = data.pages?.value
? JSON.parse(data.pages?.value)?.properties || {}
: {};
const newPages =
Object.keys(pagesProperties).map((page) => pagesProperties[page]) || [];
setPages(newPages);
setNavigationItems([...(props.navigation?.items || []), ...newPages]);
}, [data.pages?.value]);

return (props.navigation?.items?.length && parent) || pages.length ? (
<div className="tabs-view-menu">
<Menu
widths={navigationItems.length}
widths={
navigationItems.length ||
props.navigation?.items?.length ||
pages.length
}
className={
props.data.className?.value ? props.data.className.value : ''
}
>
{navigationItems.map((item, index) => {
const url = getBasePath(item.url);
const name = item.title;
if (isActive(url, props.pathname) && url !== state.activeItem) {
setState({
...state,
activeItem: url,
});
} else if (
!isActive(url, props.pathname) &&
url === state.activeItem
if (
props.navigation.items.filter(
(navItem) => navItem.title === item.title,
).length
) {
setState({
...state,
activeItem: '',
});
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 &&
Expand All @@ -81,6 +94,7 @@ const View = ({ content, ...props }) => {
) {
return '';
}

return (
<Menu.Item
className={cx(
Expand All @@ -89,7 +103,13 @@ const View = ({ content, ...props }) => {
)}
name={name}
key={url}
active={state.activeItem === url}
active={
state.activeItem
? state.activeItem === url
: !url
? isActive(url, props.pathname)
: false
}
onClick={() => {
history.push(`${url}${props.query}`);
if (
Expand Down
1 change: 1 addition & 0 deletions src/components/manage/Blocks/PollutantIndex/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.pollutant-index-container .ui.bottom.attached.segment.active.tab {
padding-left: 0;
padding-right: 0;
background-color: transparent !important;
}

.pollutant-index-container h3 {
Expand Down
41 changes: 1 addition & 40 deletions src/components/manage/Blocks/SidebarBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,46 +238,7 @@ const makeNewNavigation = (
pathname.includes(item.url)
);
},
items: [
...item.items.map((child) => ({
...child,
redirect: (pathname) => {
// if (
// search.facilityInspireId !== facility.facilityInspireId &&
// pathname === child.url
// ) {
// history.push(item.url);
// }
},
active: (pathname) => {
return (
search.facilityInspireId ===
facility.facilityInspireId &&
search.installationInspireId === installation &&
pathname.includes(child.url)
);
},
onClick: (pathname) => {
if (
facility.facilityInspireId !==
search.facilityInspireId ||
installation !== search.installationInspireId
) {
dispatch(
setQueryParam({
queryParam: {
facilityInspireId: facility.facilityInspireId,
installationInspireId: installation,
},
}),
);
}
if (pathname !== child.url) {
history.push(child.url);
}
},
})),
],
items: [],
})) || []),
],
}))
Expand Down
59 changes: 57 additions & 2 deletions src/customizations/volto/components/theme/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { Helmet } from '@plone/volto/helpers';
import { searchContent } from '@plone/volto/actions';
import { Toolbar, Icon } from '@plone/volto/components';
import Highlighter from 'react-highlight-words';

import DiscodataSqlBuilder from 'volto-datablocks/DiscodataSqlBuilder/View';
import { setQueryParam } from 'volto-datablocks/actions';
import paginationLeftSVG from '@plone/volto/icons/left-key.svg';
import paginationRightSVG from '@plone/volto/icons/right-key.svg';

Expand Down Expand Up @@ -237,8 +238,24 @@ class Search extends Component {
* @returns {string} Markup for the component.
*/
render() {
const pollutants =
this.props.discodata_resources.data.index_pollutants || [];

return (
<Container id="page-search">
<DiscodataSqlBuilder
data={{
'@type': 'discodata_sql_builder',
sql: {
value:
'{"fieldsets":[{"id":"sql_metadata","title":"SQL","fields":["index_pollutants"]}],"properties":{"index_pollutants":{"title":"Index pollutants","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.code,\\nPOL.name,\\nPOL.startYear,\\nPOL.endYear,\\nPOL.parentId,\\nPOL.cas,\\nPOL.eperPollutantId,\\nPOL.codeEPER,\\nPOL_DET.*\\nFROM [IED].[latest].[LOV_POLLUTANT] as POL\\nLEFT JOIN [IED].[latest].[pollutants_details_table] AS POL_DET\\nON POL.pollutantId = POL_DET.pollutantId\\nORDER BY name","packageName":"index_pollutant_group_id"}},"required":[]}',
},
where: {
value:
'{"fieldsets":[{"id":"where_statements_metadata","title":"Where statements","fields":["w1","w2"]}],"properties":{"w1":{"title":"W1","sqlId":"index_pollutant_iso","urlQuery":false,"key":"pollutantId","queryParam":"index_pollutant_id"},"w2":{"title":"W2","sqlId":"index_pollutant_other_provisions","urlQuery":false,"key":"other_provision_id","queryParam":"index_pollutant_other_provisions","isExact":true}},"required":[]}',
},
}}
/>
<Helmet title="Search" />
<div className="container">
<article id="content">
Expand Down Expand Up @@ -360,6 +377,43 @@ class Search extends Component {
</article>
))}

<div className="discodata-list mb-3">
<h2 style={{ margin: '5px' }}>Pollutants</h2>
{pollutants
.filter(
(pollutant) =>
pollutant.pollutantId &&
pollutant.name.includes(this.props.searchableText),
)
.map((pollutant) => (
<Link
key={`item-${pollutant.pollutantId}`}
className="outline dark-blue"
as="a"
to="/glossary/pollutants/pollutant-index"
onClick={() => {
setQueryParam({
queryParam: {
index_pollutant_group_id: parseInt(
pollutant.parentId,
),
index_pollutant_id: parseInt(pollutant.pollutantId),
},
});
}}
>
<Highlighter
highlightClassName="highlight"
searchWords={
this.props.searchableText?.split(' ') || []
}
autoEscape={true}
textToHighlight={pollutant.name}
/>
</Link>
))}
</div>

{this.props.search?.batching && (
<div className="search-footer">
<Pagination
Expand Down Expand Up @@ -434,8 +488,9 @@ export default compose(
title: qs.parse(props.location.search).title,
description: qs.parse(props.location.search).description,
pathname: props.location.pathname,
discodata_resources: state.discodata_resources,
}),
{ searchContent },
{ searchContent, setQueryParam },
),
asyncConnect([
{
Expand Down

0 comments on commit adbb7f7

Please sign in to comment.