From adbb7f7232492fca6c8986ca8fadc6593bae86d6 Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Fri, 9 Oct 2020 21:41:53 +0300 Subject: [PATCH] Fixes --- .../Blocks/DiscodataComponents/List/style.css | 6 +- .../manage/Blocks/NavigationBlock/View.jsx | 66 ++++++++++++------- .../manage/Blocks/PollutantIndex/style.css | 1 + .../manage/Blocks/SidebarBlock/View.jsx | 41 +----------- .../volto/components/theme/Search/Search.jsx | 59 ++++++++++++++++- 5 files changed, 107 insertions(+), 66 deletions(-) diff --git a/src/components/manage/Blocks/DiscodataComponents/List/style.css b/src/components/manage/Blocks/DiscodataComponents/List/style.css index 16f7b3e9..09926920 100644 --- a/src/components/manage/Blocks/DiscodataComponents/List/style.css +++ b/src/components/manage/Blocks/DiscodataComponents/List/style.css @@ -1,4 +1,8 @@ +.discodata-list { + margin-left: -5px; +} + .discodata-list a { display: inline-block; - margin: 0.3em; + margin: 5px } \ No newline at end of file diff --git a/src/components/manage/Blocks/NavigationBlock/View.jsx b/src/components/manage/Blocks/NavigationBlock/View.jsx index ce75ba82..fd2aa15e 100644 --- a/src/components/manage/Blocks/NavigationBlock/View.jsx +++ b/src/components/manage/Blocks/NavigationBlock/View.jsx @@ -13,29 +13,36 @@ 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 ? (
{ {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 && @@ -81,6 +94,7 @@ const View = ({ content, ...props }) => { ) { return ''; } + return ( { )} 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 ( diff --git a/src/components/manage/Blocks/PollutantIndex/style.css b/src/components/manage/Blocks/PollutantIndex/style.css index 9b3d9646..26458a37 100644 --- a/src/components/manage/Blocks/PollutantIndex/style.css +++ b/src/components/manage/Blocks/PollutantIndex/style.css @@ -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 { diff --git a/src/components/manage/Blocks/SidebarBlock/View.jsx b/src/components/manage/Blocks/SidebarBlock/View.jsx index 50e37a8f..80dd186a 100644 --- a/src/components/manage/Blocks/SidebarBlock/View.jsx +++ b/src/components/manage/Blocks/SidebarBlock/View.jsx @@ -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: [], })) || []), ], })) diff --git a/src/customizations/volto/components/theme/Search/Search.jsx b/src/customizations/volto/components/theme/Search/Search.jsx index be867dfa..082f8998 100644 --- a/src/customizations/volto/components/theme/Search/Search.jsx +++ b/src/customizations/volto/components/theme/Search/Search.jsx @@ -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'; @@ -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 ( +
@@ -360,6 +377,43 @@ class Search extends Component {
))} +
+

Pollutants

+ {pollutants + .filter( + (pollutant) => + pollutant.pollutantId && + pollutant.name.includes(this.props.searchableText), + ) + .map((pollutant) => ( + { + setQueryParam({ + queryParam: { + index_pollutant_group_id: parseInt( + pollutant.parentId, + ), + index_pollutant_id: parseInt(pollutant.pollutantId), + }, + }); + }} + > + + + ))} +
+ {this.props.search?.batching && (