From 4c351504bd6aaf95d4215681d9f8d15153124252 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 23 Aug 2024 16:28:41 +0800 Subject: [PATCH] feat: add filter options for attachment selector component Signed-off-by: Ryan Wang --- .../CoreSelectorProvider.vue | 321 ++++++++++++++---- .../components/AttachmentSelectorListItem.vue | 100 ++++++ 2 files changed, 351 insertions(+), 70 deletions(-) create mode 100644 ui/console-src/modules/contents/attachments/components/selector-providers/components/AttachmentSelectorListItem.vue diff --git a/ui/console-src/modules/contents/attachments/components/selector-providers/CoreSelectorProvider.vue b/ui/console-src/modules/contents/attachments/components/selector-providers/CoreSelectorProvider.vue index 3c2b08f5f3..bab04c0758 100644 --- a/ui/console-src/modules/contents/attachments/components/selector-providers/CoreSelectorProvider.vue +++ b/ui/console-src/modules/contents/attachments/components/selector-providers/CoreSelectorProvider.vue @@ -9,19 +9,29 @@ import { IconCheckboxCircle, IconCheckboxFill, IconEye, + IconGrid, + IconList, + IconRefreshLine, IconUpload, VButton, VCard, VEmpty, + VLoading, VPagination, VSpace, } from "@halo-dev/components"; import type { AttachmentLike } from "@halo-dev/console-shared"; -import { computed, ref, watchEffect } from "vue"; +import { useLocalStorage } from "@vueuse/core"; +import { computed, ref, watch, watchEffect } from "vue"; +import { useI18n } from "vue-i18n"; import { useAttachmentControl } from "../../composables/use-attachment"; +import { useFetchAttachmentPolicy } from "../../composables/use-attachment-policy"; import AttachmentDetailModal from "../AttachmentDetailModal.vue"; import AttachmentGroupList from "../AttachmentGroupList.vue"; import AttachmentUploadModal from "../AttachmentUploadModal.vue"; +import AttachmentSelectorListItem from "./components/AttachmentSelectorListItem.vue"; + +const { t } = useI18n(); const props = withDefaults( defineProps<{ @@ -43,7 +53,12 @@ const emit = defineEmits<{ (event: "change-provider", providerId: string): void; }>(); +const { policies } = useFetchAttachmentPolicy(); + +const keyword = ref(""); const selectedGroup = ref(); +const selectedPolicy = ref(); +const selectedSort = ref(); const page = ref(1); const size = ref(20); @@ -59,15 +74,35 @@ const { handleSelectNext, handleReset, isChecked, + isFetching, } = useAttachmentControl({ groupName: selectedGroup, + policyName: selectedPolicy, + sort: selectedSort, accepts: computed(() => { return props.accepts; }), page, size, + keyword, }); +watch( + () => [selectedPolicy.value, selectedSort.value, keyword.value], + () => { + page.value = 1; + } +); + +const hasFilters = computed(() => { + return selectedPolicy.value || selectedSort.value; +}); + +function handleClearFilters() { + selectedPolicy.value = undefined; + selectedSort.value = undefined; +} + const uploadVisible = ref(false); const detailVisible = ref(false); @@ -106,9 +141,119 @@ function onGroupSelect(group: Group) { selectedGroup.value = group.metadata.name; handleReset(); } + +// View type +const viewTypes = [ + { + name: "list", + tooltip: t("core.attachment.filters.view_type.items.list"), + icon: IconList, + }, + { + name: "grid", + tooltip: t("core.attachment.filters.view_type.items.grid"), + icon: IconGrid, + }, +]; + +const viewType = useLocalStorage("attachment-selector-view-type", "grid");