Skip to content

Commit

Permalink
Simplifying the viz interface (#2005)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 11, 2017
1 parent b16930f commit 2322a76
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 2,164 deletions.
21 changes: 21 additions & 0 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
import json
from logging.handlers import TimedRotatingFileHandler

from flask import Flask, redirect
Expand All @@ -21,6 +22,26 @@
APP_DIR = os.path.dirname(__file__)
CONFIG_MODULE = os.environ.get('SUPERSET_CONFIG', 'superset.config')

with open(APP_DIR + '/assets/dist/backendSync.json', 'r') as f:
frontend_config = json.load(f)
def cast_form_data(form_data):
d = {}
fields = frontend_config.get('fields', {})
print('0982--' * 10)
print(fields)
for k, v in form_data.items():
print([k, v])
field_config = fields.get(k, {})
ft = field_config.get('type')
if ft == 'CheckboxField':
v = True if v == 'true' else False
elif ft == 'TextField' and field_config.get('isInt'):
v = int(v)
elif ft == 'TextField' and field_config.get('isFloat'):
v = float(v)
d[k] = v
return d

app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/components/FaveStar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cx from 'classnames';
import TooltipWrapper from './TooltipWrapper';

const propTypes = {
sliceId: PropTypes.string.isRequired,
sliceId: PropTypes.number.isRequired,
actions: PropTypes.object.isRequired,
isStarred: PropTypes.bool.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function runQuery(formData, datasourceType) {
$.getJSON(url, function (queryResponse) {
dispatch(chartUpdateSucceeded(queryResponse));
}).fail(function (err) {
dispatch(chartUpdateFailed(err));
dispatch(chartUpdateFailed(err.responseJSON));
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CHART_STATUS_MAP = {
const propTypes = {
actions: PropTypes.object.isRequired,
can_download: PropTypes.bool.isRequired,
slice_id: PropTypes.string.isRequired,
slice_id: PropTypes.number.isRequired,
slice_name: PropTypes.string.isRequired,
viz_type: PropTypes.string.isRequired,
height: PropTypes.string.isRequired,
Expand All @@ -43,9 +43,9 @@ class ChartContainer extends React.PureComponent {

renderViz() {
const mockSlice = this.getMockedSliceObject();
this.setState({ mockSlice });
try {
visMap[this.props.viz_type](mockSlice, this.props.queryResponse);
this.setState({ mockSlice });
} catch (e) {
this.props.actions.chartRenderingFailed(e);
}
Expand Down
6 changes: 2 additions & 4 deletions superset/assets/javascripts/explorev2/exploreUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint camelcase: 0 */
const $ = require('jquery');
function formatFilters(filters) {
// outputs an object of url params of filters
// prefix can be 'flt' or 'having'
Expand Down Expand Up @@ -38,9 +37,8 @@ export function getParamObject(form_data, datasource_type, saveNewSlice) {
}

export function getExploreUrl(form_data, datasource_type, endpoint = 'base') {
const data = getParamObject(form_data, datasource_type);
const params = `${datasource_type}/` +
`${form_data.datasource}/?${$.param(data, true)}`;
let params = `${datasource_type}/${form_data.datasource}/`;
params += '?form_data=' + encodeURIComponent(JSON.stringify(form_data));
switch (endpoint) {
case 'base':
return `/superset/explore/${params}`;
Expand Down
21 changes: 21 additions & 0 deletions superset/assets/javascripts/syncBackend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'fs';
import path from 'path';
import { fields } from './explorev2/stores/fields';

function exportFile(fileLocation, content) {
fs.writeFile(fileLocation, content, function(err) {
if (err) {
console.log(`File ${fileLocation} was not saved... :(`);
}
console.log(`File ${fileLocation} was saved!`);
});
}

function main() {
const APP_DIR = path.resolve(__dirname, './');
const blob = {
fields,
};
exportFile(APP_DIR + '/../dist/backendSync.json', JSON.stringify(blob, null, 2));
}
main();
1 change: 1 addition & 0 deletions superset/assets/js_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cd "$(dirname "$0")"
npm --version
node --version
npm install
npm run sync-backend
npm run lint
npm run test
npm run build
Expand Down
3 changes: 2 additions & 1 deletion superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dev": "NODE_ENV=dev webpack --watch --colors --progress --debug --output-pathinfo --devtool inline-source-map",
"prod": "NODE_ENV=production node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js -p --colors --progress",
"build": "NODE_ENV=production webpack --colors --progress",
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx ."
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx .",
"sync-backend": "babel-node --presets es2015 javascripts/syncBackend.js"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion superset/assets/visualizations/big_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function bigNumberVis(slice, payload) {
const div = d3.select(slice.selector);
// Define the percentage bounds that define color from red to green
div.html(''); // reset

const fd = payload.form_data;
const json = payload.data;

Expand Down
11 changes: 5 additions & 6 deletions superset/assets/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ const config = {
entry: {
'css-theme': APP_DIR + '/javascripts/css-theme.js',
common: APP_DIR + '/javascripts/common.js',
dashboard: ['babel-polyfill', APP_DIR + '/javascripts/dashboard/Dashboard.jsx'],
explore: ['babel-polyfill', APP_DIR + '/javascripts/explore/explore.jsx'],
//dashboard: ['babel-polyfill', APP_DIR + '/javascripts/dashboard/Dashboard.jsx'],
explorev2: ['babel-polyfill', APP_DIR + '/javascripts/explorev2/index.jsx'],
sqllab: ['babel-polyfill', APP_DIR + '/javascripts/SqlLab/index.jsx'],
standalone: ['babel-polyfill', APP_DIR + '/javascripts/standalone.js'],
welcome: ['babel-polyfill', APP_DIR + '/javascripts/welcome.js'],
profile: ['babel-polyfill', APP_DIR + '/javascripts/profile/index.jsx'],
//sqllab: ['babel-polyfill', APP_DIR + '/javascripts/SqlLab/index.jsx'],
//standalone: ['babel-polyfill', APP_DIR + '/javascripts/standalone.js'],
//welcome: ['babel-polyfill', APP_DIR + '/javascripts/welcome.js'],
//profile: ['babel-polyfill', APP_DIR + '/javascripts/profile/index.jsx'],
},
output: {
path: BUILD_DIR,
Expand Down
Loading

0 comments on commit 2322a76

Please sign in to comment.