ywana-core8 0.0.560 → 0.0.563

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.560",
3
+ "version": "0.0.563",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -40,6 +40,11 @@ export const CollectionPage = (props) => {
40
40
  setPageContext(Object.assign({}, pageContext))
41
41
  }
42
42
 
43
+ async function reloadSelection() {
44
+ await pageContext.reloadSelection()
45
+ setPageContext(Object.assign({}, pageContext))
46
+ }
47
+
43
48
  function add() {
44
49
  const onOK = async (form) => {
45
50
  await pageContext.create(form);
@@ -71,7 +76,7 @@ export const CollectionPage = (props) => {
71
76
  {levels ? <CollectionTree icon={icon} levels={levels} onSelect={onSelect} sorter={sorter} searchBy={searchBy} /> : <CollectionList groupBy={groupBy} onSelect={onSelect} searchBy={searchBy} />}
72
77
  </menu>
73
78
  <main key={id} className={`collection-page ${className}`}>
74
- <CollectionEditor icon={icon} schema={schema} layout={editor} autosave={autosave} delay={delay} canDelete={canDelete} canEdit={canEdit} />
79
+ <CollectionEditor icon={icon} schema={schema} layout={editor} autosave={autosave} delay={delay} canDelete={canDelete} canEdit={canEdit} onReload={reloadSelection} />
75
80
  {children ? <article>{children}</article> : null}
76
81
  </main>
77
82
  </Fragment>
@@ -133,7 +138,7 @@ export const CollectionFilters = (props) => {
133
138
  */
134
139
  const CollectionList = (props) => {
135
140
 
136
- const { groupBy, onSelect, searchBy=[] } = props
141
+ const { groupBy, onSelect, searchBy = [] } = props
137
142
  const [pageContext, setPageContext] = useContext(PageContext)
138
143
  const { all = [] } = pageContext
139
144
  const [filter, setFilter] = useState()
@@ -192,7 +197,7 @@ const CollectionList = (props) => {
192
197
  */
193
198
  export const CollectionTree = (props) => {
194
199
 
195
- const { icon = "description", levels, onSelect, sorter, searchBy=[] } = props
200
+ const { icon = "description", levels, onSelect, sorter, searchBy = [] } = props
196
201
  const [pageContext, setPageContext] = useContext(PageContext)
197
202
  const { all = [] } = pageContext
198
203
  const [filter, setFilter] = useState()
@@ -283,7 +288,7 @@ export const CollectionTree = (props) => {
283
288
  const CollectionEditor = (props) => {
284
289
  const [pageContext, setPageContext] = useContext(PageContext)
285
290
  const { selected } = pageContext
286
- const { icon, schema, layout, autosave = false, delay = 1000, canDelete, canEdit } = props
291
+ const { icon, schema, layout, autosave = false, delay = 1000, canDelete, canEdit, onReload } = props
287
292
  const timer = useRef(null)
288
293
  const [form, setForm] = useState(selected)
289
294
 
@@ -328,9 +333,9 @@ const CollectionEditor = (props) => {
328
333
  function renderEditor() {
329
334
  const content = new Content(schema, form)
330
335
  switch (layout) {
331
- case 'TABBED': return <TabbedContentEditor {...props} content={content} onChange={change} />
332
- case 'TREEDED': return <TreededContentEditor {...props} content={content} onChange={change} />
333
- default: return <ContentEditor {...props} content={content} onChange={change} />
336
+ case 'TABBED': return <TabbedContentEditor {...props} content={content} onChange={change} onReload={onReload} />
337
+ case 'TREEDED': return <TreededContentEditor {...props} content={content} onChange={change} onReload={onReload} />
338
+ default: return <ContentEditor {...props} content={content} onChange={change} onReload={onReload} />
334
339
  }
335
340
  }
336
341
 
@@ -340,7 +345,7 @@ const CollectionEditor = (props) => {
340
345
  <Icon icon="close" clickable action={clear} />
341
346
  <MenuIcon align="alignRight">
342
347
  <Menu>
343
- { canDelete ? <MenuItem label="Eliminar" onSelect={remove} /> : null }
348
+ {canDelete ? <MenuItem label="Eliminar" onSelect={remove} /> : null}
344
349
  </Menu>
345
350
  </MenuIcon>
346
351
  {autosave === true ? null : <Button icon="save" label="Guardar Cambios" raised disabled={!canSave()} action={save} />}
@@ -382,6 +387,11 @@ export const CollectionContext = (url, field, host, page, fetching) => {
382
387
  }
383
388
  },
384
389
 
390
+ async reloadSelection() {
391
+ const result = await this.fetch(selected.id)
392
+ this.selected = result
393
+ },
394
+
385
395
  async fetch(id) {
386
396
  try {
387
397
  const result = await API.find(id)
@@ -8,13 +8,17 @@ import './ContentEditor.css';
8
8
  /**
9
9
  * Content Editor
10
10
  */
11
- export const ContentEditor = ({ content, filter, outlined = true, className, onChange }) => {
11
+ export const ContentEditor = ({ content, filter, outlined = true, className, onChange, onReload }) => {
12
12
 
13
13
  function change(id, value) {
14
14
  const nextValue = Object.assign({}, content.value(), { [id]: value })
15
15
  if (onChange) onChange(nextValue)
16
16
  }
17
17
 
18
+ function reload() {
19
+ if (onReload) onReload()
20
+ }
21
+
18
22
  const sections = content.sections()
19
23
 
20
24
  return (
@@ -30,7 +34,7 @@ export const ContentEditor = ({ content, filter, outlined = true, className, onC
30
34
  <section key={title}>
31
35
  {title && title.length > 0 ? <header>{title}</header> : null}
32
36
  <main>
33
- {filtered.map((field) => <FieldEditor key={field.id} field={field} onChange={change} outlined={outlined} content={content} />)}
37
+ {filtered.map((field) => <FieldEditor key={field.id} field={field} onChange={change} onReload={reload} outlined={outlined} content={content} />)}
34
38
  </main>
35
39
  </section>
36
40
  ) : null
@@ -43,7 +47,7 @@ export const ContentEditor = ({ content, filter, outlined = true, className, onC
43
47
  /**
44
48
  * Tabbed Content Editor
45
49
  */
46
- export const TabbedContentEditor = ({ content, filter, grouped = false, onChange }) => {
50
+ export const TabbedContentEditor = ({ content, filter, grouped = false, onChange, onReload }) => {
47
51
 
48
52
  const [tab, setTab] = useState(0)
49
53
 
@@ -91,7 +95,7 @@ export const TabbedContentEditor = ({ content, filter, grouped = false, onChange
91
95
  group.fields
92
96
  .filter(field => field.id !== 'id')
93
97
  .filter(field => filter ? filter(field) : true)
94
- .map((field) => <FieldEditor key={field.id} field={field} onChange={change} content={content} />)
98
+ .map((field) => <FieldEditor key={field.id} field={field} onChange={change} content={content} onReload={onReload} />)
95
99
  }
96
100
  </Fragment>
97
101
  )
@@ -100,7 +104,7 @@ export const TabbedContentEditor = ({ content, filter, grouped = false, onChange
100
104
  fields
101
105
  .filter(field => field.id !== 'id')
102
106
  .filter(field => filter ? filter(field) : true)
103
- .map((field) => <FieldEditor key={field.id} field={field} onChange={change} content={content} />)
107
+ .map((field) => <FieldEditor key={field.id} field={field} onChange={change} content={content} onReload={onReload}/>)
104
108
  }
105
109
  </section>
106
110
  )
@@ -152,7 +156,7 @@ export const TreededContentEditor = ({ content, filter, onChange }) => {
152
156
  </Tree>
153
157
  </menu>
154
158
  <div>
155
- {selected ? <TabbedContentEditor content={selected.item} onChange={change} /> : "select"}
159
+ {selected ? <TabbedContentEditor content={selected.item} onChange={change} onReload={reload}/> : "select"}
156
160
  </div>
157
161
  </div>
158
162
  )
@@ -161,13 +165,17 @@ export const TreededContentEditor = ({ content, filter, onChange }) => {
161
165
  /**
162
166
  * FieldEditor
163
167
  */
164
- export const FieldEditor = ({ field, onChange, content, outlined = false }) => {
168
+ export const FieldEditor = ({ field, onChange, content, outlined = false, onReload }) => {
165
169
  const { id, type, item, label, editable, options, hidden = false } = field
166
170
 
167
171
  function change(id, value) {
168
172
  if (onChange) onChange(id, value)
169
173
  }
170
174
 
175
+ function reload() {
176
+ onReload()
177
+ }
178
+
171
179
  function renderField() {
172
180
  const value1 = field.value || field.value === "" ? field.value : field.default
173
181
  const isHidden = CHECK['isFunction'](hidden) ? hidden(field, value1) : hidden
@@ -186,7 +194,7 @@ export const FieldEditor = ({ field, onChange, content, outlined = false }) => {
186
194
  case TYPES.ARRAY:
187
195
  return item === TYPES.STRING ?
188
196
  options ? <MultiSelectionEditor content={content} field={field} value={value1} onChange={change} /> : <ListEditor field={field} value={value1} onChange={change} />
189
- : <CollectionEditor field={field} value={value1} onChange={change} />
197
+ : <CollectionEditor field={field} value={value1} onChange={change} onReload={reload}/>
190
198
  default:
191
199
  return <div>{label}</div>
192
200
  }
@@ -372,7 +380,7 @@ export const MultiSelectionEditor = ({ field, value = [], content, onChange }) =
372
380
  /**
373
381
  * Collection Editor
374
382
  */
375
- export const CollectionEditor = ({ field, value = [], onChange }) => {
383
+ export const CollectionEditor = ({ field, value = [], onChange, onReload }) => {
376
384
 
377
385
  const { id, item, label, Feeder, Renderer, Adder = true, editable = true } = field
378
386
 
@@ -398,6 +406,10 @@ export const CollectionEditor = ({ field, value = [], onChange }) => {
398
406
  }
399
407
  }
400
408
 
409
+ function reload() {
410
+ if (onReload) onReload()
411
+ }
412
+
401
413
  const columns = Object.values(item)
402
414
  .filter(field => field.column === true)
403
415
  .map((item) => ({ ...item, onChange: change }))
@@ -423,7 +435,7 @@ export const CollectionEditor = ({ field, value = [], onChange }) => {
423
435
 
424
436
  }
425
437
  <footer>
426
- {Feeder ? <Feeder onAdd={add} /> : null}
438
+ {Feeder ? <Feeder onAdd={add} onReload={reload} /> : null}
427
439
  {Adder ? <CollectionAdder item={item} onAdd={add} /> : null}
428
440
  </footer>
429
441
  </div>