Skip to content

Commit eadd61a

Browse files
fix(AnalyticalTable): Header is now resizable (#76)
1 parent 9e6173e commit eadd61a

File tree

9 files changed

+466
-300
lines changed

9 files changed

+466
-300
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"webpack-cli": "^3.3.2"
121121
},
122122
"resolutions": {
123-
"@types/react": "16.8.19"
123+
"@types/react": "16.8.24"
124124
},
125125
"husky": {
126126
"hooks": {

packages/main/__karma_snapshots__/AnalyticalTable.md

Lines changed: 382 additions & 254 deletions
Large diffs are not rendered by default.

packages/main/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@ui5/webcomponents-react-base": "0.4.2-rc.11",
2626
"lodash.debounce": "^4.0.8",
2727
"react-scroll": "^1.7.11",
28-
"react-table": "6.8.6",
28+
"react-table": "6.10.0",
2929
"react-toastify": "^5.0.1"
3030
},
3131
"devDependencies": {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BusyIndicatorType } from '../../../lib/BusyIndicatorType';
2+
import { BusyIndicator } from '../../../lib/BusyIndicator';
3+
import React from 'react';
4+
5+
const LoadingComponent = (props) => {
6+
if (!props.loading) {
7+
return null;
8+
}
9+
let className = '-loading -active';
10+
return (
11+
<div className={className} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
12+
<BusyIndicator size={BusyIndicatorType.Medium} active style={{ backgroundColor: 'transparent' }} />
13+
</div>
14+
);
15+
};
16+
17+
LoadingComponent.displayName = 'LoadingComponent';
18+
19+
export { LoadingComponent };
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useMemo, useCallback } from 'react';
2+
import React from 'react';
3+
4+
const Resizer = ({ children, className, ...rest }) => {
5+
const classNames = useMemo(() => {
6+
let name = 'rt-resizer';
7+
if (className) {
8+
name += ` ${className}`;
9+
}
10+
return name;
11+
}, [className]);
12+
13+
const handleOnClick = useCallback((e) => {
14+
e.preventDefault();
15+
e.stopPropagation();
16+
}, []);
17+
18+
return (
19+
<div className={classNames} {...rest} onClick={handleOnClick}>
20+
{children}
21+
</div>
22+
);
23+
};
24+
25+
Resizer.displayName = 'Resizer';
26+
27+
export { Resizer };

packages/main/src/components/AnalyticalTable/columnHeader/ColumnHeaderModal.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, withStyles } from '@ui5/webcomponents-react-base';
2-
import React, { Component, FC, ReactNode, RefObject } from 'react';
2+
import React, { Component, FC, ReactNode, RefObject, CSSProperties } from 'react';
33
import { ClassProps } from '../../../interfaces/ClassProps';
44
import { JSSTheme } from '../../../interfaces/JSSTheme';
55
import { CustomListItem } from '../../../lib/CustomListItem';
@@ -40,6 +40,7 @@ export interface ColumnHeaderModalProperties {
4040
column: ColumnType;
4141
onFilterChange: (e?: any) => void;
4242
onGroupBy: (e?: any) => void;
43+
style: CSSProperties;
4344
}
4445

4546
interface ColumnHeaderModalInternalProperties extends ColumnHeaderModalProperties, ClassProps {}
@@ -85,11 +86,12 @@ export class ColumnHeaderModal extends Component<ColumnHeaderModalProperties> {
8586
};
8687

8788
render() {
88-
const { showGroup, grouping, showSort, showFilter, FilterComponent, onFilterChange, column, filter } = this
89+
const { showGroup, grouping, showSort, showFilter, FilterComponent, onFilterChange, column, filter, style } = this
8990
.props as ColumnHeaderModalInternalProperties;
91+
9092
return (
9193
<Popover
92-
openByStyle={{ flex: '100 0 auto', width: '100px' }}
94+
openByStyle={style}
9395
openBy={this.props.openBy}
9496
noArrow
9597
horizontalAlign={PopoverHorizontalAlign.Left}

packages/main/src/components/AnalyticalTable/columnHeader/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, fonts, StyleClassHelper, withStyles } from '@ui5/webcomponents-react-base';
2-
import React, { Component, ReactNode, ReactNodeArray } from 'react';
2+
import React, { Component, ReactNode, ReactNodeArray, CSSProperties } from 'react';
33
import { ClassProps } from '../../../interfaces/ClassProps';
44
import { JSSTheme } from '../../../interfaces/JSSTheme';
55
import { Icon } from '../../../lib/Icon';
@@ -16,7 +16,7 @@ export interface ColumnHeaderProps {
1616
}
1717

1818
interface ColumnHeaderPropsInternal extends ColumnHeaderProps, ClassProps {
19-
style?: object;
19+
style?: CSSProperties;
2020
toggleSort: () => any;
2121
sorted: any[];
2222
column: ColumnType;
@@ -155,7 +155,7 @@ export class ColumnHeader extends Component<ColumnHeaderProps, ColumnHeaderState
155155
};
156156

157157
render() {
158-
const { column, filtered, filterable, groupable, sortable } = this.props as ColumnHeaderPropsInternal;
158+
const { column, filtered, filterable, groupable, sortable, style } = this.props as ColumnHeaderPropsInternal;
159159

160160
if (!column) return null;
161161

@@ -177,6 +177,7 @@ export class ColumnHeader extends Component<ColumnHeaderProps, ColumnHeaderState
177177
filter={filter}
178178
onFilterChange={this.onFilterChange}
179179
onGroupBy={this.onGroupBy}
180+
style={style}
180181
/>
181182
) : (
182183
this.openBy

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,15 @@ import ReactTable from 'react-table';
44
import 'react-table/react-table.css';
55
import { ClassProps } from '../../interfaces/ClassProps';
66
import { CommonProps } from '../../interfaces/CommonProps';
7-
import { BusyIndicator } from '../../lib/BusyIndicator';
87
import { TextAlign } from '../../lib/TextAlign';
98
import { VerticalAlign } from '../../lib/VerticalAlign';
109
import styles from './AnayticalTable.jss';
1110
import { ColumnHeader } from './columnHeader';
11+
import { LoadingComponent } from './LoadingComponent';
1212
import { Pagination } from './pagination';
13+
import { Resizer } from './Resizer';
1314
import { TitleBar } from './titleBar';
1415
import { FilterEntry } from './types/FilterEntry';
15-
import { BusyIndicatorType } from '../../lib/BusyIndicatorType';
16-
17-
const CustomLoadingComponent = (props) => {
18-
let className = '-loading';
19-
if (props.loading) {
20-
className += ' -active';
21-
}
22-
return (
23-
<div className={className} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
24-
<BusyIndicator size={BusyIndicatorType.Medium} active style={{ backgroundColor: 'transparent' }} />
25-
</div>
26-
);
27-
};
2816

2917
export interface ColumnConfiguration {
3018
accessor?: string;
@@ -102,14 +90,18 @@ export class AnalyticalTable extends Component<TablePropsInternal, TableState> {
10290
pivot: []
10391
};
10492

93+
private static DEFAULT_FILTER_METHOD(filter, row) {
94+
return new RegExp(filter.value, 'gi').test(String(row[filter.id]));
95+
}
96+
10597
getTableProps = () => {
10698
const { classes } = this.props;
10799
return {
108100
className: classes.table
109101
};
110102
};
111103

112-
getTheadProps = (state, rowInfo, column, instance) => {
104+
getTheadProps = () => {
113105
const { classes } = this.props;
114106
return {
115107
className: classes.tHead
@@ -147,7 +139,7 @@ export class AnalyticalTable extends Component<TablePropsInternal, TableState> {
147139
};
148140
};
149141

150-
getTdProps = (state, rowInfo, column, instance) => {
142+
getTdProps = (state, rowInfo, column) => {
151143
const { classes, cellHeight } = this.props;
152144
const enhancedProps: {
153145
className: string;
@@ -204,19 +196,6 @@ export class AnalyticalTable extends Component<TablePropsInternal, TableState> {
204196
};
205197
};
206198

207-
private static DEFAULT_FILTER_METHOD(filter, row) {
208-
return new RegExp(filter.value, 'gi').test(String(row[filter.id]));
209-
}
210-
211-
private onFilteredChange = (event) => {
212-
const filtered = event.getParameter('currentFilters');
213-
this.setState({ filtered });
214-
};
215-
216-
private onGroupBy = (pivotBy) => {
217-
this.setState({ pivot: pivotBy, filtered: [] });
218-
};
219-
220199
render() {
221200
const {
222201
data,
@@ -265,11 +244,12 @@ export class AnalyticalTable extends Component<TablePropsInternal, TableState> {
265244
getTdProps={this.getTdProps}
266245
getTbodyProps={this.getTbodyProps}
267246
getPaginationProps={this.getPaginationProps}
268-
LoadingComponent={CustomLoadingComponent}
247+
LoadingComponent={LoadingComponent}
269248
PaginationComponent={Pagination}
270249
PreviousComponent={undefined}
271250
NextComponent={undefined}
272251
ThComponent={ColumnHeader}
252+
ResizerComponent={Resizer}
273253
multiSort={false}
274254
filterable={filterable}
275255
filtered={this.state.filtered}
@@ -283,4 +263,13 @@ export class AnalyticalTable extends Component<TablePropsInternal, TableState> {
283263
</div>
284264
);
285265
}
266+
267+
private onFilteredChange = (event) => {
268+
const filtered = event.getParameter('currentFilters');
269+
this.setState({ filtered });
270+
};
271+
272+
private onGroupBy = (pivotBy) => {
273+
this.setState({ pivot: pivotBy, filtered: [] });
274+
};
286275
}

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,10 +2762,10 @@
27622762
dependencies:
27632763
"@types/react" "*"
27642764

2765-
"@types/react@*", "@types/[email protected].19", "@types/react@^16.8.19":
2766-
version "16.8.19"
2767-
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.19.tgz#629154ef05e2e1985cdde94477deefd823ad9be3"
2768-
integrity sha512-QzEzjrd1zFzY9cDlbIiFvdr+YUmefuuRYrPxmkwG0UQv5XF35gFIi7a95m1bNVcFU0VimxSZ5QVGSiBmlggQXQ==
2765+
"@types/react@*", "@types/[email protected].24", "@types/react@^16.8.19":
2766+
version "16.8.24"
2767+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.24.tgz#8d1ea1fcbfa214220da3d3c04e506f1077b0deac"
2768+
integrity sha512-VpFHUoD37YNY2+lr/+c7qL/tZsIU/bKuskUF3tmGUArbxIcQdb5j3zvo4cuuzu2A6UaVmVn7sJ4PgWYNFEBGzg==
27692769
dependencies:
27702770
"@types/prop-types" "*"
27712771
csstype "^2.2.0"
@@ -13258,10 +13258,10 @@ react-syntax-highlighter@^8.0.1:
1325813258
prismjs "^1.8.4"
1325913259
refractor "^2.4.1"
1326013260

13261-
react-table@6.8.6:
13262-
version "6.8.6"
13263-
resolved "https://registry.yarnpkg.com/react-table/-/react-table-6.8.6.tgz#a0ad8b4839319052d5befc012603fb161e52ede3"
13264-
integrity sha1-oK2LSDkxkFLVvvwBJgP7Fh5S7eM=
13261+
react-table@6.10.0:
13262+
version "6.10.0"
13263+
resolved "https://registry.yarnpkg.com/react-table/-/react-table-6.10.0.tgz#20444b19d8ca3c1a08e7544e5c3a93e4ba56690e"
13264+
integrity sha512-s/mQLI1+mNvlae45MfAZyZ04YIT3jUzWJqx34s0tfwpDdgJkpeK6vyzwMUkKFCpGODBxpjBOekYZzcEmk+2FiQ==
1326513265
dependencies:
1326613266
classnames "^2.2.5"
1326713267

0 commit comments

Comments
 (0)