ywana-core8 0.0.476 → 0.0.477

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.476",
3
+ "version": "0.0.477",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -15,9 +15,9 @@ import "./CollectionPage.css"
15
15
  export const CollectionPage = (props) => {
16
16
 
17
17
  const site = useContext(SiteContext)
18
- const { id = "collection", icon, title, name = "Collection 1", schema, url, page, host, groupBy, editor, field, autosave = false, delay = 1000, actions, levels, onSelect, children } = props
18
+ const { id = "collection", icon, title, name = "Collection 1", schema, url, field, host, page, fetching= false, groupBy, editor, autosave = false, delay = 1000, actions, levels, onSelect, children } = props
19
19
  const [pageContext, setPageContext] = useContext(PageContext)
20
- const context = CollectionContext(url, field, host, page)
20
+ const context = CollectionContext(url, field, host, page, fetching)
21
21
 
22
22
  useEffect(async () => {
23
23
  await context.load()
@@ -237,7 +237,7 @@ const CollectionEditor = (props) => {
237
237
  /**
238
238
  * Collection Context
239
239
  */
240
- export const CollectionContext = (url, field, host, page) => {
240
+ export const CollectionContext = (url, field, host, page, fetching) => {
241
241
 
242
242
  const API = CollectionAPI(url, host)
243
243
 
@@ -256,9 +256,23 @@ export const CollectionContext = (url, field, host, page) => {
256
256
  return
257
257
  },
258
258
 
259
- select(id) {
260
- const result = this.all.find(item => item.id === id);
261
- this.selected = result;
259
+ async select(id) {
260
+ if (fetching) {
261
+ const result = await this.fetch(id)
262
+ this.selected = result
263
+ } else {
264
+ const result = this.all.find(item => item.id === id);
265
+ this.selected = result;
266
+ }
267
+ },
268
+
269
+ async fetch(id) {
270
+ try {
271
+ const result = await API.find(id)
272
+ return result
273
+ } catch (error) {
274
+ console.log(error)
275
+ }
262
276
  },
263
277
 
264
278
  clear() {