-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed View; Added Iframe; Update QueryParamButton;
- Loading branch information
Showing
15 changed files
with
281 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.embeded-iframe { | ||
border: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.