diff --git a/superset/assets/package-lock.json b/superset/assets/package-lock.json index 5a1ce4248..7bc8fbc8f 100644 --- a/superset/assets/package-lock.json +++ b/superset/assets/package-lock.json @@ -2228,7 +2228,7 @@ "dependencies": { "whatwg-fetch": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" } } diff --git a/superset/assets/src/visualizations/Iframe/Iframe.jsx b/superset/assets/src/visualizations/Iframe/Iframe.jsx new file mode 100644 index 000000000..eca92d629 --- /dev/null +++ b/superset/assets/src/visualizations/Iframe/Iframe.jsx @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import Mustache from 'mustache'; +import React from 'react'; +import PropTypes from 'prop-types'; + +const propTypes = { + className: PropTypes.string, + width: PropTypes.number.isRequired, + height: PropTypes.number.isRequired, + url: PropTypes.string, +}; +const defaultProps = { + className: '', +}; + +class Iframe extends React.PureComponent { + render() { + const { className, url, width, height } = this.props; + const completeUrl = Mustache.render(url, { + width, + height, + }); + + return ( + + ); + } +} + +Iframe.propTypes = propTypes; +Iframe.defaultProps = defaultProps; + +export default Iframe; diff --git a/superset/assets/src/visualizations/Iframe/IframeChartPlugin.js b/superset/assets/src/visualizations/Iframe/IframeChartPlugin.js new file mode 100644 index 000000000..8d3f37eb0 --- /dev/null +++ b/superset/assets/src/visualizations/Iframe/IframeChartPlugin.js @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { t } from '@superset-ui/translation'; +import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; +import thumbnail from './images/thumbnail.png'; +import transformProps from './transformProps'; + +const metadata = new ChartMetadata({ + name: t('IFrame'), + description: 'HTML Inline Frame', + thumbnail, +}); + +export default class IframeChartPlugin extends ChartPlugin { + constructor() { + super({ + metadata, + loadChart: () => import('./Iframe.jsx'), + transformProps, + }); + } +} diff --git a/superset/assets/src/visualizations/Iframe/images/thumbnail.png b/superset/assets/src/visualizations/Iframe/images/thumbnail.png new file mode 100644 index 000000000..5c6524a3f Binary files /dev/null and b/superset/assets/src/visualizations/Iframe/images/thumbnail.png differ diff --git a/superset/assets/src/visualizations/iframe.js b/superset/assets/src/visualizations/Iframe/transformProps.js similarity index 64% rename from superset/assets/src/visualizations/iframe.js rename to superset/assets/src/visualizations/Iframe/transformProps.js index 947fb7a72..e092c7d6d 100644 --- a/superset/assets/src/visualizations/iframe.js +++ b/superset/assets/src/visualizations/Iframe/transformProps.js @@ -16,23 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -import Mustache from 'mustache'; - -export default function iframeWidget(slice) { - const { selector, formData } = slice; +export default function transformProps(chartProps) { + const { width, height, formData } = chartProps; const { url } = formData; - const width = slice.width(); - const height = slice.height(); - const container = document.querySelector(selector); - const completedUrl = Mustache.render(url, { + return { width, height, - }); - - const iframe = document.createElement('iframe'); - iframe.style.width = '100%'; - iframe.style.height = height; - iframe.setAttribute('src', completedUrl); - container.appendChild(iframe); + url, + }; } diff --git a/superset/assets/src/visualizations/markup.css b/superset/assets/src/visualizations/Markup/Markup.css similarity index 78% rename from superset/assets/src/visualizations/markup.css rename to superset/assets/src/visualizations/Markup/Markup.css index d4ea16519..0f08788bd 100644 --- a/superset/assets/src/visualizations/markup.css +++ b/superset/assets/src/visualizations/Markup/Markup.css @@ -17,16 +17,16 @@ * under the License. */ .markup.slice_container { - margin: 10px; + margin: 10px; } .separator { - background-color: transparent !important; + background-color: transparent !important; } .separator hr { - border: 0; - height: 1px; - background-image: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 1), rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); + border: 0; + height: 1px; + background-image: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 1), rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); } .separator .chart-header { - border: none !important; + border: none !important; } diff --git a/superset/assets/src/visualizations/Markup/Markup.jsx b/superset/assets/src/visualizations/Markup/Markup.jsx new file mode 100644 index 000000000..a078ba3c3 --- /dev/null +++ b/superset/assets/src/visualizations/Markup/Markup.jsx @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React from 'react'; +import PropTypes from 'prop-types'; +import './Markup.css'; + +const propTypes = { + className: PropTypes.string, + height: PropTypes.number.isRequired, + isSeparator: PropTypes.bool, + html: PropTypes.string, + cssFiles: PropTypes.arrayOf(PropTypes.string), +}; +const defaultProps = { + className: '', + isSeparator: false, + html: '', +}; + +const CONTAINER_STYLE = { + position: 'relative', + overflow: 'auto', +}; + +class Markup extends React.PureComponent { + render() { + const { className, height, isSeparator, html, cssFiles } = this.props; + + return ( +