ywana-core8 0.0.706 → 0.0.708

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.706",
3
+ "version": "0.0.708",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -39,7 +39,7 @@ export const CollectionContextProvider = (props) => {
39
39
 
40
40
  async function select(id) {
41
41
  if (fetching) {
42
- const result = await this.fetch(id)
42
+ const result = await fetch(id)
43
43
  setSelected(result)
44
44
  } else {
45
45
  const result = this.all.find(item => item.id === id);
@@ -56,13 +56,7 @@ export const CollectionContextProvider = (props) => {
56
56
  delete next[id]
57
57
  setCustomFilters(next)
58
58
  }
59
-
60
- /*
61
- async function reloadSelection() {
62
- const result = await this.fetch(this.selected.id)
63
- this.selected = result
64
- }
65
-
59
+
66
60
  async function fetch(id) {
67
61
  try {
68
62
  const result = await API.find(id)
@@ -71,6 +65,13 @@ export const CollectionContextProvider = (props) => {
71
65
  console.log(error)
72
66
  }
73
67
  }
68
+
69
+ /*
70
+ async function reloadSelection() {
71
+ const result = await this.fetch(this.selected.id)
72
+ this.selected = result
73
+ }
74
+
74
75
 
75
76
  function clear() {
76
77
  this.selected = null
@@ -1,17 +1,15 @@
1
1
  import React, { useContext } from 'react'
2
- import { CollectionContext } from './CollectionContext'
3
2
 
4
3
  /**
5
4
  * Collection Editor
6
5
  */
7
6
  export const CollectionEditor = (props) => {
8
7
 
9
- const context = useContext(CollectionContext)
10
- const { selected } = context
8
+ const { customEditor } = props
11
9
 
12
10
  return (
13
11
  <div className="collection-editor">
14
- editor
12
+ {customEditor}
15
13
  </div>
16
14
  )
17
15
  }
@@ -3,6 +3,7 @@
3
3
  flex-direction: column;
4
4
  width: 30rem;
5
5
  background-color: rgb(243, 243, 243);
6
+ border-right: solid 1px var(--divider-color);
6
7
  }
7
8
 
8
9
  .collection-filters>header {
@@ -29,6 +30,7 @@
29
30
  padding: 0.5rem;
30
31
  font-size: .8rem;
31
32
  font-weight: 300;
33
+ text-transform: uppercase;
32
34
  }
33
35
 
34
36
  .collection-filter-resume-label {
@@ -47,4 +49,5 @@
47
49
  display: flex;
48
50
  flex-direction: column;
49
51
  padding: 0 0 1rem 0;
52
+ border-bottom: solid 1px var(--divider-color);
50
53
  }
@@ -20,7 +20,7 @@ export const CollectionFilters = (props) => {
20
20
  }, [schema])
21
21
 
22
22
  function change(id, value) {
23
- context.setFilters({ ...filters, [id]: value })
23
+ if (filters) context.setFilters({ ...filters, [id]: value })
24
24
  }
25
25
 
26
26
  function toggle() {
@@ -0,0 +1,17 @@
1
+ .collection-list {
2
+ overflow: hidden;
3
+ display: flex;
4
+ flex-direction: column;
5
+ border-right: solid 1px var(--divider-color);
6
+ }
7
+
8
+ .collection-list .list {
9
+ flex: 1;
10
+ }
11
+
12
+ .collection-list .search-box {
13
+ border-top: solid 1px var(--divider-color);
14
+ padding: .5rem;
15
+ display: flex;
16
+ align-items: center;
17
+ }
@@ -1,30 +1,55 @@
1
- import React, { useContext, useEffect } from 'react'
2
- import { List } from '../html'
1
+ import React, { useContext, useEffect, useState } from 'react'
2
+ import { List, TextField, Icon } from '../html'
3
3
  import { CollectionContext } from './CollectionContext'
4
+ import './CollectionList.css'
4
5
 
5
6
  /**
6
7
  * Collection List
7
8
  */
8
9
  export const CollectionList = (props) => {
9
10
 
11
+ const { itemRenderer, groupBy, searchBy = [] } = props
10
12
  const context = useContext(CollectionContext)
11
13
  const { all = [], selected, filters, customFilters } = context
14
+ const [search, setSearch] = useState('')
12
15
 
13
16
  useEffect(() => {
14
17
  context.load()
15
18
  }, [filters, customFilters])
16
19
 
17
- const items = all.map(item => {
18
- return {
19
- icon: "folder",
20
- line1: item.name,
21
- meta: item.state,
22
- }
23
- })
20
+ function changeSearch(id, value) {
21
+ setSearch(value)
22
+ }
23
+
24
+ function select(id) {
25
+ context.select(id)
26
+ }
27
+
28
+ const searched = searchBy.length > 0 && search.length > 0 ? all.filter(item => {
29
+ const text = searchBy.map(field => item[field]).join(' ').toLowerCase()
30
+ return text.includes(search.toLowerCase())
31
+ }) : all
32
+
33
+ const items = searched
34
+ .map(item => {
35
+ if (itemRenderer) return itemRenderer(item)
36
+ return {
37
+ id: item.id,
38
+ icon: "folder",
39
+ line1: item.name,
40
+ meta: item.state,
41
+ }
42
+ })
24
43
 
25
44
  return (
26
45
  <div className="collection-list">
27
- <List items={items} />
46
+ <List items={items} onSelect={select} groupBy={groupBy} />
47
+ {searchBy.length > 0 ? (
48
+ <div className="search-box">
49
+ <Icon icon="search" size="small" />
50
+ <TextField placeholder="Search" onChange={changeSearch} outlined />
51
+ </div>
52
+ ) : null}
28
53
  </div>
29
54
  )
30
55
  }
@@ -1,3 +1,10 @@
1
+ .collection-page {
2
+ border: solid 3px red;
3
+ width: 100%;
4
+ height: 100%;
5
+ overflow: hidden;
6
+ }
7
+
1
8
  .collection-page.ide {
2
9
  display: grid;
3
10
  grid-template-areas: "header header"
@@ -9,6 +16,7 @@
9
16
 
10
17
  .collection-page.ide .header {
11
18
  grid-area: header;
19
+ border-bottom: solid 1px var(--divider-color);
12
20
  }
13
21
 
14
22
  .collection-page.ide .collection-filters {
@@ -14,16 +14,19 @@ export const CollectionPage = (props) => {
14
14
  const {
15
15
  host, url, schema,
16
16
  layout,
17
- canFilter, customFilters
17
+ title,
18
+ canFilter, customFilters,
19
+ listGroupBy, listSearchBy, listItemRenderer,
20
+ customEditor
18
21
  } = props
19
22
 
20
23
  return (
21
24
  <div className={`collection-page ${layout}`}>
22
25
  <CollectionContextProvider host={host} url={url}>
23
- <Header title="CollectionPage" />
26
+ <Header title={title} />
24
27
  {canFilter ? <CollectionFilters schema={schema} >{customFilters}</CollectionFilters> : null}
25
- <CollectionList />
26
- <CollectionEditor />
28
+ <CollectionList itemRenderer={listItemRenderer} groupBy={listGroupBy} searchBy={listSearchBy} />
29
+ <CollectionEditor customEditor={customEditor} />
27
30
  </CollectionContextProvider>
28
31
  </div>
29
32
 
@@ -16,14 +16,28 @@ const CollectionPageTest = (prop) => {
16
16
  }
17
17
  }
18
18
 
19
+ const listItemRenderer = (item) => {
20
+ return {
21
+ id: item.id,
22
+ icon: "star",
23
+ line1: item.name,
24
+ line2: item.name,
25
+ meta: item.state,
26
+ }
27
+ }
19
28
 
20
29
  const props = {
21
30
  host: "http://localhost:3000",
22
31
  url: "/references",
23
32
  schema,
24
33
  layout: "ide",
34
+ title: <CustomTitle />,
25
35
  canFilter: true,
26
- customFilters: [<CustomFilter1 />, <CustomFilter2 />]
36
+ customFilters: [<CustomFilter1 />, <CustomFilter2 />],
37
+ listSearchBy: ["name"],
38
+ listGroupBy: "name",
39
+ listItemRenderer,
40
+ customEditor: <CustomEditor />
27
41
  }
28
42
 
29
43
  return (
@@ -33,6 +47,29 @@ const CollectionPageTest = (prop) => {
33
47
  )
34
48
  }
35
49
 
50
+ const CustomTitle = (props) => {
51
+ return (
52
+ <h1>Custom Title</h1>
53
+ )
54
+ }
55
+
56
+ const CustomEditor = () => {
57
+
58
+ const context = useContext(CollectionContext)
59
+ const { all, selected } = context
60
+
61
+ return (
62
+ <div>
63
+ <header>
64
+ CUSTOM EDITOR {all.length}
65
+ </header>
66
+ <main>
67
+ ID: {selected ? selected.id : null}
68
+ </main>
69
+ </div>
70
+ )
71
+ }
72
+
36
73
  const CustomFilter1 = (props) => {
37
74
 
38
75
  const context = useContext(CollectionContext)