ywana-core8 0.0.508 → 0.0.511

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.508",
3
+ "version": "0.0.511",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/html/table.js CHANGED
@@ -13,7 +13,7 @@ const isFunction = value => value && (Object.prototype.toString.call(value) ===
13
13
  */
14
14
  export const DataTable = (props) => {
15
15
 
16
- const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className} = props
16
+ const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className } = props
17
17
  const [sortDir, setSortDir] = useState({})
18
18
  const [allChecked, setAllChecked] = useState(false)
19
19
 
@@ -83,12 +83,12 @@ export const DataTable = (props) => {
83
83
  <tr>
84
84
  {columns.map(({ id, label, type, item, sortable }) => {
85
85
  const sort = sortDir[id] ? sortDir[id] : null
86
- const [rowspan, colspan] = type === TYPES.ENTITY ? [1, Object.values(item).filter(v=>v.column===true).length] : [2, 1]
86
+ const [rowspan, colspan] = type === TYPES.ENTITY ? [1, Object.values(item).filter(v => v.column === true).length] : [2, 1]
87
87
  return (
88
88
  <th key={id} rowSpan={rowspan} colSpan={colspan}>
89
89
  <div>
90
90
  {id === "checked" ? <CheckBox onChange={checkAll} value={allChecked} /> : <Text key={`th_${id}`}>{label}</Text>}
91
- {sortable ? <Icon icon="expand_less" size="small" clickable action={() => changeSort(id)}/> : null}
91
+ {sortable ? <Icon icon="expand_less" size="small" clickable action={() => changeSort(id)} /> : null}
92
92
  </div>
93
93
  </th>
94
94
  )
@@ -127,7 +127,7 @@ export const DataTable = (props) => {
127
127
  const DataTableRow = (props) => {
128
128
 
129
129
  const { row, columns = [], onSelect, editable, expanded = false } = props
130
- const { className} = row
130
+ const { className } = row
131
131
  const [isInfoOpen, toggleInfo] = useState(expanded)
132
132
  const infoIcon = isInfoOpen ? 'expand_more' : 'expand_less'
133
133
 
@@ -180,7 +180,7 @@ const DataTableCell = ({ row, column, cell, editable }) => {
180
180
  }
181
181
  }
182
182
 
183
- return column.type === TYPES.ENTITY ? <EntityCellViewer id={column.id} item={column.item} value={cell} /> : (
183
+ return column.type === TYPES.ENTITY ? <EntityCellViewer id={column.id} item={column.item} value={cell} format={column.format} /> : (
184
184
  <td key={column.id} className={column.id}>{render(column.type)}</td>
185
185
  )
186
186
  }
@@ -190,10 +190,35 @@ const DataTableCell = ({ row, column, cell, editable }) => {
190
190
  * @param {*} param0
191
191
  * @returns
192
192
  */
193
- const EntityCellViewer = ({ id, item, value }) => {
193
+ const EntityCellViewer = ({ id, item, value, format = "" }) => {
194
194
  const fields = Object.values(item).filter(field => field.column === true)
195
- return fields.map( field => {
196
- return (<td key={field.id} className={`entity-cell ${field.id}`} >{value[field.id]}</td>)
195
+
196
+ return fields.map(field => {
197
+
198
+ let text = value[field.id]
199
+
200
+ if (format) {
201
+ switch (format) {
202
+ case FORMATS.COLOR:
203
+ text = <input type="color" value={text} disabled />
204
+ case FORMATS.URL:
205
+ text = <a href={text} target="download" download >{text}</a>
206
+ break;
207
+ case FORMATS.IMG:
208
+ text = <img src={text} />
209
+ break;
210
+ case FORMATS.DATE:
211
+ let fecha = new Date(text)
212
+ fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
213
+ text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
214
+ break;
215
+ case FORMATS.TIME:
216
+ text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
217
+ break;
218
+ }
219
+ }
220
+
221
+ return (<td key={field.id} className={`entity-cell ${field.id}`} >{text}</td>)
197
222
  })
198
223
  }
199
224
 
@@ -213,27 +238,27 @@ const StringCellViewer = ({ id, value, format, options }) => {
213
238
  function buildOptions() {
214
239
  const opts = typeof options === 'function' ? options() : options
215
240
  return opts
216
- }
217
-
241
+ }
242
+
218
243
  const option = options ? buildOptions().find(o => o.value === value) : null
219
244
  let text = option ? option.label : value
220
245
  const locale = window.navigator.userLanguage || window.navigator.language;
221
246
  switch (format) {
222
247
  case FORMATS.COLOR:
223
- text = <input type="color" value={text} disabled/>
248
+ text = <input type="color" value={text} disabled />
224
249
  case FORMATS.URL:
225
250
  text = <a href={text} target="download" download >{text}</a>
226
251
  break;
227
- case FORMATS.IMG:
252
+ case FORMATS.IMG:
228
253
  text = <img src={text} />
229
254
  break;
230
- case FORMATS.DATE:
255
+ case FORMATS.DATE:
231
256
  let fecha = new Date(text)
232
257
  fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
233
- text = fecha.toLocaleString( locale, { day: 'numeric', month: 'numeric', year: 'numeric'});
258
+ text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
234
259
  break;
235
- case FORMATS.TIME:
236
- text = new Date(text).toLocaleString( locale, { year: 'hour', month: 'minute', day: 'second' });
260
+ case FORMATS.TIME:
261
+ text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
237
262
  break;
238
263
  }
239
264
  return (<div className="field-editor string-viewer">{text}</div>)