@drax/crud-vue 3.17.0 → 3.18.0
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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.18.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@drax/common-front": "^3.11.0",
|
|
28
28
|
"@drax/crud-front": "^3.11.0",
|
|
29
29
|
"@drax/crud-share": "^3.17.0",
|
|
30
|
-
"@drax/media-vue": "^3.
|
|
30
|
+
"@drax/media-vue": "^3.18.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"pinia": "^3.0.4",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"vue-tsc": "^3.2.4",
|
|
51
51
|
"vuetify": "^3.11.8"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c7709f3912ba1f8ae6a7e78376e17d50b32cfa7d"
|
|
54
54
|
}
|
|
@@ -2,6 +2,7 @@ import {computed} from "vue"
|
|
|
2
2
|
import type {Ref} from "vue"
|
|
3
3
|
import {useI18n} from "vue-i18n"
|
|
4
4
|
import type {
|
|
5
|
+
IEntityCrudField,
|
|
5
6
|
IEntityCrudFilter,
|
|
6
7
|
IEntityCrudFieldTypes
|
|
7
8
|
} from "@drax/crud-share"
|
|
@@ -19,21 +20,60 @@ export function useDynamicFilters(
|
|
|
19
20
|
})
|
|
20
21
|
|
|
21
22
|
const fieldI18n = computed(() => {
|
|
22
|
-
return (field:
|
|
23
|
-
const key = entityName.value?.toLowerCase() + ".field." +
|
|
23
|
+
return (field: Pick<IEntityCrudField, 'name' | 'label'>, fieldName = field.name) => {
|
|
24
|
+
const key = entityName.value?.toLowerCase() + ".field." + fieldName
|
|
24
25
|
return te(key) ? t(key) : field.label
|
|
25
26
|
}
|
|
26
27
|
})
|
|
27
28
|
|
|
29
|
+
function flattenFilterableFields(
|
|
30
|
+
fields: IEntityCrudField[],
|
|
31
|
+
parentPath = '',
|
|
32
|
+
parentLabels: string[] = []
|
|
33
|
+
): IEntityCrudField[] {
|
|
34
|
+
return fields.flatMap((field) => {
|
|
35
|
+
if (field.type === 'fullFile' || field.type === 'array.object') {
|
|
36
|
+
return []
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name
|
|
40
|
+
const fieldLabel = fieldI18n.value(field, fieldPath)
|
|
41
|
+
const pathLabels = [...parentLabels, fieldLabel]
|
|
42
|
+
|
|
43
|
+
if (field.type === 'object') {
|
|
44
|
+
if (!field.objectFields?.length) {
|
|
45
|
+
return []
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return flattenFilterableFields(field.objectFields, fieldPath, pathLabels)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [{
|
|
52
|
+
...field,
|
|
53
|
+
name: fieldPath,
|
|
54
|
+
label: pathLabels.join(' / ')
|
|
55
|
+
}]
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const filterableFields = computed(() => {
|
|
60
|
+
return flattenFilterableFields(entityFields.value || [])
|
|
61
|
+
})
|
|
62
|
+
|
|
28
63
|
const selectableFields = computed(() => {
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
.map((f: any) => ({
|
|
64
|
+
return filterableFields.value
|
|
65
|
+
.map((f: IEntityCrudField) => ({
|
|
32
66
|
title: fieldI18n.value(f),
|
|
33
67
|
value: f.name
|
|
34
68
|
})) || []
|
|
35
69
|
})
|
|
36
70
|
|
|
71
|
+
const fieldByName = computed(() => {
|
|
72
|
+
return new Map(
|
|
73
|
+
filterableFields.value.map((field) => [field.name, field] as const)
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
37
77
|
function normalizeFieldType(type: string): IEntityCrudFieldTypes {
|
|
38
78
|
if (type === 'array.ref') return 'ref'
|
|
39
79
|
if (type === 'array.string') return 'string'
|
|
@@ -52,9 +92,7 @@ export function useDynamicFilters(
|
|
|
52
92
|
filter.operator = 'eq'
|
|
53
93
|
}
|
|
54
94
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const field = entityFields.value?.find((e: any) => e.name === filterName)
|
|
95
|
+
const field = fieldByName.value.get(filter.name)
|
|
58
96
|
|
|
59
97
|
filter.value = null
|
|
60
98
|
if (!field) return
|