CommonSimpleEntityList.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts" generic="T">
  3. import { computed } from 'vue'
  4. import type { ObjectLike } from '#shared/types/utils.ts'
  5. import CommonSectionCollapse from '#desktop/components/CommonSectionCollapse/CommonSectionCollapse.vue'
  6. import CommonShowMoreButton from '#desktop/components/CommonShowMoreButton/CommonShowMoreButton.vue'
  7. import entityModules from '#desktop/components/CommonSimpleEntityList/plugins/index.ts'
  8. import {
  9. type Entity,
  10. EntityType,
  11. } from '#desktop/components/CommonSimpleEntityList/types.ts'
  12. interface Props {
  13. id: string
  14. entity: Entity<ObjectLike>
  15. type: EntityType
  16. label?: string
  17. }
  18. const props = defineProps<Props>()
  19. const modelValue = defineModel<boolean>({
  20. default: false,
  21. })
  22. defineEmits<{
  23. 'load-more': []
  24. }>()
  25. const entitySetup = computed(() => {
  26. const { component, ...context } = entityModules[props.type]
  27. return {
  28. component,
  29. context,
  30. array: props.entity.array,
  31. }
  32. })
  33. </script>
  34. <template>
  35. <CommonSectionCollapse
  36. :id="id"
  37. v-model="modelValue"
  38. :title="label"
  39. :no-header="!label"
  40. >
  41. <ul v-if="entity.array?.length" class="flex flex-col gap-1.5">
  42. <li v-for="item in entitySetup.array" :key="`entity-${item.id}`">
  43. <component
  44. :is="entitySetup.component"
  45. :entity="item"
  46. :context="entitySetup.context"
  47. />
  48. </li>
  49. </ul>
  50. <CommonLabel v-if="!entity.array?.length" class="block"
  51. >{{ entitySetup.context.emptyMessage }}
  52. </CommonLabel>
  53. <CommonShowMoreButton
  54. v-if="entity"
  55. class="self-end"
  56. :entities="entity.array"
  57. :total-count="entity.totalCount"
  58. @click="$emit('load-more')"
  59. />
  60. </CommonSectionCollapse>
  61. </template>