import Modal from 'sonar-ui-common/components/controls/Modal';
import Select from 'sonar-ui-common/components/controls/Select';
import { translate } from 'sonar-ui-common/helpers/l10n';
+import { parseAsOptionalString } from 'sonar-ui-common/helpers/query';
import {
changeProfileParent,
createQualityProfile,
getImporters
} from '../../../api/quality-profiles';
+import { Location } from '../../../components/hoc/withRouter';
import { Profile } from '../types';
interface Props {
languages: Array<{ key: string; name: string }>;
+ location: Location;
onClose: () => void;
onCreate: Function;
organization: string | null;
render() {
const header = translate('quality_profiles.new_profile');
+ const languageQueryFilter = parseAsOptionalString(this.props.location.query.language);
const languages = sortBy(this.props.languages, 'name');
let profiles: Array<{ label: string; value: string }> = [];
- const selectedLanguage = this.state.language || languages[0].key;
+ const selectedLanguage = this.state.language || languageQueryFilter || languages[0].key;
const importers = this.state.importers.filter(importer =>
importer.languages.includes(selectedLanguage)
);
id="create-profile-language"
name="language"
onChange={this.handleLanguageChange}
- options={languages.map(language => ({
- label: language.name,
- value: language.key
+ options={languages.map(l => ({
+ label: l.name,
+ value: l.key
}))}
value={selectedLanguage}
/>
*/
import * as React from 'react';
import { Actions } from '../../../api/quality-profiles';
+import { Location } from '../../../components/hoc/withRouter';
import { Profile } from '../types';
import Evolution from './Evolution';
import PageHeader from './PageHeader';
interface Props {
actions: Actions;
languages: Array<{ key: string; name: string }>;
- location: { query: T.Dict<string> };
+ location: Location;
organization: string | null;
profiles: Profile[];
updateProfiles: () => Promise<void>;
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { Actions } from '../../../api/quality-profiles';
-import { Router, withRouter } from '../../../components/hoc/withRouter';
+import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
import { Profile } from '../types';
import { getProfilePath } from '../utils';
import CreateProfileForm from './CreateProfileForm';
interface Props {
actions: Actions;
languages: Array<{ key: string; name: string }>;
+ location: Location;
organization: string | null;
profiles: Profile[];
router: Pick<Router, 'push'>;
};
render() {
- const { actions, languages, organization, profiles } = this.props;
+ const { actions, languages, location, organization, profiles } = this.props;
return (
<header className="page-header">
<h1 className="page-title">{translate('quality_profiles.page')}</h1>
{this.state.createFormOpen && (
<CreateProfileForm
languages={languages}
+ location={location}
onClose={this.closeCreateForm}
onCreate={this.handleCreate}
organization={organization}
import * as React from 'react';
import { mockEvent, waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
import { changeProfileParent, createQualityProfile } from '../../../../api/quality-profiles';
-import { mockQualityProfile } from '../../../../helpers/testMocks';
+import { mockLocation, mockQualityProfile } from '../../../../helpers/testMocks';
import CreateProfileForm from '../CreateProfileForm';
beforeEach(() => jest.clearAllMocks());
getImporters: jest.fn().mockResolvedValue([
{
key: 'key_importer',
- languages: ['lang1_importer', 'lang2_importer', 'kr'],
+ languages: ['lang1_importer', 'lang2_importer', 'js'],
name: 'name_importer'
}
])
it('should render correctly', async () => {
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
- expect(wrapper).toMatchSnapshot();
+
+ expect(wrapper).toMatchSnapshot('default');
+ expect(
+ wrapper.setProps({ location: mockLocation({ query: { language: 'js' } }) })
+ ).toMatchSnapshot('with query filter');
});
it('should handle form submit correctly', async () => {
function shallowRender(props?: Partial<CreateProfileForm['props']>) {
return shallow<CreateProfileForm>(
<CreateProfileForm
- languages={[{ key: 'kr', name: 'Hangeul' }]}
+ languages={[
+ { key: 'js', name: 'JavaScript' },
+ { key: 'css', name: 'CSS' }
+ ]}
+ location={mockLocation()}
onClose={jest.fn()}
onCreate={jest.fn()}
organization="org"
- profiles={[mockQualityProfile()]}
+ profiles={[mockQualityProfile(), mockQualityProfile({ language: 'css' })]}
{...props}
/>
);
import { shallow } from 'enzyme';
import * as React from 'react';
import { click } from 'sonar-ui-common/helpers/testUtils';
-import { mockLanguage, mockQualityProfile, mockRouter } from '../../../../helpers/testMocks';
+import {
+ mockLanguage,
+ mockLocation,
+ mockQualityProfile,
+ mockRouter
+} from '../../../../helpers/testMocks';
import { PageHeader } from '../PageHeader';
it('should render correctly', () => {
<PageHeader
actions={{ create: false }}
languages={[mockLanguage()]}
+ location={mockLocation()}
organization="foo"
profiles={[mockQualityProfile()]}
router={mockRouter()}
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should render correctly 1`] = `
+exports[`should render correctly: default 1`] = `
<Modal
contentLabel="quality_profiles.new_profile"
onRequestClose={[MockFunction]}
options={
Array [
Object {
- "label": "Hangeul",
- "value": "kr",
+ "label": "CSS",
+ "value": "css",
+ },
+ Object {
+ "label": "JavaScript",
+ "value": "js",
+ },
+ ]
+ }
+ value="css"
+ />
+ </div>
+ <div
+ className="modal-field"
+ >
+ <label
+ htmlFor="create-profile-parent"
+ >
+ quality_profiles.parent
+ </label>
+ <Select
+ clearable={true}
+ id="create-profile-parent"
+ name="parentKey"
+ onChange={[Function]}
+ options={
+ Array [
+ Object {
+ "label": "none",
+ "value": "",
+ },
+ Object {
+ "label": "name",
+ "value": "key",
+ },
+ ]
+ }
+ value=""
+ />
+ </div>
+ <input
+ name="hello-ie11"
+ type="hidden"
+ value=""
+ />
+ </div>
+ <div
+ className="modal-foot"
+ >
+ <SubmitButton
+ disabled={false}
+ id="create-profile-submit"
+ >
+ create
+ </SubmitButton>
+ <ResetButtonLink
+ id="create-profile-cancel"
+ onClick={[MockFunction]}
+ >
+ cancel
+ </ResetButtonLink>
+ </div>
+ </form>
+</Modal>
+`;
+
+exports[`should render correctly: with query filter 1`] = `
+<Modal
+ contentLabel="quality_profiles.new_profile"
+ onRequestClose={[MockFunction]}
+ size="small"
+>
+ <form
+ id="create-profile-form"
+ onSubmit={[Function]}
+ >
+ <div
+ className="modal-head"
+ >
+ <h2>
+ quality_profiles.new_profile
+ </h2>
+ </div>
+ <div
+ className="modal-body"
+ >
+ <div
+ className="modal-field"
+ >
+ <label
+ htmlFor="create-profile-name"
+ >
+ name
+ <em
+ className="mandatory"
+ >
+ *
+ </em>
+ </label>
+ <input
+ autoFocus={true}
+ id="create-profile-name"
+ maxLength={100}
+ name="name"
+ onChange={[Function]}
+ required={true}
+ size={50}
+ type="text"
+ value=""
+ />
+ </div>
+ <div
+ className="modal-field"
+ >
+ <label
+ htmlFor="create-profile-language"
+ >
+ language
+ <em
+ className="mandatory"
+ >
+ *
+ </em>
+ </label>
+ <Select
+ clearable={false}
+ id="create-profile-language"
+ name="language"
+ onChange={[Function]}
+ options={
+ Array [
+ Object {
+ "label": "CSS",
+ "value": "css",
+ },
+ Object {
+ "label": "JavaScript",
+ "value": "js",
},
]
}
- value="kr"
+ value="js"
/>
</div>
<div
"label": "none",
"value": "",
},
+ Object {
+ "label": "name",
+ "value": "key",
+ },
]
}
value=""
},
]
}
+ location={
+ Object {
+ "action": "PUSH",
+ "hash": "",
+ "key": "key",
+ "pathname": "/path",
+ "query": Object {},
+ "search": "",
+ "state": Object {},
+ }
+ }
onClose={[Function]}
onCreate={[Function]}
organization="foo"