diff --git a/app/assets/stylesheets/application.scss.erb b/app/assets/stylesheets/application.scss.erb index 8070bb97..14457520 100644 --- a/app/assets/stylesheets/application.scss.erb +++ b/app/assets/stylesheets/application.scss.erb @@ -1048,7 +1048,6 @@ label[for="user_remember_me"] { } .sidebarFilterBox { - display:none; width: 319px; padding: 16px 0; overflow-y: auto; diff --git a/frontend/src/Metamaps/Filter.js b/frontend/src/Metamaps/Filter.js index e8361bd3..6b7adaad 100644 --- a/frontend/src/Metamaps/Filter.js +++ b/frontend/src/Metamaps/Filter.js @@ -27,43 +27,6 @@ const Filter = { }, isOpen: false, changing: false, - toggleBox: function(event) { - var self = Filter - - if (self.isOpen) self.close() - else self.open() - - event.stopPropagation() - }, - open: function() { - var self = Filter - - GlobalUI.Account.close() - $('.sidebarFilterIcon div').addClass('hide') - - if (!self.isOpen && !self.changing) { - self.changing = true - - var height = $(document).height() - 108 - $('.sidebarFilterBox').css('max-height', height + 'px').fadeIn(200, function() { - self.changing = false - self.isOpen = true - }) - } - }, - close: function() { - var self = Filter - $('.sidebarFilterIcon div').removeClass('hide') - - if (!self.changing) { - self.changing = true - - $('.sidebarFilterBox').fadeOut(200, function() { - self.changing = false - self.isOpen = false - }) - } - }, reset: function() { var self = Filter self.filters.metacodes = [] diff --git a/frontend/src/Metamaps/GlobalUI/Account.js b/frontend/src/Metamaps/GlobalUI/Account.js index c06b45fc..59d9527d 100644 --- a/frontend/src/Metamaps/GlobalUI/Account.js +++ b/frontend/src/Metamaps/GlobalUI/Account.js @@ -17,7 +17,6 @@ const Account = { }, open: function() { var self = Account - Filter.close() $('.sidebarAccountIcon .tooltipsUnder').addClass('hide') if (!self.isOpen && !self.changing) { self.changing = true diff --git a/frontend/src/Metamaps/GlobalUI/ReactApp.js b/frontend/src/Metamaps/GlobalUI/ReactApp.js index a2a77f8b..d75d505f 100644 --- a/frontend/src/Metamaps/GlobalUI/ReactApp.js +++ b/frontend/src/Metamaps/GlobalUI/ReactApp.js @@ -188,7 +188,6 @@ const ReactApp = { const self = ReactApp return { filterData: Filter.dataForPresentation, - toggleFilterBox: Filter.toggleBox, allForFiltering: Filter.filters, visibleForFiltering: Filter.visible, toggleMetacode: Filter.toggleMetacode, diff --git a/frontend/src/Metamaps/JIT.js b/frontend/src/Metamaps/JIT.js index 7e0708de..4cf8a28a 100644 --- a/frontend/src/Metamaps/JIT.js +++ b/frontend/src/Metamaps/JIT.js @@ -1010,7 +1010,6 @@ const JIT = { Create.newTopic.open() } else if (!Mouse.didPan) { // SINGLE CLICK, no pan - Filter.close() TopicCard.hideCard() SynapseCard.hideCard() Create.newTopic.hide() diff --git a/frontend/src/Metamaps/Map/index.js b/frontend/src/Metamaps/Map/index.js index fad4cc0b..7eff2db4 100644 --- a/frontend/src/Metamaps/Map/index.js +++ b/frontend/src/Metamaps/Map/index.js @@ -142,7 +142,6 @@ const Map = { SynapseCard.hideCard() Create.newTopic.hide(true) // true means force (and override pinned) Create.newSynapse.hide() - Filter.close() InfoBox.close() Realtime.endActiveMap() self.requests = [] diff --git a/frontend/src/Metamaps/Topic.js b/frontend/src/Metamaps/Topic.js index 55b6c934..df5789c8 100644 --- a/frontend/src/Metamaps/Topic.js +++ b/frontend/src/Metamaps/Topic.js @@ -76,7 +76,6 @@ const Topic = { $('.rightclickmenu').remove() TopicCard.hideCard() SynapseCard.hideCard() - Filter.close() } }, centerOn: function(nodeid, callback) { diff --git a/frontend/src/components/MapView/MapButtons.js b/frontend/src/components/MapView/MapButtons.js index fbfe8a75..670e5ddd 100644 --- a/frontend/src/components/MapView/MapButtons.js +++ b/frontend/src/components/MapView/MapButtons.js @@ -8,7 +8,6 @@ class MapButtons extends Component { canEditMap: PropTypes.bool, onImportClick: PropTypes.func, onForkClick: PropTypes.func, - onFilterClick: PropTypes.func, filterData: PropTypes.object, allForFiltering: PropTypes.object, visibleForFiltering: PropTypes.object, @@ -20,10 +19,24 @@ class MapButtons extends Component { filterAllSynapses: PropTypes.func, } + constructor(props) { + super(props) + this.state = {filterBoxOpen: false} + } + + reset = () => { + this.setState({filterBoxOpen: false}) + } + + toggleFilterBox = event => { + this.setState({filterBoxOpen: !this.state.filterBoxOpen}) + } + render () { const { currentUser, canEditMap, filterBoxHtml, onFilterClick, onImportClick, onForkClick, filterData, allForFiltering, visibleForFiltering, toggleMetacode, toggleMapper, toggleSynapse, filterAllMetacodes, filterAllMappers, filterAllSynapses } = this.props + const { filterBoxOpen } = this.state return
{canEditMap &&
@@ -31,10 +44,10 @@ class MapButtons extends Component {
}
-
+
Filter
- + filterAllSynapses={filterAllSynapses} + closeBox={() => this.reset()} />}
{currentUser &&
diff --git a/frontend/src/components/MapView/index.js b/frontend/src/components/MapView/index.js index 204c5e09..b78ddeb5 100644 --- a/frontend/src/components/MapView/index.js +++ b/frontend/src/components/MapView/index.js @@ -17,7 +17,6 @@ class MapView extends Component { mapIsStarred: PropTypes.bool, onMapStar: PropTypes.func, onMapUnstar: PropTypes.func, - toggleFilterBox: PropTypes.func, filterData: PropTypes.object, allForFiltering: PropTypes.object, visibleForFiltering: PropTypes.object, @@ -53,6 +52,7 @@ class MapView extends Component { chatOpen: false }) this.mapChat.reset() + this.mapButtons.reset() this.props.endActiveMap() } @@ -69,7 +69,7 @@ class MapView extends Component { render = () => { const { mobile, map, currentUser, onOpen, onClose, - toggleMapInfoBox, infoBoxHtml, toggleFilterBox, allForFiltering, visibleForFiltering, + toggleMapInfoBox, infoBoxHtml, allForFiltering, visibleForFiltering, toggleMetacode, toggleMapper, toggleSynapse, filterAllMetacodes, filterAllMappers, filterAllSynapses, filterData, openImportLightbox, forkMap, openHelpLightbox, @@ -87,11 +87,11 @@ class MapView extends Component { const canEditMap = map && map.authorizeToEdit(currentUser) // TODO: stop using {...this.props} and make explicit return
- this.mapButtons = x} + currentUser={currentUser} onImportClick={openImportLightbox} onForkClick={forkMap} canEditMap={canEditMap} - onFilterClick={toggleFilterBox} filterData={filterData} allForFiltering={allForFiltering} visibleForFiltering={visibleForFiltering} diff --git a/frontend/src/components/common/FilterBox.js b/frontend/src/components/common/FilterBox.js index 0899e008..b5a5275b 100644 --- a/frontend/src/components/common/FilterBox.js +++ b/frontend/src/components/common/FilterBox.js @@ -1,5 +1,7 @@ import React, { Component, PropTypes } from 'react' +import onClickOutsideAddon from 'react-onclickoutside' + class FilterBox extends Component { static propTypes = { filterData: PropTypes.object, @@ -10,13 +12,20 @@ class FilterBox extends Component { toggleSynapse: PropTypes.func, filterAllMetacodes: PropTypes.func, filterAllMappers: PropTypes.func, - filterAllSynapses: PropTypes.func + filterAllSynapses: PropTypes.func, + closeBox: PropTypes.func + } + + handleClickOutside = () => { + this.props.closeBox() } render () { const { filterData, allForFiltering, visibleForFiltering, toggleMetacode, toggleMapper, toggleSynapse, filterAllMetacodes, filterAllMappers, filterAllSynapses } = this.props - + const style = { + maxHeight: document.body.clientHeight - 108 + 'px' + } const mapperAllClass = "showAll showAllMappers" + (allForFiltering.mappers.length === visibleForFiltering.mappers.length ? ' active' : '') const mapperNoneClass = "hideAll hideAllMappers" @@ -29,7 +38,7 @@ class FilterBox extends Component { + (allForFiltering.synapses.length === visibleForFiltering.synapses.length ? ' active' : '') const synapseNoneClass = "hideAll hideAllSynapses" + (visibleForFiltering.synapses.length === 0 ? ' active' : '') - return
+ return

FILTER BY

@@ -96,10 +105,10 @@ function Metacode({ visible, name, id, icon, toggle }) { } function Synapse({ visible, desc, icon, toggle }) { - return
  • toggle(desc)} key={desc} className={visible ? '' : 'toggledOff'}> + return
  • toggle(desc)} key={desc.replace(/ /g, '')} className={visible ? '' : 'toggledOff'}> synapse icon

    {desc}

  • } -export default FilterBox +export default onClickOutsideAddon(FilterBox)