Skip to content

Commit

Permalink
tabs navigation based on config
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-macaneata committed Jul 27, 2020
1 parent f328f4b commit 4322c28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/components/theme/View/TabsChildView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { defineMessages, injectIntl } from 'react-intl';
import { map, isMatch } from 'lodash';
import cx from 'classnames';
import SearchBlock from 'volto-addons/SearchBlock/View';
import { getBasePath } from '~/helpers';

import {
Helmet,
Expand All @@ -20,7 +21,7 @@ import {
} from '@plone/volto/helpers';

import { deepSearch } from '~/helpers';
import { blocks, settings } from '~/config';
import { blocks, settings } from '../../../config';

const messages = defineMessages({
unknownBlock: {
Expand Down Expand Up @@ -51,6 +52,8 @@ const DefaultView = props => {
activeTab: 0,
isMobileSidebarOpen: false,
});

// TODO: fix this
const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);

Expand All @@ -77,16 +80,19 @@ const DefaultView = props => {
});
return sidebar;
};
console.log('aici', props.location.pathname);
useEffect(() => {
const sidebar = [];
sidebar.push(...getSidebar(navigation.items?.[state.activeTab], 1));
setState({
...state,
sidebar,
});
if (navigation) {
const sidebar = [];
sidebar.push(...getSidebar(navigation.items?.[state.activeTab], 1));
setState({
...state,
sidebar,
});
}
/* eslint-disable-next-line */
}, [props.navigation, state.activeTab]);
// TODO: fix this
if (!navigation) return '';

return hasBlocksData(content) ? (
<div className="ui wrapper">
Expand Down Expand Up @@ -272,11 +278,16 @@ DefaultView.propTypes = {
export default compose(
injectIntl,
connect((state, props) => ({
navigation: state.navigation.items.filter(item =>
props.location.pathname.includes('raw-data')
? item.title === 'Raw data'
: item.title === 'Glossary',
)[0],
navigation: state.navigation.items.filter(item => {
const basePath = getBasePath(item.url);
// sectionsWithTabsView
const { sectionsWithTabsView } = settings;
const filterBy = sectionsWithTabsView.find(i => i === basePath);
if (props.location.pathname.includes(filterBy)) {
return item.title;
}
return false;
})[0],
pathname: props.location.pathname,
lang: state.intl.locale,
content:
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const settings = {
'&expand.navigation.depth=5',
],
providerUrl: 'https://discodata.eea.europa.eu/sql',
sectionsWithTabsView: ['/raw-data', '/glossary'],
};

export const views = {
Expand Down

0 comments on commit 4322c28

Please sign in to comment.