refactor: unify edit collection API methods and ensure consistent naming convention
This commit is contained in:
@@ -278,7 +278,7 @@ const saveRequestAs = async () => {
|
|||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
workspaceService.activeWorkspaceHandle.value,
|
workspaceService.activeWorkspaceHandle.value,
|
||||||
picked.value.folderPath
|
`${picked.value.folderPath}/${picked.value.requestIndex.toString()}`
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(requestHandleResult)) {
|
if (E.isLeft(requestHandleResult)) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
class="pointer-events-none flex min-w-0 flex-1 py-2 pr-2 transition group-hover:text-secondaryDark"
|
class="pointer-events-none flex min-w-0 flex-1 py-2 pr-2 transition group-hover:text-secondaryDark"
|
||||||
>
|
>
|
||||||
<span class="truncate">
|
<span class="truncate">
|
||||||
{{ collectionView.collection.name }}
|
{{ collectionView.name }}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -170,20 +170,20 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(event: "toggle-children"): void
|
(event: "toggle-children"): void
|
||||||
(event: "add-request", parentCollIndexPath: string): void
|
(event: "add-request", parentCollectionIndexPath: string): void
|
||||||
(event: "add-child-collection", parentCollIndexPath: string): void
|
(event: "add-child-collection", parentCollectionIndexPath: string): void
|
||||||
(
|
(
|
||||||
event: "edit-root-collection",
|
event: "edit-root-collection",
|
||||||
payload: { collIndexPath: string; collectionName: string }
|
payload: { collectionIndexPath: string; collectionName: string }
|
||||||
): void
|
): void
|
||||||
(
|
(
|
||||||
event: "edit-child-collection",
|
event: "edit-child-collection",
|
||||||
payload: { collIndexPath: string; collectionName: string }
|
payload: { collectionIndexPath: string; collectionName: string }
|
||||||
): void
|
): void
|
||||||
(event: "edit-collection-properties", collIndexPath: string): void
|
(event: "edit-collection-properties", collectionIndexPath: string): void
|
||||||
(event: "export-data"): void
|
(event: "export-data"): void
|
||||||
(event: "remove-root-collection", collIndexPath: string): void
|
(event: "remove-root-collection", collectionIndexPath: string): void
|
||||||
(event: "remove-child-collection", collIndexPath: string): void
|
(event: "remove-child-collection", collectionIndexPath: string): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const tippyActions = ref<TippyComponent | null>(null)
|
const tippyActions = ref<TippyComponent | null>(null)
|
||||||
@@ -207,17 +207,15 @@ const addRequest = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const editCollection = () => {
|
const editCollection = () => {
|
||||||
const {
|
const { collectionID: collectionIndexPath, name: collectionName } =
|
||||||
collectionID: collIndexPath,
|
props.collectionView
|
||||||
collection: { name: collectionName },
|
|
||||||
} = props.collectionView
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
collIndexPath,
|
collectionIndexPath,
|
||||||
collectionName,
|
collectionName,
|
||||||
}
|
}
|
||||||
|
|
||||||
collIndexPath.split("/").length > 1
|
collectionIndexPath.split("/").length > 1
|
||||||
? emit("edit-child-collection", data)
|
? emit("edit-child-collection", data)
|
||||||
: emit("edit-root-collection", data)
|
: emit("edit-root-collection", data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,14 +83,14 @@
|
|||||||
/>
|
/>
|
||||||
<CollectionsEdit
|
<CollectionsEdit
|
||||||
:show="showModalEditRootColl"
|
:show="showModalEditRootColl"
|
||||||
:editing-collection-name="editingRootCollName ?? ''"
|
: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="editingChildCollName ?? ''"
|
:editing-folder-name="editingChildCollectionName ?? ''"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
@submit="onEditChildCollection"
|
@submit="onEditChildCollection"
|
||||||
@hide-modal="displayModalEditChildCollection(false)"
|
@hide-modal="displayModalEditChildCollection(false)"
|
||||||
@@ -126,7 +126,7 @@
|
|||||||
import * as E from "fp-ts/lib/Either"
|
import * as E from "fp-ts/lib/Either"
|
||||||
|
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { markRaw, ref } from "vue"
|
import { markRaw, nextTick, ref } from "vue"
|
||||||
|
|
||||||
import { useI18n } from "~/composables/i18n"
|
import { useI18n } from "~/composables/i18n"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
@@ -149,6 +149,7 @@ import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
|
|||||||
import { TeamCollection } from "~/helpers/backend/graphql"
|
import { TeamCollection } from "~/helpers/backend/graphql"
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
import { useStreamStatic } from "~/composables/stream"
|
import { useStreamStatic } from "~/composables/stream"
|
||||||
|
import { updateInheritedPropertiesForAffectedRequests } from "~/helpers/collection/collection"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -182,10 +183,10 @@ const showModalEditRequest = ref(false)
|
|||||||
const showModalEditProperties = ref(false)
|
const showModalEditProperties = ref(false)
|
||||||
const showConfirmModal = ref(false)
|
const showConfirmModal = ref(false)
|
||||||
|
|
||||||
const editingCollIndexPath = ref<string>("")
|
const editingCollectionIndexPath = ref<string>("")
|
||||||
const editingChildCollIndexPath = ref<string>("")
|
const editingChildCollectionIndexPath = ref<string>("")
|
||||||
const editingRootCollName = ref<string>("")
|
const editingRootCollectionName = ref<string>("")
|
||||||
const editingChildCollName = ref<string>("")
|
const editingChildCollectionName = ref<string>("")
|
||||||
const editingRequestName = ref<string>("")
|
const editingRequestName = ref<string>("")
|
||||||
const editingRequestIndexPath = ref<string>("")
|
const editingRequestIndexPath = ref<string>("")
|
||||||
|
|
||||||
@@ -269,33 +270,34 @@ const addNewRootCollection = async (name: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const removeRootCollection = (collPathIndex: string) => {
|
const removeRootCollection = (collPathIndex: string) => {
|
||||||
editingCollIndexPath.value = collPathIndex
|
editingCollectionIndexPath.value = collPathIndex
|
||||||
|
|
||||||
confirmModalTitle.value = `${t("confirm.remove_collection")}`
|
confirmModalTitle.value = `${t("confirm.remove_collection")}`
|
||||||
displayConfirmModal(true)
|
displayConfirmModal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onRemoveRootCollection = async () => {
|
const onRemoveRootCollection = async () => {
|
||||||
const collIndexPath = editingCollIndexPath.value
|
const collectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
collIndexPath
|
collectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.removeRESTRootCollection(collHandle)
|
const result =
|
||||||
|
await workspaceService.removeRESTRootCollection(collectionHandle)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
@@ -312,32 +314,32 @@ const onRemoveRootCollection = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const addRequest = (requestPathIndex: string) => {
|
const addRequest = (requestPathIndex: string) => {
|
||||||
editingCollIndexPath.value = requestPathIndex
|
editingCollectionIndexPath.value = requestPathIndex
|
||||||
displayModalAddRequest(true)
|
displayModalAddRequest(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onAddRequest = async (requestName: string) => {
|
const onAddRequest = async (requestName: string) => {
|
||||||
const parentCollIndexPath = editingCollIndexPath.value
|
const parentCollectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
parentCollIndexPath
|
parentCollectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.createRESTRequest(
|
const result = await workspaceService.createRESTRequest(
|
||||||
collHandle,
|
collectionHandle,
|
||||||
requestName,
|
requestName,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
@@ -355,34 +357,34 @@ const onAddRequest = async (requestName: string) => {
|
|||||||
displayModalAddRequest(false)
|
displayModalAddRequest(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const addChildCollection = (parentCollIndexPath: string) => {
|
const addChildCollection = (parentCollectionIndexPath: string) => {
|
||||||
editingCollIndexPath.value = parentCollIndexPath
|
editingCollectionIndexPath.value = parentCollectionIndexPath
|
||||||
displayModalAddChildColl(true)
|
displayModalAddChildColl(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onAddChildCollection = async (childCollName: string) => {
|
const onAddChildCollection = async (childCollectionName: string) => {
|
||||||
const parentCollIndexPath = editingCollIndexPath.value
|
const parentCollectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
parentCollIndexPath
|
parentCollectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.createRESTChildCollection(
|
const result = await workspaceService.createRESTChildCollection(
|
||||||
collHandle,
|
collectionHandle,
|
||||||
childCollName
|
childCollectionName
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -399,40 +401,48 @@ const onAddChildCollection = async (childCollName: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const editRootCollection = (payload: {
|
const editRootCollection = (payload: {
|
||||||
collIndexPath: string
|
collectionIndexPath: string
|
||||||
collectionName: string
|
collectionName: string
|
||||||
}) => {
|
}) => {
|
||||||
const { collIndexPath, collectionName } = payload
|
const { collectionIndexPath, collectionName } = payload
|
||||||
|
|
||||||
editingCollIndexPath.value = collIndexPath
|
editingCollectionIndexPath.value = collectionIndexPath
|
||||||
editingRootCollName.value = collectionName
|
editingRootCollectionName.value = collectionName
|
||||||
|
|
||||||
displayModalEditCollection(true)
|
displayModalEditCollection(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEditRootCollection = async (newCollectionName: string) => {
|
const onEditRootCollection = async (newCollectionName: string) => {
|
||||||
const collID = editingCollIndexPath.value
|
const collectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
collID
|
collectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.editRESTRootCollection(
|
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
||||||
collHandle,
|
const updatedCollection = navigateToFolderWithIndexPath(
|
||||||
newCollectionName
|
restCollectionStore.value.state,
|
||||||
|
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||||
|
) as HoppCollection
|
||||||
|
|
||||||
|
updatedCollection.name = newCollectionName
|
||||||
|
|
||||||
|
const result = await workspaceService.editRESTCollection(
|
||||||
|
collectionHandle,
|
||||||
|
updatedCollection
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -450,40 +460,48 @@ const onEditRootCollection = async (newCollectionName: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const editChildCollection = (payload: {
|
const editChildCollection = (payload: {
|
||||||
collIndexPath: string
|
collectionIndexPath: string
|
||||||
collectionName: string
|
collectionName: string
|
||||||
}) => {
|
}) => {
|
||||||
const { collIndexPath, collectionName } = payload
|
const { collectionIndexPath, collectionName } = payload
|
||||||
|
|
||||||
editingChildCollIndexPath.value = collIndexPath
|
editingChildCollectionIndexPath.value = collectionIndexPath
|
||||||
editingChildCollName.value = collectionName
|
editingChildCollectionName.value = collectionName
|
||||||
|
|
||||||
displayModalEditChildCollection(true)
|
displayModalEditChildCollection(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEditChildCollection = async (newCollectionName: string) => {
|
const onEditChildCollection = async (newCollectionName: string) => {
|
||||||
const collID = editingChildCollIndexPath.value
|
const collectionIndexPath = editingChildCollectionIndexPath.value
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
collID
|
collectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.editRESTChildCollection(
|
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
||||||
collHandle,
|
const updatedCollection = navigateToFolderWithIndexPath(
|
||||||
newCollectionName
|
restCollectionStore.value.state,
|
||||||
|
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||||
|
) as HoppCollection
|
||||||
|
|
||||||
|
updatedCollection.name = newCollectionName
|
||||||
|
|
||||||
|
const result = await workspaceService.editRESTCollection(
|
||||||
|
collectionHandle,
|
||||||
|
updatedCollection
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -500,35 +518,37 @@ const onEditChildCollection = async (newCollectionName: string) => {
|
|||||||
toast.success(t("collection.renamed"))
|
toast.success(t("collection.renamed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeChildCollection = (parentCollIndexPath: string) => {
|
const removeChildCollection = (parentCollectionIndexPath: string) => {
|
||||||
editingCollIndexPath.value = parentCollIndexPath
|
editingCollectionIndexPath.value = parentCollectionIndexPath
|
||||||
|
|
||||||
confirmModalTitle.value = `${t("confirm.remove_folder")}`
|
confirmModalTitle.value = `${t("confirm.remove_folder")}`
|
||||||
displayConfirmModal(true)
|
displayConfirmModal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onRemoveChildCollection = async () => {
|
const onRemoveChildCollection = async () => {
|
||||||
const parentCollIndexPath = editingCollIndexPath.value
|
const parentCollectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const parentCollHandleResult = await workspaceService.getCollectionHandle(
|
const parentCollectionHandleResult =
|
||||||
|
await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
parentCollIndexPath
|
parentCollectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(parentCollHandleResult)) {
|
if (E.isLeft(parentCollectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentCollHandle = parentCollHandleResult.right
|
const parentCollectionHandle = parentCollectionHandleResult.right
|
||||||
|
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (parentCollectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result =
|
const result = await workspaceService.removeRESTChildCollection(
|
||||||
await workspaceService.removeRESTChildCollection(parentCollHandle)
|
parentCollectionHandle
|
||||||
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
@@ -545,9 +565,9 @@ const onRemoveChildCollection = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const removeRequest = (requestIndexPath: string) => {
|
const removeRequest = (requestIndexPath: string) => {
|
||||||
const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
editingCollIndexPath.value = collIndexPath
|
editingCollectionIndexPath.value = collectionIndexPath
|
||||||
editingRequestIndexPath.value = requestIndexPath
|
editingRequestIndexPath.value = requestIndexPath
|
||||||
|
|
||||||
confirmModalTitle.value = `${t("confirm.remove_request")}`
|
confirmModalTitle.value = `${t("confirm.remove_request")}`
|
||||||
@@ -591,7 +611,7 @@ const onRemoveRequest = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectRequest = async (requestIndexPath: string) => {
|
const selectRequest = async (requestIndexPath: string) => {
|
||||||
const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
@@ -617,13 +637,13 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
let possibleTab = null
|
let possibleTab = null
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||||
collIndexPath,
|
collectionIndexPath,
|
||||||
"rest"
|
"rest"
|
||||||
)
|
)
|
||||||
possibleTab = tabs.getTabRefWithSaveContext({
|
possibleTab = tabs.getTabRefWithSaveContext({
|
||||||
originLocation: "user-collection",
|
originLocation: "user-collection",
|
||||||
requestIndex,
|
requestIndex,
|
||||||
folderPath: collIndexPath,
|
folderPath: collectionIndexPath,
|
||||||
})
|
})
|
||||||
if (possibleTab) {
|
if (possibleTab) {
|
||||||
tabs.setActiveTab(possibleTab.value.id)
|
tabs.setActiveTab(possibleTab.value.id)
|
||||||
@@ -634,7 +654,7 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
isDirty: false,
|
isDirty: false,
|
||||||
saveContext: {
|
saveContext: {
|
||||||
originLocation: "user-collection",
|
originLocation: "user-collection",
|
||||||
folderPath: collIndexPath,
|
folderPath: collectionIndexPath,
|
||||||
requestIndex,
|
requestIndex,
|
||||||
},
|
},
|
||||||
inheritedProperties: {
|
inheritedProperties: {
|
||||||
@@ -646,7 +666,7 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const duplicateRequest = async (requestIndexPath: string) => {
|
const duplicateRequest = async (requestIndexPath: string) => {
|
||||||
const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
@@ -672,7 +692,7 @@ const duplicateRequest = async (requestIndexPath: string) => {
|
|||||||
name: `${request.name} - ${t("action.duplicate")}`,
|
name: `${request.name} - ${t("action.duplicate")}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
saveRESTRequestAs(collPath, newRequest)
|
saveRESTRequestAs(collectionIndexPath, newRequest)
|
||||||
|
|
||||||
toast.success(t("request.duplicated"))
|
toast.success(t("request.duplicated"))
|
||||||
}
|
}
|
||||||
@@ -683,9 +703,9 @@ const editRequest = (payload: {
|
|||||||
}) => {
|
}) => {
|
||||||
const { requestIndexPath, requestName } = payload
|
const { requestIndexPath, requestName } = payload
|
||||||
|
|
||||||
const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
editingCollIndexPath.value = collPath
|
editingCollectionIndexPath.value = collectionIndexPath
|
||||||
editingRequestIndexPath.value = requestIndexPath
|
editingRequestIndexPath.value = requestIndexPath
|
||||||
|
|
||||||
editingRequestName.value = requestName
|
editingRequestName.value = requestName
|
||||||
@@ -737,8 +757,8 @@ const onEditRequest = async (newReqName: string) => {
|
|||||||
toast.success(t("request.renamed"))
|
toast.success(t("request.renamed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
const editCollectionProperties = async (collIndexPath: string) => {
|
const editCollectionProperties = async (collectionIndexPath: string) => {
|
||||||
const parentIndex = collIndexPath.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
|
const parentIndex = collectionIndexPath.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
|
||||||
|
|
||||||
let inheritedProperties = {
|
let inheritedProperties = {
|
||||||
auth: {
|
auth: {
|
||||||
@@ -770,19 +790,19 @@ const editCollectionProperties = async (collIndexPath: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
collIndexPath
|
collectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -797,13 +817,13 @@ const editCollectionProperties = async (collIndexPath: string) => {
|
|||||||
|
|
||||||
const collection = navigateToFolderWithIndexPath(
|
const collection = navigateToFolderWithIndexPath(
|
||||||
restCollectionState.value.state,
|
restCollectionState.value.state,
|
||||||
collIndexPath.split("/").map((i) => parseInt(i))
|
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||||
)
|
)
|
||||||
|
|
||||||
editingProperties.value = {
|
editingProperties.value = {
|
||||||
collection,
|
collection,
|
||||||
isRootCollection: isAlreadyInRoot(collIndexPath),
|
isRootCollection: isAlreadyInRoot(collectionIndexPath),
|
||||||
path: collIndexPath,
|
path: collectionIndexPath,
|
||||||
inheritedProperties,
|
inheritedProperties,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,30 +833,42 @@ const editCollectionProperties = async (collIndexPath: string) => {
|
|||||||
const setCollectionProperties = async (updatedCollectionProps: {
|
const setCollectionProperties = async (updatedCollectionProps: {
|
||||||
auth: HoppRESTAuth
|
auth: HoppRESTAuth
|
||||||
headers: HoppCollection["headers"]
|
headers: HoppCollection["headers"]
|
||||||
collIndexPath: string
|
collectionIndexPath: string
|
||||||
}) => {
|
}) => {
|
||||||
const { collIndexPath, auth, headers } = updatedCollectionProps
|
const { collectionIndexPath, auth, headers } = updatedCollectionProps
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
collIndexPath
|
collectionIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_WORKSPACE_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.editRESTCollectionProperties(
|
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
||||||
collHandle,
|
const collection = navigateToFolderWithIndexPath(
|
||||||
{ auth, headers }
|
restCollectionStore.value.state,
|
||||||
|
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||||
|
) as HoppCollection
|
||||||
|
|
||||||
|
const updatedCollection = {
|
||||||
|
...collection,
|
||||||
|
auth,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await workspaceService.editRESTCollection(
|
||||||
|
collectionHandle,
|
||||||
|
updatedCollection
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -849,6 +881,20 @@ const setCollectionProperties = async (updatedCollectionProps: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { auth: cascadedAuth, headers: cascadedHeaders } =
|
||||||
|
cascadeParentCollectionForHeaderAuth(collectionIndexPath, "rest")
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
updateInheritedPropertiesForAffectedRequests(
|
||||||
|
collectionIndexPath,
|
||||||
|
{
|
||||||
|
auth: cascadedAuth,
|
||||||
|
headers: cascadedHeaders,
|
||||||
|
},
|
||||||
|
"rest"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
toast.success(t("collection.properties_updated"))
|
toast.success(t("collection.properties_updated"))
|
||||||
|
|
||||||
displayModalEditProperties(false)
|
displayModalEditProperties(false)
|
||||||
@@ -871,7 +917,7 @@ const resolveConfirmModal = (title: string | null) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const resetSelectedData = () => {
|
const resetSelectedData = () => {
|
||||||
editingCollIndexPath.value = ""
|
editingCollectionIndexPath.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import {
|
|||||||
shallowRef,
|
shallowRef,
|
||||||
watch,
|
watch,
|
||||||
} from "vue"
|
} from "vue"
|
||||||
import { UpdatedCollectionProperties, WorkspaceProvider } from "./provider"
|
import { WorkspaceProvider } from "./provider"
|
||||||
import { HandleRef } from "./handle"
|
import { HandleRef } from "./handle"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Workspace, WorkspaceCollection, WorkspaceRequest } from "./workspace"
|
import { Workspace, WorkspaceCollection, WorkspaceRequest } from "./workspace"
|
||||||
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
||||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
|
||||||
export type WorkspaceError<ServiceErr> =
|
export type WorkspaceError<ServiceErr> =
|
||||||
| { type: "SERVICE_ERROR"; error: ServiceErr }
|
| { type: "SERVICE_ERROR"; error: ServiceErr }
|
||||||
@@ -202,7 +202,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createRESTChildCollection(
|
public async createRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collectionName: string
|
collectionName: string
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
@@ -210,12 +210,12 @@ export class NewWorkspaceService extends Service {
|
|||||||
HandleRef<WorkspaceCollection>
|
HandleRef<WorkspaceCollection>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (parentCollectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
parentCollHandle.value.data.providerID
|
parentCollectionHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
@@ -223,7 +223,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.createRESTChildCollection(
|
const result = await provider.createRESTChildCollection(
|
||||||
parentCollHandle,
|
parentCollectionHandle,
|
||||||
collectionName
|
collectionName
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -234,96 +234,30 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.right(result.right)
|
return E.right(result.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async editRESTRootCollection(
|
public async editRESTCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
updatedCollection: HoppCollection
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<boolean>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
collHandle.value.data.providerID
|
collectionHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.editRESTRootCollection(
|
const result = await provider.editRESTCollection(
|
||||||
collHandle,
|
collectionHandle,
|
||||||
newCollectionName
|
updatedCollection
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
|
||||||
}
|
|
||||||
|
|
||||||
return E.right(result.right)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async editRESTChildCollection(
|
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
newCollectionName: string
|
|
||||||
): Promise<
|
|
||||||
E.Either<
|
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
if (collHandle.value.type === "invalid") {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
|
||||||
collHandle.value.data.providerID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await provider.editRESTChildCollection(
|
|
||||||
collHandle,
|
|
||||||
newCollectionName
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
|
||||||
}
|
|
||||||
|
|
||||||
return E.right(result.right)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async editRESTCollectionProperties(
|
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
updatedCollProps: UpdatedCollectionProperties
|
|
||||||
): Promise<
|
|
||||||
E.Either<
|
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
if (collHandle.value.type === "invalid") {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
|
||||||
collHandle.value.data.providerID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await provider.editRESTCollectionProperties(
|
|
||||||
collHandle,
|
|
||||||
updatedCollProps
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -334,26 +268,26 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async removeRESTRootCollection(
|
public async removeRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<boolean>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
collHandle.value.data.providerID
|
collectionHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.removeRESTRootCollection(collHandle)
|
const result = await provider.removeRESTRootCollection(collectionHandle)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
@@ -363,26 +297,28 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async removeRESTChildCollection(
|
public async removeRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>
|
parentCollectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<boolean>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (parentCollectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
parentCollHandle.value.data.providerID
|
parentCollectionHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.removeRESTChildCollection(parentCollHandle)
|
const result = await provider.removeRESTChildCollection(
|
||||||
|
parentCollectionHandle
|
||||||
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
@@ -392,7 +328,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createRESTRequest(
|
public async createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
requestName: string,
|
requestName: string,
|
||||||
openInNewTab: boolean
|
openInNewTab: boolean
|
||||||
): Promise<
|
): Promise<
|
||||||
@@ -401,12 +337,12 @@ export class NewWorkspaceService extends Service {
|
|||||||
HandleRef<WorkspaceCollection>
|
HandleRef<WorkspaceCollection>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (parentCollectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
parentCollHandle.value.data.providerID
|
parentCollectionHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
@@ -414,7 +350,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.createRESTRequest(
|
const result = await provider.createRESTRequest(
|
||||||
parentCollHandle,
|
parentCollectionHandle,
|
||||||
requestName,
|
requestName,
|
||||||
openInNewTab
|
openInNewTab
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,16 +8,7 @@ import {
|
|||||||
WorkspaceRequest,
|
WorkspaceRequest,
|
||||||
} from "./workspace"
|
} from "./workspace"
|
||||||
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
||||||
import {
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
HoppRESTAuth,
|
|
||||||
HoppRESTHeaders,
|
|
||||||
HoppRESTRequest,
|
|
||||||
} from "@hoppscotch/data"
|
|
||||||
|
|
||||||
export type UpdatedCollectionProperties = {
|
|
||||||
auth: HoppRESTAuth
|
|
||||||
headers: HoppRESTHeaders
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorkspaceProvider {
|
export interface WorkspaceProvider {
|
||||||
providerID: string
|
providerID: string
|
||||||
@@ -51,37 +42,29 @@ export interface WorkspaceProvider {
|
|||||||
collectionName: string
|
collectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
createRESTChildCollection(
|
createRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collectionName: string
|
collectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
editRESTRootCollection(
|
editRESTCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
updatedCollection: HoppCollection
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
|
||||||
editRESTChildCollection(
|
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
newCollectionName: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
|
||||||
editRESTCollectionProperties(
|
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
updatedCollProps: UpdatedCollectionProperties
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
removeRESTRootCollection(
|
removeRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
removeRESTChildCollection(
|
removeRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>
|
parentCollectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
createRESTRequest(
|
createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
requestName: string,
|
requestName: string,
|
||||||
openInNewTab: boolean
|
openInNewTab: boolean
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
removeRESTRequest(
|
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
|
||||||
updateRESTRequest(
|
updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: HoppRESTRequest
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
|
removeRESTRequest(
|
||||||
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HoppCollection, makeCollection } from "@hoppscotch/data"
|
import { HoppCollection, makeCollection } from "@hoppscotch/data"
|
||||||
import { Service } from "dioc"
|
import { Service } from "dioc"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue"
|
import { Ref, computed, markRaw, ref, shallowRef } from "vue"
|
||||||
|
|
||||||
import PersonalWorkspaceSelector from "~/components/workspace/PersonalWorkspaceSelector.vue"
|
import PersonalWorkspaceSelector from "~/components/workspace/PersonalWorkspaceSelector.vue"
|
||||||
import { useStreamStatic } from "~/composables/stream"
|
import { useStreamStatic } from "~/composables/stream"
|
||||||
@@ -23,10 +23,7 @@ import {
|
|||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
import { HandleRef } from "~/services/new-workspace/handle"
|
import { HandleRef } from "~/services/new-workspace/handle"
|
||||||
import {
|
import { WorkspaceProvider } from "~/services/new-workspace/provider"
|
||||||
UpdatedCollectionProperties,
|
|
||||||
WorkspaceProvider,
|
|
||||||
} from "~/services/new-workspace/provider"
|
|
||||||
import {
|
import {
|
||||||
RESTCollectionChildrenView,
|
RESTCollectionChildrenView,
|
||||||
RESTCollectionViewItem,
|
RESTCollectionViewItem,
|
||||||
@@ -52,7 +49,6 @@ import path from "path"
|
|||||||
import {
|
import {
|
||||||
resolveSaveContextOnCollectionReorder,
|
resolveSaveContextOnCollectionReorder,
|
||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
updateInheritedPropertiesForAffectedRequests,
|
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
|
|
||||||
export class PersonalWorkspaceProviderService
|
export class PersonalWorkspaceProviderService
|
||||||
@@ -209,9 +205,9 @@ export class PersonalWorkspaceProviderService
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public editRESTRootCollection(
|
public editRESTCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
updatedCollection: HoppCollection
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collHandle.value.type !== "ok" ||
|
||||||
@@ -250,129 +246,6 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedCollection = {
|
|
||||||
...collection,
|
|
||||||
name: newCollectionName,
|
|
||||||
}
|
|
||||||
|
|
||||||
const collectionIndex = parseInt(collectionID)
|
|
||||||
editRESTCollection(collectionIndex, updatedCollection)
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public editRESTChildCollection(
|
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
newCollectionName: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve(
|
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "WORKSPACE_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID } = collHandle.value.data
|
|
||||||
|
|
||||||
const collection: HoppCollection | null =
|
|
||||||
navigateToFolderWithIndexPath(
|
|
||||||
this.restCollectionState.value.state,
|
|
||||||
collectionID.split("/").map((id) => parseInt(id))
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!collection) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "COLLECTION_NOT_FOUND" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedCollection = {
|
|
||||||
...collection,
|
|
||||||
name: newCollectionName,
|
|
||||||
}
|
|
||||||
|
|
||||||
editRESTFolder(collectionID, updatedCollection)
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public editRESTCollectionProperties(
|
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
|
||||||
updatedCollProps: UpdatedCollectionProperties
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve(
|
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "WORKSPACE_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID } = collHandle.value.data
|
|
||||||
|
|
||||||
const { auth, headers } = updatedCollProps
|
|
||||||
|
|
||||||
const collection: HoppCollection | null =
|
|
||||||
navigateToFolderWithIndexPath(
|
|
||||||
this.restCollectionState.value.state,
|
|
||||||
collectionID.split("/").map((id) => parseInt(id))
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!collection) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "COLLECTION_NOT_FOUND" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedCollection = {
|
|
||||||
...collection,
|
|
||||||
auth,
|
|
||||||
headers,
|
|
||||||
} as HoppCollection
|
|
||||||
|
|
||||||
const isRootCollection = collectionID.split("/").length === 1
|
const isRootCollection = collectionID.split("/").length === 1
|
||||||
|
|
||||||
if (isRootCollection) {
|
if (isRootCollection) {
|
||||||
@@ -381,20 +254,6 @@ export class PersonalWorkspaceProviderService
|
|||||||
editRESTFolder(collectionID, updatedCollection)
|
editRESTFolder(collectionID, updatedCollection)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { auth: cascadedAuth, headers: cascadedHeaders } =
|
|
||||||
cascadeParentCollectionForHeaderAuth(collectionID, "rest")
|
|
||||||
|
|
||||||
nextTick(() => {
|
|
||||||
updateInheritedPropertiesForAffectedRequests(
|
|
||||||
collectionID,
|
|
||||||
{
|
|
||||||
auth: cascadedAuth,
|
|
||||||
headers: cascadedHeaders,
|
|
||||||
},
|
|
||||||
"rest"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: true,
|
data: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user