ywana-core8 0.0.94 → 0.0.98

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.94",
3
+ "version": "0.0.98",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -16,7 +16,16 @@ const http = HTTPClient(window.API || process.env.REACT_APP_API, Session);
16
16
  export const TablePage = (props) => {
17
17
 
18
18
  const site = useContext(SiteContext)
19
- const { id = "table", icon, title, name = "table 1", schema, url, field, delay = 1000, actions, editable, canFilter=false, canAdd = true, canDelete = true, dev = false, autosave = true, groupBy, validator, scenario, formFilter, tableFilter, tableActions } = props
19
+ const { id = "table",
20
+ icon, title, name,
21
+ schema, url, field,
22
+ actions, dev = false, tableActions,
23
+ editable, canFilter = false, canQuery = false, canAdd = true, canDelete = true,
24
+ autosave = true, delay = 1000,
25
+ groupBy, validator, scenario,
26
+ formFilter, tableFilter,
27
+ } = props
28
+
20
29
  const [pageContext, setPageContext] = useContext(PageContext)
21
30
  const { selected } = pageContext
22
31
  const timer = useRef(null)
@@ -106,7 +115,10 @@ export const TablePage = (props) => {
106
115
  ) : null}
107
116
  {actions}
108
117
  </Header>
109
- {canFilter ? <menu className="table-page"><TableFilters schema={schema} /></menu> : null}
118
+ <menu className="table-page">
119
+ {canQuery ? <TableQueries schema={schema} /> : null}
120
+ {canFilter ? <TableFilters schema={schema} /> : null}
121
+ </menu>
110
122
  <main key={id} className="table-page">
111
123
  <TableEditor icon={icon} title={name} schema={schema} delay={delay} editable={editable} groupBy={groupBy} filter={tableFilter} actions={tableActions} canDelete={canDelete} />
112
124
  </main>
@@ -115,6 +127,20 @@ export const TablePage = (props) => {
115
127
  )
116
128
  }
117
129
 
130
+ /**
131
+ * Table Queries
132
+ */
133
+ const TableQueries = (props) => {
134
+ return (
135
+ <Fragment>
136
+ <Header className="table-queries" title={<Text>Queries</Text>} />
137
+ <main className="table-queries">
138
+ ...
139
+ </main>
140
+ </Fragment>
141
+ )
142
+ }
143
+
118
144
  /**
119
145
  * Table Filters
120
146
  */
@@ -132,8 +158,6 @@ const TableFilters = (props) => {
132
158
  }
133
159
 
134
160
  Object.values(filterSchema).forEach(field => field.section = null)
135
-
136
- Object.keys
137
161
  delete filterSchema.flows
138
162
  return filterSchema
139
163
  }, [schema])
@@ -145,16 +169,16 @@ const TableFilters = (props) => {
145
169
  }
146
170
 
147
171
  function clear() {
148
- setForm({})
172
+ change({})
149
173
  }
150
174
 
151
175
  const content = new Content(filterSchema, form)
152
176
  return (
153
177
  <Fragment>
154
- <Header title={<Text>Filtros</Text>} >
155
- <Button icon="filter_list_off" label="Limpiar" action={clear} />
178
+ <Header className="table-filters" title={<Text>Filters</Text>} >
179
+ <Button icon="filter_list_off" label="Clean" action={clear} />
156
180
  </Header>
157
- <main>
181
+ <main className="table-filters">
158
182
  <ContentEditor content={content} onChange={change} />
159
183
  </main>
160
184
  </Fragment>
@@ -200,6 +224,8 @@ const TableEditor = (props) => {
200
224
  setPageContext(Object.assign({}, pageContext))
201
225
  }
202
226
 
227
+ async function check(ids = []) {}
228
+
203
229
  function run(action, item) {
204
230
  action.action(item.id, pageContext, async () => {
205
231
  await pageContext.load()
@@ -257,7 +283,7 @@ const TableEditor = (props) => {
257
283
  <Header title={groupName} >
258
284
  <span className="size">{groupSize}</span>
259
285
  </Header>
260
- <DataTable {...table} onRowSelection={select} editable={editable} />
286
+ <DataTable {...table} onRowSelection={select} editable={editable} onCheckAll={check}/>
261
287
  </Fragment>
262
288
  )
263
289
  })
package/src/html/table.js CHANGED
@@ -10,7 +10,7 @@ import './table.css'
10
10
  */
11
11
  export const DataTable = (props) => {
12
12
 
13
- const { columns = [], rows = [], onRowSelection, onSort, editable, outlined } = props
13
+ const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined } = props
14
14
  const [sortDir, setSortDir] = useState({})
15
15
 
16
16
  function multiSort(array, sortObject = {}) {
@@ -60,6 +60,11 @@ export const DataTable = (props) => {
60
60
  if (onSort) onSort(dragged, dropped)
61
61
  }
62
62
 
63
+ function checkAll() {
64
+ const ids = rows.map(row => row.id)
65
+ if (onCheckAll) onCheckAll(ids)
66
+ }
67
+
63
68
  const style = outlined ? "outlined" : ""
64
69
  return (
65
70
  <div className={`datatable8 ${style}`}>
@@ -70,7 +75,7 @@ export const DataTable = (props) => {
70
75
  const sort = sortDir[id] ? sortDir[id] : null
71
76
  return (
72
77
  <th>
73
- <Text>{label}</Text>
78
+ {id === "checked" ? <CheckBox action={checkAll}/> : <Text>{label}</Text>}
74
79
  {sortable ? <Icon icon="arrow_up" size="small" clickable /> : null}
75
80
  </th>
76
81
  )
@@ -80,7 +85,7 @@ export const DataTable = (props) => {
80
85
  <tbody>
81
86
  {
82
87
  multiSort(rows, sortDir).map(row => (
83
- <DataTableRow key={row.id} row={row} columns={columns} onSelect={select} onDrop={sort} editable={editable}/>
88
+ <DataTableRow key={row.id} row={row} columns={columns} onSelect={select} onDrop={sort} editable={editable} />
84
89
  ))
85
90
  }
86
91
  </tbody>
@@ -102,7 +107,7 @@ const DataTableRow = (props) => {
102
107
  return (
103
108
  <Fragment>
104
109
  <tr onClick={ev => onSelect(row, ev)}>
105
- {columns.map(column => <DataTableCell row={row} column={column} cell={row[column.id]} editable={editable}/>)}
110
+ {columns.map(column => <DataTableCell row={row} column={column} cell={row[column.id]} editable={editable} />)}
106
111
  {row.info ? <Icon icon={infoIcon} clickable action={() => toggleInfo(!isInfoOpen)} /> : null}
107
112
  </tr>
108
113
  {row.info && isInfoOpen ? (
@@ -121,7 +126,9 @@ const DataTableCell = ({ row, column, cell, editable }) => {
121
126
 
122
127
  const render = (type) => {
123
128
  const { id, disabled = false, min, max, onChange, options } = column
124
- if (editable && onChange) {
129
+ if (id === "checked") {
130
+ return <CheckBox id={id} value={cell} onChange={(id, value) => onChange(row.id, id, value)} />
131
+ } else if (editable && onChange) {
125
132
  switch (type) {
126
133
  case "ICON": return <Icon icon={cell} />
127
134
  case "BOOLEAN": return <CheckBox id={id} value={cell} onChange={(id, value) => onChange(row.id, id, value)} disabled={disabled} />
@@ -153,7 +160,7 @@ const DataTableCell = ({ row, column, cell, editable }) => {
153
160
  * Boolean Cell Viewer
154
161
  */
155
162
  const BooleanCellViewer = ({ id, value = false }) => {
156
- const icon = value === true ? "check_box" : "check_box_outline_blank"
163
+ const icon = value === true ? "check_box" : "check_box_outline_blank"
157
164
  return <Icon icon={icon} />
158
165
  }
159
166
 
@@ -161,7 +168,7 @@ const BooleanCellViewer = ({ id, value = false }) => {
161
168
  * String Cell Viewer
162
169
  */
163
170
  const StringCellViewer = ({ id, value, options }) => {
164
- const option = options ? options.find( o => o.value === value) : null
171
+ const option = options ? options.find(o => o.value === value) : null
165
172
  const text = option ? option.label : value
166
173
  return (<div className="field-editor string-editor">{text}</div>)
167
174
  }