@drax/crud-vue 3.39.0 → 3.46.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.39.0",
6
+ "version": "3.46.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "@drax/common-front": "^3.29.0",
28
28
  "@drax/crud-front": "^3.21.0",
29
- "@drax/crud-share": "^3.39.0",
30
- "@drax/media-vue": "^3.39.0"
29
+ "@drax/crud-share": "^3.46.0",
30
+ "@drax/media-vue": "^3.46.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": "9490eb0473fe037d100742aa7c21e9478b941eb5"
53
+ "gitHead": "a90e6d81ea836f1f921c7baf6f149b82a0aced38"
54
54
  }
@@ -1,47 +1,46 @@
1
1
  <script setup lang="ts">
2
- import {onMounted, ref, computed} from "vue";
2
+ import {ref, watch} from "vue";
3
3
  import type {PropType} from "vue";
4
4
  import type {IEntityCrud} from "@drax/crud-share";
5
- import type {IDraxFieldFilter} from "@drax/crud-share";
5
+ import {useCrudRefDisplay} from "../composables/useCrudRefDisplay";
6
6
 
7
- const {entity, value, refDisplay} = defineProps({
7
+ const props = defineProps({
8
8
  entity: {type: Object as PropType<IEntityCrud | undefined>, required: true},
9
- value: {type: Array as PropType<any[]>, required: true},
10
- refDisplay: {type: String as PropType<String>, required: true},
9
+ value: {type: null, required: true},
10
+ displayField: {type: String, required: false},
11
+ refDisplay: {type: String, required: false},
11
12
  })
12
13
 
14
+ const {refDisplay} = useCrudRefDisplay()
13
15
  const loading = ref(false)
14
- const items = ref<any[]>([])
15
-
16
- onMounted(()=> {
17
- console.log('onMounted',entity, value, refDisplay)
18
- fetch()
19
- })
16
+ const display = ref<any>('')
20
17
 
21
18
  async function fetch() {
22
19
  try{
23
20
  loading.value = true
24
- if(entity?.provider?.find){
25
- const ids = Array.isArray(value) ? value : [value]
26
- const filters: IDraxFieldFilter[] = [{field: '_id', operator: 'in', value: ids}]
27
- items.value = await entity.provider.find({filters})
21
+ if(props.entity){
22
+ display.value = await refDisplay(
23
+ props.entity,
24
+ props.value,
25
+ props.displayField ?? props.refDisplay
26
+ )
28
27
  }
29
28
  }catch (e){
30
29
  console.error(e)
30
+ display.value = props.value
31
31
  }finally{
32
32
  loading.value = false
33
33
  }
34
34
  }
35
35
 
36
- const display = computed(() => {
37
- return items.value.map(item => item[refDisplay as any]).join(', ')
38
- })
39
-
40
-
36
+ watch(
37
+ () => [props.entity, props.value, props.displayField, props.refDisplay],
38
+ fetch,
39
+ {immediate: true}
40
+ )
41
41
  </script>
42
42
 
43
43
  <template>
44
- {{display}}
45
-
44
+ <span v-if="loading">...</span>
45
+ <span v-else>{{display}}</span>
46
46
  </template>
47
-
@@ -2,14 +2,37 @@ import type {IEntityCrud} from '@drax/crud-share'
2
2
 
3
3
  export function useCrudRefDisplay() {
4
4
 
5
- async function refDisplay(entity: IEntityCrud, value: any, refDisplay: string) {
5
+ function getDisplayValue(item: any, displayField: string, fallback: any = '') {
6
+ return item?.[displayField] ?? fallback
7
+ }
8
+
9
+ async function refDisplay(entity: IEntityCrud, value: any, displayField?: string) {
6
10
  try{
7
- if(entity?.provider?.findByIds){
8
- // Asegurar que value sea un array
9
- const ids = Array.isArray(value) ? value : [value]
11
+ const field = displayField ?? entity.displayField
12
+
13
+ if(value == null || !field){
14
+ return value
15
+ }
16
+
17
+ if(Array.isArray(value)){
18
+ if(!entity?.provider?.findByIds){
19
+ return value
20
+ }
21
+ const ids = value
10
22
  const items = await entity.provider.findByIds(ids)
11
- return items.map(item => item[refDisplay as any]).join(', ')
23
+ return items.map(item => getDisplayValue(item, field)).join(', ')
12
24
  }
25
+
26
+ if(entity?.provider?.findById){
27
+ const item = await entity.provider.findById(value)
28
+ return item ? getDisplayValue(item, field, value) : value
29
+ }
30
+
31
+ if(entity?.provider?.findByIds){
32
+ const items = await entity.provider.findByIds([value])
33
+ return items[0] ? getDisplayValue(items[0], field, value) : value
34
+ }
35
+
13
36
  return value
14
37
  }catch (e){
15
38
  console.error(e)
package/src/index.ts CHANGED
@@ -15,12 +15,14 @@ import CrudFiltersAction from "./components/CrudFiltersAction.vue";
15
15
  import CrudNotify from "./components/CrudNotify.vue";
16
16
  import CrudSearch from "./components/CrudSearch.vue";
17
17
  import CrudAutocomplete from "./components/CrudAutocomplete.vue";
18
+ import CrudRefDisplay from "./components/CrudRefDisplay.vue";
18
19
  import CrudSavedQueriesButton from "./components/buttons/CrudSavedQueriesButton.vue";
19
20
  import CrudRefreshButton from "./components/buttons/CrudRefreshButton.vue";
20
21
  import EntityCombobox from "./components/combobox/EntityCombobox.vue";
21
22
  import {useCrudStore} from "./stores/UseCrudStore";
22
23
  import {useEntityStore} from "./stores/UseEntityStore";
23
24
  import {useCrud} from "./composables/UseCrud";
25
+ import {useCrudRefDisplay} from "./composables/useCrudRefDisplay";
24
26
  import {useDynamicFilters} from "./composables/UseDynamicFilters";
25
27
  import {useFilterIcon} from "./composables/UseFilterIcon";
26
28
  import {useFormUtils} from "./composables/UseFormUtils";
@@ -43,6 +45,7 @@ export {
43
45
  CrudNotify,
44
46
  CrudSearch,
45
47
  CrudAutocomplete,
48
+ CrudRefDisplay,
46
49
  CrudSavedQueriesButton,
47
50
  CrudRefreshButton,
48
51
  CrudFilters,
@@ -54,6 +57,7 @@ export {
54
57
  useCrudStore,
55
58
  useInputErrorI18n,
56
59
  useFilterIcon,
60
+ useCrudRefDisplay,
57
61
  EntityCrud,
58
62
  useEntityStore,
59
63
  EntityCombobox