mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Export more UI components via extensions-api (#1285)
* export more UI components via extensions-api, touches #1277 #1284 Signed-off-by: Roman <ixrock@gmail.com> * fix build, added table + notification-store exports Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
85f0ef8c2e
commit
f69f8c793f
31 files changed
+138
-120
No files matched your search
@@ -1 +1,2 @@
|
||||
export * from './notifications'
|
||||
export * from './notifications.store'
|
||||
@@ -5,8 +5,8 @@ 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 type NotificationId = string | number;
|
||||
export type NotificationMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed;
|
||||
|
||||
export enum NotificationStatus {
|
||||
OK = "ok",
|
||||
@@ -14,20 +14,20 @@ export enum NotificationStatus {
|
||||
INFO = "info",
|
||||
}
|
||||
|
||||
export interface INotification {
|
||||
id?: IMessageId;
|
||||
message: IMessage;
|
||||
export interface Notification {
|
||||
id?: NotificationId;
|
||||
message: NotificationMessage;
|
||||
status?: NotificationStatus;
|
||||
timeout?: number; // auto-hiding timeout in milliseconds, 0 = no hide
|
||||
}
|
||||
|
||||
@autobind()
|
||||
export class NotificationsStore {
|
||||
public notifications = observable<INotification>([], { deep: false });
|
||||
public notifications = observable<Notification>([], { deep: false });
|
||||
|
||||
protected autoHideTimers = new Map<IMessageId, number>();
|
||||
protected autoHideTimers = new Map<NotificationId, number>();
|
||||
|
||||
addAutoHideTimer(notification: INotification) {
|
||||
addAutoHideTimer(notification: Notification) {
|
||||
this.removeAutoHideTimer(notification);
|
||||
const { id, timeout } = notification;
|
||||
if (timeout) {
|
||||
@@ -36,7 +36,7 @@ export class NotificationsStore {
|
||||
}
|
||||
}
|
||||
|
||||
removeAutoHideTimer(notification: INotification) {
|
||||
removeAutoHideTimer(notification: Notification) {
|
||||
const { id } = notification;
|
||||
if (this.autoHideTimers.has(id)) {
|
||||
clearTimeout(this.autoHideTimers.get(id));
|
||||
@@ -45,7 +45,7 @@ export class NotificationsStore {
|
||||
}
|
||||
|
||||
@action
|
||||
add(notification: INotification) {
|
||||
add(notification: Notification) {
|
||||
if (!notification.id) {
|
||||
notification.id = uniqueId("notification_");
|
||||
}
|
||||
@@ -56,11 +56,11 @@ export class NotificationsStore {
|
||||
}
|
||||
|
||||
@action
|
||||
remove(itemOrId: IMessageId | INotification) {
|
||||
remove(itemOrId: NotificationId | Notification) {
|
||||
if (!isObject(itemOrId)) {
|
||||
itemOrId = this.notifications.find(item => item.id === itemOrId);
|
||||
}
|
||||
return this.notifications.remove(itemOrId as INotification);
|
||||
return this.notifications.remove(itemOrId as Notification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react"
|
||||
import { JsonApiErrorParsed } from "../../api/json-api";
|
||||
import { cssNames, prevDefault } from "../../utils";
|
||||
import { IMessage, INotification, notificationsStore, NotificationStatus } from "./notifications.store";
|
||||
import { NotificationMessage, Notification, notificationsStore, NotificationStatus } from "./notifications.store";
|
||||
import { Animate } from "../animate";
|
||||
import { Icon } from "../icon"
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Icon } from "../icon"
|
||||
export class Notifications extends React.Component {
|
||||
public elem: HTMLElement;
|
||||
|
||||
static ok(message: IMessage) {
|
||||
static ok(message: NotificationMessage) {
|
||||
notificationsStore.add({
|
||||
message: message,
|
||||
timeout: 2500,
|
||||
@@ -21,7 +21,7 @@ export class Notifications extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
static error(message: IMessage) {
|
||||
static error(message: NotificationMessage) {
|
||||
notificationsStore.add({
|
||||
message: message,
|
||||
timeout: 10000,
|
||||
@@ -29,7 +29,7 @@ export class Notifications extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
static info(message: IMessage, customOpts: Partial<INotification> = {}) {
|
||||
static info(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
||||
return notificationsStore.add({
|
||||
status: NotificationStatus.INFO,
|
||||
timeout: 0,
|
||||
@@ -56,7 +56,7 @@ export class Notifications extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
getMessage(notification: INotification) {
|
||||
getMessage(notification: Notification) {
|
||||
let { message } = notification;
|
||||
if (message instanceof JsonApiErrorParsed) {
|
||||
message = message.toString();
|
||||
|
||||
Reference in new issue
Block a user