refactor: unify markup
This commit is contained in:
@@ -1,52 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="!activeWorkspaceHandle">No Workspace Selected.</div>
|
<div v-if="!activeWorkspaceHandle">No Workspace Selected.</div>
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
:class="{
|
|
||||||
'rounded border border-divider': saveRequest,
|
|
||||||
'bg-primaryDark':
|
|
||||||
draggingToRoot && currentReorderingStatus.type !== 'request',
|
|
||||||
}"
|
|
||||||
class="flex-1"
|
|
||||||
@drop.prevent="dropToRoot"
|
|
||||||
@dragover.prevent="draggingToRoot = true"
|
|
||||||
@dragend="draggingToRoot = false"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="sticky z-10 flex flex-shrink-0 flex-col overflow-x-auto border-b border-dividerLight bg-primary"
|
|
||||||
:style="{
|
|
||||||
top: 0,
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<WorkspaceCurrent :section="t('tab.collections')" />
|
|
||||||
<input
|
|
||||||
v-model="searchText"
|
|
||||||
type="search"
|
|
||||||
autocomplete="off"
|
|
||||||
class="flex h-8 w-full bg-transparent p-4 py-2"
|
|
||||||
:placeholder="t('action.search')"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<NewCollectionsRest
|
<NewCollectionsRest
|
||||||
v-if="platform === 'rest'"
|
v-else-if="platform === 'rest'"
|
||||||
:picked="picked"
|
:picked="picked"
|
||||||
:save-request="saveRequest"
|
:save-request="saveRequest"
|
||||||
:workspace-handle="activeWorkspaceHandle"
|
:workspace-handle="activeWorkspaceHandle"
|
||||||
@select="(payload) => emit('select', payload)"
|
@select="(payload) => emit('select', payload)"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { ref } from "vue"
|
|
||||||
import { useI18n } from "~/composables/i18n"
|
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
|
||||||
import { useToast } from "~/composables/toast"
|
|
||||||
import { Picked } from "~/helpers/types/HoppPicked"
|
import { Picked } from "~/helpers/types/HoppPicked"
|
||||||
import toast from "~/modules/toast"
|
|
||||||
import { moveRESTFolder } from "~/newstore/collections"
|
|
||||||
import { currentReorderingStatus$ } from "~/newstore/reordering"
|
|
||||||
import { NewWorkspaceService } from "~/services/new-workspace"
|
import { NewWorkspaceService } from "~/services/new-workspace"
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -59,50 +26,7 @@ const emit = defineEmits<{
|
|||||||
(event: "select", payload: Picked | null): void
|
(event: "select", payload: Picked | null): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const t = useI18n()
|
|
||||||
const toast = useToast()
|
|
||||||
|
|
||||||
const draggingToRoot = ref(false)
|
|
||||||
const searchText = ref("")
|
|
||||||
|
|
||||||
const workspaceService = useService(NewWorkspaceService)
|
const workspaceService = useService(NewWorkspaceService)
|
||||||
|
|
||||||
const activeWorkspaceHandle = workspaceService.activeWorkspaceHandle
|
const activeWorkspaceHandle = workspaceService.activeWorkspaceHandle
|
||||||
|
|
||||||
const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, {
|
|
||||||
type: "collection",
|
|
||||||
id: "",
|
|
||||||
parentID: "",
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is called when the user drops the collection
|
|
||||||
* to the root
|
|
||||||
* @param payload - object containing the collection index dragged
|
|
||||||
*/
|
|
||||||
const dropToRoot = ({ dataTransfer }: DragEvent) => {
|
|
||||||
if (dataTransfer) {
|
|
||||||
const collectionIndexDragged = dataTransfer.getData("collectionIndex")
|
|
||||||
if (!collectionIndexDragged) return
|
|
||||||
// check if the collection is already in the root
|
|
||||||
if (isAlreadyInRoot(collectionIndexDragged)) {
|
|
||||||
toast.error(`${t("collection.invalid_root_move")}`)
|
|
||||||
} else {
|
|
||||||
moveRESTFolder(collectionIndexDragged, null)
|
|
||||||
toast.success(`${t("collection.moved")}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
draggingToRoot.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the collection is already in the root
|
|
||||||
* @param id - path of the collection
|
|
||||||
* @returns boolean - true if the collection is already in the root
|
|
||||||
*/
|
|
||||||
const isAlreadyInRoot = (id: string) => {
|
|
||||||
const indexPath = id.split("/")
|
|
||||||
return indexPath.length === 1
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,4 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div
|
||||||
|
:class="{
|
||||||
|
'rounded border border-divider': saveRequest,
|
||||||
|
'bg-primaryDark':
|
||||||
|
draggingToRoot && currentReorderingStatus.type !== 'request',
|
||||||
|
}"
|
||||||
|
class="flex-1"
|
||||||
|
@drop.prevent="dropToRoot"
|
||||||
|
@dragover.prevent="draggingToRoot = true"
|
||||||
|
@dragend="draggingToRoot = false"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="sticky z-10 flex flex-shrink-0 flex-col overflow-x-auto border-b border-dividerLight bg-primary"
|
||||||
|
:style="{
|
||||||
|
top: 0,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<WorkspaceCurrent :section="t('tab.collections')" />
|
||||||
|
<input
|
||||||
|
v-model="searchText"
|
||||||
|
type="search"
|
||||||
|
autocomplete="off"
|
||||||
|
class="flex h-8 w-full bg-transparent p-4 py-2"
|
||||||
|
:placeholder="t('action.search')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="flex flex-1 flex-col">
|
<div class="flex flex-1 flex-col">
|
||||||
<div
|
<div
|
||||||
class="sticky z-10 flex flex-1 justify-between border-b border-dividerLight bg-primary"
|
class="sticky z-10 flex flex-1 justify-between border-b border-dividerLight bg-primary"
|
||||||
@@ -70,7 +96,9 @@
|
|||||||
toggleChildren(),
|
toggleChildren(),
|
||||||
saveRequest &&
|
saveRequest &&
|
||||||
onSelectPick({
|
onSelectPick({
|
||||||
pickedType: isAlreadyInRoot(node.data.value.collectionID)
|
pickedType: isAlreadyInRoot(
|
||||||
|
node.data.value.collectionID
|
||||||
|
)
|
||||||
? 'my-collection'
|
? 'my-collection'
|
||||||
: 'my-folder',
|
: 'my-folder',
|
||||||
...getCollectionIndexPathArgs(
|
...getCollectionIndexPathArgs(
|
||||||
@@ -211,6 +239,7 @@
|
|||||||
@set-collection-properties="setCollectionProperties"
|
@set-collection-properties="setCollectionProperties"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -229,7 +258,6 @@ import { WorkspaceRESTCollectionTreeAdapter } from "~/helpers/adapters/Workspace
|
|||||||
import { TeamCollection } from "~/helpers/backend/graphql"
|
import { TeamCollection } from "~/helpers/backend/graphql"
|
||||||
import {
|
import {
|
||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
resolveSaveContextOnCollectionReorder,
|
|
||||||
updateInheritedPropertiesForAffectedRequests,
|
updateInheritedPropertiesForAffectedRequests,
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
@@ -253,6 +281,7 @@ import { RESTTabService } from "~/services/tab/rest"
|
|||||||
import IconImport from "~icons/lucide/folder-down"
|
import IconImport from "~icons/lucide/folder-down"
|
||||||
import IconHelpCircle from "~icons/lucide/help-circle"
|
import IconHelpCircle from "~icons/lucide/help-circle"
|
||||||
import IconPlus from "~icons/lucide/plus"
|
import IconPlus from "~icons/lucide/plus"
|
||||||
|
import { currentReorderingStatus$ } from "~/newstore/reordering"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -306,6 +335,12 @@ const emit = defineEmits<{
|
|||||||
const workspaceService = useService(NewWorkspaceService)
|
const workspaceService = useService(NewWorkspaceService)
|
||||||
const restCollectionState = useReadonlyStream(restCollections$, [])
|
const restCollectionState = useReadonlyStream(restCollections$, [])
|
||||||
|
|
||||||
|
const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, {
|
||||||
|
type: "collection",
|
||||||
|
id: "",
|
||||||
|
parentID: "",
|
||||||
|
})
|
||||||
|
|
||||||
const treeAdapter = markRaw(
|
const treeAdapter = markRaw(
|
||||||
new WorkspaceRESTCollectionTreeAdapter(
|
new WorkspaceRESTCollectionTreeAdapter(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
@@ -313,6 +348,9 @@ const treeAdapter = markRaw(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const draggingToRoot = ref(false)
|
||||||
|
const searchText = ref("")
|
||||||
|
|
||||||
const modalLoadingState = ref(false)
|
const modalLoadingState = ref(false)
|
||||||
|
|
||||||
const showModalAdd = ref(false)
|
const showModalAdd = ref(false)
|
||||||
@@ -1292,6 +1330,27 @@ const dropEvent = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called when the user drops the collection
|
||||||
|
* to the root
|
||||||
|
* @param payload - object containing the collection index dragged
|
||||||
|
*/
|
||||||
|
const dropToRoot = ({ dataTransfer }: DragEvent) => {
|
||||||
|
if (dataTransfer) {
|
||||||
|
const collectionIndexDragged = dataTransfer.getData("collectionIndex")
|
||||||
|
if (!collectionIndexDragged) return
|
||||||
|
// check if the collection is already in the root
|
||||||
|
if (isAlreadyInRoot(collectionIndexDragged)) {
|
||||||
|
toast.error(`${t("collection.invalid_root_move")}`)
|
||||||
|
} else {
|
||||||
|
moveRESTFolder(collectionIndexDragged, null)
|
||||||
|
toast.success(`${t("collection.moved")}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
draggingToRoot.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const dropRequest = (payload: {
|
const dropRequest = (payload: {
|
||||||
parentCollectionIndexPath?: string | undefined
|
parentCollectionIndexPath?: string | undefined
|
||||||
requestIndex: string
|
requestIndex: string
|
||||||
|
|||||||
@@ -64,9 +64,14 @@ export function resolveSaveContextOnCollectionReorder(
|
|||||||
const tabService = getService(RESTTabService)
|
const tabService = getService(RESTTabService)
|
||||||
|
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
const tabs = tabService.getTabsRefTo((tab) => {
|
||||||
|
if (tab.document.saveContext?.originLocation === "user-collection") {
|
||||||
|
return affectedPaths.has(tab.document.saveContext.folderPath)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
tab.document.saveContext?.originLocation === "user-collection" &&
|
tab.document.saveContext?.originLocation ===
|
||||||
affectedPaths.has(tab.document.saveContext.folderPath)
|
"workspace-user-collection" &&
|
||||||
|
affectedPaths.has(tab.document.saveContext.collectionID)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -77,6 +82,16 @@ export function resolveSaveContextOnCollectionReorder(
|
|||||||
)!
|
)!
|
||||||
tab.value.document.saveContext.folderPath = newPath
|
tab.value.document.saveContext.folderPath = newPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
tab.value.document.saveContext?.originLocation ===
|
||||||
|
"workspace-user-collection"
|
||||||
|
) {
|
||||||
|
const newPath = affectedPaths.get(
|
||||||
|
tab.value.document.saveContext?.collectionID
|
||||||
|
)!
|
||||||
|
tab.value.document.saveContext.collectionID = newPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +108,14 @@ export function updateSaveContextForAffectedRequests(
|
|||||||
) {
|
) {
|
||||||
const tabService = getService(RESTTabService)
|
const tabService = getService(RESTTabService)
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
const tabs = tabService.getTabsRefTo((tab) => {
|
||||||
|
if (tab.document.saveContext?.originLocation === "user-collection") {
|
||||||
|
return tab.document.saveContext.folderPath.startsWith(oldFolderPath)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
tab.document.saveContext?.originLocation === "user-collection" &&
|
tab.document.saveContext?.originLocation ===
|
||||||
tab.document.saveContext.folderPath.startsWith(oldFolderPath)
|
"workspace-user-collection" &&
|
||||||
|
tab.document.saveContext.collectionID.startsWith(oldFolderPath)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -109,6 +129,19 @@ export function updateSaveContextForAffectedRequests(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
tab.value.document.saveContext?.originLocation ===
|
||||||
|
"workspace-user-collection"
|
||||||
|
) {
|
||||||
|
tab.value.document.saveContext = {
|
||||||
|
...tab.value.document.saveContext,
|
||||||
|
collectionID: tab.value.document.saveContext.collectionID.replace(
|
||||||
|
oldFolderPath,
|
||||||
|
newFolderPath
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -281,9 +314,14 @@ export function updateInheritedPropertiesForAffectedRequests(
|
|||||||
function resetSaveContextForAffectedRequests(folderPath: string) {
|
function resetSaveContextForAffectedRequests(folderPath: string) {
|
||||||
const tabService = getService(RESTTabService)
|
const tabService = getService(RESTTabService)
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
const tabs = tabService.getTabsRefTo((tab) => {
|
||||||
|
if (tab.document.saveContext?.originLocation === "user-collection") {
|
||||||
|
return tab.document.saveContext.folderPath.startsWith(folderPath)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
tab.document.saveContext?.originLocation === "user-collection" &&
|
tab.document.saveContext?.originLocation ===
|
||||||
tab.document.saveContext.folderPath.startsWith(folderPath)
|
"workspace-user-collection" &&
|
||||||
|
tab.document.saveContext.collectionID.startsWith(folderPath)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,21 @@ export function resolveSaveContextOnRequestReorder(payload: {
|
|||||||
|
|
||||||
const tabService = getService(RESTTabService)
|
const tabService = getService(RESTTabService)
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
const tabs = tabService.getTabsRefTo((tab) => {
|
||||||
|
if (tab.document.saveContext?.originLocation === "user-collection") {
|
||||||
return (
|
return (
|
||||||
tab.document.saveContext?.originLocation === "user-collection" &&
|
|
||||||
tab.document.saveContext.folderPath === folderPath &&
|
tab.document.saveContext.folderPath === folderPath &&
|
||||||
affectedIndexes.has(tab.document.saveContext.requestIndex)
|
affectedIndexes.has(tab.document.saveContext.requestIndex)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
tab.document.saveContext?.originLocation ===
|
||||||
|
"workspace-user-collection" &&
|
||||||
|
tab.document.saveContext.collectionID === folderPath &&
|
||||||
|
affectedIndexes.has(
|
||||||
|
parseInt(tab.document.saveContext.requestID.split("/").slice(-1)[0])
|
||||||
|
)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
|
|||||||
@@ -508,13 +508,11 @@ export class PersonalWorkspaceProviderService
|
|||||||
draggedCollectionIndex,
|
draggedCollectionIndex,
|
||||||
destinationCollectionIndex
|
destinationCollectionIndex
|
||||||
)
|
)
|
||||||
// resolveSaveContextOnCollectionReorder({
|
resolveSaveContextOnCollectionReorder({
|
||||||
// lastIndex: pathToLastIndex(draggedCollectionIndex),
|
lastIndex: this.pathToLastIndex(draggedCollectionIndex),
|
||||||
// newIndex: pathToLastIndex(
|
newIndex: this.pathToLastIndex(destinationCollectionIndex ?? ""),
|
||||||
// destinationCollectionIndex ? destinationCollectionIndex : ""
|
folderPath: draggedCollectionIndex.split("/").slice(0, -1).join("/"),
|
||||||
// ),
|
})
|
||||||
// folderPath: draggedCollectionIndex.split("/").slice(0, -1).join("/"),
|
|
||||||
// })
|
|
||||||
|
|
||||||
return Promise.resolve(E.right(undefined))
|
return Promise.resolve(E.right(undefined))
|
||||||
}
|
}
|
||||||
@@ -533,34 +531,38 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
const draggedCollectionIndex = collectionHandle.value.data.collectionID
|
const draggedCollectionIndex = collectionHandle.value.data.collectionID
|
||||||
|
|
||||||
// const parentFolder = draggedCollectionIndex
|
|
||||||
// .split("/")
|
|
||||||
// .slice(0, -1)
|
|
||||||
// .join("/") // remove last folder to get parent folder
|
|
||||||
|
|
||||||
// const totalFoldersOfDestinationCollection =
|
|
||||||
// getFoldersByPath(
|
|
||||||
// restCollectionStore.value.state,
|
|
||||||
// destinationCollectionIndex
|
|
||||||
// ).length - (parentFolder === destinationCollectionIndex ? 1 : 0)
|
|
||||||
|
|
||||||
moveRESTFolder(draggedCollectionIndex, destinationCollectionIndex)
|
moveRESTFolder(draggedCollectionIndex, destinationCollectionIndex)
|
||||||
|
|
||||||
// resolveSaveContextOnCollectionReorder(
|
if (destinationCollectionIndex === null) {
|
||||||
// {
|
return Promise.resolve(E.right(undefined))
|
||||||
// lastIndex: pathToLastIndex(draggedCollectionIndex),
|
}
|
||||||
// newIndex: -1,
|
|
||||||
// folderPath: parentFolder,
|
|
||||||
// length: getFoldersByPath(restCollectionStore.value.state, parentFolder)
|
|
||||||
// .length,
|
|
||||||
// },
|
|
||||||
// "drop"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// updateSaveContextForAffectedRequests(
|
const parentFolder = draggedCollectionIndex
|
||||||
// draggedCollectionIndex,
|
.split("/")
|
||||||
// `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
|
.slice(0, -1)
|
||||||
// )
|
.join("/") // remove last folder to get parent folder
|
||||||
|
|
||||||
|
const totalFoldersOfDestinationCollection =
|
||||||
|
getFoldersByPath(
|
||||||
|
restCollectionStore.value.state,
|
||||||
|
destinationCollectionIndex
|
||||||
|
).length - (parentFolder === destinationCollectionIndex ? 1 : 0)
|
||||||
|
|
||||||
|
resolveSaveContextOnCollectionReorder(
|
||||||
|
{
|
||||||
|
lastIndex: this.pathToLastIndex(draggedCollectionIndex),
|
||||||
|
newIndex: -1,
|
||||||
|
folderPath: parentFolder,
|
||||||
|
length: getFoldersByPath(restCollectionStore.value.state, parentFolder)
|
||||||
|
.length,
|
||||||
|
},
|
||||||
|
"drop"
|
||||||
|
)
|
||||||
|
|
||||||
|
updateSaveContextForAffectedRequests(
|
||||||
|
draggedCollectionIndex,
|
||||||
|
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
|
||||||
|
)
|
||||||
|
|
||||||
// const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
// const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||||
// `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
|
// `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user