Skip to content

Commit 78c5c94

Browse files
authored
Updates (#27)
Updating Ant.design table to latest version Cutting down unnecessary libraries Fix issue with child selection when onRowClick selection is enabled
1 parent 99be47c commit 78c5c94

File tree

10 files changed

+2398
-2296
lines changed

10 files changed

+2398
-2296
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Show a tree-like structure in Mendix.
4040
- Dynamic columns
4141
- Much more...
4242

43-
> This widget is only ~600Kb uncompressed, so in your cloud environment this would be about ~150Kb. This is light-weight for any project.
43+
> This widget is only ~500Kb uncompressed, so in your cloud environment this would be about ~140Kb. This is light-weight for any project.
4444
4545
Tested:
4646
- IE11

package-lock.json

Lines changed: 2337 additions & 2243 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mxtreetable",
33
"widgetName": "MxTreeTable",
4-
"version": "2.1.0",
4+
"version": "2.2.0",
55
"description": "TreeTable widget",
66
"copyright": "Mendix 2019",
77
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",
@@ -54,16 +54,14 @@
5454
},
5555
"dependencies": {
5656
"@jeltemx/mendix-react-widget-utils": "^0.7.0",
57-
"@thi.ng/strings": "^1.8.3",
58-
"antd": "^3.26.7",
57+
"antd": "^4.8.5",
5958
"array-to-tree": "^3.3.2",
6059
"big.js": "^5.2.2",
6160
"classnames": "^2.2.6",
6261
"debounce": "^1.2.0",
63-
"mobx": "^4.15.2",
64-
"mobx-react": "^6.2.2",
62+
"mobx": "^4.15.7",
63+
"mobx-react": "^6.3.1",
6564
"promise-queue": "^2.2.5",
66-
"react-icons": "^3.10.0",
67-
"store2": "^2.11.1"
65+
"store2": "^2.12.0"
6866
}
6967
}

src/MxTreeTable.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import { findDOMNode } from "react-dom";
44
import { observer } from "mobx-react";
55
import store from "store2";
66

7-
// import * as ls from "local-storage";
8-
// // @ts-ignore;
9-
// window.ls = ls;
10-
117
import {
128
IAction,
139
getObjectContextFromObjects,
@@ -42,7 +38,7 @@ import { TreeTable } from "./components/TreeTable";
4238
import { TreeRowObject } from "./store/objects/row";
4339
import { getReferencePart } from "./util/index";
4440
import { TableState } from "./store/index";
45-
import { ColumnProps } from "antd/es/table/interface";
41+
import { ColumnProps } from "antd/es/table";
4642

4743
export interface Action extends IAction {}
4844
export type ActionReturn = null | string | number | boolean | mendix.lib.MxObject | mendix.lib.MxObject[] | void;

src/components/Icons.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createElement } from "react";
2+
3+
export const ExpandIcon = () => {
4+
return (
5+
<svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 448 512">
6+
<path
7+
fill="currentColor"
8+
d="M212.686 315.314L120 408l32.922 31.029c15.12 15.12 4.412 40.971-16.97 40.971h-112C10.697 480 0 469.255 0 456V344c0-21.382 25.803-32.09 40.922-16.971L72 360l92.686-92.686c6.248-6.248 16.379-6.248 22.627 0l25.373 25.373c6.249 6.248 6.249 16.378 0 22.627zm22.628-118.628L328 104l-32.922-31.029C279.958 57.851 290.666 32 312.048 32h112C437.303 32 448 42.745 448 56v112c0 21.382-25.803 32.09-40.922 16.971L376 152l-92.686 92.686c-6.248 6.248-16.379 6.248-22.627 0l-25.373-25.373c-6.249-6.248-6.249-16.378 0-22.627z"
9+
/>
10+
</svg>
11+
);
12+
};
13+
14+
export const CompressIcon = () => {
15+
return (
16+
<svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 448 512">
17+
<path
18+
fill="currentColor"
19+
d="M4.686 427.314L104 328l-32.922-31.029C55.958 281.851 66.666 256 88.048 256h112C213.303 256 224 266.745 224 280v112c0 21.382-25.803 32.09-40.922 16.971L152 376l-99.314 99.314c-6.248 6.248-16.379 6.248-22.627 0L4.686 449.941c-6.248-6.248-6.248-16.379 0-22.627zM443.314 84.686L344 184l32.922 31.029c15.12 15.12 4.412 40.971-16.97 40.971h-112C234.697 256 224 245.255 224 232V120c0-21.382 25.803-32.09 40.922-16.971L296 136l99.314-99.314c6.248-6.248 16.379-6.248 22.627 0l25.373 25.373c6.248 6.248 6.248 16.379 0 22.627z"
20+
/>
21+
</svg>
22+
);
23+
};

src/components/TreeTable.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Component, ReactNode, createElement } from "react";
22
import { observer } from "mobx-react";
33
import classNames from "classnames";
4-
import { FaExpandAlt, FaCompressAlt } from "react-icons/fa";
5-
import Table, { TableRowSelection, ColumnProps } from "antd/es/table";
4+
5+
import { ExpandIcon, CompressIcon } from "./Icons";
6+
7+
import Table, { ColumnProps } from "antd/es/table";
8+
import { TableRowSelection } from "antd/es/table/interface";
69

710
// Importing seperate so we don't pollute the CSS too much
811
import "../ui/MxTreeTable.scss";
@@ -93,9 +96,16 @@ export class TreeTable extends Component<TreeTableProps> {
9396
}
9497
};
9598

96-
const onRow = (record: TableRecord): { [name: string]: () => void } => {
99+
const onRow = (record: TableRecord): { [name: string]: (event: MouseEvent) => void } => {
97100
return {
98-
onClick: () => {
101+
onClick: (event: MouseEvent) => {
102+
// When we click the checkbox, we also fire onClick. We check if it is the checkbox, if so, stop this
103+
if (event.target !== null) {
104+
const className = (event.target as HTMLElement).className;
105+
if (className.includes("ant-checkbox")) {
106+
return;
107+
}
108+
}
99109
clearDebounce();
100110
this.debounce = window.setTimeout(() => {
101111
this.onRowClick(record);
@@ -117,7 +127,14 @@ export class TreeTable extends Component<TreeTableProps> {
117127
}
118128
}, DEBOUNCE);
119129
},
120-
onDoubleClick: () => {
130+
onDoubleClick: (event: MouseEvent) => {
131+
// When we click the checkbox, we also fire onClick. We check if it is the checkbox, if so, stop this
132+
if (event.target !== null) {
133+
const className = (event.target as HTMLElement).className;
134+
if (className.includes("ant-checkbox")) {
135+
return;
136+
}
137+
}
121138
clearDebounce();
122139
this.debounce = window.setTimeout(() => {
123140
this.onRowDblClick(record); // double click row
@@ -228,13 +245,13 @@ export class TreeTable extends Component<TreeTableProps> {
228245
if (expanded) {
229246
return (
230247
<div role="button" className={className} onClick={this.collapseAll}>
231-
<FaCompressAlt />
248+
<CompressIcon />
232249
</div>
233250
);
234251
}
235252
return (
236253
<div role="button" className={className} onClick={this.expandAll}>
237-
<FaExpandAlt />
254+
<ExpandIcon />
238255
</div>
239256
);
240257
}

src/components/icons.js

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

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="MxTreeTable" version="2.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="MxTreeTable" version="2.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="MxTreeTable.xml"/>
66
</widgetFiles>

src/util/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { camel } from "@thi.ng/strings";
1+
const lower = (x: string) => x.toLowerCase();
2+
const upper = (x: string) => x.toUpperCase();
3+
const camel = (x: string, delim = "-") =>
4+
lower(x).replace(new RegExp(`\\${delim}+(\\w)`, "g"), (_, c: string) => upper(c));
25

36
export const createCamelcaseId = (str: string): string => {
47
const camelCased = camel(str);

webpack.config.prod.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const baseConfig = require("./node_modules/@mendix/pluggable-widgets-tools/confi
1010
const TerserPlugin = require("terser-webpack-plugin");
1111
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
1212

13-
// We're doing dirty hacking, because our camel case stuff doesn't transpile nicely to ES5. Need another solution, but this works in IE11
14-
baseConfig[0].module.rules[1].exclude = /node_modules\/(?!(@thi.ng)\/).*/
1513
baseConfig[0].module.rules[1].use.options.presets[0] = [
1614
'@babel/preset-env',
1715
{
@@ -22,7 +20,6 @@ baseConfig[0].module.rules[1].use.options.presets[0] = [
2220
"corejs": "2"
2321
}
2422
]
25-
baseConfig[1].module.rules[1].exclude = /node_modules\/(?!(@thi.ng)\/).*/
2623
baseConfig[1].module.rules[1].use.options.presets[0] = [
2724
'@babel/preset-env',
2825
{
@@ -68,16 +65,9 @@ const customConfig = {
6865
]
6966
},
7067
plugins: [
71-
// new BundleAnalyzerPlugin(),
7268
// We only include the moment locale for en-gb, as this is not used in a lot of places and we don't need all the locales
7369
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
74-
],
75-
// We add this to further slim down the package
76-
resolve: {
77-
alias: {
78-
'@ant-design/icons/lib/dist$': path.join(__dirname, 'src/components/icons.js')
79-
}
80-
}
70+
]
8171
};
8272

8373
if (args.length === 5 && args[4] === "--analyze") {
@@ -118,15 +108,9 @@ const previewConfig = {
118108
]
119109
},
120110
plugins: [
121-
// new BundleAnalyzerPlugin(),
122111
// We only include the moment locale for en-gb, as this is not used in a lot of places and we don't need all the locales
123112
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
124-
],
125-
resolve: {
126-
alias: {
127-
'@ant-design/icons/lib/dist$': path.join(__dirname, 'src/components/icons.js')
128-
}
129-
}
113+
]
130114
};
131115

132116
module.exports = [merge(baseConfig[0], customConfig), merge(baseConfig[1], previewConfig)];

0 commit comments

Comments
 (0)