ywana-core8 0.0.796 → 0.0.798
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/dist/index.cjs +42 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +42 -23
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +42 -23
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain2/CollectionContext.js +27 -9
- package/src/domain2/CollectionContext.test.js +20 -7
- package/src/domain2/CollectionList.js +2 -2
package/package.json
CHANGED
@@ -14,7 +14,10 @@ export const CollectionContextProvider = (props) => {
|
|
14
14
|
const [all, setAll] = useState([])
|
15
15
|
const [filters, setFilters] = useState(filtersValue)
|
16
16
|
const [likes, setLikes] = useState([])
|
17
|
+
|
17
18
|
const [customFilters, setCustomFilters] = useState({})
|
19
|
+
const [filtered, setFiltered] = useState([])
|
20
|
+
|
18
21
|
const [queries, setQueries] = useState([])
|
19
22
|
const [selected, setSelected] = useState(null)
|
20
23
|
|
@@ -28,21 +31,28 @@ export const CollectionContextProvider = (props) => {
|
|
28
31
|
return () => {
|
29
32
|
mounted = false;
|
30
33
|
}
|
31
|
-
}, [filters
|
34
|
+
}, [filters])
|
35
|
+
|
36
|
+
useEffect(() => {
|
37
|
+
runCustomFilters()
|
38
|
+
}, [customFilters])
|
32
39
|
|
33
40
|
async function load() {
|
34
41
|
|
42
|
+
/*
|
35
43
|
const runCustomFilters = (all) => {
|
36
44
|
const cfs = Object.values(customFilters)
|
37
45
|
const data = cfs.length ? cfs.reduce((acc, filter) => filter(acc), all) : all;
|
38
46
|
return data
|
39
47
|
}
|
48
|
+
*/
|
40
49
|
|
41
50
|
try {
|
42
51
|
const response = await API.all(filters, likes, page);
|
43
52
|
const next = field ? response[field] : response;
|
44
|
-
const data = runCustomFilters(next)
|
45
|
-
return data
|
53
|
+
//const data = runCustomFilters(next)
|
54
|
+
//return data
|
55
|
+
return next;
|
46
56
|
} catch (error) {
|
47
57
|
console.log(error)
|
48
58
|
}
|
@@ -57,7 +67,7 @@ export const CollectionContextProvider = (props) => {
|
|
57
67
|
console.log(error)
|
58
68
|
}
|
59
69
|
}
|
60
|
-
|
70
|
+
|
61
71
|
async function select(id) {
|
62
72
|
if (fetching) {
|
63
73
|
const result = await fetch(id)
|
@@ -85,6 +95,12 @@ export const CollectionContextProvider = (props) => {
|
|
85
95
|
setCustomFilters(next)
|
86
96
|
return
|
87
97
|
}
|
98
|
+
|
99
|
+
function runCustomFilters() {
|
100
|
+
const cfs = Object.values(customFilters)
|
101
|
+
const data = cfs.length ? cfs.reduce((acc, filter) => filter(acc), all) : all;
|
102
|
+
setFiltered(data)
|
103
|
+
}
|
88
104
|
|
89
105
|
async function fetch(id) {
|
90
106
|
try {
|
@@ -99,7 +115,7 @@ export const CollectionContextProvider = (props) => {
|
|
99
115
|
try {
|
100
116
|
if (versioning) form.version = 1
|
101
117
|
await API.create(form);
|
102
|
-
await this.
|
118
|
+
await this.reload();
|
103
119
|
} catch (error) {
|
104
120
|
console.log(error)
|
105
121
|
}
|
@@ -110,7 +126,7 @@ export const CollectionContextProvider = (props) => {
|
|
110
126
|
try {
|
111
127
|
if (versioning) form.version = form.version ? form.version + 1 : 1
|
112
128
|
await API.update(form)
|
113
|
-
await this.
|
129
|
+
await this.reload()
|
114
130
|
} catch (error) {
|
115
131
|
console.log(error)
|
116
132
|
}
|
@@ -121,7 +137,7 @@ export const CollectionContextProvider = (props) => {
|
|
121
137
|
try {
|
122
138
|
if (versioning) form.version = form.version ? form.version + 1 : 1
|
123
139
|
await API.patch(id, form)
|
124
|
-
await this.
|
140
|
+
await this.reload()
|
125
141
|
} catch (error) {
|
126
142
|
console.log(error)
|
127
143
|
}
|
@@ -131,7 +147,7 @@ export const CollectionContextProvider = (props) => {
|
|
131
147
|
async function updateProperty(id, propertyName, form) {
|
132
148
|
try {
|
133
149
|
await API.updateProperty(id, propertyName, form)
|
134
|
-
await this.
|
150
|
+
await this.reload()
|
135
151
|
} catch (error) {
|
136
152
|
console.log(error)
|
137
153
|
}
|
@@ -141,7 +157,7 @@ export const CollectionContextProvider = (props) => {
|
|
141
157
|
async function remove(id) {
|
142
158
|
try {
|
143
159
|
await API.remove(id)
|
144
|
-
await this.
|
160
|
+
await this.reload()
|
145
161
|
} catch (error) {
|
146
162
|
console.log(error)
|
147
163
|
}
|
@@ -162,6 +178,8 @@ export const CollectionContextProvider = (props) => {
|
|
162
178
|
setLikes,
|
163
179
|
|
164
180
|
customFilters,
|
181
|
+
filtered,
|
182
|
+
runCustomFilters,
|
165
183
|
addCustomFilter,
|
166
184
|
removeCustomFilter,
|
167
185
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useContext } from 'react'
|
1
|
+
import React, { useContext, useEffect, useState } from 'react'
|
2
2
|
import { CheckBox } from '../html'
|
3
3
|
import { CollectionContext, CollectionContextProvider } from './CollectionContext'
|
4
4
|
import { CollectionEditor } from './CollectionEditor'
|
@@ -42,17 +42,30 @@ const CollectionContextTest = (props) => {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
const CustomFilter1 = (props) => {
|
45
|
-
|
46
|
-
const
|
45
|
+
|
46
|
+
const context = useContext(CollectionContext)
|
47
|
+
const [active, setActive] = useState(false)
|
48
|
+
|
49
|
+
useEffect(() => {
|
50
|
+
if (active) {
|
51
|
+
context.addCustomFilter("ACTIVE", filter)
|
52
|
+
} else {
|
53
|
+
context.removeCustomFilter("ACTIVE")
|
54
|
+
}
|
55
|
+
}, [active])
|
47
56
|
|
48
57
|
function change(id, value) {
|
49
|
-
|
58
|
+
setActive(value)
|
59
|
+
}
|
60
|
+
|
61
|
+
function filter(all) {
|
62
|
+
console.log("CUSTOMFILTER1 DO NOTHING")
|
63
|
+
return all
|
50
64
|
}
|
51
65
|
|
52
66
|
return (
|
53
67
|
<div>
|
54
|
-
<CheckBox id="custom1" label="Custom Filter 1" value={
|
68
|
+
<CheckBox id="custom1" label="Custom Filter 1" value={active} onChange={change} />
|
55
69
|
</div>
|
56
70
|
)
|
57
|
-
}
|
58
|
-
|
71
|
+
}
|
@@ -10,7 +10,7 @@ export const CollectionList = (props) => {
|
|
10
10
|
|
11
11
|
const { itemRenderer, groupBy, groupRenderer, searchBy = [], sortBy, sortDir } = props
|
12
12
|
const context = useContext(CollectionContext)
|
13
|
-
const { all = [], selected, filters, customFilters } = context
|
13
|
+
const { all = [], filtered=[], selected, filters, customFilters } = context
|
14
14
|
const [search, setSearch] = useState('')
|
15
15
|
|
16
16
|
function changeSearch(id, value) {
|
@@ -21,7 +21,7 @@ export const CollectionList = (props) => {
|
|
21
21
|
context.select(id)
|
22
22
|
}
|
23
23
|
|
24
|
-
const searched = searchBy.length > 0 && search.length > 0 ?
|
24
|
+
const searched = searchBy.length > 0 && search.length > 0 ? filtered.filter(item => {
|
25
25
|
const text = searchBy.map(field => item[field]).join(' ').toLowerCase()
|
26
26
|
return text.includes(search.toLowerCase())
|
27
27
|
}) : all
|