chore: add fallback url and add reqIndex for graphql saving
This commit is contained in:
@@ -193,6 +193,7 @@ import { PersistedOAuthConfig } from "~/services/oauth/oauth.service"
|
|||||||
import { GQLOptionTabs } from "~/components/graphql/RequestOptions.vue"
|
import { GQLOptionTabs } from "~/components/graphql/RequestOptions.vue"
|
||||||
import { EditingProperties } from "../Properties.vue"
|
import { EditingProperties } from "../Properties.vue"
|
||||||
import { defineActionHandler } from "~/helpers/actions"
|
import { defineActionHandler } from "~/helpers/actions"
|
||||||
|
import { getDefaultGQLRequest } from "~/helpers/graphql/default"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -380,32 +381,26 @@ const editCollection = (
|
|||||||
displayModalEdit(true)
|
displayModalEdit(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onAddRequest = ({
|
const onAddRequest = ({ name, path }: { name: string; path: string }) => {
|
||||||
name,
|
|
||||||
path,
|
|
||||||
index,
|
|
||||||
}: {
|
|
||||||
name: string
|
|
||||||
path: string
|
|
||||||
index: number
|
|
||||||
}) => {
|
|
||||||
const newRequest = {
|
const newRequest = {
|
||||||
...tabs.currentActiveTab.value.document.request,
|
...tabs.currentActiveTab.value.document.request,
|
||||||
name,
|
name,
|
||||||
|
url:
|
||||||
|
tabs.currentActiveTab.value.document.request.url ||
|
||||||
|
getDefaultGQLRequest().url,
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGraphqlRequestAs(path, newRequest)
|
const insertionIndex = saveGraphqlRequestAs(path, newRequest)
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||||
path,
|
path,
|
||||||
"graphql"
|
"graphql"
|
||||||
)
|
)
|
||||||
|
|
||||||
tabs.createNewTab({
|
tabs.createNewTab({
|
||||||
saveContext: {
|
saveContext: {
|
||||||
originLocation: "user-collection",
|
originLocation: "user-collection",
|
||||||
folderPath: path,
|
folderPath: path,
|
||||||
requestIndex: index,
|
requestIndex: insertionIndex,
|
||||||
},
|
},
|
||||||
request: newRequest,
|
request: newRequest,
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ import { PersistenceService } from "~/services/persistence"
|
|||||||
import { PersistedOAuthConfig } from "~/services/oauth/oauth.service"
|
import { PersistedOAuthConfig } from "~/services/oauth/oauth.service"
|
||||||
import { RESTOptionTabs } from "../http/RequestOptions.vue"
|
import { RESTOptionTabs } from "../http/RequestOptions.vue"
|
||||||
import { EditingProperties } from "./Properties.vue"
|
import { EditingProperties } from "./Properties.vue"
|
||||||
|
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -790,6 +791,9 @@ const onAddRequest = (requestName: string) => {
|
|||||||
const newRequest = {
|
const newRequest = {
|
||||||
...cloneDeep(tabs.currentActiveTab.value.document.request),
|
...cloneDeep(tabs.currentActiveTab.value.document.request),
|
||||||
name: requestName,
|
name: requestName,
|
||||||
|
endpoint:
|
||||||
|
tabs.currentActiveTab.value.document.request.endpoint ||
|
||||||
|
getDefaultRESTRequest().endpoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = editingFolderPath.value
|
const path = editingFolderPath.value
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ const request = useVModel(props, "modelValue", emit)
|
|||||||
|
|
||||||
const url = computedWithControl(
|
const url = computedWithControl(
|
||||||
() => tabs.currentActiveTab.value,
|
() => tabs.currentActiveTab.value,
|
||||||
() => tabs.currentActiveTab.value.document.request.url
|
() =>
|
||||||
|
tabs.currentActiveTab.value.document.request.url ||
|
||||||
|
getDefaultGQLRequest().url
|
||||||
)
|
)
|
||||||
|
|
||||||
const activeGQLHeadersCount = computed(
|
const activeGQLHeadersCount = computed(
|
||||||
|
|||||||
@@ -1393,6 +1393,14 @@ export function editGraphqlRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function saveGraphqlRequestAs(path: string, request: HoppGQLRequest) {
|
export function saveGraphqlRequestAs(path: string, request: HoppGQLRequest) {
|
||||||
|
// For calculating the insertion request index
|
||||||
|
const targetLocation = navigateToFolderWithIndexPath(
|
||||||
|
graphqlCollectionStore.value.state,
|
||||||
|
path.split("/").map((x) => parseInt(x))
|
||||||
|
)
|
||||||
|
|
||||||
|
const insertionIndex = targetLocation!.requests.length
|
||||||
|
|
||||||
graphqlCollectionStore.dispatch({
|
graphqlCollectionStore.dispatch({
|
||||||
dispatcher: "saveRequestAs",
|
dispatcher: "saveRequestAs",
|
||||||
payload: {
|
payload: {
|
||||||
@@ -1400,6 +1408,8 @@ export function saveGraphqlRequestAs(path: string, request: HoppGQLRequest) {
|
|||||||
request,
|
request,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return insertionIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeGraphqlRequest(
|
export function removeGraphqlRequest(
|
||||||
|
|||||||
Reference in New Issue
Block a user