mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add eslint rule padding-line-between-statements (#1593)
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
7b77f18376
commit
dcf253e7d5
401 files changed
+2018
-40
No files matched your search
@@ -45,6 +45,7 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
|
||||
}
|
||||
this.dropAreaActive = false;
|
||||
const files = Array.from(evt.dataTransfer.files);
|
||||
|
||||
if (files.length > 0) {
|
||||
this.props.onDropFiles(files, { evt });
|
||||
}
|
||||
@@ -53,12 +54,15 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
|
||||
render() {
|
||||
const { onDragEnter, onDragLeave, onDragOver, onDrop } = this;
|
||||
const { disabled, className } = this.props;
|
||||
|
||||
try {
|
||||
const contentElem = React.Children.only(this.props.children) as React.ReactElement<React.HTMLProps<HTMLElement>>;
|
||||
|
||||
if (disabled) {
|
||||
return contentElem;
|
||||
}
|
||||
const isValidContentElem = React.isValidElement(contentElem);
|
||||
|
||||
if (isValidContentElem) {
|
||||
const contentElemProps: React.HTMLProps<HTMLElement> = {
|
||||
className: cssNames("DropFileInput", contentElem.props.className, className, {
|
||||
@@ -69,10 +73,12 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
|
||||
onDragOver,
|
||||
onDrop,
|
||||
};
|
||||
|
||||
return React.cloneElement(contentElem, contentElemProps);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Error: <DropFileInput/> must contain only single child element`);
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,17 @@ export class FileInput extends React.Component<Props> {
|
||||
|
||||
protected onChange = async (evt: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const fileList = Array.from(evt.target.files);
|
||||
|
||||
if (!fileList.length) {
|
||||
return;
|
||||
}
|
||||
let selectedFiles: FileInputSelection[] = fileList.map(file => ({ file }));
|
||||
|
||||
if (this.props.readAsText) {
|
||||
const readingFiles: Promise<FileInputSelection>[] = fileList.map(file => {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onloadend = () => {
|
||||
resolve({
|
||||
file,
|
||||
@@ -46,6 +49,7 @@ export class FileInput extends React.Component<Props> {
|
||||
reader.readAsText(file);
|
||||
});
|
||||
});
|
||||
|
||||
selectedFiles = await Promise.all(readingFiles);
|
||||
}
|
||||
this.props.onSelectFiles(...selectedFiles);
|
||||
@@ -53,6 +57,7 @@ export class FileInput extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const { onSelectFiles, readAsText, ...props } = this.props;
|
||||
|
||||
return (
|
||||
<input
|
||||
type="file"
|
||||
|
||||
@@ -12,6 +12,7 @@ import isBoolean from "lodash/isBoolean";
|
||||
import uniqueId from "lodash/uniqueId";
|
||||
|
||||
const { conditionalValidators, ...InputValidators } = Validators;
|
||||
|
||||
export { InputValidators, InputValidator };
|
||||
|
||||
type InputElement = HTMLInputElement | HTMLTextAreaElement;
|
||||
@@ -70,16 +71,20 @@ export class Input extends React.Component<InputProps, State> {
|
||||
setValue(value: string) {
|
||||
if (value !== this.getValue()) {
|
||||
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(this.input.constructor.prototype, "value").set;
|
||||
|
||||
nativeInputValueSetter.call(this.input, value);
|
||||
const evt = new Event("input", { bubbles: true });
|
||||
|
||||
this.input.dispatchEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
getValue(): string {
|
||||
const { value, defaultValue = "" } = this.props;
|
||||
|
||||
if (value !== undefined) return value; // controlled input
|
||||
if (this.input) return this.input.value; // uncontrolled input
|
||||
|
||||
return defaultValue as string;
|
||||
}
|
||||
|
||||
@@ -97,6 +102,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
|
||||
private autoFitHeight() {
|
||||
const { multiLine, rows, maxRows } = this.props;
|
||||
|
||||
if (!multiLine) {
|
||||
return;
|
||||
}
|
||||
@@ -104,6 +110,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
const lineHeight = parseFloat(window.getComputedStyle(textArea).lineHeight);
|
||||
const rowsCount = (this.getValue().match(/\n/g) || []).length + 1;
|
||||
const height = lineHeight * Math.min(Math.max(rowsCount, rows), maxRows);
|
||||
|
||||
textArea.style.height = `${height}px`;
|
||||
}
|
||||
|
||||
@@ -121,6 +128,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
break;
|
||||
}
|
||||
const result = validator.validate(value, this.props);
|
||||
|
||||
if (isBoolean(result) && !result) {
|
||||
errors.push(this.getValidatorError(value, validator));
|
||||
} else if (result instanceof Promise) {
|
||||
@@ -143,6 +151,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
if (asyncValidators.length > 0) {
|
||||
this.setState({ validating: true, valid: false });
|
||||
const asyncErrors = await Promise.all(asyncValidators);
|
||||
|
||||
if (this.validationId === validationId) {
|
||||
this.setValidation(errors.concat(...asyncErrors.filter(err => err)));
|
||||
}
|
||||
@@ -161,6 +170,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
|
||||
private getValidatorError(value: string, { message }: InputValidator) {
|
||||
if (isFunction(message)) return message(value, this.props);
|
||||
|
||||
return message || "";
|
||||
}
|
||||
|
||||
@@ -173,6 +183,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
// debounce async validators
|
||||
.map(({ debounce, ...validator }) => {
|
||||
if (debounce) validator.validate = debouncePromise(validator.validate, debounce);
|
||||
|
||||
return validator;
|
||||
});
|
||||
// run validation
|
||||
@@ -187,6 +198,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
@autobind()
|
||||
onFocus(evt: React.FocusEvent<InputElement>) {
|
||||
const { onFocus, autoSelectOnFocus } = this.props;
|
||||
|
||||
if (onFocus) onFocus(evt);
|
||||
if (autoSelectOnFocus) this.select();
|
||||
this.setState({ focused: true });
|
||||
@@ -195,6 +207,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
@autobind()
|
||||
onBlur(evt: React.FocusEvent<InputElement>) {
|
||||
const { onBlur } = this.props;
|
||||
|
||||
if (onBlur) onBlur(evt);
|
||||
if (this.state.dirtyOnBlur) this.setState({ dirty: true, dirtyOnBlur: false });
|
||||
this.setState({ focused: false });
|
||||
@@ -238,6 +251,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
|
||||
get showMaxLenIndicator() {
|
||||
const { maxLength, multiLine } = this.props;
|
||||
|
||||
return maxLength && multiLine;
|
||||
}
|
||||
|
||||
@@ -252,13 +266,16 @@ export class Input extends React.Component<InputProps, State> {
|
||||
|
||||
componentDidUpdate(prevProps: InputProps) {
|
||||
const { defaultValue, value, dirty, validators } = this.props;
|
||||
|
||||
if (prevProps.value !== value || defaultValue !== prevProps.defaultValue) {
|
||||
this.validate();
|
||||
this.autoFitHeight();
|
||||
}
|
||||
|
||||
if (prevProps.dirty !== dirty) {
|
||||
this.setDirty(dirty);
|
||||
}
|
||||
|
||||
if (prevProps.validators !== validators) {
|
||||
this.setupValidators();
|
||||
}
|
||||
@@ -307,8 +324,10 @@ export class Input extends React.Component<InputProps, State> {
|
||||
);
|
||||
const componentId = id || showErrorsAsTooltip ? getRandId({ prefix: "input_tooltip_id" }) : undefined;
|
||||
let tooltipError: React.ReactNode;
|
||||
|
||||
if (showErrorsAsTooltip && showErrors) {
|
||||
const tooltipProps = typeof showErrorsAsTooltip === "object" ? showErrorsAsTooltip : {};
|
||||
|
||||
tooltipProps.className = cssNames("InputTooltipError", tooltipProps.className);
|
||||
tooltipError = (
|
||||
<Tooltip targetId={componentId} {...tooltipProps}>
|
||||
@@ -319,6 +338,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div id={componentId} className={className}>
|
||||
{tooltipError}
|
||||
|
||||
@@ -28,6 +28,7 @@ export const isNumber: InputValidator = {
|
||||
message: () => _i18n._(t`Invalid number`),
|
||||
validate: (value, { min, max }) => {
|
||||
const numVal = +value;
|
||||
|
||||
return !(
|
||||
isNaN(numVal) ||
|
||||
(min != null && numVal < min) ||
|
||||
@@ -61,6 +62,7 @@ export const maxLength: InputValidator = {
|
||||
};
|
||||
|
||||
const systemNameMatcher = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
|
||||
|
||||
export const systemName: InputValidator = {
|
||||
message: () => _i18n._(t`A System Name must be lowercase DNS labels separated by dots. DNS labels are alphanumerics and dashes enclosed by alphanumerics.`),
|
||||
validate: value => !!value.match(systemNameMatcher),
|
||||
|
||||
@@ -30,6 +30,7 @@ export class SearchInputUrl extends React.Component<Props> {
|
||||
|
||||
onChange = (val: string, evt: React.ChangeEvent<any>) => {
|
||||
this.setValue(val);
|
||||
|
||||
if (this.props.onChange) {
|
||||
this.props.onChange(val, evt);
|
||||
}
|
||||
@@ -37,6 +38,7 @@ export class SearchInputUrl extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const { inputVal } = this;
|
||||
|
||||
return (
|
||||
<SearchInput
|
||||
value={inputVal}
|
||||
|
||||
@@ -42,6 +42,7 @@ export class SearchInput extends React.Component<Props> {
|
||||
@autobind()
|
||||
onGlobalKey(evt: KeyboardEvent) {
|
||||
const meta = evt.metaKey || evt.ctrlKey;
|
||||
|
||||
if (meta && evt.key === "f") {
|
||||
this.inputRef.current.focus();
|
||||
}
|
||||
@@ -54,6 +55,7 @@ export class SearchInput extends React.Component<Props> {
|
||||
}
|
||||
// clear on escape-key
|
||||
const escapeKey = evt.nativeEvent.code === "Escape";
|
||||
|
||||
if (escapeKey) {
|
||||
this.clear();
|
||||
evt.stopPropagation();
|
||||
@@ -72,9 +74,11 @@ export class SearchInput extends React.Component<Props> {
|
||||
render() {
|
||||
const { className, compact, onClear, showClearIcon, bindGlobalFocusHotkey, value, ...inputProps } = this.props;
|
||||
let rightIcon = <Icon small material="search"/>;
|
||||
|
||||
if (showClearIcon && value) {
|
||||
rightIcon = <Icon small material="close" onClick={this.clear}/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...inputProps}
|
||||
|
||||
Reference in new issue
Block a user