mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 19:45:51 +01:00
set repository name suggestion in import form just at leaving the input field
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import React, { ChangeEvent, KeyboardEvent } from "react";
|
import React, { ChangeEvent, KeyboardEvent, FocusEvent } from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import LabelWithHelpIcon from "./LabelWithHelpIcon";
|
import LabelWithHelpIcon from "./LabelWithHelpIcon";
|
||||||
import { createAttributesForTesting } from "../devBuild";
|
import { createAttributesForTesting } from "../devBuild";
|
||||||
@@ -41,6 +41,7 @@ type Props = {
|
|||||||
helpText?: string;
|
helpText?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
testId?: string;
|
testId?: string;
|
||||||
|
onBlur?: (value: string, name?: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InputField extends React.Component<Props> {
|
class InputField extends React.Component<Props> {
|
||||||
@@ -61,6 +62,12 @@ class InputField extends React.Component<Props> {
|
|||||||
this.props.onChange(event.target.value, this.props.name);
|
this.props.onChange(event.target.value, this.props.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
||||||
|
if (this.props.onBlur) {
|
||||||
|
this.props.onBlur(event.target.value, this.props.name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
handleKeyPress = (event: KeyboardEvent<HTMLInputElement>) => {
|
handleKeyPress = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||||
const onReturnPressed = this.props.onReturnPressed;
|
const onReturnPressed = this.props.onReturnPressed;
|
||||||
if (!onReturnPressed) {
|
if (!onReturnPressed) {
|
||||||
@@ -102,6 +109,7 @@ class InputField extends React.Component<Props> {
|
|||||||
onChange={this.handleInput}
|
onChange={this.handleInput}
|
||||||
onKeyPress={this.handleKeyPress}
|
onKeyPress={this.handleKeyPress}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
{...createAttributesForTesting(testId)}
|
{...createAttributesForTesting(testId)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -48,19 +48,20 @@ const ImportFromUrlForm: FC<Props> = ({ repository, onChange, setValid, disabled
|
|||||||
const [urlValidationError, setUrlValidationError] = useState(false);
|
const [urlValidationError, setUrlValidationError] = useState(false);
|
||||||
|
|
||||||
const handleImportUrlChange = (importUrl: string) => {
|
const handleImportUrlChange = (importUrl: string) => {
|
||||||
const changedRepo = { ...repository, importUrl };
|
onChange({ ...repository, importUrl });
|
||||||
|
const valid = validation.isUrlValid(importUrl);
|
||||||
|
setUrlValidationError(!valid);
|
||||||
|
setValid(valid);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImportUrlBlur = (importUrl: string) => {
|
||||||
if (!repository.name) {
|
if (!repository.name) {
|
||||||
// If the repository name is not fill we set a name suggestion
|
// If the repository name is not fill we set a name suggestion
|
||||||
const match = importUrl.match(/([^\/]+?)(?:.git)?$/);
|
const match = importUrl.match(/([^\/]+?)(?:.git)?$/);
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
changedRepo.name = match[1];
|
onChange({ ...repository, name: match[1] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onChange(changedRepo);
|
|
||||||
const valid = validation.isUrlValid(importUrl);
|
|
||||||
setUrlValidationError(!valid);
|
|
||||||
setValid(valid);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -74,6 +75,7 @@ const ImportFromUrlForm: FC<Props> = ({ repository, onChange, setValid, disabled
|
|||||||
validationError={urlValidationError}
|
validationError={urlValidationError}
|
||||||
errorMessage={t("validation.url-invalid")}
|
errorMessage={t("validation.url-invalid")}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
onBlur={handleImportUrlBlur}
|
||||||
/>
|
/>
|
||||||
</Column>
|
</Column>
|
||||||
<Column className="column is-half">
|
<Column className="column is-half">
|
||||||
|
|||||||
Reference in New Issue
Block a user