* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// @flow
-import React from 'react';
import { connect } from 'react-redux';
import SubCategoryDefinitionsList from './SubCategoryDefinitionsList';
+import { fetchValues } from '../store/actions';
import { getSettingsAppSettingsForCategory } from '../../../store/rootReducer';
-function CategoryDefinitionsList(props) {
- return <SubCategoryDefinitionsList {...props} />;
-}
-
const mapStateToProps = (state, ownProps) => ({
settings: getSettingsAppSettingsForCategory(
state,
)
});
-export default connect(mapStateToProps)(CategoryDefinitionsList);
+const mapDispatchToProps = { fetchValues };
+
+export default connect(mapStateToProps, mapDispatchToProps)(SubCategoryDefinitionsList);
// @flow
import React from 'react';
import PropTypes from 'prop-types';
-import { groupBy, sortBy } from 'lodash';
+import { groupBy, isEqual, sortBy } from 'lodash';
import DefinitionsList from './DefinitionsList';
import EmailForm from './EmailForm';
import { getSubCategoryName, getSubCategoryDescription } from '../utils';
export default class SubCategoryDefinitionsList extends React.PureComponent {
static propTypes = {
component: PropTypes.object,
+ fetchValues: PropTypes.func,
settings: PropTypes.array.isRequired
};
+ componentDidMount() {
+ this.fetchValues();
+ }
+
+ componentDidUpdate(prevProps /*: Object */) {
+ const prevKeys = prevProps.settings.map(setting => setting.definition.key);
+ const keys = this.props.settings.map(setting => setting.definition.key);
+ if (prevProps.component !== this.props.component || !isEqual(prevKeys, keys)) {
+ this.fetchValues();
+ }
+ }
+
+ fetchValues() {
+ const keys = this.props.settings.map(setting => setting.definition.key).join();
+ this.props.fetchValues(keys, this.props.component && this.props.component.key);
+ }
+
renderEmailForm(subCategoryKey /*: string */) {
const isEmailSettings = this.props.category === 'general' && subCategoryKey === 'email';
if (!isEmailSettings) {
import { getSettingsAppDefinition, getSettingsAppChangedValue } from '../../../store/rootReducer';
export const fetchSettings = componentKey => dispatch => {
- return getDefinitions(componentKey)
- .then(definitions => {
+ return getDefinitions(componentKey).then(
+ definitions => {
const filtered = definitions
.filter(definition => definition.type !== 'LICENSE')
// do not display this setting on project level
componentKey == null || definition.key !== 'sonar.branch.longLivedBranches.regex'
);
dispatch(receiveDefinitions(filtered));
- const keys = filtered.map(definition => definition.key).join();
- return getValues(keys, componentKey);
- })
- .then(settings => {
+ },
+ e => parseError(e).then(message => dispatch(addGlobalErrorMessage(message)))
+ );
+};
+
+export const fetchValues = (keys, componentKey) => dispatch =>
+ getValues(keys, componentKey).then(
+ settings => {
dispatch(receiveValues(settings, componentKey));
dispatch(closeAllGlobalMessages());
- })
- .catch(e => parseError(e).then(message => dispatch(addGlobalErrorMessage(message))));
-};
+ },
+ () => {}
+ );
export const saveValue = (key, componentKey) => (dispatch, getState) => {
dispatch(startLoading(key));