CommonSimpleEntityList.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. defineEmits<{
  20. 'load-more': []
  21. }>()
  22. const entitySetup = computed(() => {
  23. const { component, ...context } = entityModules[props.type]
  24. return {
  25. component,
  26. context,
  27. array: props.entity.array,
  28. }
  29. })
  30. </script>
  31. <template>
  32. <CommonSectionCollapse :id="id" :title="label" :no-header="!label">
  33. <ul v-if="entity.array?.length" class="flex flex-col gap-1.5">
  34. <li v-for="item in entitySetup.array" :key="`entity-${item.id}`">
  35. <component
  36. :is="entitySetup.component"
  37. :entity="item"
  38. :context="entitySetup.context"
  39. />
  40. </li>
  41. </ul>
  42. <CommonLabel v-if="!entity.array?.length" class="block"
  43. >{{ entitySetup.context.emptyMessage }}
  44. </CommonLabel>
  45. <CommonShowMoreButton
  46. v-if="entity"
  47. class="self-end"
  48. :entities="entity.array"
  49. :total-count="entity.totalCount"
  50. @click="$emit('load-more')"
  51. />
  52. </CommonSectionCollapse>
  53. </template>