From 610538ca02666b0250adbeef3b7bebbf8f7d8330 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Wed, 2 Aug 2023 21:24:02 +0600 Subject: [PATCH] chore: type and ux improvement for SmartTree (#3126) --- .../src/components/collections/Collection.vue | 102 +++++++----------- .../src/components/smart/Tree.vue | 1 + .../src/components/smart/TreeBranch.vue | 12 ++- 3 files changed, 48 insertions(+), 67 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/Collection.vue b/packages/hoppscotch-common/src/components/collections/Collection.vue index 0c069a545..44caea729 100644 --- a/packages/hoppscotch-common/src/components/collections/Collection.vue +++ b/packages/hoppscotch-common/src/components/collections/Collection.vue @@ -193,7 +193,7 @@ import IconTrash2 from "~icons/lucide/trash-2" import IconEdit from "~icons/lucide/edit" import IconFolder from "~icons/lucide/folder" import IconFolderOpen from "~icons/lucide/folder-open" -import { PropType, ref, computed, watch } from "vue" +import { ref, computed, watch } from "vue" import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { useI18n } from "@composables/i18n" import { TippyComponent } from "vue-tippy" @@ -209,67 +209,36 @@ type FolderType = "collection" | "folder" const t = useI18n() -const props = defineProps({ - id: { - type: String, - default: "", - required: true, - }, - parentID: { - type: String as PropType, - default: null, - required: false, - }, - data: { - type: Object as PropType | TeamCollection>, - default: () => ({}), - required: true, - }, - collectionsType: { - type: String as PropType, - default: "my-collections", - required: true, - }, - /** - * Collection component can be used for both collections and folders. - * folderType is used to determine which one it is. - */ - folderType: { - type: String as PropType, - default: "collection", - required: true, - }, - isOpen: { - type: Boolean, - default: false, - required: true, - }, - isSelected: { - type: Boolean as PropType, - default: false, - required: false, - }, - exportLoading: { - type: Boolean, - default: false, - required: false, - }, - hasNoTeamAccess: { - type: Boolean, - default: false, - required: false, - }, - collectionMoveLoading: { - type: Array as PropType, - default: () => [], - required: false, - }, - isLastItem: { - type: Boolean, - default: false, - required: false, - }, -}) +const props = withDefaults( + defineProps<{ + id: string + parentID?: string | null + data: HoppCollection | TeamCollection + /** + * Collection component can be used for both collections and folders. + * folderType is used to determine which one it is. + */ + collectionsType: CollectionType + folderType: FolderType + isOpen: boolean + isSelected?: boolean | null + exportLoading?: boolean + hasNoTeamAccess?: boolean + collectionMoveLoading?: string[] + isLastItem?: boolean + }>(), + { + id: "", + parentID: null, + collectionsType: "my-collections", + folderType: "collection", + isOpen: false, + isSelected: false, + exportLoading: false, + hasNoTeamAccess: false, + isLastItem: false, + } +) const emit = defineEmits<{ (event: "toggle-children"): void @@ -448,8 +417,13 @@ const notSameDestination = computed(() => { }) const isCollLoading = computed(() => { - if (props.collectionMoveLoading.length > 0 && props.data.id) { - return props.collectionMoveLoading.includes(props.data.id) + const { collectionMoveLoading } = props + if ( + collectionMoveLoading && + collectionMoveLoading.length > 0 && + props.data.id + ) { + return collectionMoveLoading.includes(props.data.id) } else { return false } diff --git a/packages/hoppscotch-common/src/components/smart/Tree.vue b/packages/hoppscotch-common/src/components/smart/Tree.vue index 3c9a07459..781459254 100644 --- a/packages/hoppscotch-common/src/components/smart/Tree.vue +++ b/packages/hoppscotch-common/src/components/smart/Tree.vue @@ -10,6 +10,7 @@ class="flex flex-col flex-1" > diff --git a/packages/hoppscotch-common/src/components/smart/TreeBranch.vue b/packages/hoppscotch-common/src/components/smart/TreeBranch.vue index 45366755a..9fcac990e 100644 --- a/packages/hoppscotch-common/src/components/smart/TreeBranch.vue +++ b/packages/hoppscotch-common/src/components/smart/TreeBranch.vue @@ -85,19 +85,25 @@ const props = defineProps<{ * The node item that will be used to render the tree branch content */ nodeItem: TreeNode + /** + * Total number of rootNode + */ + rootNodesLength?: number }>() const CHILD_SLOT_NAME = "default" const t = useI18n() +const isOnlyRootChild = computed(() => props.rootNodesLength === 1) + /** * Marks whether the children on this branch were ever rendered * See the usage inside '