Skip to content

Commit e9bc297

Browse files
refactor(AnalyticalTable): update react-table and replace grid with absolute layout (#238)
BREAKING CHANGE: Update `react-table` to `7.0.0-rc.5`
1 parent 22729e2 commit e9bc297

27 files changed

+688
-680
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"identity-obj-proxy": "^3.0.0",
6565
"jest": "^24.9.0",
6666
"jest-canvas-mock": "^2.2.0",
67-
"jest-environment-jsdom-fifteen": "^1.0.0",
67+
"jest-environment-jsdom-fifteen": "^1.0.2",
6868
"jest-enzyme": "^7.1.2",
6969
"jss-snapshot-serializer": "^1.0.0",
7070
"lerna": "^3.19.0",

packages/main/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"lodash.debounce": "^4.0.8",
3030
"react-content-loader": "^4.3.2",
3131
"react-jss": "10.0.0",
32-
"react-table": "7.0.0-beta.20",
32+
"react-table": "7.0.0-rc.5",
3333
"react-toastify": "^5.4.1",
3434
"react-window": "^1.8.5"
3535
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ describe('AnalyticalTable', () => {
226226
const wrapper = mountThemedComponent(<AnalyticalTable data={data} title={'Test'} columns={columns} />);
227227

228228
// get first column of the table and simulate dragging of it
229-
let componentDrag = wrapper.find({ role: 'columnheader' }).at(0);
229+
let componentDrag = wrapper.find('div[role="columnheader"] div[draggable]').at(0);
230230
let inst = componentDrag.instance();
231231
// @ts-ignore
232-
let dragColumnId = inst.id;
232+
let dragColumnId = inst.dataset.columnId;
233233

234234
// @ts-ignore
235235
expect(inst.draggable).toBeDefined();
@@ -244,7 +244,7 @@ describe('AnalyticalTable', () => {
244244
dataTransfer.getData = () => {
245245
return dragColumnId;
246246
};
247-
let componentDrop = wrapper.find({ role: 'columnheader' }).at(1);
247+
let componentDrop = wrapper.find('div[role="columnheader"] div[draggable]').at(1);
248248
// @ts-ignore
249249
componentDrop.simulate('drop', { dataTransfer: dataTransfer });
250250

packages/main/src/components/AnalyticalTable/AnayticalTable.jss.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const styles = ({ parameters }: JSSTheme) => ({
1515
tableHeaderRow: {
1616
boxShadow: 'none !important',
1717
height: '2.75rem',
18-
display: 'grid',
1918
zIndex: 1,
2019
position: 'relative'
2120
},
@@ -58,7 +57,6 @@ const styles = ({ parameters }: JSSTheme) => ({
5857
}
5958
},
6059
tr: {
61-
display: 'grid',
6260
zIndex: 0,
6361
backgroundColor: parameters.sapUiListBackground,
6462
color: parameters.sapUiListTextColor

packages/main/src/components/AnalyticalTable/ColumnHeader/Resizer.tsx

Lines changed: 0 additions & 65 deletions
This file was deleted.

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

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
import '@ui5/webcomponents-icons/dist/icons/filter';
2+
import '@ui5/webcomponents-icons/dist/icons/group-2';
3+
import '@ui5/webcomponents-icons/dist/icons/sort-ascending';
4+
import '@ui5/webcomponents-icons/dist/icons/sort-descending';
15
import { Event } from '@ui5/webcomponents-react-base/lib/Event';
26
import { StyleClassHelper } from '@ui5/webcomponents-react-base/lib/StyleClassHelper';
37
import { Icon } from '@ui5/webcomponents-react/lib/Icon';
48
import React, { CSSProperties, DragEventHandler, FC, ReactNode, ReactNodeArray, useMemo } from 'react';
59
import { createUseStyles, useTheme } from 'react-jss';
610
import { JSSTheme } from '../../../interfaces/JSSTheme';
7-
import { Resizer } from './Resizer';
811
import { ColumnType } from '../types/ColumnType';
912
import { ColumnHeaderModal } from './ColumnHeaderModal';
10-
import '@ui5/webcomponents-icons/dist/icons/filter';
11-
import '@ui5/webcomponents-icons/dist/icons/group-2';
12-
import '@ui5/webcomponents-icons/dist/icons/sort-descending';
13-
import '@ui5/webcomponents-icons/dist/icons/sort-ascending';
1413

1514
export interface ColumnHeaderProps {
1615
id: string;
@@ -64,6 +63,16 @@ const styles = ({ parameters }: JSSTheme) => ({
6463
'& :last-child': {
6564
marginLeft: '0.25rem'
6665
}
66+
},
67+
resizer: {
68+
display: 'inline-block',
69+
width: '16px',
70+
height: '100%',
71+
position: 'absolute',
72+
right: 0,
73+
top: 0,
74+
transform: 'translateX(50%)',
75+
zIndex: 1
6776
}
6877
});
6978

@@ -106,7 +115,16 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props) => {
106115
const groupingIcon = column.isGrouped ? <Icon name="group-2" /> : null;
107116

108117
return (
109-
<div className={classNames.valueOf()}>
118+
<div
119+
className={classNames.valueOf()}
120+
draggable={isDraggable}
121+
onDragEnter={onDragEnter}
122+
onDragOver={onDragOver}
123+
onDragStart={onDragStart}
124+
onDrop={onDrop}
125+
onDragEnd={onDragEnd}
126+
data-column-id={id}
127+
>
110128
<span
111129
title={typeof children === 'string' ? children : null}
112130
style={{ textOverflow: 'ellipsis', overflowX: 'hidden', whiteSpace: 'nowrap' }}
@@ -120,13 +138,26 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props) => {
120138
</div>
121139
</div>
122140
);
123-
}, [classes, column.filterValue, column.isSorted, column.isGrouped, column.isSortedDesc, children]);
141+
}, [
142+
classes,
143+
column.filterValue,
144+
column.isSorted,
145+
column.isGrouped,
146+
column.isSortedDesc,
147+
children,
148+
isDraggable,
149+
onDragEnter,
150+
onDragOver,
151+
onDragStart,
152+
onDrop,
153+
onDragEnd,
154+
id
155+
]);
124156

125157
const isResizable = !isLastColumn && column.canResize;
126158
const theme = useTheme() as JSSTheme;
127159
const innerStyle: CSSProperties = useMemo(() => {
128-
const modifiedStyles = {
129-
...style,
160+
const modifiedStyles: CSSProperties = {
130161
width: '100%',
131162
fontWeight: 'normal',
132163
cursor: 'pointer',
@@ -137,26 +168,15 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props) => {
137168
modifiedStyles.maxWidth = `calc(100% - 16px)`;
138169
}
139170
if (dragOver) {
140-
modifiedStyles.borderLeft = '3px solid ' + theme.parameters.sapSelectedColor;
171+
modifiedStyles.borderLeft = `3px solid ${theme.parameters.sapSelectedColor}`;
141172
}
142-
return modifiedStyles as CSSProperties;
143-
}, [style, isResizable]);
173+
return modifiedStyles;
174+
}, [isResizable, dragOver]);
144175

145176
if (!column) return null;
146177

147178
return (
148-
<div
149-
id={id}
150-
className={className}
151-
style={style}
152-
role="columnheader"
153-
draggable={isDraggable}
154-
onDragEnter={onDragEnter}
155-
onDragOver={onDragOver}
156-
onDragStart={onDragStart}
157-
onDrop={onDrop}
158-
onDragEnd={onDragEnd}
159-
>
179+
<div id={id} className={className} style={style} role="columnheader">
160180
{groupable || sortable || filterable ? (
161181
<ColumnHeaderModal
162182
openBy={openBy}
@@ -171,7 +191,7 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props) => {
171191
) : (
172192
<div style={{ ...innerStyle, display: 'inline-block', cursor: 'auto' }}>{openBy}</div>
173193
)}
174-
{isResizable && <Resizer {...props} />}
194+
<div {...column.getResizerProps()} className={classes.resizer} />
175195
</div>
176196
);
177197
};

0 commit comments

Comments
 (0)