frappe-ui 0.1.272 → 0.1.274
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/frappe/Filter/Filter.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, ref } from "vue";
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
3
|
import type { FilterProps, StateRow } from "./types";
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getOperators,
|
|
8
8
|
getValueControl,
|
|
9
9
|
parseFilters,
|
|
10
|
+
reverseOperatorMap,
|
|
10
11
|
} from "./utils";
|
|
11
12
|
|
|
12
13
|
import Badge from "../../src/components/Badge/Badge.vue";
|
|
@@ -19,13 +20,13 @@ import { createResource } from "../../src/resources";
|
|
|
19
20
|
import FilterIcon from "../Icons/FilterIcon.vue";
|
|
20
21
|
|
|
21
22
|
let props = defineProps<FilterProps>();
|
|
23
|
+
const model = defineModel<any[]>();
|
|
22
24
|
|
|
23
25
|
const doctypeFields = createResource({
|
|
24
26
|
url: "frappe.desk.form.load.getdoctype",
|
|
25
27
|
method: "GET",
|
|
26
28
|
params: { doctype: props.doctype },
|
|
27
29
|
auto: true,
|
|
28
|
-
|
|
29
30
|
transform(data) {
|
|
30
31
|
const options = data.docs[0].fields.map((x) => {
|
|
31
32
|
return {
|
|
@@ -41,6 +42,9 @@ const doctypeFields = createResource({
|
|
|
41
42
|
|
|
42
43
|
return options;
|
|
43
44
|
},
|
|
45
|
+
onSuccess(data) {
|
|
46
|
+
setFilters()
|
|
47
|
+
}
|
|
44
48
|
});
|
|
45
49
|
|
|
46
50
|
const dummyObj = () => ({
|
|
@@ -52,6 +56,40 @@ const dummyObj = () => ({
|
|
|
52
56
|
const rows = ref([dummyObj()]);
|
|
53
57
|
const insertRow = () => rows.value.push(dummyObj());
|
|
54
58
|
|
|
59
|
+
watch(
|
|
60
|
+
() => model.value,
|
|
61
|
+
() => setFilters(),
|
|
62
|
+
{ deep: true }
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const setFilters = () => {
|
|
66
|
+
if (!doctypeFields.data?.length || !model.value?.length) return;
|
|
67
|
+
|
|
68
|
+
const _filters = model.value
|
|
69
|
+
.map((filter: any) => {
|
|
70
|
+
let [fieldName, operator, value] = filter;
|
|
71
|
+
const field = doctypeFields.data.find((f: any) => f.value === fieldName);
|
|
72
|
+
if (!field) return null;
|
|
73
|
+
|
|
74
|
+
if (field.type === "Check") {
|
|
75
|
+
value = value ? "Yes" : "No"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
field: {
|
|
80
|
+
fieldName: field.value,
|
|
81
|
+
fieldType: field.type,
|
|
82
|
+
options: field.options,
|
|
83
|
+
},
|
|
84
|
+
operator: reverseOperatorMap[operator] || operator,
|
|
85
|
+
value: value,
|
|
86
|
+
};
|
|
87
|
+
})
|
|
88
|
+
.filter((row) => row !== null) as StateRow[];
|
|
89
|
+
|
|
90
|
+
rows.value = _filters as typeof rows.value;
|
|
91
|
+
}
|
|
92
|
+
|
|
55
93
|
const clearRows = (closePopup: () => void) => {
|
|
56
94
|
rows.value = [dummyObj()];
|
|
57
95
|
closePopup();
|
|
@@ -84,7 +122,6 @@ const updateFilter = (val: string, index: number) => {
|
|
|
84
122
|
apply();
|
|
85
123
|
};
|
|
86
124
|
|
|
87
|
-
const model = defineModel();
|
|
88
125
|
const apply = () => {
|
|
89
126
|
model.value = parseFilters(rows.value);
|
|
90
127
|
};
|
package/frappe/Filter/utils.ts
CHANGED
|
@@ -220,6 +220,10 @@ const operatorMap = {
|
|
|
220
220
|
timespan: 'timespan',
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
export const reverseOperatorMap = Object.fromEntries(
|
|
224
|
+
Object.entries(operatorMap).map(([key, value]) => [value, key])
|
|
225
|
+
);
|
|
226
|
+
|
|
223
227
|
export const parseFilters = (filters: any) => {
|
|
224
228
|
const _filters = JSON.parse(JSON.stringify(filters))
|
|
225
229
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { reactive, watch } from 'vue'
|
|
1
|
+
import { reactive, watch, effectScope } from 'vue'
|
|
2
2
|
import { getCacheKey, createResource } from './resources'
|
|
3
3
|
import {
|
|
4
4
|
updateRowInListResource,
|
|
@@ -143,16 +143,20 @@ export function createDocumentResource(options, vm) {
|
|
|
143
143
|
setDoc,
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
// keep track of isDirty as doc changes
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
// keep track of isDirty as doc changes, use effectScope to handle isDirty state reactivity for cached data
|
|
147
|
+
const scope = effectScope(true)
|
|
148
|
+
scope.run(() => {
|
|
149
|
+
watch(
|
|
150
|
+
() => out.doc,
|
|
151
|
+
() => {
|
|
152
|
+
out.isDirty =
|
|
153
|
+
JSON.stringify(out.doc) !== JSON.stringify(out.originalDoc)
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
deep: true,
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
})
|
|
156
160
|
|
|
157
161
|
for (let methodKey in options.whitelistedMethods) {
|
|
158
162
|
let methodOptions = options.whitelistedMethods[methodKey]
|