cleanup Lens repo with tighter linting

Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
Sebastian Malton committed 2020-07-09 17:00:23 -04:00
1 parent e468105143
commit b1ff34879a
470 files changed
+8447 -7443

No files matched your search

+35 -22
View File
@@ -47,63 +47,75 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
isOpen: this.props.isOpen,
}
get elem() {
get elem(): HTMLElement {
// eslint-disable-next-line react/no-find-dom-node
return findDOMNode(this) as HTMLElement;
}
get isOpen() {
get isOpen(): boolean {
return this.state.isOpen;
}
componentDidMount() {
if (this.isOpen) this.onOpen();
componentDidMount(): void {
if (this.isOpen) {
this.onOpen();
}
}
componentDidUpdate(prevProps: DialogProps) {
componentDidUpdate(prevProps: DialogProps): void {
const { isOpen } = this.props;
if (isOpen !== prevProps.isOpen) {
this.toggle(isOpen);
}
}
componentWillUnmount() {
if (this.isOpen) this.onClose();
componentWillUnmount(): void {
if (this.isOpen) {
this.onClose();
}
}
toggle(isOpen: boolean) {
if (isOpen) this.open();
else this.close();
toggle(isOpen: boolean): void {
if (isOpen) {
this.open();
} else {
this.close();
}
}
open() {
open(): void {
requestAnimationFrame(this.onOpen); // wait for render(), bind close-event to this.elem
this.setState({ isOpen: true });
this.props.open();
}
close() {
close(): void {
this.onClose(); // must be first to get access to dialog's content from outside
this.setState({ isOpen: false });
this.props.close();
}
onOpen = () => {
onOpen = (): void => {
this.props.onOpen();
if (!this.props.pinned) {
if (this.elem) this.elem.addEventListener('click', this.onClickOutside);
if (this.elem) {
this.elem.addEventListener('click', this.onClickOutside);
}
window.addEventListener('keydown', this.onEscapeKey);
}
}
onClose = () => {
onClose = (): void => {
this.props.onClose();
if (!this.props.pinned) {
if (this.elem) this.elem.removeEventListener('click', this.onClickOutside);
if (this.elem) {
this.elem.removeEventListener('click', this.onClickOutside);
}
window.removeEventListener('keydown', this.onEscapeKey);
}
}
onEscapeKey = (evt: KeyboardEvent) => {
onEscapeKey = (evt: KeyboardEvent): void=> {
const escapeKey = evt.code === "Escape";
if (escapeKey) {
this.close();
@@ -111,7 +123,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
}
}
onClickOutside = (evt: MouseEvent) => {
onClickOutside = (evt: MouseEvent): void => {
const target = evt.target as HTMLElement;
if (!this.contentElem.contains(target)) {
this.close();
@@ -119,13 +131,15 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
}
}
render() {
render(): JSX.Element {
const { modal, animated, pinned } = this.props;
let { className } = this.props;
className = cssNames("Dialog flex center", className, { modal, pinned });
let dialog = (
<div className={className} onClick={stopPropagation}>
<div className="box" ref={e => this.contentElem = e}>
<div className="box" ref={(e): void => {
this.contentElem = e;
}}>
{this.props.children}
</div>
</div>
@@ -136,8 +150,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
{dialog}
</Animate>
);
}
else if (!this.isOpen) {
} else if (!this.isOpen) {
return null;
}
return createPortal(dialog, document.body);
+1 -1
View File
@@ -1 +1 @@
export * from './dialog'
export * from './dialog';
@@ -18,15 +18,15 @@ interface Props extends DialogProps {
export class LogsDialog extends React.Component<Props> {
public logsElem: HTMLElement;
copyToClipboard = () => {
copyToClipboard = (): void => {
if (copyToClipboard(this.logsElem)) {
Notifications.ok(_i18n._(t`Logs copied to clipboard.`))
Notifications.ok(_i18n._(t`Logs copied to clipboard.`));
}
}
render() {
render(): JSX.Element {
const { title, logs, ...dialogProps } = this.props;
const header = <h5>{title}</h5>
const header = <h5>{title}</h5>;
const customButtons = (
<div className="buttons flex gaps align-center justify-space-between">
<Button plain onClick={this.copyToClipboard}>
@@ -36,17 +36,19 @@ export class LogsDialog extends React.Component<Props> {
<Trans>Close</Trans>
</Button>
</div>
)
);
return (
<Dialog {...dialogProps} className="LogsDialog">
<Wizard header={header} done={dialogProps.close}>
<WizardStep scrollable={false} customButtons={customButtons}>
<code ref={e => this.logsElem = e}>
<code ref={(e): void => {
this.logsElem = e;
}}>
{logs || <Trans>There are no logs available.</Trans>}
</code>
</WizardStep>
</Wizard>
</Dialog>
)
);
}
}