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

@@ -1 +1 @@
export * from './notifications'
export * from './notifications';
@@ -1,14 +1,14 @@
import * as React from "react";
import { action, observable } from "mobx"
import { action, observable } from "mobx";
import { autobind } from "../../utils";
import isObject from "lodash/isObject"
import isObject from "lodash/isObject";
import uniqueId from "lodash/uniqueId";
import { JsonApiErrorParsed } from "../../api/json-api";
export type IMessageId = string | number;
export type IMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed;
export interface INotification {
export interface Notification {
id?: IMessageId;
message: IMessage;
status?: "ok" | "error" | "info";
@@ -17,11 +17,11 @@ export interface INotification {
@autobind()
export class NotificationsStore {
public notifications = observable<INotification>([], { deep: false });
public notifications = observable<Notification>([], { deep: false });
protected autoHideTimers = new Map<IMessageId, number>();
addAutoHideTimer(notification: INotification) {
addAutoHideTimer(notification: Notification): void {
this.removeAutoHideTimer(notification);
const { id, timeout } = notification;
if (timeout) {
@@ -30,7 +30,7 @@ export class NotificationsStore {
}
}
removeAutoHideTimer(notification: INotification) {
removeAutoHideTimer(notification: Notification): void {
const { id } = notification;
if (this.autoHideTimers.has(id)) {
clearTimeout(this.autoHideTimers.get(id));
@@ -39,22 +39,25 @@ export class NotificationsStore {
}
@action
add(notification: INotification) {
add(notification: Notification): void {
if (!notification.id) {
notification.id = uniqueId("notification_");
}
const index = this.notifications.findIndex(item => item.id === notification.id);
if (index > -1) this.notifications.splice(index, 1, notification)
else this.notifications.push(notification);
if (index > -1) {
this.notifications.splice(index, 1, notification);
} else {
this.notifications.push(notification);
}
this.addAutoHideTimer(notification);
}
@action
remove(itemOrId: IMessageId | INotification) {
remove(itemOrId: IMessageId | Notification): boolean {
if (!isObject(itemOrId)) {
itemOrId = this.notifications.find(item => item.id === itemOrId);
}
return this.notifications.remove(itemOrId as INotification);
return this.notifications.remove(itemOrId);
}
}
@@ -1,27 +1,27 @@
import './notifications.scss';
import React from 'react'
import React from 'react';
import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"
import { disposeOnUnmount, observer } from "mobx-react";
import { JsonApiErrorParsed } from "../../api/json-api";
import { cssNames, prevDefault } from "../../utils";
import { IMessage, INotification, notificationsStore } from "./notifications.store";
import { IMessage, Notification, notificationsStore } from "./notifications.store";
import { Animate } from "../animate";
import { Icon } from "../icon"
import { Icon } from "../icon";
@observer
export class Notifications extends React.Component {
public elem: HTMLElement;
static ok(message: IMessage) {
static ok(message: IMessage): void {
notificationsStore.add({
message: message,
timeout: 2500,
status: "ok"
})
});
}
static error(message: IMessage) {
static error(message: IMessage): void {
notificationsStore.add({
message: message,
timeout: 10000,
@@ -29,7 +29,7 @@ export class Notifications extends React.Component {
});
}
static info(message: IMessage) {
static info(message: IMessage): void {
return notificationsStore.add({
message: message,
timeout: 0,
@@ -37,7 +37,7 @@ export class Notifications extends React.Component {
});
}
componentDidMount() {
componentDidMount(): void {
disposeOnUnmount(this, [
reaction(() => notificationsStore.notifications.length, () => {
this.scrollToLastNotification();
@@ -45,17 +45,17 @@ export class Notifications extends React.Component {
]);
}
scrollToLastNotification() {
scrollToLastNotification(): void {
if (!this.elem) {
return;
}
this.elem.scrollTo({
top: this.elem.scrollHeight,
behavior: "smooth"
})
});
}
getMessage(notification: INotification) {
getMessage(notification: Notification): React.ReactNode[] {
let { message } = notification;
if (message instanceof JsonApiErrorParsed) {
message = message.toString();
@@ -63,10 +63,12 @@ export class Notifications extends React.Component {
return React.Children.toArray(message);
}
render() {
render(): JSX.Element {
const { notifications, remove, addAutoHideTimer, removeAutoHideTimer } = notificationsStore;
return (
<div className="Notifications flex column align-flex-end" ref={e => this.elem = e}>
<div className="Notifications flex column align-flex-end" ref={(e): void => {
this.elem = e;
}}>
{notifications.map(notification => {
const { id, status } = notification;
const msgText = this.getMessage(notification);
@@ -74,8 +76,8 @@ export class Notifications extends React.Component {
<Animate key={id}>
<div
className={cssNames("notification flex align-center", status)}
onMouseLeave={() => addAutoHideTimer(notification)}
onMouseEnter={() => removeAutoHideTimer(notification)}>
onMouseLeave={(): void => addAutoHideTimer(notification)}
onMouseEnter={(): void => removeAutoHideTimer(notification)}>
<div className="box center">
<Icon material="info_outline"/>
</div>
@@ -88,9 +90,9 @@ export class Notifications extends React.Component {
</div>
</div>
</Animate>
)
);
})}
</div>
)
);
}
}