ywana-core8 0.0.100 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -224,8 +224,10 @@ const TableEditor = (props) => {
224
224
  setPageContext(Object.assign({}, pageContext))
225
225
  }
226
226
 
227
- async function check(ids = []) {
228
- console.log("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))
229
231
  }
230
232
 
231
233
  function run(action, item) {
@@ -261,7 +263,7 @@ const TableEditor = (props) => {
261
263
  id: field.id,
262
264
  label: field.label,
263
265
  type: field.type,
264
- onChange: field.editable ? change : null,
266
+ onChange: field.editable ? change : field.id === "checked" ? check : null, /* checked has it´s own handler */
265
267
  options
266
268
  }
267
269
  }),
@@ -297,6 +299,7 @@ const TableEditor = (props) => {
297
299
  .map(field => ({ label: field.label, value: field.id }))
298
300
  }
299
301
 
302
+ console.log('table page checked', pageContext.checked)
300
303
  return (
301
304
  <Fragment>
302
305
  <Header icon={icon} title={<Text>{title}</Text>}>
@@ -319,6 +322,7 @@ const TableContext = (url, field) => {
319
322
  return {
320
323
 
321
324
  all: [],
325
+ checked: new Set(),
322
326
  selected: null,
323
327
  filters: {},
324
328
 
@@ -339,6 +343,14 @@ const TableContext = (url, field) => {
339
343
  return
340
344
  },
341
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
+
342
354
  select(id) {
343
355
  const result = this.all.find(item => item.id === id);
344
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" : ""
@@ -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)}>