Skip to content

Commit a84f7ed

Browse files
committed
Merge remote-tracking branch 'origin/main' into 1.30-releases
2 parents 862ad90 + 6943d57 commit a84f7ed

40 files changed

+2291
-237
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **compass**.
2-
This document was automatically generated on Wed Dec 22 2021.
2+
This document was automatically generated on Wed Jan 05 2022.
33

44
## List of dependencies
55

packages/compass-components/src/components/file-input.spec.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,50 @@ describe('FileInput', function () {
136136
const link = screen.getByTestId('file-input-link');
137137
expect(link).to.exist;
138138
});
139+
140+
it('adds description if description is specified', function () {
141+
render(
142+
<FileInput
143+
id="file-input"
144+
label="Select something"
145+
onChange={spy}
146+
variant={Variant.Horizontal}
147+
description={'Learn more'}
148+
/>
149+
);
150+
151+
const description = screen.getByTestId('file-input-description');
152+
expect(description).to.exist;
153+
});
154+
155+
it('adds link and description if specified', function () {
156+
render(
157+
<FileInput
158+
id="file-input"
159+
label="Select something"
160+
onChange={spy}
161+
variant={Variant.Horizontal}
162+
link="http://google.com/"
163+
description={'Learn more'}
164+
/>
165+
);
166+
167+
const linkDescription = screen.getByTestId('file-input-link');
168+
expect(linkDescription).to.exist;
169+
});
170+
171+
it('adds error message if specified', function () {
172+
render(
173+
<FileInput
174+
id="file-input"
175+
label="Select something"
176+
onChange={spy}
177+
error={true}
178+
errorMessage={'Error'}
179+
/>
180+
);
181+
182+
const errorMessage = screen.getByTestId('file-input-error');
183+
expect(errorMessage).to.exist;
184+
});
139185
});

packages/compass-components/src/components/file-input.tsx

Lines changed: 120 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
import React from 'react';
22
import path from 'path';
3-
import { css, cx } from '@emotion/css';
3+
import { css, cx } from '@leafygreen-ui/emotion';
4+
import { uiColors } from '@leafygreen-ui/palette';
5+
import { spacing } from '@leafygreen-ui/tokens';
46

5-
import { Button, Icon } from '..';
7+
import { Button, Icon, Label, Link, Description } from '..';
68

7-
const formItemHorizontalStyles = css`
8-
margin: 15px auto 15px;
9-
display: flex;
10-
justify-content: flex-end;
11-
`;
9+
const { base: redBaseColor } = uiColors.red;
10+
11+
const formItemHorizontalStyles = css({
12+
marginTop: spacing[2],
13+
marginBottom: spacing[2],
14+
marginRight: 'auto',
15+
marginLeft: 'auto',
16+
display: 'flex',
17+
alignItems: 'center',
18+
});
1219

1320
const formItemVerticalStyles = css`
1421
margin: 5px auto 20px;
1522
`;
1623

1724
const formItemErrorStyles = css`
18-
border: 1px solid red;
19-
25+
border: 1px solid ${redBaseColor};
26+
border-radius: 5px;
2027
&:focus {
21-
border: 1px solid red;
28+
border: 1px solid ${redBaseColor};
2229
}
2330
`;
2431

2532
const buttonStyles = css`
2633
width: 100%;
2734
`;
2835

29-
const buttonErrorStyles = css`
30-
border: 1px solid red;
31-
`;
32-
33-
const labelHorizontalStyles = css`
34-
width: 70%;
35-
text-align: right;
36-
vertical-align: middle;
37-
padding-right: 15px;
38-
margin: auto;
39-
margin-bottom: 0;
40-
`;
36+
const errorMessageStyles = css({
37+
color: `${redBaseColor} !important`,
38+
});
4139

42-
const labelErrorStyles = css`
43-
color: red;
44-
`;
40+
const labelHorizontalStyles = css({
41+
width: '70%',
42+
display: 'grid',
43+
gridTemplateAreas: `'label icon' 'description .'`,
44+
gridTemplateColumns: '1fr auto',
45+
alignItems: 'center',
46+
columnGap: spacing[1],
47+
paddingRight: spacing[3],
48+
});
4549

4650
const labelIconStyles = css`
4751
display: inline-block;
@@ -83,21 +87,29 @@ type FileWithPath = File & {
8387
function FileInput({
8488
id,
8589
label,
90+
dataTestId,
8691
onChange,
8792
multi = false,
8893
error = false,
94+
errorMessage,
8995
variant = Variant.Horizontal,
9096
link,
97+
description,
9198
values,
99+
labelAlignment = 'left',
92100
}: {
93101
id: string;
94102
label: string;
103+
dataTestId: string;
95104
onChange: (files: string[]) => void;
96105
multi?: boolean;
97106
error?: boolean;
107+
errorMessage?: string;
98108
variant?: Variant;
99109
link?: string;
110+
description?: string;
100111
values?: string[];
112+
labelAlignment?: 'right' | 'left' | 'center';
101113
}): React.ReactElement {
102114
const inputRef = React.useRef<HTMLInputElement>(null);
103115

@@ -120,57 +132,94 @@ function FileInput({
120132
[onChange]
121133
);
122134

123-
return (
124-
<div
125-
className={cx(
126-
{ [formItemHorizontalStyles]: variant === Variant.Horizontal },
127-
{ [formItemVerticalStyles]: variant === Variant.Vertical },
128-
{ [formItemErrorStyles]: error }
129-
)}
130-
>
131-
<label
132-
htmlFor={id}
135+
const renderDescription = () => {
136+
if (!link && !description) {
137+
return <></>;
138+
}
139+
if (!link) {
140+
return (
141+
<Description
142+
data-testid={'file-input-description'}
143+
style={{ gridArea: 'description' }}
144+
>
145+
{description}
146+
</Description>
147+
);
148+
}
149+
return (
150+
<Link
151+
data-testid={'file-input-link'}
152+
href={link}
133153
className={cx(
134-
{ [labelHorizontalStyles]: variant === Variant.Horizontal },
135-
{ [labelErrorStyles]: error }
154+
{
155+
[labelIconStyles]: !description,
156+
},
157+
css({
158+
gridArea: description ? 'description' : 'icon',
159+
})
136160
)}
161+
hideExternalIcon={!description}
137162
>
138-
<span>{label}</span>
139-
{link && (
140-
<a
141-
href={link}
142-
target="_blank"
143-
rel="noreferrer"
144-
className={labelIconStyles}
145-
data-testid="file-input-link"
146-
>
147-
148-
</a>
163+
{description ?? ''}
164+
</Link>
165+
);
166+
};
167+
168+
return (
169+
<div>
170+
<div
171+
className={cx(
172+
{ [formItemHorizontalStyles]: variant === Variant.Horizontal },
173+
{ [formItemVerticalStyles]: variant === Variant.Vertical },
174+
{ [formItemErrorStyles]: error }
149175
)}
150-
</label>
151-
<input
152-
ref={inputRef}
153-
id={`${id}_file_input`}
154-
name={id}
155-
type="file"
156-
multiple={multi}
157-
onChange={onFilesChanged}
158-
style={{ display: 'none' }}
159-
/>
160-
<Button
161-
id={id}
162-
data-testid="file-input-button"
163-
className={cx({ [buttonStyles]: true }, { [buttonErrorStyles]: error })}
164-
onClick={() => {
165-
if (inputRef.current) {
166-
inputRef.current.click();
167-
}
168-
}}
169-
title="Select a file"
170-
leftGlyph={<Icon glyph="AddFile" title={null} fill="currentColor" />}
171176
>
172-
{buttonText}
173-
</Button>
177+
<label
178+
htmlFor={`${id}_file_input`}
179+
className={cx(
180+
{ [labelHorizontalStyles]: variant === Variant.Horizontal },
181+
css({
182+
textAlign: labelAlignment,
183+
})
184+
)}
185+
>
186+
<span style={{ gridArea: 'label' }}>{label}</span>
187+
{renderDescription()}
188+
</label>
189+
<input
190+
data-testid={dataTestId ?? 'file-input'}
191+
ref={inputRef}
192+
id={`${id}_file_input`}
193+
name={id}
194+
type="file"
195+
multiple={multi}
196+
onChange={onFilesChanged}
197+
style={{ display: 'none' }}
198+
/>
199+
<Button
200+
id={id}
201+
data-testid="file-input-button"
202+
className={cx({ [buttonStyles]: true })}
203+
onClick={() => {
204+
if (inputRef.current) {
205+
inputRef.current.click();
206+
}
207+
}}
208+
title="Select a file"
209+
leftGlyph={<Icon glyph="AddFile" title={null} fill="currentColor" />}
210+
>
211+
{buttonText}
212+
</Button>
213+
</div>
214+
{error && errorMessage && (
215+
<Label
216+
data-testid={'file-input-error'}
217+
className={errorMessageStyles}
218+
htmlFor={''}
219+
>
220+
{errorMessage}
221+
</Label>
222+
)}
174223
</div>
175224
);
176225
}

packages/compass-connect/src/components/form/ssh-tunnel-identity-file-validation.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class SSHTunnelIdentityFileValidation extends React.Component {
162162
/>
163163
<FileInput
164164
label="SSH Identity File"
165+
labelAlignment="right"
165166
id="sshTunnelIdentityFile"
166167
error={this.getFileError()}
167168
onChange={this.onSSHTunnelIdentityFileChanged.bind(this)}

packages/compass-connect/src/components/form/ssl-server-client-validation.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class SSLServerClientValidation extends React.Component {
116116
>
117117
<FileInput
118118
label="Certificate Authority"
119+
labelAlignment="right"
119120
id="sslCA"
120121
error={this.getCertAuthError()}
121122
onChange={this.onCertificateAuthorityChanged.bind(this)}
@@ -124,6 +125,7 @@ class SSLServerClientValidation extends React.Component {
124125
/>
125126
<FileInput
126127
label="Client Certificate"
128+
labelAlignment="right"
127129
id="sslCert"
128130
error={this.getClientCertError()}
129131
onChange={this.onClientCertificateChanged.bind(this)}
@@ -132,6 +134,7 @@ class SSLServerClientValidation extends React.Component {
132134
/>
133135
<FileInput
134136
label="Client Private Key"
137+
labelAlignment="right"
135138
id="sslKey"
136139
error={this.getClientKeyError()}
137140
onChange={this.onClientPrivateKeyChanged.bind(this)}

packages/compass-connect/src/components/form/ssl-server-validation.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SSLServerValidation extends React.Component {
4646
className={classnames(styles['form-group'])}>
4747
<FileInput
4848
label="Certificate Authority"
49+
labelAlignment="right"
4950
onChange={this.onSSLCAChanged.bind(this)}
5051
values={this.props.connectionModel.sslCA}
5152
error={this.getError()}

packages/compass-shell/src/components/compass-shell/compass-shell.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class CompassShell extends Component {
4141
constructor(props) {
4242
super(props);
4343

44+
this.shellRef = React.createRef();
45+
4446
this.shellOutput = this.props.shellOutput || [];
4547

4648
this.state = {
@@ -136,6 +138,13 @@ export class CompassShell extends Component {
136138
);
137139
}
138140

141+
hideInfoModal() {
142+
this.setState({ showInfoModal: false });
143+
if (this.shellRef.current) {
144+
this.shellRef.current.focusEditor();
145+
}
146+
}
147+
139148
/**
140149
* Render CompassShell component.
141150
*
@@ -160,7 +169,7 @@ export class CompassShell extends Component {
160169
<Fragment>
161170
<InfoModal
162171
show={showInfoModal}
163-
hideInfoModal={() => this.setState({ showInfoModal: false })}
172+
hideInfoModal={this.hideInfoModal.bind(this)}
164173
/>
165174
<div
166175
data-test-id="shell-section"
@@ -194,6 +203,7 @@ export class CompassShell extends Component {
194203
)}
195204
>
196205
<Shell
206+
ref={this.shellRef}
197207
runtime={this.props.runtime}
198208
initialHistory={this.state.initialHistory}
199209
initialOutput={this.shellOutput}

0 commit comments

Comments
 (0)