Skip to content

Commit

Permalink
Fixed View; Added Iframe; Update QueryParamButton;
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Sep 3, 2020
1 parent ba9c699 commit ea45091
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 24 deletions.
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"compilerOptions": {
"paths": {
"volto-slate": [
"develop/volto-slate/src"
],
"volto-tabsview": [
"develop/volto-tabsview/src"
],
Expand Down
5 changes: 5 additions & 0 deletions mrs.developer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"volto-slate": {
"url": "https://github.com/eea/volto-slate.git",
"path": "src",
"branch": "develop"
},
"volto-tabsview": {
"url": "https://github.com/eea/volto-tabsview.git",
"branch": "master",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "0.4.1",
"private": true,
"workspaces": [
"src/develop/volto-slate",
"src/develop/volto-grid-block",
"src/develop/volto-addons",
"src/develop/volto-datablocks"
Expand Down Expand Up @@ -109,9 +110,10 @@
"@eeacms/volto-image-zoom-and-flip": "github:eea/volto-image-zoom-and-flip#0.1.0",
"@eeacms/volto-metadata-block": "github:eea/volto-metadata-block#0.2.0",
"@eeacms/volto-slate-metadata-mentions": "github:eea/volto-slate-metadata-mentions#0.2.0",
"@eeacms/volto-widgets-view": "github:eea/volto-widgets-view#0.2.4",
"@eeacms/volto-tabs-block": "github:eea/volto-tabs-block#0.2.2",
"@eeacms/volto-widgets-view": "github:eea/volto-widgets-view#0.2.4",
"@plone/volto": "github:eea/volto#7.11.1-beta.1",
"@tinymce/tinymce-react": "^3.6.0",
"axios": "^0.20.0",
"jsonp": "^0.2.1",
"ol": "^6.4.3",
Expand All @@ -120,6 +122,7 @@
"react-component-queries": "^2.3.0",
"react-dom": "^16.13.1",
"react-highlight-words": "^0.16.0",
"react-iframe": "^1.8.0",
"react-loadable": "^5.5.0",
"react-sizeme": "^2.6.12",
"react-visibility-sensor": "^5.1.1",
Expand Down
94 changes: 94 additions & 0 deletions src/components/manage/Blocks/Iframe/Edit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
import _uniqueId from 'lodash/uniqueId';
import RenderFields from 'volto-addons/Widgets/RenderFields';
import View from './View';
import { settings } from '~/config';
import './style.css';

const getSchema = (props) => {
return {
url: {
title: 'Url',
type: 'text',
},
title: {
title: 'Title',
type: 'text',
},
width: {
title: 'Width',
type: 'text',
},
height: {
title: 'Height',
type: 'text',
},
hideToolbar: {
title: 'Hide toolbar',
type: 'boolean',
},
overflow: {
title: 'Overflow',
type: 'boolean',
},
queryParameters: {
title: 'Query parameters',
type: 'schema',
fieldSetTitle: 'Query parameters',
fieldSetId: 'query_parameters',
fieldSetSchema: {
fieldsets: [
{
id: 'default',
title: 'title',
fields: ['title', 'id', 'queryParam'],
},
],
properties: {
title: {
title: 'Title',
type: 'text',
},
id: {
title: 'Id',
type: 'text',
description: 'This will be used as query param key for tableau',
},
queryParam: {
title: 'Query to use',
type: 'text',
},
},
required: ['id', 'title', 'key'],
},
editFieldset: false,
deleteFieldset: false,
},
};
};

const Edit = (props) => {
const [state, setState] = useState({
schema: getSchema({ ...props, providerUrl: settings.providerUrl }),
id: _uniqueId('block_'),
});
return (
<div>
<RenderFields
schema={state.schema}
{...props}
title="Iframe"
noValueKey={true}
/>
<View {...props} id={state.id} mode="edit" />
</div>
);
};

export default compose(
connect((state, props) => ({
pathname: state.router.location.pathname,
})),
)(Edit);
72 changes: 72 additions & 0 deletions src/components/manage/Blocks/Iframe/View.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* REACT */
import React, { useState, useEffect } from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import Iframe from 'react-iframe';
import qs from 'query-string';
import './style.css';

const View = ({ content, ...props }) => {
const [discodataQuery, setDiscodataQuery] = useState({});
const { data } = props;
const { url = '', title = '', width = '100%', height = 'auto' } = data;
const { hideToolbar = false, overflow = false } = data;
useEffect(() => {
if (props.data.queryParameters?.value) {
try {
const newDiscodataQuery = {};
const properties = JSON.parse(props.data.queryParameters?.value)
.properties;
properties &&
Object.entries(properties).forEach(([key, value]) => {
if (props.searhc[value.queryParam]) {
newDiscodataQuery[key] = props.search[value.queryParam] || '';
}
});

if (
JSON.stringify(newDiscodataQuery) !== JSON.stringify(discodataQuery)
) {
setDiscodataQuery(newDiscodataQuery);
}
} catch {
setDiscodataQuery({});
}
}
/* eslint-disable-next-line */
}, [props.data.queryParameters])

const getUrl = (url) => {
const newUrl = new URL(url);
return newUrl.protocol + '//' + newUrl.host + newUrl.pathname;
};
const applyQueryParameters = (url, query) => {
const queryParameters = {
...query,
':toolbar': hideToolbar ? 'n' : 'y',
':embed': 'y',
};
return `${getUrl(url)}?${qs.stringify(queryParameters)}`;
};
return (
<div>
<Iframe
title={title}
url={applyQueryParameters(url, discodataQuery)}
width={width}
height={height}
className="embeded-iframe"
display="initial"
position="relative"
overflow={overflow ? 'visible' : 'hidden'}
/>
</div>
);
};

export default compose(
connect((state, props) => ({
query: state.router.location.search,
search: state.discodata_query.search,
})),
)(View);
3 changes: 3 additions & 0 deletions src/components/manage/Blocks/Iframe/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.embeded-iframe {
border: none;
}
22 changes: 21 additions & 1 deletion src/components/manage/Blocks/QueryParamButton/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,29 @@ const getSchema = (props) => {
type: 'text',
},
page: {
title: 'Page',
title: 'Internal page',
widget: 'object_by_path',
},
link: {
title: 'Outside link',
type: 'text',
},
linkTarget: {
title: 'Link target',
type: 'array',
choices: [
['_blank', 'New window'],
['_self', 'Current window'],
],
},
use: {
title: 'Use',
type: 'array',
choices: [
['page', 'Internal page'],
['link', 'Outside link'],
],
},
leftText: {
title: 'Left text',
widget: 'textarea',
Expand Down
27 changes: 21 additions & 6 deletions src/components/manage/Blocks/QueryParamButton/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ const View = ({ content, ...props }) => {
className = '',
inlineStyle = '',
page = '',
link = '',
linkTarget = '_self',
use = '',
} = data;
const queryText = props.search[queryParam];
const queryText = props.search[queryParam] || '';

const text = `${leftText} ${queryText} ${rightText}`;

const hasText = leftText || queryText || rightText;

let parsedInlineStyle;
try {
parsedInlineStyle = JSON.parse(inlineStyle);
Expand All @@ -27,15 +32,25 @@ const View = ({ content, ...props }) => {
}

return (
<div>
{props.mode === 'edit' ? !queryText ? <p>Query param button</p> : '' : ''}
{queryText ? (
<>
{props.mode === 'edit' && !hasText ? <p>Query param button</p> : ''}
{hasText ? (
<button
className={className}
style={parsedInlineStyle}
onClick={() => {
if (page) {
if (use === 'page') {
history.push(page);
} else if (use === 'link') {
try {
new URL(link);
const linkElement = document.createElement('a');
linkElement.href = link;
linkElement.target = linkTarget;
linkElement.click();
} catch {
console.log('NOT URL');
}
}
}}
>
Expand All @@ -44,7 +59,7 @@ const View = ({ content, ...props }) => {
) : (
''
)}
</div>
</>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/manage/Blocks/QueryParamText/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const View = ({ content, ...props }) => {
const text = `${leftText} ${queryText} ${rightText}`;

return (
<div>
<>
{props.mode === 'edit' ? !queryText ? <p>Query param text</p> : '' : ''}
{components[component]
? components[component](text, isColor(color) ? color : '#000')
: ''}
</div>
</>
);
};

Expand Down
8 changes: 1 addition & 7 deletions src/components/theme/View/DefaultView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ const messages = defineMessages({
const DefaultView = ({ content, intl, location }) => {
const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);
React.useEffect(() => {
console.log('MOUNTING DEFAULT VIEW');
return () => {
console.log('UNMOUNTING DEFAULT VIEW');
};
/* eslint-disable-next-line */
}, [])

return hasBlocksData(content) ? (
<div id="page-document" className="ui container">
{map(content[blocksLayoutFieldname].items, (block) => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/theme/View/RedirectView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RedirectView = (props) => {
setMounted(true);
/* eslint-disable-next-line */
}, [])
console.log(mounted, redirect, props.navigation);
if (mounted && !redirect && !props.navigation.loading) {
if (redirectPage) {
const currentPath = getBasePath(currentPage);
Expand All @@ -25,7 +26,7 @@ const RedirectView = (props) => {
}
}
return (
<Dimmer active inverted>
<Dimmer active inverted className="redirect-loader">
<Loader inverted>European Environment Agency</Loader>
</Dimmer>
);
Expand Down
23 changes: 18 additions & 5 deletions src/customizations/volto/components/theme/View/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,24 @@ class View extends Component {
this.props.content[getLayoutFieldname(this.props.content)]
] || null;

getRenderedView = () =>
this.props.content?.['@id'] &&
getBasePath(this.props.content?.['@id']) === this.props.pathname
? this.getViewByType() || this.getViewByLayout() || this.getViewDefault()
: null;
getRenderedView = () => {
if (this.props.content?.['@id']) {
const contentPathname = getBasePath(this.props.content?.['@id']).replace(
/\/$/,
'',
);
const pathname = this.props.pathname.replace(/\/$/, '');
if (contentPathname === pathname) {
return (
this.getViewByType() ||
this.getViewByLayout() ||
this.getViewDefault()
);
}
return null;
}
return null;
};

/**
* Cleans the component displayName (specially for connected components)
Expand Down
Loading

0 comments on commit ea45091

Please sign in to comment.