forked from apache/superset
-
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.
New "Time Series - Table" visualization (apache#3543)
* [WiP] adding a new "Time Series - Table" viz * Adding drag-n-drop to collection * Using keys in arrays * tests
- Loading branch information
1 parent
fe50f8b
commit 23a8adb
Showing
20 changed files
with
710 additions
and
90 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
119 changes: 119 additions & 0 deletions
119
superset/assets/javascripts/explore/components/controls/CollectionControl.jsx
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,119 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ListGroup, ListGroupItem } from 'react-bootstrap'; | ||
import shortid from 'shortid'; | ||
import { | ||
SortableContainer, SortableHandle, SortableElement, arrayMove, | ||
} from 'react-sortable-hoc'; | ||
|
||
import InfoTooltipWithTrigger from '../../../components/InfoTooltipWithTrigger'; | ||
import ControlHeader from '../ControlHeader'; | ||
|
||
const propTypes = { | ||
name: PropTypes.string.isRequired, | ||
label: PropTypes.string, | ||
description: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
addTooltip: PropTypes.string, | ||
itemGenerator: PropTypes.func, | ||
keyAccessor: PropTypes.func, | ||
onChange: PropTypes.func, | ||
value: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
]), | ||
isFloat: PropTypes.bool, | ||
isInt: PropTypes.bool, | ||
control: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
label: null, | ||
description: null, | ||
onChange: () => {}, | ||
placeholder: 'Empty collection', | ||
itemGenerator: () => ({ key: shortid.generate() }), | ||
keyAccessor: o => o.key, | ||
value: [], | ||
addTooltip: 'Add an item', | ||
}; | ||
const SortableListGroupItem = SortableElement(ListGroupItem); | ||
const SortableListGroup = SortableContainer(ListGroup); | ||
const SortableDragger = SortableHandle(() => ( | ||
<i className="fa fa-bars text-primary" style={{ cursor: 'ns-resize' }} />)); | ||
|
||
export default class CollectionControl extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.onAdd = this.onAdd.bind(this); | ||
} | ||
onChange(i, value) { | ||
Object.assign(this.props.value[i], value); | ||
this.props.onChange(this.props.value); | ||
} | ||
onAdd() { | ||
this.props.onChange(this.props.value.concat([this.props.itemGenerator()])); | ||
} | ||
onSortEnd({ oldIndex, newIndex }) { | ||
this.props.onChange(arrayMove(this.props.value, oldIndex, newIndex)); | ||
} | ||
removeItem(i) { | ||
this.props.onChange(this.props.value.filter((o, ix) => i !== ix)); | ||
} | ||
renderList() { | ||
if (this.props.value.length === 0) { | ||
return <div className="text-muted">{this.props.placeholder}</div>; | ||
} | ||
return ( | ||
<SortableListGroup | ||
useDragHandle | ||
lockAxis="y" | ||
onSortEnd={this.onSortEnd.bind(this)} | ||
> | ||
{this.props.value.map((o, i) => ( | ||
<SortableListGroupItem | ||
className="clearfix" | ||
key={this.props.keyAccessor(o)} | ||
index={i} | ||
> | ||
<div className="pull-left m-r-5"> | ||
<SortableDragger /> | ||
</div> | ||
<div className="pull-left"> | ||
<this.props.control | ||
{...o} | ||
onChange={this.onChange.bind(this, i)} | ||
/> | ||
</div> | ||
<div className="pull-right"> | ||
<InfoTooltipWithTrigger | ||
icon="times" | ||
label="remove-item" | ||
tooltip="remove item" | ||
bsStyle="primary" | ||
onClick={this.removeItem.bind(this, i)} | ||
/> | ||
</div> | ||
</SortableListGroupItem>))} | ||
</SortableListGroup> | ||
); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<ControlHeader {...this.props} /> | ||
{this.renderList()} | ||
<InfoTooltipWithTrigger | ||
icon="plus-circle" | ||
label="add-item" | ||
tooltip={this.props.addTooltip} | ||
bsStyle="primary" | ||
className="fa-lg" | ||
onClick={this.onAdd} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
CollectionControl.propTypes = propTypes; | ||
CollectionControl.defaultProps = defaultProps; |
Oops, something went wrong.