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
|
<NewCollectionsRest
|
||||||
:class="{
|
v-else-if="platform === 'rest'"
|
||||||
'rounded border border-divider': saveRequest,
|
:picked="picked"
|
||||||
'bg-primaryDark':
|
:save-request="saveRequest"
|
||||||
draggingToRoot && currentReorderingStatus.type !== 'request',
|
:workspace-handle="activeWorkspaceHandle"
|
||||||
}"
|
@select="(payload) => emit('select', payload)"
|
||||||
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
|
|
||||||
v-if="platform === 'rest'"
|
|
||||||
:picked="picked"
|
|
||||||
:save-request="saveRequest"
|
|
||||||
:workspace-handle="activeWorkspaceHandle"
|
|
||||||
@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,215 +1,244 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-1 flex-col">
|
<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
|
<div
|
||||||
class="sticky z-10 flex flex-1 justify-between border-b border-dividerLight bg-primary"
|
class="sticky z-10 flex flex-shrink-0 flex-col overflow-x-auto border-b border-dividerLight bg-primary"
|
||||||
:style="
|
:style="{
|
||||||
saveRequest
|
top: 0,
|
||||||
? 'top: calc(var(--upper-primary-sticky-fold) - var(--line-height-body))'
|
}"
|
||||||
: 'top: var(--upper-primary-sticky-fold)'
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<HoppButtonSecondary
|
<WorkspaceCurrent :section="t('tab.collections')" />
|
||||||
:icon="IconPlus"
|
<input
|
||||||
:label="t('add.new')"
|
v-model="searchText"
|
||||||
class="!rounded-none"
|
type="search"
|
||||||
@click="showModalAdd = true"
|
autocomplete="off"
|
||||||
|
class="flex h-8 w-full bg-transparent p-4 py-2"
|
||||||
|
:placeholder="t('action.search')"
|
||||||
/>
|
/>
|
||||||
<span class="flex">
|
|
||||||
<HoppButtonSecondary
|
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
|
||||||
to="https://docs.hoppscotch.io/documentation/features/collections"
|
|
||||||
blank
|
|
||||||
:title="t('app.wiki')"
|
|
||||||
:icon="IconHelpCircle"
|
|
||||||
/>
|
|
||||||
<HoppButtonSecondary
|
|
||||||
v-if="!saveRequest"
|
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
|
||||||
:icon="IconImport"
|
|
||||||
:title="t('modal.import_export')"
|
|
||||||
@click="displayModalImportExport(true)"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-1 flex-col">
|
<div class="flex flex-1 flex-col">
|
||||||
<HoppSmartTree :adapter="treeAdapter">
|
<div
|
||||||
<template
|
class="sticky z-10 flex flex-1 justify-between border-b border-dividerLight bg-primary"
|
||||||
#content="{ highlightChildren, isOpen, node, toggleChildren }"
|
:style="
|
||||||
>
|
saveRequest
|
||||||
<NewCollectionsRestCollection
|
? 'top: calc(var(--upper-primary-sticky-fold) - var(--line-height-body))'
|
||||||
v-if="node.data.type === 'collection'"
|
: 'top: var(--upper-primary-sticky-fold)'
|
||||||
:collection-view="node.data.value"
|
"
|
||||||
:is-last-item="node.data.value.isLastItem"
|
>
|
||||||
:is-open="isOpen"
|
<HoppButtonSecondary
|
||||||
:is-selected="
|
:icon="IconPlus"
|
||||||
isSelected(
|
:label="t('add.new')"
|
||||||
getCollectionIndexPathArgs(node.data.value.collectionID)
|
class="!rounded-none"
|
||||||
)
|
@click="showModalAdd = true"
|
||||||
"
|
/>
|
||||||
:save-request="saveRequest"
|
<span class="flex">
|
||||||
@add-request="addRequest"
|
<HoppButtonSecondary
|
||||||
@add-child-collection="addChildCollection"
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
@dragging="
|
to="https://docs.hoppscotch.io/documentation/features/collections"
|
||||||
(isDraging) =>
|
blank
|
||||||
highlightChildren(
|
:title="t('app.wiki')"
|
||||||
isDraging ? node.data.value.collectionID : null
|
:icon="IconHelpCircle"
|
||||||
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-if="!saveRequest"
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:icon="IconImport"
|
||||||
|
:title="t('modal.import_export')"
|
||||||
|
@click="displayModalImportExport(true)"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-1 flex-col">
|
||||||
|
<HoppSmartTree :adapter="treeAdapter">
|
||||||
|
<template
|
||||||
|
#content="{ highlightChildren, isOpen, node, toggleChildren }"
|
||||||
|
>
|
||||||
|
<NewCollectionsRestCollection
|
||||||
|
v-if="node.data.type === 'collection'"
|
||||||
|
:collection-view="node.data.value"
|
||||||
|
:is-last-item="node.data.value.isLastItem"
|
||||||
|
:is-open="isOpen"
|
||||||
|
:is-selected="
|
||||||
|
isSelected(
|
||||||
|
getCollectionIndexPathArgs(node.data.value.collectionID)
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
@drag-event="dragEvent($event, node.data.value.collectionID)"
|
:save-request="saveRequest"
|
||||||
@drop-event="dropEvent($event, node.data.value.collectionID)"
|
@add-request="addRequest"
|
||||||
@edit-child-collection="editChildCollection"
|
@add-child-collection="addChildCollection"
|
||||||
@edit-root-collection="editRootCollection"
|
@dragging="
|
||||||
@edit-collection-properties="editCollectionProperties"
|
(isDraging) =>
|
||||||
@export-collection="exportCollection"
|
highlightChildren(
|
||||||
@remove-child-collection="removeChildCollection"
|
isDraging ? node.data.value.collectionID : null
|
||||||
@remove-root-collection="removeRootCollection"
|
)
|
||||||
@select-pick="onSelectPick"
|
"
|
||||||
@toggle-children="
|
@drag-event="dragEvent($event, node.data.value.collectionID)"
|
||||||
() => {
|
@drop-event="dropEvent($event, node.data.value.collectionID)"
|
||||||
toggleChildren(),
|
@edit-child-collection="editChildCollection"
|
||||||
saveRequest &&
|
@edit-root-collection="editRootCollection"
|
||||||
onSelectPick({
|
@edit-collection-properties="editCollectionProperties"
|
||||||
pickedType: isAlreadyInRoot(node.data.value.collectionID)
|
@export-collection="exportCollection"
|
||||||
? 'my-collection'
|
@remove-child-collection="removeChildCollection"
|
||||||
: 'my-folder',
|
@remove-root-collection="removeRootCollection"
|
||||||
...getCollectionIndexPathArgs(
|
@select-pick="onSelectPick"
|
||||||
node.data.value.collectionID
|
@toggle-children="
|
||||||
),
|
() => {
|
||||||
})
|
toggleChildren(),
|
||||||
}
|
saveRequest &&
|
||||||
"
|
onSelectPick({
|
||||||
@update-collection-order="
|
pickedType: isAlreadyInRoot(
|
||||||
updateCollectionOrder($event, {
|
node.data.value.collectionID
|
||||||
destinationCollectionIndex: node.data.value.collectionID,
|
)
|
||||||
destinationCollectionParentIndex:
|
? 'my-collection'
|
||||||
node.data.value.parentCollectionID,
|
: 'my-folder',
|
||||||
})
|
...getCollectionIndexPathArgs(
|
||||||
"
|
node.data.value.collectionID
|
||||||
@update-last-collection-order="
|
),
|
||||||
updateCollectionOrder($event, {
|
})
|
||||||
destinationCollectionIndex: null,
|
}
|
||||||
destinationCollectionParentIndex:
|
"
|
||||||
node.data.value.parentCollectionID,
|
@update-collection-order="
|
||||||
})
|
updateCollectionOrder($event, {
|
||||||
"
|
destinationCollectionIndex: node.data.value.collectionID,
|
||||||
/>
|
destinationCollectionParentIndex:
|
||||||
|
node.data.value.parentCollectionID,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
@update-last-collection-order="
|
||||||
|
updateCollectionOrder($event, {
|
||||||
|
destinationCollectionIndex: null,
|
||||||
|
destinationCollectionParentIndex:
|
||||||
|
node.data.value.parentCollectionID,
|
||||||
|
})
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
|
||||||
<NewCollectionsRestRequest
|
<NewCollectionsRestRequest
|
||||||
v-else-if="node.data.type === 'request'"
|
v-else-if="node.data.type === 'request'"
|
||||||
:is-active="isActiveRequest(node.data.value)"
|
:is-active="isActiveRequest(node.data.value)"
|
||||||
:is-last-item="node.data.value.isLastItem"
|
:is-last-item="node.data.value.isLastItem"
|
||||||
:is-selected="
|
:is-selected="
|
||||||
isSelected(getRequestIndexPathArgs(node.data.value.requestID))
|
isSelected(getRequestIndexPathArgs(node.data.value.requestID))
|
||||||
"
|
"
|
||||||
:request-view="node.data.value"
|
:request-view="node.data.value"
|
||||||
:save-request="saveRequest"
|
:save-request="saveRequest"
|
||||||
@drag-request="
|
@drag-request="
|
||||||
dragRequest($event, {
|
dragRequest($event, {
|
||||||
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
||||||
requestIndex: node.data.value.requestID,
|
requestIndex: node.data.value.requestID,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
@duplicate-request="duplicateRequest"
|
@duplicate-request="duplicateRequest"
|
||||||
@edit-request="editRequest"
|
@edit-request="editRequest"
|
||||||
@remove-request="removeRequest"
|
@remove-request="removeRequest"
|
||||||
@select-pick="onSelectPick"
|
@select-pick="onSelectPick"
|
||||||
@select-request="selectRequest"
|
@select-request="selectRequest"
|
||||||
@share-request="shareRequest"
|
@share-request="shareRequest"
|
||||||
@update-request-order="
|
@update-request-order="
|
||||||
updateRequestOrder($event, {
|
updateRequestOrder($event, {
|
||||||
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
||||||
requestIndex: node.data.value.requestID,
|
requestIndex: node.data.value.requestID,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
@update-last-request-order="
|
@update-last-request-order="
|
||||||
updateRequestOrder($event, {
|
updateRequestOrder($event, {
|
||||||
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
parentCollectionIndexPath: node.data.value.parentCollectionID,
|
||||||
requestIndex: null,
|
requestIndex: null,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
<div v-else @click="toggleChildren">
|
<div v-else @click="toggleChildren">
|
||||||
{{ node.data.value }}
|
{{ node.data.value }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #emptyNode>
|
<template #emptyNode>
|
||||||
<!-- TODO: Implement -->
|
<!-- TODO: Implement -->
|
||||||
<div>Empty Node!</div>
|
<div>Empty Node!</div>
|
||||||
</template>
|
</template>
|
||||||
</HoppSmartTree>
|
</HoppSmartTree>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <div
|
<!-- <div
|
||||||
class="py-15 hidden flex-1 flex-col items-center justify-center bg-primaryDark px-4 text-secondaryLight"
|
class="py-15 hidden flex-1 flex-col items-center justify-center bg-primaryDark px-4 text-secondaryLight"
|
||||||
:class="{
|
:class="{
|
||||||
'!flex': draggingToRoot && currentReorderingStatus.type !== 'request',
|
'!flex': draggingToRoot && currentReorderingStatus.type !== 'request',
|
||||||
}"
|
}"
|
||||||
> -->
|
> -->
|
||||||
|
|
||||||
<CollectionsAdd
|
<CollectionsAdd
|
||||||
:show="showModalAdd"
|
:show="showModalAdd"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@submit="addNewRootCollection"
|
@submit="addNewRootCollection"
|
||||||
@hide-modal="showModalAdd = false"
|
@hide-modal="showModalAdd = false"
|
||||||
/>
|
/>
|
||||||
<CollectionsAddRequest
|
<CollectionsAddRequest
|
||||||
:show="showModalAddRequest"
|
:show="showModalAddRequest"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@add-request="onAddRequest"
|
@add-request="onAddRequest"
|
||||||
@hide-modal="displayModalAddRequest(false)"
|
@hide-modal="displayModalAddRequest(false)"
|
||||||
/>
|
/>
|
||||||
<CollectionsAddFolder
|
<CollectionsAddFolder
|
||||||
:show="showModalAddChildColl"
|
:show="showModalAddChildColl"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@add-folder="onAddChildCollection"
|
@add-folder="onAddChildCollection"
|
||||||
@hide-modal="displayModalAddChildColl(false)"
|
@hide-modal="displayModalAddChildColl(false)"
|
||||||
/>
|
/>
|
||||||
<CollectionsEdit
|
<CollectionsEdit
|
||||||
:show="showModalEditRootColl"
|
:show="showModalEditRootColl"
|
||||||
:editing-collection-name="editingRootCollectionName ?? ''"
|
:editing-collection-name="editingRootCollectionName ?? ''"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@hide-modal="displayModalEditCollection(false)"
|
@hide-modal="displayModalEditCollection(false)"
|
||||||
@submit="onEditRootCollection"
|
@submit="onEditRootCollection"
|
||||||
/>
|
/>
|
||||||
<CollectionsEditFolder
|
<CollectionsEditFolder
|
||||||
:show="showModalEditChildColl"
|
:show="showModalEditChildColl"
|
||||||
:editing-folder-name="editingChildCollectionName ?? ''"
|
:editing-folder-name="editingChildCollectionName ?? ''"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@submit="onEditChildCollection"
|
@submit="onEditChildCollection"
|
||||||
@hide-modal="displayModalEditChildCollection(false)"
|
@hide-modal="displayModalEditChildCollection(false)"
|
||||||
/>
|
/>
|
||||||
<CollectionsEditRequest
|
<CollectionsEditRequest
|
||||||
v-model="editingRequestName"
|
v-model="editingRequestName"
|
||||||
:show="showModalEditRequest"
|
:show="showModalEditRequest"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@submit="onEditRequest"
|
@submit="onEditRequest"
|
||||||
@hide-modal="displayModalEditRequest(false)"
|
@hide-modal="displayModalEditRequest(false)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<HoppSmartConfirmModal
|
<HoppSmartConfirmModal
|
||||||
:show="showConfirmModal"
|
:show="showConfirmModal"
|
||||||
:title="confirmModalTitle"
|
:title="confirmModalTitle"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@hide-modal="showConfirmModal = false"
|
@hide-modal="showConfirmModal = false"
|
||||||
@resolve="resolveConfirmModal"
|
@resolve="resolveConfirmModal"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- TODO: Supply `collectionsType` once teams implementation is in place -->
|
<!-- TODO: Supply `collectionsType` once teams implementation is in place -->
|
||||||
<!-- Defaults to `my-collections` -->
|
<!-- Defaults to `my-collections` -->
|
||||||
<CollectionsImportExport
|
<CollectionsImportExport
|
||||||
v-if="showImportExportModal"
|
v-if="showImportExportModal"
|
||||||
@hide-modal="displayModalImportExport(false)"
|
@hide-modal="displayModalImportExport(false)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- TODO: Remove the `emitWithFullCollection` prop after porting all usages of the below component -->
|
<!-- TODO: Remove the `emitWithFullCollection` prop after porting all usages of the below component -->
|
||||||
<CollectionsProperties
|
<CollectionsProperties
|
||||||
:show="showModalEditProperties"
|
:show="showModalEditProperties"
|
||||||
:editing-properties="editingProperties"
|
:editing-properties="editingProperties"
|
||||||
:emit-with-full-collection="false"
|
:emit-with-full-collection="false"
|
||||||
@hide-modal="displayModalEditProperties(false)"
|
@hide-modal="displayModalEditProperties(false)"
|
||||||
@set-collection-properties="setCollectionProperties"
|
@set-collection-properties="setCollectionProperties"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -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,10 +39,20 @@ 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 (
|
||||||
|
tab.document.saveContext.folderPath === folderPath &&
|
||||||
|
affectedIndexes.has(tab.document.saveContext.requestIndex)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
tab.document.saveContext?.originLocation === "user-collection" &&
|
tab.document.saveContext?.originLocation ===
|
||||||
tab.document.saveContext.folderPath === folderPath &&
|
"workspace-user-collection" &&
|
||||||
affectedIndexes.has(tab.document.saveContext.requestIndex)
|
tab.document.saveContext.collectionID === folderPath &&
|
||||||
|
affectedIndexes.has(
|
||||||
|
parseInt(tab.document.saveContext.requestID.split("/").slice(-1)[0])
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -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