Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions caravel/assets/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
node_modules/*
vendor/*
**/*{.,-}min.js
**/*.sh
coverage/**
dist/*
stylesheets/*
images/*
node_modules/*
node_modules*/*
spec/*
coverage/**
**/*{.,-}min.js
stylesheets/*
vendor/*
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,27 @@ class SqlEditorTopToolbar extends React.Component {
const tableName = tableOpt.value;
const qe = this.props.queryEditor;
const url = `/caravel/table/${qe.dbId}/${tableName}/${qe.schema}/`;

this.setState({ tableLoading: true });
$.get(url, (data) => {
this.props.actions.addTable({
id: shortid.generate(),
dbId: this.props.queryEditor.dbId,
queryEditorId: this.props.queryEditor.id,
name: data.name,
indexes: data.indexes,
schema: qe.schema,
columns: data.columns,
expanded: true,
});
this.setState({ tableLoading: false });
})
.fail(() => {
this.props.actions.addAlert({
msg: 'Error occurred while fetching metadata',
bsStyle: 'danger',
});
this.setState({ tableLoading: false });
});
}
render() {
Expand Down
23 changes: 23 additions & 0 deletions caravel/assets/javascripts/SqlLab/components/TableElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as Actions from '../actions';
import shortid from 'shortid';
import ModalTrigger from '../../components/ModalTrigger.jsx';

class TableElement extends React.Component {
setSelectStar() {
Expand Down Expand Up @@ -86,6 +87,27 @@ class TableElement extends React.Component {
</a>
);
}
let keyLink;
if (this.props.table.indexes && this.props.table.indexes.length > 0) {
keyLink = (
<ModalTrigger
modalTitle={
<div>
Keys for table <strong>{this.props.table.name}</strong>
</div>
}
modalBody={
<pre>{JSON.stringify(this.props.table.indexes, null, 4)}</pre>
}
triggerNode={
<Link
className="fa fa-key pull-left m-l-2"
tooltip={`View indexes (${this.props.table.indexes.length})`}
/>
}
/>
);
}
return (
<div>
<div className="clearfix">
Expand All @@ -94,6 +116,7 @@ class TableElement extends React.Component {
</div>
<div className="pull-right">
<ButtonGroup className="ws-el-controls pull-right">
{keyLink}
<Link
className="fa fa-pencil pull-left m-l-2"
onClick={this.setSelectStar.bind(this)}
Expand Down
12 changes: 3 additions & 9 deletions caravel/assets/javascripts/SqlLab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ import TabbedSqlEditors from './components/TabbedSqlEditors';
import QueryAutoRefresh from './components/QueryAutoRefresh';
import Alerts from './components/Alerts';

import { bindActionCreators, compose, createStore } from 'redux';
import { bindActionCreators, createStore } from 'redux';
import { connect, Provider } from 'react-redux';

import { initialState, sqlLabReducer } from './reducers';
import persistState from 'redux-localstorage';
import { enhancer } from '../reduxUtils';

require('./main.css');

let enhancer = compose(persistState());
if (process.env.NODE_ENV === 'dev') {
enhancer = compose(
persistState(), window.devToolsExtension && window.devToolsExtension()
);
}
let store = createStore(sqlLabReducer, initialState, enhancer);
let store = createStore(sqlLabReducer, initialState, enhancer());

// jquery hack to highlight the navbar menu
$('a[href="/caravel/sqllab"]').parent().addClass('active');
Expand Down
64 changes: 2 additions & 62 deletions caravel/assets/javascripts/SqlLab/reducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import shortid from 'shortid';
import * as actions from './actions';
import { now } from '../modules/dates';
import { addToObject, alterInObject, alterInArr, removeFromArr, getFromArr, addToArr }
from '../reduxUtils.js';

const defaultQueryEditor = {
id: shortid.generate(),
Expand All @@ -23,68 +25,6 @@ export const initialState = {
queriesLastUpdate: 0,
};

function addToObject(state, arrKey, obj) {
const newObject = Object.assign({}, state[arrKey]);
const copiedObject = Object.assign({}, obj);

if (!copiedObject.id) {
copiedObject.id = shortid.generate();
}
newObject[copiedObject.id] = copiedObject;
return Object.assign({}, state, { [arrKey]: newObject });
}

function alterInObject(state, arrKey, obj, alterations) {
const newObject = Object.assign({}, state[arrKey]);
newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations);
return Object.assign({}, state, { [arrKey]: newObject });
}

function alterInArr(state, arrKey, obj, alterations) {
// Finds an item in an array in the state and replaces it with a
// new object with an altered property
const idKey = 'id';
const newArr = [];
state[arrKey].forEach((arrItem) => {
if (obj[idKey] === arrItem[idKey]) {
newArr.push(Object.assign({}, arrItem, alterations));
} else {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
}

function removeFromArr(state, arrKey, obj, idKey = 'id') {
const newArr = [];
state[arrKey].forEach((arrItem) => {
if (!(obj[idKey] === arrItem[idKey])) {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
}

function getFromArr(arr, id) {
let obj;
arr.forEach((o) => {
if (o.id === id) {
obj = o;
}
});
return obj;
}

function addToArr(state, arrKey, obj) {
const newObj = Object.assign({}, obj);
if (!newObj.id) {
newObj.id = shortid.generate();
}
const newState = {};
newState[arrKey] = [...state[arrKey], newObj];
return Object.assign({}, state, newState);
}

export const sqlLabReducer = function (state, action) {
const actionHandlers = {
[actions.ADD_QUERY_EDITOR]() {
Expand Down
26 changes: 26 additions & 0 deletions caravel/assets/javascripts/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ function dashboardContainer(dashboardData) {
setFilter(sliceId, col, vals, refresh) {
this.addFilter(sliceId, col, vals, false, refresh);
},
effectiveExtraFilters(sliceId) {
// Summarized filter, not defined by sliceId
// returns k=field, v=array of values
const f = {};
if (sliceId && this.metadata.filter_immune_slices.includes(sliceId)) {
// The slice is immune to dashboard fiterls
return f;
}

// Building a list of fields the slice is immune to filters on
let immuneToFields = [];
if (
sliceId &&
this.metadata.filter_immune_slice_fields &&
this.metadata.filter_immune_slice_fields[sliceId]) {
immuneToFields = this.metadata.filter_immune_slice_fields[sliceId];
}
for (const filteringSliceId in this.filters) {
for (const field in this.filters[filteringSliceId]) {
if (!immuneToFields.includes(field)) {
f[field] = this.filters[filteringSliceId][field];
}
}
}
return f;
},
addFilter(sliceId, col, vals, merge = true, refresh = true) {
if (!(sliceId in this.filters)) {
this.filters[sliceId] = {};
Expand Down
12 changes: 8 additions & 4 deletions caravel/assets/javascripts/modules/caravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const px = function () {
const containerId = data.token + '_con';
const selector = '#' + containerId;
const container = $(selector);
const sliceId = data.sliceId;
const sliceId = data.slice_id;
let dttm = 0;
const stopwatch = function () {
dttm += 10;
Expand All @@ -81,9 +81,13 @@ const px = function () {
const parser = document.createElement('a');
parser.href = data.json_endpoint;
if (dashboard !== undefined) {
const flts =
newParams.extraFilters === false ? '' :
encodeURIComponent(JSON.stringify(dashboard.filters));
let flts;
if (newParams.extraFilters === false) {
flts = '';
} else {
flts = dashboard.effectiveExtraFilters(sliceId);
flts = encodeURIComponent(JSON.stringify(flts));
}
qrystr = parser.search + '&extra_filters=' + flts;
} else if ($('#query').length === 0) {
qrystr = parser.search;
Expand Down
75 changes: 75 additions & 0 deletions caravel/assets/javascripts/reduxUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import shortid from 'shortid';
import { compose } from 'redux';
import persistState from 'redux-localstorage';

export function addToObject(state, arrKey, obj) {
const newObject = Object.assign({}, state[arrKey]);
const copiedObject = Object.assign({}, obj);

if (!copiedObject.id) {
copiedObject.id = shortid.generate();
}
newObject[copiedObject.id] = copiedObject;
return Object.assign({}, state, { [arrKey]: newObject });
}

export function alterInObject(state, arrKey, obj, alterations) {
const newObject = Object.assign({}, state[arrKey]);
newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations);
return Object.assign({}, state, { [arrKey]: newObject });
}

export function alterInArr(state, arrKey, obj, alterations) {
// Finds an item in an array in the state and replaces it with a
// new object with an altered property
const idKey = 'id';
const newArr = [];
state[arrKey].forEach((arrItem) => {
if (obj[idKey] === arrItem[idKey]) {
newArr.push(Object.assign({}, arrItem, alterations));
} else {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
}

export function removeFromArr(state, arrKey, obj, idKey = 'id') {
const newArr = [];
state[arrKey].forEach((arrItem) => {
if (!(obj[idKey] === arrItem[idKey])) {
newArr.push(arrItem);
}
});
return Object.assign({}, state, { [arrKey]: newArr });
}

export function getFromArr(arr, id) {
let obj;
arr.forEach((o) => {
if (o.id === id) {
obj = o;
}
});
return obj;
}

export function addToArr(state, arrKey, obj) {
const newObj = Object.assign({}, obj);
if (!newObj.id) {
newObj.id = shortid.generate();
}
const newState = {};
newState[arrKey] = [...state[arrKey], newObj];
return Object.assign({}, state, newState);
}

export function enhancer() {
let enhancerWithPersistState = compose(persistState());
if (process.env.NODE_ENV === 'dev') {
enhancerWithPersistState = compose(
persistState(), window.devToolsExtension && window.devToolsExtension()
);
}
return enhancerWithPersistState;
}
16 changes: 7 additions & 9 deletions caravel/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"cover": "babel-node ./node_modules/.bin/istanbul cover _mocha -- --require spec/helpers/browser.js --recursive spec/**/*_spec.*",
"dev": "NODE_ENV=dev webpack -d --watch --colors --progress",
"prod": "NODE_ENV=production webpack -p --colors --progress",
"lint": "npm run --silent lint:js",
"lint:js": "eslint --ignore-path=.eslintignore --ext .js,.jsx ."
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx ."
},
"repository": {
"type": "git",
Expand All @@ -39,6 +38,7 @@
"dependencies": {
"autobind-decorator": "^1.3.3",
"babel-cli": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"bootstrap": "^3.3.6",
"bootstrap-datepicker": "^1.6.0",
"brace": "^0.7.0",
Expand All @@ -62,11 +62,11 @@
"moments": "0.0.2",
"mustache": "^2.2.1",
"nvd3": "1.8.4",
"react": "^15.2.1",
"react": "^15.3.2",
"react-ace": "^3.4.1",
"react-bootstrap": "^0.30.3",
"react-bootstrap-table": "^2.3.8",
"react-dom": "^0.14.8",
"react-dom": "^15.3.2",
"react-draggable": "^2.1.2",
"react-grid-layout": "^0.13.1",
"react-map-gl": "^1.0.0-beta-10",
Expand All @@ -89,8 +89,7 @@
"babel": "^6.3.26",
"babel-core": "^6.10.4",
"babel-loader": "^6.2.4",
"babel-preset-airbnb": "^1.1.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-airbnb": "^2.0.0",
"babel-preset-react": "^6.11.1",
"chai": "^3.5.0",
"codeclimate-test-reporter": "^0.3.3",
Expand All @@ -99,7 +98,7 @@
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.11.1",
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-jsx-a11y": "^1.2.0",
"eslint-plugin-react": "^5.2.2",
"exports-loader": "^0.6.3",
"istanbul": "^1.0.0-alpha",
Expand All @@ -110,8 +109,7 @@
"less": "^2.6.1",
"less-loader": "^2.2.2",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.8",
"react-dom": "^0.14.8",
"react-addons-test-utils": "^15.3.2",
"style-loader": "^0.13.0",
"transform-loader": "^0.2.3",
"url-loader": "^0.5.7",
Expand Down
10 changes: 10 additions & 0 deletions caravel/assets/visualizations/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const TIME_CHOICES = [
'1 hour ago',
'12 hours ago',
'1 day ago',
'7 days ago',
'28 days ago',
'90 days ago',
'1 year ago',
];

Loading