From: Grégoire Aubert Date: Wed, 14 Nov 2018 16:11:59 +0000 (+0100) Subject: Rewrite part of the settings page X-Git-Tag: 7.5~152 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=02c56111d2490e2066f9d2dcc71b54ccc8786bdd;p=sonarqube.git Rewrite part of the settings page --- diff --git a/server/sonar-web/src/main/js/api/settings.ts b/server/sonar-web/src/main/js/api/settings.ts index 2c0ad2d7210..fbea55db86b 100644 --- a/server/sonar-web/src/main/js/api/settings.ts +++ b/server/sonar-web/src/main/js/api/settings.ts @@ -19,41 +19,18 @@ */ import { omitBy } from 'lodash'; import { getJSON, RequestData, post, postJSON } from '../helpers/request'; -import { TYPE_PROPERTY_SET } from '../apps/settings/constants'; -import { BranchParameters } from '../app/types'; +import { + BranchParameters, + SettingCategoryDefinition, + SettingValue, + SettingType +} from '../app/types'; import throwGlobalError from '../app/utils/throwGlobalError'; -interface DefinitionField { - description: string; - key: string; - name: string; - options: string[]; -} - -export interface Definition { - category: string; - description: string; - fields: DefinitionField[]; - key: string; - name: string; - options: string[]; - subCategory: string; - type: string; -} - -export function getDefinitions(component?: string): Promise<{ definitions: Definition[] }> { +export function getDefinitions(component?: string): Promise { return getJSON('/api/settings/list_definitions', { component }).then(r => r.definitions); } -export interface SettingValue { - inherited?: boolean; - key: string; - parentValue?: string; - parentValues?: string[]; - value?: any; - values?: string[]; -} - export function getValues( data: { keys: string; component?: string } & BranchParameters ): Promise { @@ -66,7 +43,7 @@ export function setSettingValue(definition: any, value: any, component?: string) if (definition.multiValues) { data.values = value; - } else if (definition.type === TYPE_PROPERTY_SET) { + } else if (definition.type === SettingType.PropertySet) { data.fieldValues = value .map((fields: any) => omitBy(fields, value => value == null)) .map(JSON.stringify); diff --git a/server/sonar-web/src/main/js/app/types.ts b/server/sonar-web/src/main/js/app/types.ts index ce8d5e90095..8e36aa98591 100644 --- a/server/sonar-web/src/main/js/app/types.ts +++ b/server/sonar-web/src/main/js/app/types.ts @@ -698,6 +698,53 @@ export enum RuleType { Unknown = 'UNKNOWN' } +export type Setting = SettingValue & { definition: SettingDefinition }; + +export enum SettingType { + String = 'STRING', + Text = 'TEXT', + Password = 'PASSWORD', + Boolean = 'BOOLEAN', + Float = 'FLOAT', + Integer = 'INTEGER', + Long = 'LONG', + SingleSelectList = 'SINGLE_SELECT_LIST', + PropertySet = 'PROPERTY_SET' +} + +export interface SettingDefinition { + description?: string; + key: string; + name?: string; + options: string[]; + type?: SettingType; +} + +export interface SettingFieldDefinition extends SettingDefinition { + description: string; + name: string; +} + +export interface SettingCategoryDefinition extends SettingDefinition { + category: string; + defaultValue?: string; + deprecatedKey?: string; + fields: SettingFieldDefinition[]; + multiValues?: boolean; + subCategory: string; +} + +export interface SettingValue { + fieldValues?: Array<{ [key: string]: string }>; + inherited?: boolean; + key: string; + parentFieldValues?: Array<{ [key: string]: string }>; + parentValue?: string; + parentValues?: string[]; + value?: string; + values?: string[]; +} + export interface ShortLivingBranch extends Branch { isMain: false; isOrphan?: true; diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/LeakPeriodForm.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/LeakPeriodForm.tsx index 5812a3d3c60..ebfc5e35072 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/LeakPeriodForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/LeakPeriodForm.tsx @@ -20,8 +20,9 @@ import * as React from 'react'; import SettingForm from './SettingForm'; import { translate } from '../../../helpers/l10n'; -import { getValues, SettingValue } from '../../../api/settings'; +import { getValues } from '../../../api/settings'; import Modal from '../../../components/controls/Modal'; +import { SettingValue } from '../../../app/types'; interface Props { branch: string; diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPattern.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPattern.tsx index 487ec48c432..e0b17e46f8e 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPattern.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPattern.tsx @@ -19,9 +19,10 @@ */ import * as React from 'react'; import LongBranchesPatternForm from './LongBranchesPatternForm'; -import { getValues, SettingValue } from '../../../api/settings'; +import { getValues } from '../../../api/settings'; import { EditButton } from '../../../components/ui/buttons'; import { translate } from '../../../helpers/l10n'; +import { SettingValue } from '../../../app/types'; interface Props { project: string; diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPatternForm.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPatternForm.tsx index ddc08a23d51..d323cf22a81 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPatternForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/LongBranchesPatternForm.tsx @@ -20,8 +20,8 @@ import * as React from 'react'; import SettingForm from './SettingForm'; import { translate } from '../../../helpers/l10n'; -import { SettingValue } from '../../../api/settings'; import Modal from '../../../components/controls/Modal'; +import { SettingValue } from '../../../app/types'; interface Props { onChange: () => void; diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/SettingForm.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/SettingForm.tsx index 45533ab1da6..08f1bb0e802 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/SettingForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/SettingForm.tsx @@ -18,9 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import { SettingValue, setSimpleSettingValue, resetSettingValue } from '../../../api/settings'; +import { setSimpleSettingValue, resetSettingValue } from '../../../api/settings'; import { Button, SubmitButton, ResetButtonLink } from '../../../components/ui/buttons'; import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { SettingValue } from '../../../app/types'; interface Props { branch?: string; diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx b/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx index f13959d9abf..76b1d29491c 100644 --- a/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/DefinitionActions-test.tsx @@ -21,6 +21,7 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import DefinitionActions from '../components/DefinitionActions'; +import { SettingType } from '../../../app/types'; const definition = { category: 'baz', @@ -30,7 +31,7 @@ const definition = { name: 'foobar', options: [], subCategory: 'bar', - type: 'foo' + type: SettingType.String }; const settings = { diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js deleted file mode 100644 index 91363999b79..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getEmptyValue, getDefaultValue } from '../utils'; -import { - TYPE_PROPERTY_SET, - TYPE_STRING, - TYPE_SINGLE_SELECT_LIST, - TYPE_BOOLEAN -} from '../constants'; - -const fields = [{ key: 'foo', type: TYPE_STRING }, { key: 'bar', type: TYPE_SINGLE_SELECT_LIST }]; - -describe('#getEmptyValue()', () => { - it('should work for property sets', () => { - const setting = { type: TYPE_PROPERTY_SET, fields }; - expect(getEmptyValue(setting)).toEqual([{ foo: '', bar: null }]); - }); - - it('should work for multi values string', () => { - const setting = { type: TYPE_STRING, multiValues: true }; - expect(getEmptyValue(setting)).toEqual(['']); - }); - - it('should work for multi values boolean', () => { - const setting = { type: TYPE_BOOLEAN, multiValues: true }; - expect(getEmptyValue(setting)).toEqual([null]); - }); -}); - -describe('#getDefaultValue()', () => { - const check = (parentValue, expected) => { - const setting = { definition: { type: TYPE_BOOLEAN }, parentValue }; - expect(getDefaultValue(setting)).toEqual(expected); - }; - - it('should work for boolean field when passing true', () => check(true, 'settings.boolean.true')); - it('should work for boolean field when passing "true"', () => - check('true', 'settings.boolean.true')); - it('should work for boolean field when passing false', () => - check(false, 'settings.boolean.false')); - it('should work for boolean field when passing "false"', () => - check('false', 'settings.boolean.false')); -}); diff --git a/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts new file mode 100644 index 00000000000..53605d927a4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/__tests__/utils-test.ts @@ -0,0 +1,67 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getEmptyValue, getDefaultValue } from '../utils'; +import { SettingFieldDefinition, SettingCategoryDefinition, SettingType } from '../../../app/types'; + +const fields = [ + { key: 'foo', type: SettingType.String } as SettingFieldDefinition, + { key: 'bar', type: SettingType.SingleSelectList } as SettingFieldDefinition +]; + +const settingDefinition: SettingCategoryDefinition = { + category: 'test', + fields: [], + key: 'test', + options: [], + subCategory: 'subtest' +}; + +describe('#getEmptyValue()', () => { + it('should work for property sets', () => { + const setting = { ...settingDefinition, type: SettingType.PropertySet, fields }; + expect(getEmptyValue(setting)).toEqual([{ foo: '', bar: null }]); + }); + + it('should work for multi values string', () => { + const setting = { ...settingDefinition, type: SettingType.String, multiValues: true }; + expect(getEmptyValue(setting)).toEqual(['']); + }); + + it('should work for multi values boolean', () => { + const setting = { ...settingDefinition, type: SettingType.Boolean, multiValues: true }; + expect(getEmptyValue(setting)).toEqual([null]); + }); +}); + +describe('#getDefaultValue()', () => { + const check = (parentValue?: string, expected?: string) => { + const setting = { + definition: { key: 'test', options: [], type: SettingType.Boolean }, + parentValue, + key: 'test' + }; + expect(getDefaultValue(setting)).toEqual(expected); + }; + + it('should work for boolean field when passing "true"', () => + check('true', 'settings.boolean.true')); + it('should work for boolean field when passing "false"', () => + check('false', 'settings.boolean.false')); +}); diff --git a/server/sonar-web/src/main/js/apps/settings/components/Definition.js b/server/sonar-web/src/main/js/apps/settings/components/Definition.js index 668c22c6377..1ce6ac3ba10 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/Definition.js +++ b/server/sonar-web/src/main/js/apps/settings/components/Definition.js @@ -36,7 +36,6 @@ import { translateWithParameters, translate } from '../../../helpers/l10n'; import { resetValue, saveValue, checkValue } from '../store/actions'; import { passValidation } from '../store/settingsPage/validationMessages/actions'; import { cancelChange, changeValue } from '../store/settingsPage/changedValues/actions'; -import { TYPE_PASSWORD } from '../constants'; import { getSettingsAppChangedValue, isSettingsAppLoading, @@ -196,6 +195,7 @@ class Definition extends React.PureComponent { hasValueChanged={hasValueChanged} onCancel={this.handleCancel} onChange={this.handleChange} + onSave={this.handleSave} setting={setting} value={effectiveValue} /> diff --git a/server/sonar-web/src/main/js/apps/settings/components/DefinitionActions.tsx b/server/sonar-web/src/main/js/apps/settings/components/DefinitionActions.tsx index 2f2df148296..b7fab85c9ad 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/DefinitionActions.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/DefinitionActions.tsx @@ -19,10 +19,10 @@ */ import * as React from 'react'; import Modal from '../../../components/controls/Modal'; +import { Button, ResetButtonLink, SubmitButton } from '../../../components/ui/buttons'; import { isEmptyValue, getDefaultValue, getSettingValue } from '../utils'; import { translate } from '../../../helpers/l10n'; -import { Button, ResetButtonLink, SubmitButton } from '../../../components/ui/buttons'; -import { SettingValue, Definition } from '../../../api/settings'; +import { Setting } from '../../../app/types'; type Props = { changedValue: string; @@ -32,7 +32,7 @@ type Props = { onCancel: () => void; onReset: () => void; onSave: () => void; - setting: SettingValue & { definition: Definition }; + setting: Setting; }; type State = { reseting: boolean }; diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.js deleted file mode 100644 index 852fcc43043..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import PropTypes from 'prop-types'; -import PropertySetInput from './PropertySetInput'; -import MultiValueInput from './MultiValueInput'; -import PrimitiveInput from './PrimitiveInput'; -import { TYPE_PROPERTY_SET } from '../../constants'; - -export default class Input extends React.PureComponent { - static propTypes = { - setting: PropTypes.object.isRequired, - value: PropTypes.any, - onChange: PropTypes.func.isRequired - }; - - render() { - const { definition } = this.props.setting; - - if (definition.multiValues) { - return ; - } - - if (definition.type === TYPE_PROPERTY_SET) { - return ; - } - - return ; - } -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.tsx new file mode 100644 index 00000000000..cbe09c0278d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/Input.tsx @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import PropertySetInput from './PropertySetInput'; +import MultiValueInput from './MultiValueInput'; +import PrimitiveInput from './PrimitiveInput'; +import { DefaultInputProps, isCategoryDefinition } from '../../utils'; +import { SettingType } from '../../../../app/types'; + +export default function Input(props: DefaultInputProps) { + const { definition } = props.setting; + + if (isCategoryDefinition(definition) && definition.multiValues) { + return ; + } + + if (definition.type === SettingType.PropertySet) { + return ; + } + + return ; +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.js deleted file mode 100644 index 1a7cb685cdb..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import PropTypes from 'prop-types'; -import Toggle from '../../../../components/controls/Toggle'; -import { defaultInputPropTypes } from '../../propTypes'; -import { translate } from '../../../../helpers/l10n'; - -export default class InputForBoolean extends React.PureComponent { - static propTypes = { - ...defaultInputPropTypes, - value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]) - }; - - render() { - const hasValue = this.props.value != null; - const displayedValue = hasValue ? this.props.value : false; - - return ( -
- - - {!hasValue && {translate('settings.not_set')}} -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.tsx new file mode 100644 index 00000000000..0be73027098 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForBoolean.tsx @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import Toggle from '../../../../components/controls/Toggle'; +import { translate } from '../../../../helpers/l10n'; +import { DefaultSpecializedInputProps } from '../../utils'; + +interface Props extends DefaultSpecializedInputProps { + value: string | boolean | undefined; +} + +export default function InputForBoolean({ onChange, name, value }: Props) { + const displayedValue = value != null ? value : false; + return ( +
+ + {value == null && {translate('settings.not_set')}} +
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.js deleted file mode 100644 index b756f60a82d..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import SimpleInput from './SimpleInput'; - -export default function InputForNumber(props) { - return ; -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.tsx new file mode 100644 index 00000000000..21d75702d9c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForNumber.tsx @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import SimpleInput from './SimpleInput'; +import { DefaultSpecializedInputProps } from '../../utils'; + +export default function InputForNumber(props: DefaultSpecializedInputProps) { + return ; +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js deleted file mode 100644 index 9a91a268bfb..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import * as theme from '../../../../app/theme'; -import { translate } from '../../../../helpers/l10n'; -import { defaultInputPropTypes } from '../../propTypes'; -import LockIcon from '../../../../components/icons-components/LockIcon'; -import { Button } from '../../../../components/ui/buttons'; - -export default class InputForPassword extends React.PureComponent { - static propTypes = defaultInputPropTypes; - - state = { - value: '', - changing: false - }; - - componentWillReceiveProps(nextProps /*: Props*/) { - if (!nextProps.hasValueChanged && this.props.hasValueChanged) { - this.setState({ changing: false, value: '' }); - } - } - - handleInputChange(e) { - this.props.onChange(e.target.value); - this.setState({ changing: true, value: e.target.value }); - } - - handleChangeClick = () => { - this.setState({ changing: true }); - }; - - renderInput() { - return ( -
- - this.handleInputChange(e)} - type="password" - value={this.state.value} - /> -
- ); - } - - render() { - const hasValue = !!this.props.value; - - if (this.state.changing || !hasValue) { - return this.renderInput(); - } - - return ( -
- - -
- ); - } -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.tsx new file mode 100644 index 00000000000..412bff6891d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForPassword.tsx @@ -0,0 +1,89 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import * as theme from '../../../../app/theme'; +import LockIcon from '../../../../components/icons-components/LockIcon'; +import { Button } from '../../../../components/ui/buttons'; +import { translate } from '../../../../helpers/l10n'; +import { DefaultSpecializedInputProps } from '../../utils'; + +interface State { + changing: boolean; + value: string; +} + +export default class InputForPassword extends React.PureComponent< + DefaultSpecializedInputProps, + State +> { + state: State = { + value: '', + changing: false + }; + + componentDidUpdate(prevProps: DefaultSpecializedInputProps) { + if (!prevProps.hasValueChanged && this.props.hasValueChanged) { + this.setState({ changing: false, value: '' }); + } + } + + handleInputChange = (event: React.ChangeEvent) => { + this.props.onChange(event.target.value); + this.setState({ changing: true, value: event.target.value }); + }; + + handleChangeClick = () => { + this.setState({ changing: true }); + }; + + renderInput() { + return ( +
+ + +
+ ); + } + + render() { + const hasValue = !!this.props.value; + + if (this.state.changing || !hasValue) { + return this.renderInput(); + } + + return ( + <> + + + + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForSingleSelectList.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForSingleSelectList.js deleted file mode 100644 index 15173960462..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForSingleSelectList.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import PropTypes from 'prop-types'; -import Select from '../../../../components/controls/Select'; -import { defaultInputPropTypes } from '../../propTypes'; - -export default class InputForSingleSelectList extends React.PureComponent { - static propTypes = { - ...defaultInputPropTypes, - options: PropTypes.arrayOf(PropTypes.string).isRequired - }; - - handleInputChange(option) { - this.props.onChange(option.value); - } - - render() { - const options = this.props.options.map(option => ({ - label: option, - value: option - })); - - return ( - + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.js deleted file mode 100644 index a83756912fc..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import SimpleInput from './SimpleInput'; - -export default function InputForString(props) { - return ; -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.tsx new file mode 100644 index 00000000000..da681e1cf78 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForString.tsx @@ -0,0 +1,26 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import SimpleInput from './SimpleInput'; +import { DefaultSpecializedInputProps } from '../../utils'; + +export default function InputForString(props: DefaultSpecializedInputProps) { + return ; +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForText.js b/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForText.js deleted file mode 100644 index 7193e8a118d..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/InputForText.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import React from 'react'; -import { defaultInputPropTypes } from '../../propTypes'; - -export default class InputForText extends React.PureComponent { - static propTypes = defaultInputPropTypes; - - handleInputChange(e) { - this.props.onChange(e.target.value); - } - - render() { - return ( -