1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix build, added table + notification-store exports

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-11-09 14:50:18 +02:00
parent 8ba78d9a10
commit 581d6b7b35
10 changed files with 41 additions and 40 deletions

View File

@ -17,6 +17,7 @@ export * from "../../renderer/components/input/input"
export * from "../../renderer/components/icon" export * from "../../renderer/components/icon"
export * from "../../renderer/components/tooltip" export * from "../../renderer/components/tooltip"
export * from "../../renderer/components/tabs" export * from "../../renderer/components/tabs"
export * from "../../renderer/components/table"
export * from "../../renderer/components/badge" export * from "../../renderer/components/badge"
export * from "../../renderer/components/drawer" export * from "../../renderer/components/drawer"
export * from "../../renderer/components/dialog" export * from "../../renderer/components/dialog"
@ -29,8 +30,6 @@ export * from "../../renderer/components/stepper"
// kube helpers // kube helpers
export * from "../../renderer/components/kube-object" export * from "../../renderer/components/kube-object"
export * from "../../renderer/components/kube-object/kube-object-meta"
export * from "../../renderer/components/kube-object/kube-object-list-layout";
export * from "../../renderer/components/+events/kube-event-details" export * from "../../renderer/components/+events/kube-event-details"
// specific exports // specific exports

View File

@ -10,7 +10,7 @@ import { KubeObject } from "../../api/kube-object";
import { ICRDRouteParams } from "./crd.route"; import { ICRDRouteParams } from "./crd.route";
import { autorun, computed } from "mobx"; import { autorun, computed } from "mobx";
import { crdStore } from "./crd.store"; import { crdStore } from "./crd.store";
import { SortingCallback } from "../table"; import { TableSortCallback } from "../table";
import { apiManager } from "../../api/api-manager"; import { apiManager } from "../../api/api-manager";
interface Props extends RouteComponentProps<ICRDRouteParams> { interface Props extends RouteComponentProps<ICRDRouteParams> {
@ -50,7 +50,7 @@ export class CrdResources extends React.Component<Props> {
if (!crd) return null; if (!crd) return null;
const isNamespaced = crd.isNamespaced(); const isNamespaced = crd.isNamespaced();
const extraColumns = crd.getPrinterColumns(false); // Cols with priority bigger than 0 are shown in details const extraColumns = crd.getPrinterColumns(false); // Cols with priority bigger than 0 are shown in details
const sortingCallbacks: { [sortBy: string]: SortingCallback } = { const sortingCallbacks: { [sortBy: string]: TableSortCallback } = {
[sortBy.name]: (item: KubeObject) => item.getName(), [sortBy.name]: (item: KubeObject) => item.getName(),
[sortBy.namespace]: (item: KubeObject) => item.getNs(), [sortBy.namespace]: (item: KubeObject) => item.getNs(),
[sortBy.age]: (item: KubeObject) => item.metadata.creationTimestamp, [sortBy.age]: (item: KubeObject) => item.metadata.creationTimestamp,

View File

@ -6,7 +6,7 @@ import { computed, observable, reaction, toJS, when } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { Plural, Trans } from "@lingui/macro"; import { Plural, Trans } from "@lingui/macro";
import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog"; import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog";
import { SortingCallback, Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps } from "../table"; import { TableSortCallback, Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps } from "../table";
import { autobind, createStorage, cssNames, IClassName, isReactNode, noop, prevDefault, stopPropagation } from "../../utils"; import { autobind, createStorage, cssNames, IClassName, isReactNode, noop, prevDefault, stopPropagation } from "../../utils";
import { AddRemoveButtons, AddRemoveButtonsProps } from "../add-remove-buttons"; import { AddRemoveButtons, AddRemoveButtonsProps } from "../add-remove-buttons";
import { NoItems } from "../no-items"; import { NoItems } from "../no-items";
@ -52,7 +52,7 @@ export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
isSelectable?: boolean; // show checkbox in rows for selecting items isSelectable?: boolean; // show checkbox in rows for selecting items
isSearchable?: boolean; // apply search-filter & add search-input isSearchable?: boolean; // apply search-filter & add search-input
copyClassNameFromHeadCells?: boolean; copyClassNameFromHeadCells?: boolean;
sortingCallbacks?: { [sortBy: string]: SortingCallback }; sortingCallbacks?: { [sortBy: string]: TableSortCallback };
tableProps?: Partial<TableProps>; // low-level table configuration tableProps?: Partial<TableProps>; // low-level table configuration
renderTableHeader: TableCellProps[] | null; renderTableHeader: TableCellProps[] | null;
renderTableContents: (item: T) => (ReactNode | TableCellProps)[]; renderTableContents: (item: T) => (ReactNode | TableCellProps)[];

View File

@ -1,3 +1,4 @@
export * from "./kube-object-details" export * from "./kube-object-details"
export * from "./kube-object-list-layout" export * from "./kube-object-list-layout"
export * from "./kube-object-menu" export * from "./kube-object-menu"
export * from "./kube-object-meta"

View File

@ -11,7 +11,7 @@ import { Spinner } from "../spinner";
import { apiManager } from "../../api/api-manager"; import { apiManager } from "../../api/api-manager";
import { crdStore } from "../+custom-resources/crd.store"; import { crdStore } from "../+custom-resources/crd.store";
import { CrdResourceDetails } from "../+custom-resources"; import { CrdResourceDetails } from "../+custom-resources";
import { KubeObjectMenu } from "./kube-object-menu" import { KubeObjectMenu } from "./kube-object-menu"
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
export interface KubeObjectDetailsProps<T = KubeObject> { export interface KubeObjectDetailsProps<T = KubeObject> {

View File

@ -1 +1,2 @@
export * from './notifications' export * from './notifications'
export * from './notifications.store'

View File

@ -5,8 +5,8 @@ import isObject from "lodash/isObject"
import uniqueId from "lodash/uniqueId"; import uniqueId from "lodash/uniqueId";
import { JsonApiErrorParsed } from "../../api/json-api"; import { JsonApiErrorParsed } from "../../api/json-api";
export type IMessageId = string | number; export type NotificationId = string | number;
export type IMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed; export type NotificationMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed;
export enum NotificationStatus { export enum NotificationStatus {
OK = "ok", OK = "ok",
@ -14,20 +14,20 @@ export enum NotificationStatus {
INFO = "info", INFO = "info",
} }
export interface INotification { export interface Notification {
id?: IMessageId; id?: NotificationId;
message: IMessage; message: NotificationMessage;
status?: NotificationStatus; status?: NotificationStatus;
timeout?: number; // auto-hiding timeout in milliseconds, 0 = no hide timeout?: number; // auto-hiding timeout in milliseconds, 0 = no hide
} }
@autobind() @autobind()
export class NotificationsStore { 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); this.removeAutoHideTimer(notification);
const { id, timeout } = notification; const { id, timeout } = notification;
if (timeout) { if (timeout) {
@ -36,7 +36,7 @@ export class NotificationsStore {
} }
} }
removeAutoHideTimer(notification: INotification) { removeAutoHideTimer(notification: Notification) {
const { id } = notification; const { id } = notification;
if (this.autoHideTimers.has(id)) { if (this.autoHideTimers.has(id)) {
clearTimeout(this.autoHideTimers.get(id)); clearTimeout(this.autoHideTimers.get(id));
@ -45,7 +45,7 @@ export class NotificationsStore {
} }
@action @action
add(notification: INotification) { add(notification: Notification) {
if (!notification.id) { if (!notification.id) {
notification.id = uniqueId("notification_"); notification.id = uniqueId("notification_");
} }
@ -56,11 +56,11 @@ export class NotificationsStore {
} }
@action @action
remove(itemOrId: IMessageId | INotification) { remove(itemOrId: NotificationId | Notification) {
if (!isObject(itemOrId)) { if (!isObject(itemOrId)) {
itemOrId = this.notifications.find(item => item.id === itemOrId); itemOrId = this.notifications.find(item => item.id === itemOrId);
} }
return this.notifications.remove(itemOrId as INotification); return this.notifications.remove(itemOrId as Notification);
} }
} }

View File

@ -5,7 +5,7 @@ import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react" import { disposeOnUnmount, observer } from "mobx-react"
import { JsonApiErrorParsed } from "../../api/json-api"; import { JsonApiErrorParsed } from "../../api/json-api";
import { cssNames, prevDefault } from "../../utils"; 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 { Animate } from "../animate";
import { Icon } from "../icon" import { Icon } from "../icon"
@ -13,7 +13,7 @@ import { Icon } from "../icon"
export class Notifications extends React.Component { export class Notifications extends React.Component {
public elem: HTMLElement; public elem: HTMLElement;
static ok(message: IMessage) { static ok(message: NotificationMessage) {
notificationsStore.add({ notificationsStore.add({
message: message, message: message,
timeout: 2500, timeout: 2500,
@ -21,7 +21,7 @@ export class Notifications extends React.Component {
}) })
} }
static error(message: IMessage) { static error(message: NotificationMessage) {
notificationsStore.add({ notificationsStore.add({
message: message, message: message,
timeout: 10000, 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({ return notificationsStore.add({
status: NotificationStatus.INFO, status: NotificationStatus.INFO,
timeout: 0, timeout: 0,
@ -56,7 +56,7 @@ export class Notifications extends React.Component {
}) })
} }
getMessage(notification: INotification) { getMessage(notification: Notification) {
let { message } = notification; let { message } = notification;
if (message instanceof JsonApiErrorParsed) { if (message instanceof JsonApiErrorParsed) {
message = message.toString(); message = message.toString();

View File

@ -1,5 +1,5 @@
import "./table-cell.scss"; import "./table-cell.scss";
import type { SortBy, SortParams } from "./table"; import type { TableSortBy, TableSortParams } from "./table";
import React, { ReactNode } from "react"; import React, { ReactNode } from "react";
import { autobind, cssNames } from "../../utils"; import { autobind, cssNames } from "../../utils";
@ -13,9 +13,9 @@ export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
title?: ReactNode; title?: ReactNode;
checkbox?: boolean; // render cell with a checkbox checkbox?: boolean; // render cell with a checkbox
isChecked?: boolean; // mark checkbox as checked or not isChecked?: boolean; // mark checkbox as checked or not
sortBy?: SortBy; // column name, must be same as key in sortable object <Table sortable={}/> sortBy?: TableSortBy; // column name, must be same as key in sortable object <Table sortable={}/>
_sorting?: Partial<SortParams>; // <Table> sorting state, don't use this prop outside (!) _sorting?: Partial<TableSortParams>; // <Table> sorting state, don't use this prop outside (!)
_sort?(sortBy: SortBy): void; // <Table> sort function, don't use this prop outside (!) _sort?(sortBy: TableSortBy): void; // <Table> sort function, don't use this prop outside (!)
_nowrap?: boolean; // indicator, might come from parent <TableHead>, don't use this prop outside (!) _nowrap?: boolean; // indicator, might come from parent <TableHead>, don't use this prop outside (!)
} }

View File

@ -14,10 +14,10 @@ import { ItemObject } from "../../item.store";
// todo: refactor + decouple search from location // todo: refactor + decouple search from location
export type SortBy = string; export type TableSortBy = string;
export type OrderBy = "asc" | "desc" | string; export type TableOrderBy = "asc" | "desc" | string;
export type SortParams = { sortBy: SortBy; orderBy: OrderBy } export type TableSortParams = { sortBy: TableSortBy; orderBy: TableOrderBy }
export type SortingCallback<D = any> = (data: D) => string | number | (string | number)[]; export type TableSortCallback<D = any> = (data: D) => string | number | (string | number)[];
export interface TableProps extends React.DOMAttributes<HTMLDivElement> { export interface TableProps extends React.DOMAttributes<HTMLDivElement> {
items?: ItemObject[]; // Raw items data items?: ItemObject[]; // Raw items data
@ -29,11 +29,11 @@ export interface TableProps extends React.DOMAttributes<HTMLDivElement> {
sortable?: { sortable?: {
// Define sortable callbacks for every column in <TableHead><TableCell sortBy="someCol"><TableHead> // Define sortable callbacks for every column in <TableHead><TableCell sortBy="someCol"><TableHead>
// @sortItem argument in the callback is an object, provided in <TableRow sortItem={someColDataItem}/> // @sortItem argument in the callback is an object, provided in <TableRow sortItem={someColDataItem}/>
[sortBy: string]: SortingCallback; [sortBy: string]: TableSortCallback;
}; };
sortSyncWithUrl?: boolean; // sorting state is managed globally from url params sortSyncWithUrl?: boolean; // sorting state is managed globally from url params
sortByDefault?: Partial<SortParams>; // default sorting params sortByDefault?: Partial<TableSortParams>; // default sorting params
onSort?: (params: SortParams) => void; // callback on sort change, default: global sync with url onSort?: (params: TableSortParams) => void; // callback on sort change, default: global sync with url
noItems?: React.ReactNode; // Show no items state table list is empty noItems?: React.ReactNode; // Show no items state table list is empty
selectedItemId?: string; // Allows to scroll list to selected item selectedItemId?: string; // Allows to scroll list to selected item
virtual?: boolean; // Use virtual list component to render only visible rows virtual?: boolean; // Use virtual list component to render only visible rows
@ -55,7 +55,7 @@ export class Table extends React.Component<TableProps> {
@observable sortParamsLocal = this.props.sortByDefault; @observable sortParamsLocal = this.props.sortByDefault;
@computed get sortParams(): Partial<SortParams> { @computed get sortParams(): Partial<TableSortParams> {
if (this.props.sortSyncWithUrl) { if (this.props.sortSyncWithUrl) {
const sortBy = navigation.searchParams.get("sortBy") const sortBy = navigation.searchParams.get("sortBy")
const orderBy = navigation.searchParams.get("orderBy") const orderBy = navigation.searchParams.get("orderBy")
@ -105,7 +105,7 @@ export class Table extends React.Component<TableProps> {
} }
@autobind() @autobind()
protected onSort(params: SortParams) { protected onSort(params: TableSortParams) {
const { sortSyncWithUrl, onSort } = this.props; const { sortSyncWithUrl, onSort } = this.props;
if (sortSyncWithUrl) { if (sortSyncWithUrl) {
setQueryParams(params) setQueryParams(params)
@ -119,11 +119,11 @@ export class Table extends React.Component<TableProps> {
} }
@autobind() @autobind()
sort(colName: SortBy) { sort(colName: TableSortBy) {
const { sortBy, orderBy } = this.sortParams; const { sortBy, orderBy } = this.sortParams;
const sameColumn = sortBy == colName; const sameColumn = sortBy == colName;
const newSortBy: SortBy = colName; const newSortBy: TableSortBy = colName;
const newOrderBy: OrderBy = (!orderBy || !sameColumn || orderBy === "desc") ? "asc" : "desc"; const newOrderBy: TableOrderBy = (!orderBy || !sameColumn || orderBy === "desc") ? "asc" : "desc";
this.onSort({ this.onSort({
sortBy: String(newSortBy), sortBy: String(newSortBy),
orderBy: newOrderBy, orderBy: newOrderBy,