generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
danac
committed
Dec 29, 2022
1 parent
5f067b7
commit 54e45b2
Showing
7 changed files
with
225 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import { getContent } from '@plone/volto/actions'; | ||
import View from './View'; | ||
import Schema from './schema'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
|
||
const Edit = (props) => { | ||
const { data, block, onChangeBlock } = props; | ||
const schema = React.useMemo(() => Schema(props), [props]); | ||
|
||
React.useEffect(() => { | ||
if (!Object.hasOwn(data, 'show_sources')) { | ||
onChangeBlock(block, { | ||
...data, | ||
show_sources: true, | ||
}); | ||
} | ||
}, [block, data, onChangeBlock]); | ||
|
||
return ( | ||
<> | ||
<View data={data} mode="edit" /> | ||
<SidebarPortal selected={props.selected}> | ||
<BlockDataForm | ||
block={block} | ||
title={schema.title} | ||
schema={schema} | ||
onChangeField={(id, value) => { | ||
props.onChangeBlock(block, { | ||
...data, | ||
[id]: value, | ||
}); | ||
}} | ||
formData={data} | ||
/> | ||
</SidebarPortal> | ||
</> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect( | ||
(state, props) => ({ | ||
block_data: state.content.data, | ||
}), | ||
{ | ||
getContent, | ||
}, | ||
), | ||
)(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,25 @@ | ||
import React from 'react'; | ||
import TableauView from '../../TableauBlock/View'; | ||
import { Sources } from '../../Sources'; | ||
|
||
const View = (props) => { | ||
const { data } = props || {}; | ||
const { vis_url = '' } = data; | ||
const with_sources = data?.with_sources ?? false; | ||
|
||
React.useEffect(() => { | ||
if (vis_url) { | ||
props.getContent(vis_url, null); | ||
} | ||
}, [vis_url]); | ||
|
||
return ( | ||
<> | ||
<TableauView {...props} /> | ||
{with_sources && | ||
(props.mode !== 'edit' ? <Sources data={data.tableauSources} /> : '')} | ||
</> | ||
); | ||
}; | ||
|
||
export default 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,71 @@ | ||
const sourceSchema = { | ||
title: 'Source', | ||
|
||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['source', 'source_link'], | ||
}, | ||
], | ||
|
||
properties: { | ||
source: { | ||
title: 'Source', | ||
widget: 'textarea', | ||
}, | ||
source_link: { | ||
title: 'Link', | ||
type: 'string', | ||
}, | ||
}, | ||
|
||
required: ['source'], | ||
}; | ||
|
||
const Schema = (props) => { | ||
return { | ||
title: 'Embed EEA Tableau', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['vis_url', 'height', 'show_sources'], | ||
}, | ||
{ | ||
id: 'sources', | ||
title: 'Sources', | ||
fields: ['tableauSources', 'with_sources'], | ||
}, | ||
], | ||
properties: { | ||
vis_url: { | ||
widget: 'object_by_path', | ||
title: 'Visualization', | ||
}, | ||
height: { | ||
title: 'Height', | ||
type: 'number', | ||
default: 450, | ||
}, | ||
tableauSources: { | ||
widget: 'object_list', | ||
title: 'Sources', | ||
schema: sourceSchema, | ||
}, | ||
show_sources: { | ||
title: 'Toggle sources', | ||
type: 'boolean', | ||
}, | ||
with_sources: { | ||
title: 'Sources visible', | ||
type: 'boolean', | ||
defaultValue: true, | ||
}, | ||
}, | ||
|
||
required: ['vis_url'], | ||
}; | ||
}; | ||
|
||
export default Schema; |
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,42 @@ | ||
import React from 'react'; | ||
import { UniversalLink, Icon } from '@plone/volto/components'; | ||
|
||
import rightKeySVG from '@plone/volto/icons/right-key.svg'; | ||
import downKeySVG from '@plone/volto/icons/down-key.svg'; | ||
|
||
import './style.css'; | ||
|
||
const SourcesWidget = ({ data }) => { | ||
const [expand, setExpand] = React.useState(true); | ||
|
||
return ( | ||
<div> | ||
<a className="embed-sources-header" onClick={() => setExpand(!expand)}> | ||
<h3> | ||
<Icon | ||
name={expand ? downKeySVG : rightKeySVG} | ||
title={expand ? 'Collapse' : 'Expand'} | ||
size="17px" | ||
/> | ||
Sources: | ||
</h3> | ||
</a> | ||
{expand && ( | ||
<ul> | ||
{data.map((param, i) => ( | ||
<li key={i} className="embed-source-param"> | ||
<UniversalLink | ||
className="embed-sources-param-title" | ||
href={param.source_link} | ||
> | ||
{param.source} | ||
</UniversalLink> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SourcesWidget; |
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 @@ | ||
import Sources from './Sources'; | ||
|
||
export { Sources }; |
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,7 @@ | ||
.embed-sources-header { | ||
cursor: pointer; | ||
} | ||
|
||
.embed-sources-param-description { | ||
margin-left: 5px; | ||
} |
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