* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { getByText, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import selectEvent from 'react-select-event';
import { byRole, byText } from '~sonar-aligned/helpers/testSelector';
}),
listLinkJavaQualityProfile: byRole('link', { name: 'java quality profile' }),
returnToList: byRole('link', { name: 'quality_profiles.page' }),
- languageSelect: byRole('combobox', { name: 'language' }),
- profileExtendSelect: byRole('combobox', {
+ languageSelect: byRole('searchbox', { name: 'language' }),
+ profileExtendSelect: byRole('searchbox', {
name: 'quality_profiles.creation.choose_parent_quality_profile',
}),
- profileCopySelect: byRole('combobox', {
+ profileCopySelect: byRole('searchbox', {
name: 'quality_profiles.creation.choose_copy_quality_profile',
}),
nameCreatePopupInput: byRole('textbox', { name: 'name required' }),
// Creation form should have language pre-selected
await user.click(await ui.createButton.find());
- // eslint-disable-next-line testing-library/prefer-screen-queries
- expect(getByText(ui.popup.get(), 'C')).toBeInTheDocument();
+ expect(ui.languageSelect.get()).toHaveValue('C');
});
describe('Evolution', () => {
await user.click(ui.returnToList.get());
await user.click(ui.createButton.get());
await user.click(ui.extendRadio.get());
- await selectEvent.select(ui.languageSelect.get(), 'C');
- await selectEvent.select(ui.profileExtendSelect.get(), ui.newCQualityProfileName);
+
+ await user.click(ui.languageSelect.get());
+ await user.click(byRole('option', { name: 'C' }).get());
+
+ await user.click(ui.profileExtendSelect.get());
+ await user.click(byRole('option', { name: ui.newCQualityProfileName }).get());
+
await user.type(ui.nameCreatePopupInput.get(), ui.newCQualityProfileNameFromCreateButton);
await user.click(ui.createButton.get(ui.popup.get()));
await user.click(ui.returnToList.get());
await user.click(ui.createButton.get());
await user.click(ui.copyRadio.get());
- await selectEvent.select(ui.languageSelect.get(), 'C');
- await selectEvent.select(ui.profileCopySelect.get(), ui.newCQualityProfileName);
+
+ await user.click(ui.languageSelect.get());
+ await user.click(byRole('option', { name: 'C' }).get());
+
+ await user.click(ui.profileCopySelect.get());
+ await user.click(byRole('option', { name: ui.newCQualityProfileName }).get());
+
await user.type(ui.nameCreatePopupInput.get(), ui.newCQualityProfileNameFromCreateButton);
await user.click(ui.createButton.get(ui.popup.get()));
await user.click(await ui.createButton.find());
await user.click(ui.blankRadio.get());
- await selectEvent.select(ui.languageSelect.get(), 'C');
+
+ await user.click(ui.languageSelect.get());
+ await user.click(byRole('option', { name: 'C' }).get());
+
await user.type(ui.nameCreatePopupInput.get(), ui.newCQualityProfileName);
await user.click(ui.createButton.get(ui.popup.get()));
await user.click(await ui.createButton.find());
await user.click(ui.blankRadio.get());
- await selectEvent.select(ui.languageSelect.get(), 'C');
+
+ await user.click(ui.languageSelect.get());
+ await user.click(byRole('option', { name: 'C' }).get());
expect(ui.importerA.get()).toBeInTheDocument();
expect(ui.importerB.get()).toBeInTheDocument();
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { Select, Spinner } from '@sonarsource/echoes-react';
import {
ButtonPrimary,
FileInput,
FlagMessage,
FormField,
InputField,
- LabelValueSelectOption,
LightLabel,
Modal,
Note,
- PopupZLevel,
- SearchSelectDropdown,
SelectionCard,
- Spinner,
} from 'design-system';
import { sortBy } from 'lodash';
import * as React from 'react';
import { useRef } from 'react';
import { useIntl } from 'react-intl';
-import { SingleValue } from 'react-select';
import { Location } from '~sonar-aligned/types/router';
import {
changeProfileParent,
);
const handleLanguageChange = React.useCallback(
- (option: SingleValue<LabelValueSelectOption<string>>) => {
- setLanguage(option?.value);
+ (option: string) => {
+ setLanguage(option);
setIsValidLanguage(true);
setProfile(undefined);
setIsValidProfile(false);
[setLanguage, setIsValidLanguage],
);
- const handleQualityProfileChange = React.useCallback(
- (option: SingleValue<LabelValueSelectOption<Profile>>) => {
- setProfile(option?.value);
- setIsValidProfile(Boolean(option?.value));
- },
- [setProfile, setIsValidProfile],
- );
-
const handleFormSubmit = React.useCallback(async () => {
setSubmitting(true);
const profileKey = profile?.key;
const profilesForSelectedLanguage = profiles.filter((p) => p.language === selectedLanguage);
const profileOptions = sortBy(profilesForSelectedLanguage, 'name').map((profile) => ({
+ ...profile,
label: profile.isBuiltIn
? `${profile.name} (${intl.formatMessage({ id: 'quality_profiles.built_in' })})`
: profile.name,
- value: profile,
+ value: profile.key,
}));
+ const handleQualityProfileChange = React.useCallback(
+ (option: string) => {
+ const selectedProfile = profileOptions.find((p) => p.key === option);
+ setProfile(selectedProfile);
+ setIsValidProfile(selectedProfile !== undefined);
+ },
+ [setProfile, setIsValidProfile, profileOptions],
+ );
+
const languagesOptions = sortBy(languages, 'name').map((l) => ({
label: l.name,
value: l.key,
}));
- function handleSearch<T>(
- options: { label: string; value: T }[],
- query: string,
- cb: (options: LabelValueSelectOption<T>[]) => void,
- ) {
- cb(options.filter((option) => option.label.toLowerCase().includes(query.toLowerCase())));
- }
-
return (
<Modal
headerTitle={header}
<div className="sw-my-4">
<MandatoryFieldsExplanation />
</div>
- <FormField label={intl.formatMessage({ id: 'language' })} required>
- <SearchSelectDropdown
- controlAriaLabel={intl.formatMessage({ id: 'language' })}
- autoFocus
- inputId="create-profile-language-input"
- name="language"
- onChange={handleLanguageChange}
- defaultOptions={languagesOptions}
- loadOptions={(inputValue, cb) => handleSearch(languagesOptions, inputValue, cb)}
- value={languagesOptions.find((o) => o.value === selectedLanguage)}
- zLevel={PopupZLevel.Global}
- />
- </FormField>
+
+ <Select
+ className="sw-mb-4"
+ data={languagesOptions}
+ id="create-profile-language-input"
+ isRequired
+ isSearchable
+ label={intl.formatMessage({ id: 'language' })}
+ name="language"
+ onChange={handleLanguageChange}
+ value={selectedLanguage}
+ />
+
{action !== undefined && (
- <FormField label={intl.formatMessage({ id: 'quality_profiles.parent' })} required>
- <SearchSelectDropdown
- controlAriaLabel={intl.formatMessage({
- id:
- action === ProfileActionModals.Copy
- ? 'quality_profiles.creation.choose_copy_quality_profile'
- : 'quality_profiles.creation.choose_parent_quality_profile',
- })}
- autoFocus
- inputId="create-profile-parent-input"
- name="parentKey"
- onChange={handleQualityProfileChange}
- defaultOptions={profileOptions}
- loadOptions={(inputValue, cb) => handleSearch(profileOptions, inputValue, cb)}
- isSearchable
- value={profileOptions.find((o) => o.value === profile)}
- />
- </FormField>
+ <Select
+ ariaLabel={intl.formatMessage({
+ id:
+ action === ProfileActionModals.Copy
+ ? 'quality_profiles.creation.choose_copy_quality_profile'
+ : 'quality_profiles.creation.choose_parent_quality_profile',
+ })}
+ className="sw-mb-4"
+ data={profileOptions}
+ id="create-profile-parent-input"
+ isRequired
+ isSearchable
+ label={intl.formatMessage({ id: 'quality_profiles.parent' })}
+ name="parentKey"
+ onChange={handleQualityProfileChange}
+ value={profile?.key}
+ />
)}
<FormField
htmlFor="create-profile-name"
{intl.formatMessage({ id: 'quality_profiles.optional_configuration_file' })}
</Note>
</FormField>
- ))}{' '}
+ ))}
</form>
)}
- <Spinner loading={submitting || isLoading} />
+ <Spinner isLoading={submitting || isLoading} />
</>
}
/>
header={renderHeader(languageKey, profilesToShow[languageKey].length)}
data-language={languageKey}
>
- {profilesToShow[languageKey].map((profile) => (
+ {(profilesToShow[languageKey] ?? []).map((profile) => (
<ProfilesListRow
key={profile.key}
profile={profile}
quality_profiles.warning.used_by_projects_no_rules=The current profile is used on several projects, but it has no active rules. Please activate at least 1 rule for this profile.
quality_profiles.warning.is_default_no_rules=The current profile is the default profile, but it has no active rules. Please activate at least 1 rule for this profile.
quality_profiles.x_sonarway_missing_rules={linkCount} Sonar way {count, plural, one {rule} other {rules}} not included
-quality_profiles.parent=Parent:
+quality_profiles.parent=Parent
quality_profiles.parameter_set_to=Parameter {0} set to {1}
quality_profile.summary_additional={count} additional {count, plural, one {rule} other {rules}}
quality_profile.summary_fewer={count} fewer {count, plural, one {rule} other {rules}}