Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! feat: added expose URL parameters …
Browse files Browse the repository at this point in the history
…widget
  • Loading branch information
olexii4 committed Apr 23, 2024
1 parent 8b84ef5 commit 6a1bd91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('AdditionalGitRemotesField', () => {
expect(inputURLsAfter[3]).toHaveValue('');

expect(mockOnChange).toHaveBeenNthCalledWith(
4,
1,
[
{ name: 'test-1', url: 'https://test-1.repo.git' },
{ name: 'test-2', url: 'https://test-2.repo.git' },
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('AdditionalGitRemotesField', () => {
expect(inputURLsAfter[1]).toHaveValue('https://test-3.repo.git');

expect(mockOnChange).toHaveBeenNthCalledWith(
4,
1,
[
{ name: 'test-2', url: 'https://test-2.repo.git' },
{ name: 'test-3', url: 'https://test-3.repo.git' },
Expand All @@ -174,29 +174,29 @@ describe('AdditionalGitRemotesField', () => {

userEvent.paste(inputNames[0], '-updated');

expect(mockOnChange).toHaveBeenCalledTimes(2);
expect(mockOnChange).toHaveBeenCalledTimes(1);
expect(mockOnChange).toHaveBeenNthCalledWith(
2,
1,
[{ name: 'test-updated', url: 'https://test' }],
true,
);

userEvent.paste(inputURLs[0], '-updated');
// userEvent.clear(inputURLs[0]);

expect(mockOnChange).toHaveBeenCalledTimes(3);
expect(mockOnChange).toHaveBeenCalledTimes(2);
expect(mockOnChange).toHaveBeenNthCalledWith(
3,
2,
[{ name: 'test-updated', url: 'https://test-updated' }],
true,
);

userEvent.clear(inputURLs[0]);
expect(mockOnChange).toHaveBeenNthCalledWith(5, [{ name: 'test-updated', url: '' }], false);
expect(mockOnChange).toHaveBeenNthCalledWith(4, [{ name: 'test-updated', url: '' }], false);

userEvent.paste(inputURLs[0], 'https://test2');
expect(mockOnChange).toHaveBeenNthCalledWith(
7,
5,
[{ name: 'test-updated', url: 'https://test2' }],
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,24 @@ export type State = {
nameValidated: ValidatedOptions;
url: string;
urlValidated: ValidatedOptions;
hasSshKeys: boolean;
};

class AdditionalGitRemote extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);

this.state = {
name: '',
nameValidated: ValidatedOptions.default,
url: '',
urlValidated: ValidatedOptions.default,
hasSshKeys: this.props.sshKeys.length > 0,
};
}

public componentDidMount(): void {
const {
remote: { name, url },
} = this.props;
if (name !== '' || url !== '') {
const nameValidated = this.validateName(name);
const urlValidated = this.validateUrl(url);
this.setState({
name,
nameValidated,
url,
urlValidated,
});
}

const nameValidated = name === '' ? ValidatedOptions.default : this.validateName(name);
const urlValidated = url === '' ? ValidatedOptions.default : this.validateUrl(url);

this.state = {
name,
nameValidated,
url,
urlValidated,
};
}

public componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>): void {
Expand Down Expand Up @@ -111,8 +99,7 @@ class AdditionalGitRemote extends React.PureComponent<Props, State> {
}

private validateUrl(url: string): ValidatedOptions {
const { hasSshKeys } = this.state;
return validateLocation(url, hasSshKeys);
return validateLocation(url, this.props.sshKeys.length > 0);
}

private validateName(name: string): ValidatedOptions {
Expand Down Expand Up @@ -143,7 +130,7 @@ class AdditionalGitRemote extends React.PureComponent<Props, State> {
private getErrorMessage(location: string): string | React.ReactNode {
const isValidGitSsh = FactoryLocationAdapter.isSshLocation(location);

if (isValidGitSsh && !this.state.hasSshKeys) {
if (isValidGitSsh && this.props.sshKeys.length === 0) {
return (
<FormHelperText icon={<ExclamationCircleIcon />} isHidden={false} isError={true}>
No SSH keys found. Please add your SSH keys in the{' '}
Expand Down

0 comments on commit 6a1bd91

Please sign in to comment.