ywana-core8 0.0.98 → 0.0.102

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.98",
3
+ "version": "0.0.102",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -224,7 +224,11 @@ const TableEditor = (props) => {
224
224
  setPageContext(Object.assign({}, pageContext))
225
225
  }
226
226
 
227
- async function check(ids = []) {}
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
+ }
228
232
 
229
233
  function run(action, item) {
230
234
  action.action(item.id, pageContext, async () => {
@@ -259,7 +263,7 @@ const TableEditor = (props) => {
259
263
  id: field.id,
260
264
  label: field.label,
261
265
  type: field.type,
262
- onChange: field.editable ? change : null,
266
+ onChange: field.editable ? change : field.id === "checked" ? check : null, /* checked has it´s own handler */
263
267
  options
264
268
  }
265
269
  }),
@@ -283,7 +287,7 @@ const TableEditor = (props) => {
283
287
  <Header title={groupName} >
284
288
  <span className="size">{groupSize}</span>
285
289
  </Header>
286
- <DataTable {...table} onRowSelection={select} editable={editable} onCheckAll={check}/>
290
+ <DataTable {...table} onRowSelection={select} editable={editable} onCheckAll={check} />
287
291
  </Fragment>
288
292
  )
289
293
  })
@@ -295,6 +299,7 @@ const TableEditor = (props) => {
295
299
  .map(field => ({ label: field.label, value: field.id }))
296
300
  }
297
301
 
302
+ console.log('table page checked', pageContext.checked)
298
303
  return (
299
304
  <Fragment>
300
305
  <Header icon={icon} title={<Text>{title}</Text>}>
@@ -317,6 +322,7 @@ const TableContext = (url, field) => {
317
322
  return {
318
323
 
319
324
  all: [],
325
+ checked: new Set(),
320
326
  selected: null,
321
327
  filters: {},
322
328
 
@@ -337,6 +343,14 @@ const TableContext = (url, field) => {
337
343
  return
338
344
  },
339
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
+
340
354
  select(id) {
341
355
  const result = this.all.find(item => item.id === id);
342
356
  this.selected = result;
package/src/html/table.js CHANGED
@@ -1,10 +1,12 @@
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
  */
@@ -60,9 +62,9 @@ export const DataTable = (props) => {
60
62
  if (onSort) onSort(dragged, dropped)
61
63
  }
62
64
 
63
- function checkAll() {
65
+ function checkAll(id, value) {
64
66
  const ids = rows.map(row => row.id)
65
- if (onCheckAll) onCheckAll(ids)
67
+ if (onCheckAll) onCheckAll(ids, value)
66
68
  }
67
69
 
68
70
  const style = outlined ? "outlined" : ""
@@ -75,7 +77,7 @@ export const DataTable = (props) => {
75
77
  const sort = sortDir[id] ? sortDir[id] : null
76
78
  return (
77
79
  <th>
78
- {id === "checked" ? <CheckBox action={checkAll}/> : <Text>{label}</Text>}
80
+ {id === "checked" ? <CheckBox onChange={checkAll}/> : <Text>{label}</Text>}
79
81
  {sortable ? <Icon icon="arrow_up" size="small" clickable /> : null}
80
82
  </th>
81
83
  )
@@ -98,12 +100,12 @@ export const DataTable = (props) => {
98
100
  * DataTable Row
99
101
  */
100
102
  const DataTableRow = (props) => {
103
+
101
104
  const { row, columns = [], onSelect, editable } = props
105
+
102
106
  const [isInfoOpen, toggleInfo] = useState(false)
103
107
  const infoIcon = isInfoOpen ? 'expand_more' : 'expand_less'
104
108
 
105
- const isFunction = value => value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
106
-
107
109
  return (
108
110
  <Fragment>
109
111
  <tr onClick={ev => onSelect(row, ev)}>