ywana-core8 0.0.506 → 0.0.509

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.506",
3
+ "version": "0.0.509",
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={format} /> : (
184
184
  <td key={column.id} className={column.id}>{render(column.type)}</td>
185
185
  )
186
186
  }
@@ -190,10 +190,33 @@ 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
+ switch (format) {
201
+ case FORMATS.COLOR:
202
+ text = <input type="color" value={text} disabled />
203
+ case FORMATS.URL:
204
+ text = <a href={text} target="download" download >{text}</a>
205
+ break;
206
+ case FORMATS.IMG:
207
+ text = <img src={text} />
208
+ break;
209
+ case FORMATS.DATE:
210
+ let fecha = new Date(text)
211
+ fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
212
+ text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
213
+ break;
214
+ case FORMATS.TIME:
215
+ text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
216
+ break;
217
+ }
218
+
219
+ return (<td key={field.id} className={`entity-cell ${field.id}`} >{text}</td>)
197
220
  })
198
221
  }
199
222
 
@@ -213,27 +236,27 @@ const StringCellViewer = ({ id, value, format, options }) => {
213
236
  function buildOptions() {
214
237
  const opts = typeof options === 'function' ? options() : options
215
238
  return opts
216
- }
217
-
239
+ }
240
+
218
241
  const option = options ? buildOptions().find(o => o.value === value) : null
219
242
  let text = option ? option.label : value
220
243
  const locale = window.navigator.userLanguage || window.navigator.language;
221
244
  switch (format) {
222
245
  case FORMATS.COLOR:
223
- text = <input type="color" value={text} disabled/>
246
+ text = <input type="color" value={text} disabled />
224
247
  case FORMATS.URL:
225
248
  text = <a href={text} target="download" download >{text}</a>
226
249
  break;
227
- case FORMATS.IMG:
250
+ case FORMATS.IMG:
228
251
  text = <img src={text} />
229
252
  break;
230
- case FORMATS.DATE:
253
+ case FORMATS.DATE:
231
254
  let fecha = new Date(text)
232
255
  fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
233
- text = fecha.toLocaleString( locale, { year: 'numeric', month: 'numeric', day: 'numeric'});
256
+ text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
234
257
  break;
235
- case FORMATS.TIME:
236
- text = new Date(text).toLocaleString( locale, { year: 'hour', month: 'minute', day: 'second' });
258
+ case FORMATS.TIME:
259
+ text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
237
260
  break;
238
261
  }
239
262
  return (<div className="field-editor string-viewer">{text}</div>)
@@ -14,7 +14,7 @@ export const TableTest = (prop) => {
14
14
  { id: 6, checked: false, name: "John Smith" , color: "#CCFFFF" },
15
15
  { id: 7, checked: false, name: "Ann Martin" , color: "#CCFFFF" },
16
16
  { id: 8, checked: false, name: "Martin Freeman", color: "#CCFFFF" },
17
- { id: 9, checked: false, name: "Ann Martin" , color: "#CCFFFF" },
17
+ { id: 9, checked: false, name: "Ann Martin" , color: "#CCFFFF", date: new Date().toString() },
18
18
  ]
19
19
  )
20
20
 
@@ -44,6 +44,7 @@ export const TableTest = (prop) => {
44
44
  { id: "name", label: "Name", type: "String", sortable: true },
45
45
  { id: "thumb", label: "Thumb", type: "String", format: FORMATS.IMG },
46
46
  { id: "color", label: "Color", type: "String", format: FORMATS.COLOR },
47
+ { id: "date", label: "Date", type: "String", format: FORMATS.DATE },
47
48
  ],
48
49
  rows
49
50
  }
@@ -129,7 +129,7 @@ export const Planner = ({ title, events = [], lanes = [], navigation = true, onS
129
129
  })}
130
130
  </div>
131
131
 
132
- {lanes.map((lane) => <PlannerRow lane={lane} events={events} period={period} onSelectCell={selectCell} onChange={onChange}/>)}
132
+ {lanes.map((lane) => <PlannerRow key={lane.id} lane={lane} events={events} period={period} onSelectCell={selectCell} onChange={onChange}/>)}
133
133
 
134
134
  </div>
135
135
  </main>
@@ -161,7 +161,7 @@ const PlannerRow = (props) => {
161
161
  return eventDate.getTime() === slotDate.getTime();
162
162
  })
163
163
  return (
164
- <PlannerCell lane={lane} date={date} events={cellEvents} onSelect={onSelectCell} onDrop={change}/>
164
+ <PlannerCell key={`${lane.id}-${slotDate.toString()}`} lane={lane} date={date} events={cellEvents} onSelect={onSelectCell} onDrop={change}/>
165
165
  );
166
166
  })}
167
167
  </div>
@@ -208,10 +208,10 @@ const PlannerCell = ({ lane, events, date, disabled = false, onAdd, onDelete, on
208
208
  const weekend = isWekend ? "weekend" : "";
209
209
  const dragOverStyle = dragOver ? "drag-over" : ""
210
210
  return (
211
- <div key={`${lane}-${date}`} className={`cell ${weekend} ${dragOverStyle}`} onDragOver={onDragOver} onDragLeave={onDragLeave} onDrop={drop} onClick={select}>
211
+ <div className={`cell ${weekend} ${dragOverStyle}`} onDragOver={onDragOver} onDragLeave={onDragLeave} onDrop={drop} onClick={select}>
212
212
  {events.map(event => {
213
213
  const { Renderer = EventCard } = event
214
- return <Renderer event={event} />
214
+ return <Renderer key={event.id} event={event} />
215
215
  })}
216
216
  </div>
217
217
  );