ywana-core8 0.0.97 → 0.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +28 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +28 -3
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +28 -3
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/TablePage.js +18 -2
- package/src/html/table.js +12 -5
package/package.json
CHANGED
package/src/domain/TablePage.js
CHANGED
@@ -224,6 +224,12 @@ const TableEditor = (props) => {
|
|
224
224
|
setPageContext(Object.assign({}, pageContext))
|
225
225
|
}
|
226
226
|
|
227
|
+
async function check(id, value) {
|
228
|
+
const ids = Array.isArray(id) ? id : [ id ]
|
229
|
+
pageContext.check(ids, value)
|
230
|
+
setPageContext(Object.assign({}, pageContext))
|
231
|
+
}
|
232
|
+
|
227
233
|
function run(action, item) {
|
228
234
|
action.action(item.id, pageContext, async () => {
|
229
235
|
await pageContext.load()
|
@@ -257,7 +263,7 @@ const TableEditor = (props) => {
|
|
257
263
|
id: field.id,
|
258
264
|
label: field.label,
|
259
265
|
type: field.type,
|
260
|
-
onChange: field.editable ? change : null,
|
266
|
+
onChange: field.editable ? change : field.id === "checked" ? check : null, /* checked has it´s own handler */
|
261
267
|
options
|
262
268
|
}
|
263
269
|
}),
|
@@ -281,7 +287,7 @@ const TableEditor = (props) => {
|
|
281
287
|
<Header title={groupName} >
|
282
288
|
<span className="size">{groupSize}</span>
|
283
289
|
</Header>
|
284
|
-
<DataTable {...table} onRowSelection={select} editable={editable} />
|
290
|
+
<DataTable {...table} onRowSelection={select} editable={editable} onCheckAll={check}/>
|
285
291
|
</Fragment>
|
286
292
|
)
|
287
293
|
})
|
@@ -293,6 +299,7 @@ const TableEditor = (props) => {
|
|
293
299
|
.map(field => ({ label: field.label, value: field.id }))
|
294
300
|
}
|
295
301
|
|
302
|
+
console.log('table page checked', pageContext.checked)
|
296
303
|
return (
|
297
304
|
<Fragment>
|
298
305
|
<Header icon={icon} title={<Text>{title}</Text>}>
|
@@ -315,6 +322,7 @@ const TableContext = (url, field) => {
|
|
315
322
|
return {
|
316
323
|
|
317
324
|
all: [],
|
325
|
+
checked: new Set(),
|
318
326
|
selected: null,
|
319
327
|
filters: {},
|
320
328
|
|
@@ -335,6 +343,14 @@ const TableContext = (url, field) => {
|
|
335
343
|
return
|
336
344
|
},
|
337
345
|
|
346
|
+
check(ids, isChecked = true) {
|
347
|
+
if (isChecked) {
|
348
|
+
ids.forEach(id => this.checked.add(id))
|
349
|
+
} else {
|
350
|
+
ids.forEach(id => this.checked.delete(id)
|
351
|
+
}
|
352
|
+
},
|
353
|
+
|
338
354
|
select(id) {
|
339
355
|
const result = this.all.find(item => item.id === id);
|
340
356
|
this.selected = result;
|
package/src/html/table.js
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
import React, { Fragment, useState } from 'react'
|
2
|
+
import { DropDown, TextField } from './textfield'
|
2
3
|
import { CheckBox } from './checkbox'
|
3
4
|
import { Icon } from './icon'
|
4
5
|
import { Text } from './text'
|
5
|
-
import { DropDown, TextField } from './textfield'
|
6
6
|
import './table.css'
|
7
7
|
|
8
|
+
const isFunction = value => value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
|
9
|
+
|
8
10
|
/**
|
9
11
|
* DataTable
|
10
12
|
*/
|
11
13
|
export const DataTable = (props) => {
|
12
14
|
|
13
|
-
const { columns = [], rows = [], onRowSelection, onSort, editable, outlined } = props
|
15
|
+
const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined } = props
|
14
16
|
const [sortDir, setSortDir] = useState({})
|
15
17
|
|
16
18
|
function multiSort(array, sortObject = {}) {
|
@@ -60,6 +62,11 @@ export const DataTable = (props) => {
|
|
60
62
|
if (onSort) onSort(dragged, dropped)
|
61
63
|
}
|
62
64
|
|
65
|
+
function checkAll(id, value) {
|
66
|
+
const ids = rows.map(row => row.id)
|
67
|
+
if (onCheckAll) onCheckAll(ids, value)
|
68
|
+
}
|
69
|
+
|
63
70
|
const style = outlined ? "outlined" : ""
|
64
71
|
return (
|
65
72
|
<div className={`datatable8 ${style}`}>
|
@@ -70,7 +77,7 @@ export const DataTable = (props) => {
|
|
70
77
|
const sort = sortDir[id] ? sortDir[id] : null
|
71
78
|
return (
|
72
79
|
<th>
|
73
|
-
<Text>{label}</Text>
|
80
|
+
{id === "checked" ? <CheckBox onChange={checkAll}/> : <Text>{label}</Text>}
|
74
81
|
{sortable ? <Icon icon="arrow_up" size="small" clickable /> : null}
|
75
82
|
</th>
|
76
83
|
)
|
@@ -93,12 +100,12 @@ export const DataTable = (props) => {
|
|
93
100
|
* DataTable Row
|
94
101
|
*/
|
95
102
|
const DataTableRow = (props) => {
|
103
|
+
|
96
104
|
const { row, columns = [], onSelect, editable } = props
|
105
|
+
|
97
106
|
const [isInfoOpen, toggleInfo] = useState(false)
|
98
107
|
const infoIcon = isInfoOpen ? 'expand_more' : 'expand_less'
|
99
108
|
|
100
|
-
const isFunction = value => value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
|
101
|
-
|
102
109
|
return (
|
103
110
|
<Fragment>
|
104
111
|
<tr onClick={ev => onSelect(row, ev)}>
|