Created
June 30, 2017 20:42
-
-
Save gurdasnijor/1a307dd5be3ccf5054653d38e5d7e8ec to your computer and use it in GitHub Desktop.
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
import * as React from 'react'; | |
// This is necessary so that when the extraData we're passing to ColumnDefinitions changes, | |
// the components actually update. Specifically, we want to update a line's adjustment, | |
// proposed amount, and percent change columns when the bulk adjustment is changed | |
const UpdateOnBulkAdjustmentPlugin = { | |
name: 'UpdateOnBulkAdjustmentPlugin', | |
components: { | |
TableBody: (InitialTableBody: typeof React.Component) => class extends InitialTableBody<any, any> { | |
shouldComponentUpdate(nextProps) { | |
return this.props.data !== nextProps.data || this.props.settings.extraData !== nextProps.settings.extraData; | |
} | |
}, | |
Column: InitialColumn => props => { | |
const newExtraData = {...props.extraData, bulkAdjustment: props.settings.extraData.bulkAdjustment}; | |
const columnsThatUseBulkAdjustment = ['adjustmentInput', 'proposedAmount', 'percentChange']; | |
return columnsThatUseBulkAdjustment.includes(props.id) | |
? <InitialColumn {...props} forceUpdate extraData={newExtraData} value={newExtraData.bulkAdjustment} /> | |
: <InitialColumn {...props} />; | |
} | |
} | |
}; | |
export default UpdateOnBulkAdjustmentPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment