chore: type and ux improvement for SmartTree (#3126)

This commit is contained in:
Anwarul Islam
2023-08-02 21:24:02 +06:00
committed by GitHub
parent 8970ff5c68
commit 610538ca02
3 changed files with 48 additions and 67 deletions

View File

@@ -193,7 +193,7 @@ import IconTrash2 from "~icons/lucide/trash-2"
import IconEdit from "~icons/lucide/edit" import IconEdit from "~icons/lucide/edit"
import IconFolder from "~icons/lucide/folder" import IconFolder from "~icons/lucide/folder"
import IconFolderOpen from "~icons/lucide/folder-open" 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 { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { TippyComponent } from "vue-tippy" import { TippyComponent } from "vue-tippy"
@@ -209,67 +209,36 @@ type FolderType = "collection" | "folder"
const t = useI18n() const t = useI18n()
const props = defineProps({ const props = withDefaults(
id: { defineProps<{
type: String, id: string
default: "", parentID?: string | null
required: true, data: HoppCollection<HoppRESTRequest> | TeamCollection
},
parentID: {
type: String as PropType<string | null>,
default: null,
required: false,
},
data: {
type: Object as PropType<HoppCollection<HoppRESTRequest> | TeamCollection>,
default: () => ({}),
required: true,
},
collectionsType: {
type: String as PropType<CollectionType>,
default: "my-collections",
required: true,
},
/** /**
* Collection component can be used for both collections and folders. * Collection component can be used for both collections and folders.
* folderType is used to determine which one it is. * folderType is used to determine which one it is.
*/ */
folderType: { collectionsType: CollectionType
type: String as PropType<FolderType>, folderType: FolderType
default: "collection", isOpen: boolean
required: true, isSelected?: boolean | null
}, exportLoading?: boolean
isOpen: { hasNoTeamAccess?: boolean
type: Boolean, collectionMoveLoading?: string[]
default: false, isLastItem?: boolean
required: true, }>(),
}, {
isSelected: { id: "",
type: Boolean as PropType<boolean | null>, parentID: null,
default: false, collectionsType: "my-collections",
required: false, folderType: "collection",
}, isOpen: false,
exportLoading: { isSelected: false,
type: Boolean, exportLoading: false,
default: false, hasNoTeamAccess: false,
required: false, isLastItem: false,
}, }
hasNoTeamAccess: { )
type: Boolean,
default: false,
required: false,
},
collectionMoveLoading: {
type: Array as PropType<string[]>,
default: () => [],
required: false,
},
isLastItem: {
type: Boolean,
default: false,
required: false,
},
})
const emit = defineEmits<{ const emit = defineEmits<{
(event: "toggle-children"): void (event: "toggle-children"): void
@@ -448,8 +417,13 @@ const notSameDestination = computed(() => {
}) })
const isCollLoading = computed(() => { const isCollLoading = computed(() => {
if (props.collectionMoveLoading.length > 0 && props.data.id) { const { collectionMoveLoading } = props
return props.collectionMoveLoading.includes(props.data.id) if (
collectionMoveLoading &&
collectionMoveLoading.length > 0 &&
props.data.id
) {
return collectionMoveLoading.includes(props.data.id)
} else { } else {
return false return false
} }

View File

@@ -10,6 +10,7 @@
class="flex flex-col flex-1" class="flex flex-col flex-1"
> >
<SmartTreeBranch <SmartTreeBranch
:root-nodes-length="rootNodes.data.length"
:node-item="rootNode" :node-item="rootNode"
:adapter="adapter as SmartTreeAdapter<T>" :adapter="adapter as SmartTreeAdapter<T>"
> >

View File

@@ -85,19 +85,25 @@ const props = defineProps<{
* The node item that will be used to render the tree branch content * The node item that will be used to render the tree branch content
*/ */
nodeItem: TreeNode<T> nodeItem: TreeNode<T>
/**
* Total number of rootNode
*/
rootNodesLength?: number
}>() }>()
const CHILD_SLOT_NAME = "default" const CHILD_SLOT_NAME = "default"
const t = useI18n() const t = useI18n()
const isOnlyRootChild = computed(() => props.rootNodesLength === 1)
/** /**
* Marks whether the children on this branch were ever rendered * Marks whether the children on this branch were ever rendered
* See the usage inside '<template>' for more info * See the usage inside '<template>' for more info
*/ */
const childrenRendered = ref(false) const childrenRendered = ref(isOnlyRootChild.value)
const showChildren = ref(false) const showChildren = ref(isOnlyRootChild.value)
const isNodeOpen = ref(false) const isNodeOpen = ref(isOnlyRootChild.value)
const highlightNode = ref(false) const highlightNode = ref(false)