refactor: update inheritence when moving request

This commit is contained in:
nivedin
2023-12-04 17:52:49 +05:30
committed by Andrew Bastin
parent 056a8a8719
commit 569c170fec
4 changed files with 74 additions and 10 deletions

View File

@@ -178,6 +178,7 @@
" "
@select="$emit('select', $event)" @select="$emit('select', $event)"
@select-request="$emit('select-request', $event)" @select-request="$emit('select-request', $event)"
@drop-request="$emit('drop-request', $event)"
/> />
<CollectionsGraphqlRequest <CollectionsGraphqlRequest
v-for="(request, index) in collection.requests" v-for="(request, index) in collection.requests"
@@ -241,10 +242,7 @@ import IconSettings2 from "~icons/lucide/settings-2"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useColorMode } from "@composables/theming" import { useColorMode } from "@composables/theming"
import { import { removeGraphqlCollection } from "~/newstore/collections"
removeGraphqlCollection,
moveGraphqlRequest,
} from "~/newstore/collections"
import { Picked } from "~/helpers/types/HoppPicked" import { Picked } from "~/helpers/types/HoppPicked"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { GQLTabService } from "~/services/tab/graphql" import { GQLTabService } from "~/services/tab/graphql"
@@ -282,6 +280,14 @@ const emit = defineEmits<{
): void ): void
(e: "edit-collection"): void (e: "edit-collection"): void
(e: "select-request", i: any): void (e: "select-request", i: any): void
(
e: "drop-request",
payload: {
folderPath: string
requestIndex: string
collectionIndex: number | null
}
): void
}>() }>()
// Template refs // Template refs
@@ -357,6 +363,10 @@ const dropEvent = ({ dataTransfer }: any) => {
dragging.value = !dragging.value dragging.value = !dragging.value
const folderPath = dataTransfer.getData("folderPath") const folderPath = dataTransfer.getData("folderPath")
const requestIndex = dataTransfer.getData("requestIndex") const requestIndex = dataTransfer.getData("requestIndex")
moveGraphqlRequest(folderPath, requestIndex, `${props.collectionIndex}`) emit("drop-request", {
folderPath,
requestIndex,
collectionIndex: props.collectionIndex,
})
} }
</script> </script>

View File

@@ -225,7 +225,7 @@ import IconSettings2 from "~icons/lucide/settings-2"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useColorMode } from "@composables/theming" import { useColorMode } from "@composables/theming"
import { removeGraphqlFolder, moveGraphqlRequest } from "~/newstore/collections" import { removeGraphqlFolder } from "~/newstore/collections"
import { computed, ref } from "vue" import { computed, ref } from "vue"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { GQLTabService } from "~/services/tab/graphql" import { GQLTabService } from "~/services/tab/graphql"
@@ -258,6 +258,7 @@ const emit = defineEmits([
"duplicate-request", "duplicate-request",
"edit-properties", "edit-properties",
"select-request", "select-request",
"drop-request",
]) ])
// Template refs // Template refs
@@ -332,6 +333,11 @@ const dropEvent = ({ dataTransfer }: any) => {
dragging.value = !dragging.value dragging.value = !dragging.value
const folderPath = dataTransfer.getData("folderPath") const folderPath = dataTransfer.getData("folderPath")
const requestIndex = dataTransfer.getData("requestIndex") const requestIndex = dataTransfer.getData("requestIndex")
moveGraphqlRequest(folderPath, requestIndex, props.folderPath)
emit("drop-request", {
folderPath,
requestIndex,
collectionIndex: props.folderPath,
})
} }
</script> </script>

View File

@@ -60,6 +60,7 @@
@edit-properties="editProperties($event)" @edit-properties="editProperties($event)"
@select="$emit('select', $event)" @select="$emit('select', $event)"
@select-request="selectRequest($event)" @select-request="selectRequest($event)"
@drop-request="dropRequest($event)"
/> />
</div> </div>
<HoppSmartPlaceholder <HoppSmartPlaceholder
@@ -163,6 +164,7 @@ import {
cascaseParentCollectionForHeaderAuth, cascaseParentCollectionForHeaderAuth,
editGraphqlCollection, editGraphqlCollection,
editGraphqlFolder, editGraphqlFolder,
moveGraphqlRequest,
} from "~/newstore/collections" } from "~/newstore/collections"
import IconPlus from "~icons/lucide/plus" import IconPlus from "~icons/lucide/plus"
import IconHelpCircle from "~icons/lucide/help-circle" import IconHelpCircle from "~icons/lucide/help-circle"
@@ -182,8 +184,11 @@ import {
import { Picked } from "~/helpers/types/HoppPicked" import { Picked } from "~/helpers/types/HoppPicked"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { updateInheritedPropertiesForAffectedRequests } from "~/helpers/collection/collection" import { updateInheritedPropertiesForAffectedRequests } from "~/helpers/collection/collection"
import { useToast } from "~/composables/toast"
import { getRequestsByPath } from "~/helpers/collection/request"
const t = useI18n() const t = useI18n()
const toast = useToast()
defineProps<{ defineProps<{
// Whether to activate the ability to pick items (activates 'select' events) // Whether to activate the ability to pick items (activates 'select' events)
@@ -494,6 +499,45 @@ const selectRequest = ({
}) })
} }
const dropRequest = ({
folderPath,
requestIndex,
collectionIndex,
}: {
folderPath: string
requestIndex: number
collectionIndex: number
}) => {
const { auth, headers } = cascaseParentCollectionForHeaderAuth(
`${collectionIndex}`,
"graphql"
)
const possibleTab = tabs.getTabRefWithSaveContext({
originLocation: "user-collection",
folderPath,
requestIndex: Number(requestIndex),
})
if (possibleTab) {
possibleTab.value.document.saveContext = {
originLocation: "user-collection",
folderPath: `${collectionIndex}`,
requestIndex: getRequestsByPath(collections.value, `${collectionIndex}`)
.length,
}
possibleTab.value.document.inheritedProperties = {
auth,
headers,
}
}
moveGraphqlRequest(folderPath, requestIndex, `${collectionIndex}`)
toast.success(`${t("request.moved")}`)
}
/** /**
* Checks if the collection is already in the root * Checks if the collection is already in the root
* @param id - path of the collection * @param id - path of the collection

View File

@@ -1,4 +1,8 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import {
HoppCollection,
HoppGQLRequest,
HoppRESTRequest,
} from "@hoppscotch/data"
import { getAffectedIndexes } from "./affectedIndex" import { getAffectedIndexes } from "./affectedIndex"
import { RESTTabService } from "~/services/tab/rest" import { RESTTabService } from "~/services/tab/rest"
import { getService } from "~/modules/dioc" import { getService } from "~/modules/dioc"
@@ -53,9 +57,9 @@ export function resolveSaveContextOnRequestReorder(payload: {
} }
export function getRequestsByPath( export function getRequestsByPath(
collections: HoppCollection<HoppRESTRequest>[], collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
path: string path: string
): HoppRESTRequest[] { ): HoppRESTRequest[] | HoppGQLRequest[] {
// path will be like this "0/0/1" these are the indexes of the folders // path will be like this "0/0/1" these are the indexes of the folders
const pathArray = path.split("/").map((index) => parseInt(index)) const pathArray = path.split("/").map((index) => parseInt(index))