* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import {
+ ButtonPrimary,
+ FormField,
+ InputSelect,
+ LabelValueSelectOption,
+ Modal,
+} from 'design-system';
import { sortBy } from 'lodash';
import * as React from 'react';
import { changeProfileParent } from '../../../api/quality-profiles';
-import Modal from '../../../components/controls/Modal';
-import Select from '../../../components/controls/Select';
-import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons';
-import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker';
import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation';
import { translate } from '../../../helpers/l10n';
import { Profile } from '../types';
interface State {
loading: boolean;
- selected: string | null;
+ selected: { value: string } | null;
}
export default class ChangeParentForm extends React.PureComponent<Props, State> {
}
handleSelectChange = (option: { value: string }) => {
- this.setState({ selected: option.value });
+ this.setState({ selected: option });
};
- handleFormSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
- event.preventDefault();
-
- const parent = this.props.profiles.find((p) => p.key === this.state.selected);
+ handleFormSubmit = () => {
+ const parent = this.props.profiles.find((p) => p.key === this.state.selected?.value);
this.setState({ loading: true });
changeProfileParent(this.props.profile, parent)
};
render() {
- const { profiles } = this.props;
+ const { profiles, profile } = this.props;
+ const { loading, selected } = this.state;
const options = [
{ label: translate('none'), value: '' },
})),
];
- const submitDisabled =
- this.state.loading ||
- this.state.selected == null ||
- this.state.selected === this.props.profile.parentKey;
+ const submitDisabled = loading || selected == null || selected.value === profile.parentKey;
- const selectedValue = this.state.selected ?? (this.props.profile.parentKey || '');
+ const selectedValue = selected
+ ? options.find((o) => o.value === selected?.value)
+ : options.find((o) => o.value === profile.parentKey);
return (
<Modal
- contentLabel={translate('quality_profiles.change_parent')}
- onRequestClose={this.props.onClose}
- size="small"
- >
- <form id="change-profile-parent-form" onSubmit={this.handleFormSubmit}>
- <div className="modal-head">
- <h2>{translate('quality_profiles.change_parent')}</h2>
- </div>
- <div className="modal-body">
- <MandatoryFieldsExplanation className="modal-field" />
- <div className="modal-field">
- <label htmlFor="change-profile-parent-input">
- {translate('quality_profiles.parent')}
- <MandatoryFieldMarker />
- </label>
- <Select
- className="width-100"
- autoFocus
- name="parentKey"
- isClearable={false}
- id="change-profile-parent"
- inputId="change-profile-parent-input"
- onChange={this.handleSelectChange}
+ headerTitle={translate('quality_profiles.change_parent')}
+ onClose={this.props.onClose}
+ loading={loading}
+ isOverflowVisible
+ body={
+ <>
+ <MandatoryFieldsExplanation />
+
+ <FormField
+ className="sw-mt-2"
+ htmlFor="quality-profile-new-parent"
+ label={translate('quality_profiles.parent')}
+ required
+ >
+ <InputSelect
+ id="quality-profile-new-parent"
+ name="parent"
+ onChange={(data: LabelValueSelectOption<string>) => this.handleSelectChange(data)}
options={options}
- isSearchable
- value={options.filter((o) => o.value === selectedValue)}
+ required
+ size="full"
+ value={selectedValue}
/>
- </div>
- </div>
- <div className="modal-foot">
- {this.state.loading && <i className="spinner spacer-right" />}
- <SubmitButton disabled={submitDisabled} id="change-profile-parent-submit">
- {translate('change_verb')}
- </SubmitButton>
- <ResetButtonLink id="change-profile-parent-cancel" onClick={this.props.onClose}>
- {translate('cancel')}
- </ResetButtonLink>
- </div>
- </form>
- </Modal>
+ </FormField>
+ </>
+ }
+ primaryButton={
+ <ButtonPrimary onClick={this.handleFormSubmit} disabled={submitDisabled}>
+ {translate('change_verb')}
+ </ButtonPrimary>
+ }
+ secondaryButtonLabel={translate('cancel')}
+ />
);
}
}