ywana-core8 0.0.534 → 0.0.537

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.534",
3
+ "version": "0.0.537",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -5,7 +5,6 @@ header.collection-page {
5
5
  menu.collection-page {
6
6
  display: flex;
7
7
  flex-direction: column;
8
- border: solid 3px red;
9
8
  }
10
9
 
11
10
  menu.collection-page>header {
@@ -20,7 +20,7 @@ export const CollectionPage = (props) => {
20
20
  icon, title, name = "Collection 1", className,
21
21
  schema, url, field, host, page, fetching = false,
22
22
  actions = [], onSelect,
23
- canFilter = false, canAdd = false, canDelete = false, canEdit = false,
23
+ canFilter = false, canAdd = false, canDelete = false, canEdit = false, searchBy,
24
24
  autosave = false, delay = 1000,
25
25
  groupBy, levels, sorter,
26
26
  editor,
@@ -68,7 +68,7 @@ export const CollectionPage = (props) => {
68
68
  <Header title={<Text>{name}</Text>} >
69
69
  </Header>
70
70
  {canFilter ? <CollectionFilters schema={schema} /> : null}
71
- {levels ? <CollectionTree icon={icon} levels={levels} onSelect={onSelect} sorter={sorter} /> : <CollectionList groupBy={groupBy} onSelect={onSelect} />}
71
+ {levels ? <CollectionTree icon={icon} levels={levels} onSelect={onSelect} sorter={sorter} searchBy={searchBy} /> : <CollectionList groupBy={groupBy} onSelect={onSelect} searchBy={searchBy} />}
72
72
  </menu>
73
73
  <main key={id} className={`collection-page ${className}`}>
74
74
  <CollectionEditor icon={icon} schema={schema} layout={editor} autosave={autosave} delay={delay} />
@@ -133,9 +133,10 @@ export const CollectionFilters = (props) => {
133
133
  */
134
134
  const CollectionList = (props) => {
135
135
 
136
- const { groupBy, onSelect } = props
136
+ const { groupBy, onSelect, searchBy=[] } = props
137
137
  const [pageContext, setPageContext] = useContext(PageContext)
138
138
  const { all = [] } = pageContext
139
+ const [filter, setFilter] = useState()
139
140
 
140
141
  function clear() {
141
142
  pageContext.clear()
@@ -149,15 +150,40 @@ const CollectionList = (props) => {
149
150
  if (onSelect) onSelect(id)
150
151
  }
151
152
 
152
- const items = all ? all.map(content => ({
153
+ function changeSearch(id, value) {
154
+ setFilter(value)
155
+ }
156
+
157
+ function search() {
158
+ const items = filter ? all.filter(item => {
159
+ const result = searchBy.some(fieldName => {
160
+ const value = item[fieldName]
161
+ return value ? value.indexOf(filter.toUpperCase()) >= 0 : false
162
+ })
163
+ return result
164
+ }) : all
165
+ return items
166
+ }
167
+
168
+ const items = search()
169
+ const items2 = items.map(content => ({
153
170
  id: content.id,
154
171
  line1: content.name || content.centre || content.tag, // centre: Signflow legacy
155
172
  line2: content.description,
156
173
  content
157
- })) : []
174
+ }))
158
175
 
159
176
  return (
160
- <List items={items} onSelect={select} groupBy={groupBy} />
177
+ <>
178
+ <main>
179
+ <List items={items2} onSelect={select} groupBy={groupBy} />
180
+ </main>
181
+ <footer>
182
+ <div className='search-box'>
183
+ <TextField icon="search" label="Search" onChange={changeSearch} outlined className="search-box" />
184
+ </div>
185
+ </footer>
186
+ </>
161
187
  )
162
188
  }
163
189
 
@@ -166,7 +192,7 @@ const CollectionList = (props) => {
166
192
  */
167
193
  export const CollectionTree = (props) => {
168
194
 
169
- const { icon = "description", levels, onSelect, sorter } = props
195
+ const { icon = "description", levels, onSelect, sorter, searchBy=[] } = props
170
196
  const [pageContext, setPageContext] = useContext(PageContext)
171
197
  const { all = [] } = pageContext
172
198
  const [filter, setFilter] = useState()
@@ -183,7 +209,7 @@ export const CollectionTree = (props) => {
183
209
  if (onSelect) onSelect(id)
184
210
  }
185
211
 
186
- function search(id, value) {
212
+ function changeSearch(id, value) {
187
213
  setFilter(value)
188
214
  }
189
215
 
@@ -218,8 +244,19 @@ export const CollectionTree = (props) => {
218
244
  })
219
245
  }
220
246
 
221
- const items = sorter ? sorter(all) : all
222
- const items2 = filter ? items.filter(item => item.name.toUpperCase().indexOf(filter.toUpperCase()) >= 0) : items
247
+ function search() {
248
+ const items = filter ? all.filter(item => {
249
+ const result = searchBy.some(fieldName => {
250
+ const value = item[fieldName]
251
+ return value ? value.indexOf(filter.toUpperCase()) >= 0 : false
252
+ })
253
+ return result
254
+ }) : all
255
+ return items
256
+ }
257
+
258
+ const items = search()
259
+ const items2 = sorter ? sorter(items) : items
223
260
  const nodes = generateNodes(levels, items2)
224
261
  return (
225
262
  <>
@@ -230,7 +267,7 @@ export const CollectionTree = (props) => {
230
267
  </main>
231
268
  <footer>
232
269
  <div className='search-box'>
233
- <TextField icon="search" label="Search" onChange={search} outlined className="search-box" />
270
+ <TextField icon="search" label="Search" onChange={changeSearch} outlined className="search-box" />
234
271
  </div>
235
272
  </footer>
236
273
  </>
@@ -200,6 +200,8 @@ const Page5 = (props) => {
200
200
  }
201
201
 
202
202
  const schema = {
203
+ id : { id: "id", type: TYPES.STRING },
204
+
203
205
  name : { id: "name" , section: "A", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: false, grouper: true , column: true , filter: true , like: true, label: "Name" },
204
206
  state : { id: "state" , section: "A", type: TYPES.STRING, format: FORMATS.NONE , required: true, tab: true , grouper: true , column: true , filter: false , label: "State" , options: [
205
207
  { label: "Pendiente", value: "NOT_CLASSIFIED" },
@@ -214,7 +216,7 @@ const Page5 = (props) => {
214
216
 
215
217
  return (
216
218
  <Fragment>
217
- <CollectionPage title="Referencias" schema={schema} host="http://localhost:3000" url="/references" levels={["color"]} canAdd={true} />
219
+ <CollectionPage title="Referencias" schema={schema} host="http://localhost:3000" url="/references" canAdd={true} searchBy={["field1"]} levels={["color"]}/>
218
220
  </Fragment>
219
221
  )
220
222
  }