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.
Customize TableauBlock from volto-tableau
- Loading branch information
Showing
14 changed files
with
318 additions
and
13 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
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
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,32 @@ | ||
import React from 'react'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import InlineForm from '@plone/volto/components/manage/Form/InlineForm'; | ||
import config from '@plone/volto/registry'; | ||
import getSchema from './schema'; | ||
import View from './View'; | ||
|
||
const Edit = (props) => { | ||
const [schema] = React.useState(getSchema(config)); | ||
|
||
return ( | ||
<> | ||
<View {...props} mode="edit" /> | ||
|
||
<SidebarPortal selected={props.selected}> | ||
<InlineForm | ||
schema={schema} | ||
title={schema.title} | ||
onChangeField={(id, value) => { | ||
props.onChangeBlock(props.block, { | ||
...props.data, | ||
[id]: value, | ||
}); | ||
}} | ||
formData={props.data} | ||
/> | ||
</SidebarPortal> | ||
</> | ||
); | ||
}; | ||
|
||
export default 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,109 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import { withRouter } from 'react-router'; | ||
import Tableau from '@eeacms/volto-tableau/Tableau/View'; | ||
import config from '@plone/volto/registry'; | ||
import { getLatestTableauVersion } from 'tableau-api-js'; | ||
import qs from 'querystring'; | ||
import '@eeacms/volto-tableau/less/tableau.less'; | ||
|
||
const getDevice = (config, width) => { | ||
const breakpoints = config.blocks.blocksConfig.tableau_block.breakpoints; | ||
let device = 'default'; | ||
Object.keys(breakpoints).forEach((breakpoint) => { | ||
if ( | ||
width <= breakpoints[breakpoint][0] && | ||
width >= breakpoints[breakpoint][1] | ||
) { | ||
device = breakpoint; | ||
} | ||
}); | ||
return device; | ||
}; | ||
|
||
const View = (props) => { | ||
const [error, setError] = React.useState(null); | ||
const [loaded, setLoaded] = React.useState(null); | ||
const [mounted, setMounted] = React.useState(false); | ||
const [extraFilters, setExtraFilters] = React.useState({}); | ||
const { data = {}, query = {}, screen = {} } = props; | ||
const { | ||
breakpointUrls = [], | ||
urlParameters = [], | ||
title = null, | ||
description = null, | ||
autoScale = false, | ||
} = data; | ||
const version = | ||
props.data.version || | ||
config.settings.tableauVersion || | ||
getLatestTableauVersion(); | ||
const device = getDevice(config, screen.page?.width || Infinity); | ||
const breakpointUrl = breakpointUrls.filter( | ||
(breakpoint) => breakpoint.device === device, | ||
)[0]?.url; | ||
const url = breakpointUrl || data.url; | ||
|
||
React.useEffect(() => { | ||
setMounted(true); | ||
/* eslint-disable-next-line */ | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
const newExtraFilters = { ...extraFilters }; | ||
urlParameters.forEach((element) => { | ||
if (element.field && typeof query[element.urlParam] !== 'undefined') { | ||
newExtraFilters[element.field] = query[element.urlParam]; | ||
} else if (newExtraFilters[element.field]) { | ||
delete newExtraFilters[element.field]; | ||
} | ||
}); | ||
setExtraFilters(newExtraFilters); | ||
/* eslint-disable-next-line */ | ||
}, [JSON.stringify(query), JSON.stringify(urlParameters)]); | ||
|
||
return mounted ? ( | ||
<div className="tableau-block"> | ||
{props.mode === 'edit' ? ( | ||
<div className="tableau-info"> | ||
<h3 className="tableau-version">== Tableau {version} ==</h3> | ||
{!props.data.url ? <p className="tableau-error">URL required</p> : ''} | ||
{error ? <p className="tableau-error">{error}</p> : ''} | ||
</div> | ||
) : ( | ||
'' | ||
)} | ||
{loaded && title ? <h3 className="tableau-title">{title}</h3> : ''} | ||
{loaded && description ? ( | ||
<p className="tableau-description">{description}</p> | ||
) : ( | ||
'' | ||
)} | ||
<Tableau | ||
{...props} | ||
canUpdateUrl={!breakpointUrl} | ||
extraFilters={extraFilters} | ||
extraOptions={{ device: autoScale ? 'desktop' : device }} | ||
error={error} | ||
loaded={loaded} | ||
setError={setError} | ||
setLoaded={setLoaded} | ||
version={version} | ||
url={url} | ||
/> | ||
</div> | ||
) : ( | ||
'' | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
query: { | ||
...(qs.parse(state.router.location?.search?.replace('?', '')) || {}), | ||
...(state.query?.search || {}), | ||
}, | ||
screen: state.screen, | ||
})), | ||
)(withRouter(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,28 @@ | ||
import sliderSVG from '@plone/volto/icons/slider.svg'; | ||
import TableauEdit from './Edit'; | ||
import TableauView from './View'; | ||
|
||
export default (config) => { | ||
config.blocks.blocksConfig.tableau_block = { | ||
id: 'tableau_block', | ||
title: 'Tableau', | ||
icon: sliderSVG, | ||
group: 'common', | ||
edit: TableauEdit, | ||
view: TableauView, | ||
restricted: false, | ||
mostUsed: false, | ||
sidebarTab: 1, | ||
blocks: {}, | ||
security: { | ||
addPermission: [], | ||
view: [], | ||
}, | ||
breakpoints: { | ||
desktop: [Infinity, 982], | ||
tablet: [981, 768], | ||
mobile: [767, 0], | ||
}, | ||
}; | ||
return config; | ||
}; |
Oops, something went wrong.