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
@@ -26,6 +26,7 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
if (this.props.onClick) {
|
||||
this.props.onClick(evt);
|
||||
}
|
||||
|
||||
if (this.isSortable) {
|
||||
this.props._sort(this.props.sortBy);
|
||||
}
|
||||
@@ -33,14 +34,17 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
|
||||
get isSortable() {
|
||||
const { _sorting, sortBy } = this.props;
|
||||
|
||||
return _sorting && sortBy !== undefined;
|
||||
}
|
||||
|
||||
renderSortIcon() {
|
||||
const { sortBy, _sorting } = this.props;
|
||||
|
||||
if (!this.isSortable) return;
|
||||
const sortActive = _sorting.sortBy === sortBy;
|
||||
const sortIconName = (!sortActive || _sorting.orderBy === "desc") ? "arrow_drop_down" : "arrow_drop_up";
|
||||
|
||||
return (
|
||||
<Icon
|
||||
className={cssNames("sortIcon", { enabled: sortActive })}
|
||||
@@ -52,6 +56,7 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
renderCheckbox() {
|
||||
const { checkbox, isChecked } = this.props;
|
||||
const showCheckbox = isChecked !== undefined;
|
||||
|
||||
if (checkbox && showCheckbox) {
|
||||
return <Checkbox value={isChecked} />;
|
||||
}
|
||||
@@ -65,6 +70,7 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
sorting: this.isSortable,
|
||||
});
|
||||
const content = displayBooleans(displayBoolean, title || children);
|
||||
|
||||
return (
|
||||
<div {...cellProps} id={className} className={classNames} onClick={this.onClick}>
|
||||
{this.renderCheckbox()}
|
||||
|
||||
@@ -23,6 +23,7 @@ export class TableHead extends React.Component<TableHeadProps> {
|
||||
sticky, nowrap,
|
||||
topLine: showTopLine,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={classNames} {...headProps}>
|
||||
{children}
|
||||
|
||||
@@ -20,6 +20,7 @@ export class TableRow extends React.Component<TableRowProps> {
|
||||
render() {
|
||||
const { className, nowrap, selected, disabled, children, sortItem, searchItem, ...rowProps } = this.props;
|
||||
const classNames = cssNames("TableRow", className, { selected, nowrap, disabled });
|
||||
|
||||
return (
|
||||
<div className={classNames} {...rowProps}>
|
||||
{children}
|
||||
|
||||
@@ -59,8 +59,10 @@ export class Table extends React.Component<TableProps> {
|
||||
if (this.props.sortSyncWithUrl) {
|
||||
const sortBy = navigation.searchParams.get("sortBy");
|
||||
const orderBy = navigation.searchParams.get("orderBy");
|
||||
|
||||
return { sortBy, orderBy };
|
||||
}
|
||||
|
||||
return this.sortParamsLocal || {};
|
||||
}
|
||||
|
||||
@@ -68,9 +70,11 @@ export class Table extends React.Component<TableProps> {
|
||||
const { sortable, children } = this.props;
|
||||
const content = React.Children.toArray(children) as (TableRowElem | TableHeadElem)[];
|
||||
const headElem: React.ReactElement<TableHeadProps> = content.find(elem => elem.type === TableHead);
|
||||
|
||||
if (headElem) {
|
||||
if (sortable) {
|
||||
const columns = React.Children.toArray(headElem.props.children) as TableCellElem[];
|
||||
|
||||
return React.cloneElement(headElem, {
|
||||
children: columns.map(elem => {
|
||||
if (elem.props.checkbox) {
|
||||
@@ -81,6 +85,7 @@ export class Table extends React.Component<TableProps> {
|
||||
// usable if part of TableCell's content is hidden when there is not enough space
|
||||
typeof elem.props.children === "string" ? elem.props.children : undefined
|
||||
);
|
||||
|
||||
return React.cloneElement(elem, {
|
||||
title,
|
||||
_sort: this.sort,
|
||||
@@ -90,6 +95,7 @@ export class Table extends React.Component<TableProps> {
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return headElem;
|
||||
}
|
||||
}
|
||||
@@ -97,6 +103,7 @@ export class Table extends React.Component<TableProps> {
|
||||
getSorted(items: any[]) {
|
||||
const { sortParams } = this;
|
||||
const sortingCallback = this.props.sortable[sortParams.sortBy] || noop;
|
||||
|
||||
return orderBy(
|
||||
items,
|
||||
sortingCallback,
|
||||
@@ -107,12 +114,14 @@ export class Table extends React.Component<TableProps> {
|
||||
@autobind()
|
||||
protected onSort(params: TableSortParams) {
|
||||
const { sortSyncWithUrl, onSort } = this.props;
|
||||
|
||||
if (sortSyncWithUrl) {
|
||||
setQueryParams(params);
|
||||
}
|
||||
else {
|
||||
this.sortParamsLocal = params;
|
||||
}
|
||||
|
||||
if (onSort) {
|
||||
onSort(params);
|
||||
}
|
||||
@@ -124,6 +133,7 @@ export class Table extends React.Component<TableProps> {
|
||||
const sameColumn = sortBy == colName;
|
||||
const newSortBy: TableSortBy = colName;
|
||||
const newOrderBy: TableOrderBy = (!orderBy || !sameColumn || orderBy === "desc") ? "asc" : "desc";
|
||||
|
||||
this.onSort({
|
||||
sortBy: String(newSortBy),
|
||||
orderBy: newOrderBy,
|
||||
@@ -135,26 +145,32 @@ export class Table extends React.Component<TableProps> {
|
||||
const content = React.Children.toArray(children) as (TableRowElem | TableHeadElem)[];
|
||||
let rows: React.ReactElement<TableRowProps>[] = content.filter(elem => elem.type === TableRow);
|
||||
let sortedItems = rows.length ? rows.map(row => row.props.sortItem) : [...items];
|
||||
|
||||
if (sortable) {
|
||||
sortedItems = this.getSorted(sortedItems);
|
||||
|
||||
if (rows.length) {
|
||||
rows = sortedItems.map(item => rows.find(row => {
|
||||
return item == row.props.sortItem;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (!rows.length && !items.length && noItems) {
|
||||
return noItems;
|
||||
}
|
||||
|
||||
if (virtual) {
|
||||
const lineHeight = parseFloat(rowLineHeight);
|
||||
const padding = parseFloat(rowPadding);
|
||||
let rowHeights: number[] = Array(items.length).fill(lineHeight + padding * 2);
|
||||
|
||||
if (customRowHeights) {
|
||||
rowHeights = sortedItems.map(item => {
|
||||
return customRowHeights(item, lineHeight, padding * 2);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<VirtualList
|
||||
items={sortedItems}
|
||||
@@ -165,15 +181,18 @@ export class Table extends React.Component<TableProps> {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
render() {
|
||||
const { selectable, scrollable, sortable, autoSize, virtual } = this.props;
|
||||
let { className } = this.props;
|
||||
|
||||
className = cssNames("Table flex column", className, {
|
||||
selectable, scrollable, sortable, autoSize, virtual,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{this.renderHead()}
|
||||
|
||||
Reference in new issue
Block a user