Skip to content

Commit

Permalink
Merge pull request #701 from getguesstimate/calculator-bugs
Browse files Browse the repository at this point in the history
Fixing calculator bugs.
  • Loading branch information
mmcdermott authored Aug 6, 2016
2 parents 7b52ce6 + 8332477 commit 1c610dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/components/calculators/show/calculator-space-selector.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { createSelector } from 'reselect'
import e from 'gEngine/engine'

function _sameId(idA, idB){
return idA.toString() === idB.toString()
}

function calculatorSelector(state, {calculatorId}) { return state.calculators.find(c => _sameId(c.id, calculatorId)) }
function spaceGraphSelector(state) { return _.pick(state, ['spaces', 'metrics', 'guesstimates', 'simulations', 'users', 'me', 'organizations']) }
const _sameId = (idA, idB) => idA.toString() === idB.toString()
const spaceGraphSelector = state => _.pick(state, ['spaces', 'metrics', 'guesstimates', 'simulations', 'users', 'me', 'organizations'])
const organizationFactsSelector = state => _.get(state, 'facts.organizationFacts')
const calculatorSelector = (state, {calculatorId}) => state.calculators.find(c => _sameId(c.id, calculatorId))

export const calculatorSpaceSelector = createSelector(
spaceGraphSelector,
organizationFactsSelector,
calculatorSelector,
(graph, calculator) => {
(graph, organizationFacts, calculator) => {
if (!_.has(calculator, 'space_id')) { return {} }
const {metrics, is_private} = e.space.toDSpace(calculator.space_id, graph)
const {metrics, is_private} = e.space.toDSpace(calculator.space_id, graph, organizationFacts)

const findById = id => metrics.find(m => _sameId(m.id, id))

Expand Down
2 changes: 1 addition & 1 deletion src/components/spaces/show/Toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class SpaceToolbar extends Component {
<CardListElement
key={c.id}
header={c.title}
onMouseDown={() => {this.props.showCalculator(c.id)}}
onMouseDown={() => {this.props.showCalculator(c)}}
closeOnClick={true}
icon={'calculator'}
/>
Expand Down
10 changes: 8 additions & 2 deletions src/components/spaces/show/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ShowCalculatorHeader = ({id, editableByMe, onEdit, onDelete, onClose}) =>
<div className='row'>
<div className='col-xs-12'>
<div className='button-close-text'>
<ButtonExpandText onClick={navigateFn(`/calculators/${showCalculatorId}`)}/>
<ButtonExpandText onClick={navigateFn(`/calculators/${id}`)}/>
{editableByMe && <ButtonEditText onClick={onEdit}/>}
{editableByMe && <ButtonDeleteText onClick={onDelete}/>}
<ButtonCloseText onClick={onClose}/>
Expand Down Expand Up @@ -104,14 +104,15 @@ export default class SpacesShow extends Component {
rightSidebar: {
type: !!this.props.showCalculatorId ? SHOW_CALCULATOR : CLOSED,
showCalculatorResults: this.props.showCalculatorResults,
showCalculatorId: this.props.showCalculatorId,
},
}

componentWillMount() {
window.recorder.recordMountEvent(this)

this.considerFetch(this.props)
if (!(this.props.embed || this.state.showCalculatorId)) { elev.show() }
if (!(this.props.embed || this.state.rightSidebar.type !== CLOSED)) { elev.show() }

if (_.has(this.props, 'denormalizedSpace.editableByMe')) {
this.setDefaultEditPermission(_.get(this.props, 'denormalizedSpace.editableByMe'))
Expand Down Expand Up @@ -261,6 +262,10 @@ export default class SpacesShow extends Component {
}
showCalculator({id}) { this.openRightSidebar({type: SHOW_CALCULATOR, showCalculatorId: id}) }
editCalculator(id) { this.openRightSidebar({type: EDIT_CALCULATOR_FORM, editCalculatorId: id}) }
deleteCalculator(id) {
this.props.dispatch(calculatorActions.destroy(id))
this.closeRightSidebar()
}
makeNewCalculator() { this.openRightSidebar({type: NEW_CALCULATOR_FORM}) }
showFactSidebar() { if (this.canShowFactSidebar()) { this.openRightSidebar({type: FACT_SIDEBAR}) } }

Expand All @@ -276,6 +281,7 @@ export default class SpacesShow extends Component {
header: (
<ShowCalculatorHeader
editableByMe={editableByMe}
id={showCalculatorId}
onEdit={this.editCalculator.bind(this, showCalculatorId)}
onDelete={this.deleteCalculator.bind(this, showCalculatorId)}
onClose={this.closeRightSidebar.bind(this)}
Expand Down

0 comments on commit 1c610dd

Please sign in to comment.