Skip to content

Commit

Permalink
Add iframe and markup legacy plugin (apache#6741)
Browse files Browse the repository at this point in the history
* Add iframe plugin

* Use lazy load and add description

* remove unintended files

* Add markup

* minor adjustment

(cherry picked from commit 5ca8dfa)
  • Loading branch information
kristw authored and michellethomas committed Jan 23, 2019
1 parent c8a5e80 commit 4a19dc0
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 74 deletions.
58 changes: 58 additions & 0 deletions superset/assets/src/visualizations/Iframe/Iframe.jsx
Original file line number Diff line number Diff line change
@@ -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
className={className}
title="superset-iframe"
src={completeUrl}
style={{
width: '100%',
height,
}}
/>
);
}
}

Iframe.propTypes = propTypes;
Iframe.defaultProps = defaultProps;

export default Iframe;
38 changes: 38 additions & 0 deletions superset/assets/src/visualizations/Iframe/IframeChartPlugin.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions superset/assets/src/visualizations/Iframe/transformProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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.
*/
export default function transformProps(chartProps) {
const { width, height, formData } = chartProps;
const { url } = formData;

return {
width,
height,
url,
};
}
14 changes: 14 additions & 0 deletions superset/assets/src/visualizations/Markup/Markup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.markup.slice_container {
margin: 10px;
}
.separator {
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));
}
.separator .chart-header {
border: none !important;
}
76 changes: 76 additions & 0 deletions superset/assets/src/visualizations/Markup/Markup.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div
className={className}
style={CONTAINER_STYLE}
>
<iframe
title="superset-markup"
frameBorder={0}
height={isSeparator ? height - 20 : height}
sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation"
srcDoc={`
<html>
<head>
${cssFiles.map(
href => `<link rel="stylesheet" type="text/css" href="${href}" />`,
)}
</head>
<body style="background-color: transparent;">
${html}
</body>
</html>`
}
/>
</div>
);
}
}

Markup.propTypes = propTypes;
Markup.defaultProps = defaultProps;

export default Markup;
38 changes: 38 additions & 0 deletions superset/assets/src/visualizations/Markup/MarkupChartPlugin.js
Original file line number Diff line number Diff line change
@@ -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('Markup'),
description: 'HTML Markup',
thumbnail,
});

export default class IframeChartPlugin extends ChartPlugin {
constructor() {
super({
metadata,
loadChart: () => import('./Markup.jsx'),
transformProps,
});
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions superset/assets/src/visualizations/Markup/transformProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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.
*/
export default function transformProps(chartProps) {
const { height, payload, formData } = chartProps;
const { vizType } = formData;
const {
theme_css: cssFiles,
html,
} = payload.data;

return {
height,
cssFiles,
html,
isSeparator: vizType === 'separator',
};
}
20 changes: 0 additions & 20 deletions superset/assets/src/visualizations/iframe.js

This file was deleted.

14 changes: 0 additions & 14 deletions superset/assets/src/visualizations/markup.css

This file was deleted.

40 changes: 0 additions & 40 deletions superset/assets/src/visualizations/markup.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import EventFlowChartPlugin from '../EventFlow/EventFlowChartPlugin';
import ForceDirectedChartPlugin from '../ForceDirected/ForceDirectedChartPlugin';
import HeatmapChartPlugin from '../Heatmap/HeatmapChartPlugin';
import HorizonChartPlugin from '../Horizon/HorizonChartPlugin';
import IframeChartPlugin from '../Iframe/IframeChartPlugin';
import LineMultiChartPlugin from '../nvd3/LineMulti/LineMultiChartPlugin';
import MarkupChartPlugin from '../Markup/MarkupChartPlugin';
import PairedTTestChartPlugin from '../PairedTTest/PairedTTestChartPlugin';
import ParallelCoordinatesChartPlugin from '../ParallelCoordinates/ParallelCoordinatesChartPlugin';
import RoseChartPlugin from '../Rose/RoseChartPlugin';
Expand All @@ -39,7 +41,10 @@ export default class LegacyChartPreset extends Preset {
new ForceDirectedChartPlugin().configure({ key: 'directed_force' }),
new HeatmapChartPlugin().configure({ key: 'heatmap' }),
new HorizonChartPlugin().configure({ key: 'horizon' }),
new IframeChartPlugin().configure({ key: 'iframe' }),
new LineMultiChartPlugin().configure({ key: 'line_multi' }),
new MarkupChartPlugin().configure({ key: 'markup' }),
new MarkupChartPlugin().configure({ key: 'separator' }),
new PairedTTestChartPlugin().configure({ key: 'paired_ttest' }),
new ParallelCoordinatesChartPlugin().configure({ key: 'para' }),
new RoseChartPlugin().configure({ key: 'rose' }),
Expand Down

0 comments on commit 4a19dc0

Please sign in to comment.