From 2076e3bd0143ffc4f88c180ce3fa3b9ac41b3f85 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 10 Oct 2017 16:56:47 +0200 Subject: SONAR-7709 Help users to not enter wrong date periods --- .../src/main/js/apps/issues/components/App.js | 51 ++++++++++++---------- .../js/apps/issues/sidebar/CreationDateFacet.js | 2 + .../components/ProjectActivityDateInput.js | 10 +++-- .../ProjectActivityDateInput-test.js.snap | 3 +- .../quality-profiles/changelog/ChangelogSearch.tsx | 16 ++++--- .../src/main/js/components/controls/DateInput.tsx | 13 ++++++ 6 files changed, 59 insertions(+), 36 deletions(-) (limited to 'server') diff --git a/server/sonar-web/src/main/js/apps/issues/components/App.js b/server/sonar-web/src/main/js/apps/issues/components/App.js index f6616f229ed..984aedca11c 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/App.js +++ b/server/sonar-web/src/main/js/apps/issues/components/App.js @@ -420,7 +420,7 @@ export default class App extends React.PureComponent { if (this.mounted) { this.setState({ loading: false }); } - return Promise.reject(); + return []; } ); } @@ -518,29 +518,32 @@ export default class App extends React.PureComponent { }; fetchFacet = (facet /*: string */) => { - return this.fetchIssues({ ps: 1, facets: mapFacet(facet) }).then(({ facets, ...other }) => { - if (this.mounted) { - this.setState(state => ({ - facets: { ...state.facets, ...parseFacets(facets) }, - referencedComponents: { - ...state.referencedComponents, - ...keyBy(other.components, 'uuid') - }, - referencedLanguages: { - ...state.referencedLanguages, - ...keyBy(other.languages, 'key') - }, - referencedRules: { - ...state.referencedRules, - ...keyBy(other.rules, 'key') - }, - referencedUsers: { - ...state.referencedUsers, - ...keyBy(other.users, 'login') - } - })); - } - }); + return this.fetchIssues({ ps: 1, facets: mapFacet(facet) }).then( + ({ facets, ...other }) => { + if (this.mounted) { + this.setState(state => ({ + facets: { ...state.facets, ...parseFacets(facets) }, + referencedComponents: { + ...state.referencedComponents, + ...keyBy(other.components, 'uuid') + }, + referencedLanguages: { + ...state.referencedLanguages, + ...keyBy(other.languages, 'key') + }, + referencedRules: { + ...state.referencedRules, + ...keyBy(other.rules, 'key') + }, + referencedUsers: { + ...state.referencedUsers, + ...keyBy(other.users, 'login') + } + })); + } + }, + () => {} + ); }; isFiltered = () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.js b/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.js index 461d3405d14..edc61cf799d 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.js +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.js @@ -228,6 +228,7 @@ export default class CreationDateFacet extends React.PureComponent { {'—'} diff --git a/server/sonar-web/src/main/js/components/controls/DateInput.tsx b/server/sonar-web/src/main/js/components/controls/DateInput.tsx index e3676215149..5a0c0911f61 100644 --- a/server/sonar-web/src/main/js/components/controls/DateInput.tsx +++ b/server/sonar-web/src/main/js/components/controls/DateInput.tsx @@ -30,6 +30,7 @@ interface Props { inputClassName?: string; // see http://api.jqueryui.com/datepicker/#option-maxDate for details maxDate?: Date | string | number; + minDate?: Date | string | number; name: string; onChange: (value?: string) => void; placeholder: string; @@ -48,6 +49,17 @@ export default class DateInput extends React.PureComponent { this.attachDatePicker(); } + componentDidUpdate(prevProps: Props) { + if ($.fn && ($.fn as any).datepicker && this.input) { + if (prevProps.maxDate !== this.props.maxDate) { + ($(this.input) as any).datepicker('option', { maxDate: this.props.maxDate }); + } + if (prevProps.minDate !== this.props.minDate) { + ($(this.input) as any).datepicker('option', { minDate: this.props.minDate }); + } + } + } + handleChange = () => { const { value } = this.input; this.props.onChange(value); @@ -65,6 +77,7 @@ export default class DateInput extends React.PureComponent { changeMonth: true, changeYear: true, maxDate: this.props.maxDate, + minDate: this.props.minDate, onSelect: this.handleChange }; -- cgit v1.2.3