(null)
const collectionIcon = computed(() => {
return !props.isOpen ? IconFolder : IconFolderOpen
})
+
+const addChildCollection = () => {
+ emit("add-child-collection", props.collectionView.collectionID)
+}
+
+const addRequest = () => {
+ emit("add-request", props.collectionView.collectionID)
+}
+
+const editCollection = () => {
+ const {
+ collectionID: collIndexPath,
+ collection: { name: collectionName },
+ } = props.collectionView
+
+ const data = {
+ collIndexPath,
+ collectionName,
+ }
+
+ collIndexPath.split("/").length > 1
+ ? emit("edit-child-collection", data)
+ : emit("edit-root-collection", data)
+}
+
+const removeCollection = () => {
+ const { collectionID } = props.collectionView
+
+ collectionID.split("/").length > 1
+ ? emit("remove-child-collection", collectionID)
+ : emit("remove-root-collection", collectionID)
+}
diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/Request.vue b/packages/hoppscotch-common/src/components/new-collections/rest/Request.vue
index 532c572f5..7e07cda57 100644
--- a/packages/hoppscotch-common/src/components/new-collections/rest/Request.vue
+++ b/packages/hoppscotch-common/src/components/new-collections/rest/Request.vue
@@ -6,7 +6,7 @@
>
- {{ request.method }}
+ {{ requestView.request.method }}
- {{ request.name }}
+ {{ requestView.request.name }}
{
emit('edit-request', {
- requestPath: request.requestID,
- request: request.request,
+ requestIndexPath: requestView.requestID,
+ requestName: requestView.request.name,
})
hide()
}
@@ -92,10 +92,7 @@
:shortcut="['D']"
@click="
() => {
- emit('duplicate-request', {
- requestPath: request.requestID,
- request: request.request,
- })
+ emit('duplicate-request', requestView.requestID)
hide()
}
"
@@ -132,37 +129,24 @@ import { RESTCollectionViewRequest } from "~/services/new-workspace/view"
import { computed, ref } from "vue"
import { TippyComponent } from "vue-tippy"
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
-import { HoppRESTRequest } from "@hoppscotch/data"
const t = useI18n()
const props = defineProps<{
- request: RESTCollectionViewRequest
+ requestView: RESTCollectionViewRequest
}>()
const emit = defineEmits<{
- (
- event: "duplicate-request",
- payload: {
- requestPath: string
- request: HoppRESTRequest
- }
- ): void
+ (event: "duplicate-request", requestIndexPath: string): void
(
event: "edit-request",
payload: {
- requestPath: string
- request: HoppRESTRequest
+ requestIndexPath: string
+ requestName: string
}
): void
(event: "remove-request"): void
- (
- event: "select-request",
- payload: {
- requestPath: string
- request: HoppRESTRequest
- }
- ): void
+ (event: "select-request", requestIndexPath: string): void
}>()
const tippyActions = ref(null)
@@ -172,12 +156,8 @@ const options = ref(null)
const isActive = ref(true)
const requestLabelColor = computed(() =>
- getMethodLabelColorClassOf(props.request)
+ getMethodLabelColorClassOf(props.requestView.request)
)
-const selectRequest = (requestPath: string, request: HoppRESTRequest) =>
- emit("select-request", {
- requestPath,
- request,
- })
+const selectRequest = () => emit("select-request", props.requestView.requestID)
diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
index 0e7914f54..d87ce082b 100644
--- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
+++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
@@ -22,7 +22,7 @@
v-tippy="{ theme: 'tooltip' }"
:icon="IconImport"
:title="t('modal.import_export')"
- @click="onImportExportClick"
+ @click="() => {}"
/>
@@ -33,16 +33,20 @@
+
+
+
+
+
@@ -112,18 +139,13 @@ import IconImport from "~icons/lucide/folder-down"
import IconHelpCircle from "~icons/lucide/help-circle"
import IconPlus from "~icons/lucide/plus"
import {
- resolveSaveContextOnCollectionReorder,
- getFoldersByPath,
-} from "~/helpers/collection/collection"
-import {
- navigateToFolderWithIndexPath,
- restCollectionStore,
- removeRESTFolder,
- restCollections$,
+ cascadeParentCollectionForHeaderAuth,
+ saveRESTRequestAs,
} from "~/newstore/collections"
-import { useReadonlyStream } from "~/composables/stream"
import { cloneDeep } from "lodash-es"
-import { HoppRESTRequest } from "@hoppscotch/data"
+import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
+import { TeamCollection } from "~/helpers/backend/graphql"
+import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
const t = useI18n()
const toast = useToast()
@@ -150,27 +172,54 @@ const modalLoadingState = ref(false)
const showModalAdd = ref(false)
const showModalAddRequest = ref(false)
-const showModalAddFolder = ref(false)
+const showModalAddChildColl = ref(false)
+const showModalEditRootColl = ref(false)
+const showModalEditChildColl = ref(false)
const showModalEditRequest = ref(false)
+const showModalEditProperties = ref(false)
const showConfirmModal = ref(false)
-const editingFolderPath = ref(null)
-const editingRequest = ref(null)
-const editingRequestName = ref("")
-const editingRequestIndex = ref(null)
+const editingCollIndexPath = ref("")
+const editingChildCollIndexPath = ref("")
+const editingRootCollName = ref("")
+const editingChildCollName = ref("")
+const editingRequestName = ref("")
+const editingRequestIndexPath = ref("")
+
+const editingProperties = ref<{
+ collection: Omit | TeamCollection | null
+ isRootCollection: boolean
+ path: string
+ inheritedProperties?: HoppInheritedProperty
+}>({
+ collection: null,
+ isRootCollection: false,
+ path: "",
+ inheritedProperties: undefined,
+})
const confirmModalTitle = ref(null)
-const myCollections = useReadonlyStream(restCollections$, [], "deep")
-
const displayModalAddRequest = (show: boolean) => {
showModalAddRequest.value = show
if (!show) resetSelectedData()
}
-const displayModalAddFolder = (show: boolean) => {
- showModalAddFolder.value = show
+const displayModalAddChildColl = (show: boolean) => {
+ showModalAddChildColl.value = show
+
+ if (!show) resetSelectedData()
+}
+
+const displayModalEditCollection = (show: boolean) => {
+ showModalEditRootColl.value = show
+
+ if (!show) resetSelectedData()
+}
+
+const displayModalEditChildCollection = (show: boolean) => {
+ showModalEditChildColl.value = show
if (!show) resetSelectedData()
}
@@ -181,6 +230,12 @@ const displayModalEditRequest = (show: boolean) => {
if (!show) resetSelectedData()
}
+const displayModalEditProperties = (show: boolean) => {
+ showModalEditProperties.value = show
+
+ if (!show) resetSelectedData()
+}
+
const displayConfirmModal = (show: boolean) => {
showConfirmModal.value = show
@@ -210,19 +265,19 @@ const addNewRootCollection = async (name: string) => {
showModalAdd.value = false
}
-const addRequest = (payload: { path: string }) => {
- const { path } = payload
- editingFolderPath.value = path
- displayModalAddRequest(true)
+const removeRootCollection = (collPathIndex: string) => {
+ editingCollIndexPath.value = collPathIndex
+
+ confirmModalTitle.value = `${t("confirm.remove_collection")}`
+ displayConfirmModal(true)
}
-const onAddRequest = async (requestName: string) => {
- const path = editingFolderPath.value
- if (!path) return
+const onRemoveRootCollection = async () => {
+ const collIndexPath = editingCollIndexPath.value
const collHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
- path
+ collIndexPath
)
if (E.isLeft(collHandleResult)) {
@@ -233,14 +288,54 @@ const onAddRequest = async (requestName: string) => {
const collHandle = collHandleResult.right
if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const result = await workspaceService.removeRESTRootCollection(collHandle)
+
+ if (E.isLeft(result)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ if (result.right.value.type === "invalid") {
+ // COLLECTION_INVALIDATED
+ return
+ }
+
+ toast.success(t("state.deleted"))
+ displayConfirmModal(false)
+}
+
+const addRequest = (requestPathIndex: string) => {
+ editingCollIndexPath.value = requestPathIndex
+ displayModalAddRequest(true)
+}
+
+const onAddRequest = async (requestName: string) => {
+ const parentCollIndexPath = editingCollIndexPath.value
+
+ const collHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ parentCollIndexPath
+ )
+
+ if (E.isLeft(collHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
+
+ const collHandle = collHandleResult.right
+
+ if (collHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
const result = await workspaceService.createRESTRequest(
collHandle,
- requestName,
- path
+ requestName
)
if (E.isLeft(result)) {
@@ -256,20 +351,17 @@ const onAddRequest = async (requestName: string) => {
displayModalAddRequest(false)
}
-const addFolder = (payload: { path: string }) => {
- const { path } = payload
- editingFolderPath.value = path
- displayModalAddFolder(true)
+const addChildCollection = (parentCollIndexPath: string) => {
+ editingCollIndexPath.value = parentCollIndexPath
+ displayModalAddChildColl(true)
}
-const onAddFolder = async (folderName: string) => {
- const path = editingFolderPath.value
-
- if (!path) return
+const onAddChildCollection = async (childCollName: string) => {
+ const parentCollIndexPath = editingCollIndexPath.value
const collHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
- path
+ parentCollIndexPath
)
if (E.isLeft(collHandleResult)) {
@@ -280,103 +372,224 @@ const onAddFolder = async (folderName: string) => {
const collHandle = collHandleResult.right
if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
const result = await workspaceService.createRESTChildCollection(
collHandle,
- folderName,
- path
+ childCollName
)
if (E.isLeft(result)) {
- // INVALID_WORKSPACE_HANDLE
+ // INVALID_COLLECTION_HANDLE
return
}
if (result.right.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // COLLECTION_INVALIDATED
return
}
- displayModalAddFolder(false)
+ displayModalAddChildColl(false)
}
-const removeFolder = (payload: { path: string }) => {
- const { path } = payload
- editingFolderPath.value = path
+const editRootCollection = (payload: {
+ collIndexPath: string
+ collectionName: string
+}) => {
+ const { collIndexPath, collectionName } = payload
+
+ editingCollIndexPath.value = collIndexPath
+ editingRootCollName.value = collectionName
+
+ displayModalEditCollection(true)
+}
+
+const onEditRootCollection = async (newCollectionName: string) => {
+ const collID = editingCollIndexPath.value
+
+ const collHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ collID
+ )
+
+ if (E.isLeft(collHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
+
+ const collHandle = collHandleResult.right
+
+ if (collHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const result = await workspaceService.editRESTRootCollection(
+ collHandle,
+ newCollectionName
+ )
+
+ if (E.isLeft(result)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ if (result.right.value.type === "invalid") {
+ // COLLECTION_INVALIDATED
+ return
+ }
+
+ displayModalEditCollection(false)
+ toast.success(t("collection.renamed"))
+}
+
+const editChildCollection = (payload: {
+ collIndexPath: string
+ collectionName: string
+}) => {
+ const { collIndexPath, collectionName } = payload
+
+ editingChildCollIndexPath.value = collIndexPath
+ editingChildCollName.value = collectionName
+
+ displayModalEditChildCollection(true)
+}
+
+const onEditChildCollection = async (newCollectionName: string) => {
+ const collID = editingChildCollIndexPath.value
+
+ const collHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ collID
+ )
+
+ if (E.isLeft(collHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
+
+ const collHandle = collHandleResult.right
+
+ if (collHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const result = await workspaceService.editRESTChildCollection(
+ collHandle,
+ newCollectionName
+ )
+
+ if (E.isLeft(result)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ if (result.right.value.type === "invalid") {
+ // COLLECTION_INVALIDATED
+ return
+ }
+
+ displayModalEditChildCollection(false)
+ toast.success(t("collection.renamed"))
+}
+
+const removeChildCollection = (parentCollIndexPath: string) => {
+ editingCollIndexPath.value = parentCollIndexPath
confirmModalTitle.value = `${t("confirm.remove_folder")}`
displayConfirmModal(true)
}
-const onRemoveFolder = () => {
- const path = editingFolderPath.value
+const onRemoveChildCollection = async () => {
+ const parentCollIndexPath = editingCollIndexPath.value
- if (!path) return
+ const parentCollHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ parentCollIndexPath
+ )
- const folderToRemove = path
- ? navigateToFolderWithIndexPath(
- restCollectionStore.value.state,
- path.split("/").map((i) => parseInt(i))
- )
- : undefined
+ if (E.isLeft(parentCollHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
- removeRESTFolder(path, folderToRemove ? folderToRemove.id : undefined)
+ const parentCollHandle = parentCollHandleResult.right
- const parentFolder = path.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
- resolveSaveContextOnCollectionReorder({
- lastIndex: pathToLastIndex(path),
- newIndex: -1,
- folderPath: parentFolder,
- length: getFoldersByPath(myCollections.value, parentFolder).length,
- })
+ if (parentCollHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const result =
+ await workspaceService.removeRESTChildCollection(parentCollHandle)
+
+ if (E.isLeft(result)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ if (result.right.value.type === "invalid") {
+ // COLLECTION_INVALIDATED
+ return
+ }
toast.success(t("state.deleted"))
displayConfirmModal(false)
}
-const removeRequest = (requestIndex: string) => {
- const folderPath = requestIndex.slice(0, -2)
- const requestID = requestIndex[requestIndex.length - 1]
+const removeRequest = (requestIndexPath: string) => {
+ const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
- editingFolderPath.value = folderPath
- editingRequestIndex.value = parseInt(requestID)
+ editingCollIndexPath.value = collIndexPath
+ editingRequestIndexPath.value = requestIndexPath
confirmModalTitle.value = `${t("confirm.remove_request")}`
displayConfirmModal(true)
}
const onRemoveRequest = async () => {
- const path = editingFolderPath.value
- const requestIndex = editingRequestIndex.value
+ const parentCollIndexPath = editingCollIndexPath.value
+ const requestIndexPath = editingRequestIndexPath.value
- if (path === null || requestIndex === null) return
-
- const collHandleResult = await workspaceService.getCollectionHandle(
+ const parentCollHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
- path
+ parentCollIndexPath
)
- if (E.isLeft(collHandleResult)) {
+ if (E.isLeft(parentCollHandleResult)) {
// INVALID_WORKSPACE_HANDLE
return
}
- const collHandle = collHandleResult.right
+ const parentCollHandle = parentCollHandleResult.right
- if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ if (parentCollHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
- const result = await workspaceService.removeRESTRequest(
- collHandle,
- path,
- requestIndex
+ const requestHandleResult = await workspaceService.getRequestHandle(
+ parentCollHandle,
+ requestIndexPath
)
+ if (E.isLeft(requestHandleResult)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const requestHandle = requestHandleResult.right
+
+ if (requestHandle.value.type === "invalid") {
+ // COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
+ return
+ }
+
+ const result = await workspaceService.removeRESTRequest(requestHandle)
+
if (E.isLeft(result)) {
// INVALID_WORKSPACE_HANDLE
return
@@ -391,18 +604,12 @@ const onRemoveRequest = async () => {
displayConfirmModal(false)
}
-const selectRequest = async (payload: {
- requestPath: string
- request: HoppRESTRequest
-}) => {
- const { requestPath, request } = payload
-
- const collPath = requestPath.slice(0, -2)
- const requestIndex = requestPath[requestPath.length - 1]
+const selectRequest = async (requestIndexPath: string) => {
+ const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
const collHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
- collPath
+ collIndexPath
)
if (E.isLeft(collHandleResult)) {
@@ -413,35 +620,64 @@ const selectRequest = async (payload: {
const collHandle = collHandleResult.right
if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
- const result = await workspaceService.selectRESTRequest(
+ const requestHandleResult = await workspaceService.getRequestHandle(
collHandle,
- collPath,
- requestIndex,
- request
+ requestIndexPath
)
- if (E.isLeft(result)) {
- // INVALID_WORKSPACE_HANDLE
+ if (E.isLeft(requestHandleResult)) {
+ // INVALID_COLLECTION_HANDLE
return
}
- if (result.right.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ const requestHandle = requestHandleResult.right
+
+ if (requestHandle.value.type === "invalid") {
+ // COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
return
}
+
+ const requestIndex = parseInt(requestIndexPath.split("/").slice(-1)[0])
+ const request = requestHandle.value.data.request as HoppRESTRequest
+
+ // If there is a request with this save context, switch into it
+ let possibleTab = null
+
+ const { auth, headers } = cascadeParentCollectionForHeaderAuth(
+ collIndexPath,
+ "rest"
+ )
+ possibleTab = tabs.getTabRefWithSaveContext({
+ originLocation: "user-collection",
+ requestIndex,
+ folderPath: collIndexPath,
+ })
+ if (possibleTab) {
+ tabs.setActiveTab(possibleTab.value.id)
+ } else {
+ // If not, open the request in a new tab
+ tabs.createNewTab({
+ request: cloneDeep(request),
+ isDirty: false,
+ saveContext: {
+ originLocation: "user-collection",
+ folderPath: collIndexPath,
+ requestIndex,
+ },
+ inheritedProperties: {
+ auth,
+ headers,
+ },
+ })
+ }
}
-const duplicateRequest = async (payload: {
- requestPath: string
- request: HoppRESTRequest
-}) => {
- const { requestPath, request } = payload
-
- const collPath = requestPath.slice(0, -2)
+const duplicateRequest = async (requestIndexPath: string) => {
+ const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
const collHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
@@ -456,95 +692,105 @@ const duplicateRequest = async (payload: {
const collHandle = collHandleResult.right
if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
+ const requestHandleResult = await workspaceService.getRequestHandle(
+ collHandle,
+ requestIndexPath
+ )
+
+ if (E.isLeft(requestHandleResult)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const requestHandle = requestHandleResult.right
+
+ if (requestHandle.value.type === "invalid") {
+ // COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
+ return
+ }
+
+ const request = requestHandle.value.data.request as HoppRESTRequest
+
const newRequest = {
...cloneDeep(request),
name: `${request.name} - ${t("action.duplicate")}`,
}
- const result = await workspaceService.duplicateRESTRequest(
- collHandle,
- collPath,
- newRequest
- )
-
- if (E.isLeft(result)) {
- // INVALID_WORKSPACE_HANDLE
- return
- }
-
- if (result.right.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
- return
- }
+ saveRESTRequestAs(collPath, newRequest)
toast.success(t("request.duplicated"))
}
const editRequest = (payload: {
- requestPath: string
- request: HoppRESTRequest
+ requestIndexPath: string
+ requestName: string
}) => {
- const { requestPath, request } = payload
- const collPath = requestPath.slice(0, -2)
- const requestIndex = requestPath[requestPath.length - 1]
+ const { requestIndexPath, requestName } = payload
- editingRequest.value = request
- editingRequestName.value = request.name ?? ""
- editingFolderPath.value = collPath
- editingRequestIndex.value = parseInt(requestIndex)
+ const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
+
+ editingCollIndexPath.value = collPath
+ editingRequestIndexPath.value = requestIndexPath
+
+ editingRequestName.value = requestName
displayModalEditRequest(true)
}
const onEditRequest = async (newReqName: string) => {
- const collPath = editingFolderPath.value
- const requestIndex = editingRequestIndex.value
- const request = editingRequest.value
+ const parentCollID = editingCollIndexPath.value
+ const requestID = editingRequestIndexPath.value
- if (collPath === null || requestIndex === null || !request) {
- return
- }
-
- const collHandleResult = await workspaceService.getCollectionHandle(
+ const parentCollHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
- collPath
+ parentCollID
)
- if (E.isLeft(collHandleResult)) {
+ if (E.isLeft(parentCollHandleResult)) {
// INVALID_WORKSPACE_HANDLE
return
}
- const collHandle = collHandleResult.right
+ const parentCollHandle = parentCollHandleResult.right
- if (collHandle.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ if (parentCollHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
- const updatedRequest = {
- ...request,
- name: newReqName || request.name,
+ const requestHandleResult = await workspaceService.getRequestHandle(
+ parentCollHandle,
+ requestID
+ )
+
+ if (E.isLeft(requestHandleResult)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const requestHandle = requestHandleResult.right
+
+ if (requestHandle.value.type === "invalid") {
+ // COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
+ return
}
const result = await workspaceService.editRESTRequest(
- collHandle,
- collPath,
- requestIndex,
- updatedRequest
+ requestHandle,
+ newReqName
)
if (E.isLeft(result)) {
- // INVALID_WORKSPACE_HANDLE
+ // INVALID_REQUEST_HANDLE
return
}
if (result.right.value.type === "invalid") {
- // WORKSPACE_INVALIDATED
+ // REQUEST_INVALIDATED
return
}
@@ -552,17 +798,119 @@ const onEditRequest = async (newReqName: string) => {
toast.success(t("request.renamed"))
}
-function onImportExportClick() {
- // TODO: Implement
+const editCollectionProperties = async (collIndexPath: string) => {
+ const parentIndex = collIndexPath.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
+
+ let inheritedProperties = {
+ auth: {
+ parentID: "",
+ parentName: "",
+ inheritedAuth: {
+ authType: "inherit",
+ authActive: true,
+ },
+ },
+ headers: [
+ {
+ parentID: "",
+ parentName: "",
+ inheritedHeader: {},
+ },
+ ],
+ } as HoppInheritedProperty
+
+ if (parentIndex) {
+ const { auth, headers } = cascadeParentCollectionForHeaderAuth(
+ parentIndex,
+ "rest"
+ )
+
+ inheritedProperties = {
+ auth,
+ headers,
+ }
+ }
+
+ const collHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ collIndexPath
+ )
+
+ if (E.isLeft(collHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
+
+ const collHandle = collHandleResult.right
+
+ if (collHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const { collection } = collHandle.value.data
+
+ editingProperties.value = {
+ collection,
+ isRootCollection: isAlreadyInRoot(collIndexPath),
+ path: collIndexPath,
+ inheritedProperties,
+ }
+
+ displayModalEditProperties(true)
+}
+
+const setCollectionProperties = async (updatedCollectionProps: {
+ auth: HoppRESTAuth
+ headers: HoppCollection["headers"]
+ collIndexPath: string
+}) => {
+ const { collIndexPath, auth, headers } = updatedCollectionProps
+
+ const collHandleResult = await workspaceService.getCollectionHandle(
+ props.workspaceHandle,
+ collIndexPath
+ )
+
+ if (E.isLeft(collHandleResult)) {
+ // INVALID_WORKSPACE_HANDLE
+ return
+ }
+
+ const collHandle = collHandleResult.right
+
+ if (collHandle.value.type === "invalid") {
+ // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ const result = await workspaceService.editRESTCollectionProperties(
+ collHandle,
+ { auth, headers }
+ )
+
+ if (E.isLeft(result)) {
+ // INVALID_COLLECTION_HANDLE
+ return
+ }
+
+ if (result.right.value.type === "invalid") {
+ // COLLECTION_INVALIDATED
+ return
+ }
+
+ toast.success(t("collection.properties_updated"))
+
+ displayModalEditProperties(false)
}
const resolveConfirmModal = (title: string | null) => {
if (title === `${t("confirm.remove_collection")}`) {
- // onRemoveCollection()
+ onRemoveRootCollection()
} else if (title === `${t("confirm.remove_request")}`) {
onRemoveRequest()
} else if (title === `${t("confirm.remove_folder")}`) {
- onRemoveFolder()
+ onRemoveChildCollection()
} else {
console.error(
`Confirm modal title ${title} is not handled by the component`
@@ -573,16 +921,25 @@ const resolveConfirmModal = (title: string | null) => {
}
const resetSelectedData = () => {
- editingFolderPath.value = null
+ editingCollIndexPath.value = ""
}
/**
- * Used to get the index of the request from the path
- * @param path The path of the request
- * @returns The index of the request
+ * @param path The path of the collection or request
+ * @returns The index of the collection or request
*/
-const pathToLastIndex = (path: string) => {
+const pathToIndex = (path: string) => {
const pathArr = path.split("/")
- return parseInt(pathArr[pathArr.length - 1])
+ return pathArr
+}
+
+/**
+ * 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 = pathToIndex(id)
+ return indexPath.length === 1
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/index.ts b/packages/hoppscotch-common/src/services/new-workspace/index.ts
index 29e6f006e..a9bcf0705 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/index.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/index.ts
@@ -8,10 +8,10 @@ import {
shallowRef,
watch,
} from "vue"
-import { WorkspaceProvider } from "./provider"
+import { UpdatedCollectionProperties, WorkspaceProvider } from "./provider"
import { HandleRef } from "./handle"
import * as E from "fp-ts/Either"
-import { Workspace, WorkspaceCollection } from "./workspace"
+import { Workspace, WorkspaceCollection, WorkspaceRequest } from "./workspace"
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
import { HoppRESTRequest } from "@hoppscotch/data"
@@ -138,6 +138,36 @@ export class NewWorkspaceService extends Service {
return E.right(result.right)
}
+ public async getRequestHandle(
+ parentCollHandle: HandleRef,
+ requestID: string
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ if (parentCollHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ parentCollHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.getRequestHandle(parentCollHandle, requestID)
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
public async createRESTRootCollection(
workspaceHandle: HandleRef,
collectionName: string
@@ -173,8 +203,7 @@ export class NewWorkspaceService extends Service {
public async createRESTChildCollection(
parentCollHandle: HandleRef,
- collectionName: string,
- path: string
+ collectionName: string
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
@@ -195,8 +224,7 @@ export class NewWorkspaceService extends Service {
const result = await provider.createRESTChildCollection(
parentCollHandle,
- collectionName,
- path
+ collectionName
)
if (E.isLeft(result)) {
@@ -206,10 +234,166 @@ export class NewWorkspaceService extends Service {
return E.right(result.right)
}
+ public async editRESTRootCollection(
+ collHandle: HandleRef,
+ newCollectionName: string
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ 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.editRESTRootCollection(
+ collHandle,
+ newCollectionName
+ )
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async editRESTChildCollection(
+ collHandle: HandleRef,
+ newCollectionName: string
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ 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,
+ updatedCollProps: UpdatedCollectionProperties
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ 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)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async removeRESTRootCollection(
+ collHandle: HandleRef
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ 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.removeRESTRootCollection(collHandle)
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async removeRESTChildCollection(
+ parentCollHandle: HandleRef
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ if (parentCollHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ parentCollHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.removeRESTChildCollection(parentCollHandle)
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
public async createRESTRequest(
parentCollHandle: HandleRef,
- requestName: string,
- path: string
+ requestName: string
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
@@ -230,8 +414,7 @@ export class NewWorkspaceService extends Service {
const result = await provider.createRESTRequest(
parentCollHandle,
- requestName,
- path
+ requestName
)
if (E.isLeft(result)) {
@@ -242,104 +425,26 @@ export class NewWorkspaceService extends Service {
}
public async removeRESTRequest(
- parentCollHandle: HandleRef,
- path: string,
- requestIndex: number
+ requestHandle: HandleRef
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
- HandleRef
+ HandleRef
>
> {
- if (parentCollHandle.value.type === "invalid") {
+ if (requestHandle.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
- parentCollHandle.value.data.providerID
+ requestHandle.value.data.providerID
)
if (!provider) {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
}
- const result = await provider.removeRESTRequest(
- parentCollHandle,
- path,
- requestIndex
- )
-
- if (E.isLeft(result)) {
- return E.left({ type: "PROVIDER_ERROR", error: result.left })
- }
-
- return E.right(result.right)
- }
-
- public async selectRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: string,
- request: HoppRESTRequest
- ): Promise<
- E.Either<
- WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
- HandleRef
- >
- > {
- if (parentCollHandle.value.type === "invalid") {
- return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
- }
-
- const provider = this.registeredProviders.get(
- parentCollHandle.value.data.providerID
- )
-
- if (!provider) {
- return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
- }
-
- const result = await provider.selectRESTRequest(
- parentCollHandle,
- collPath,
- requestIndex,
- request
- )
-
- if (E.isLeft(result)) {
- return E.left({ type: "PROVIDER_ERROR", error: result.left })
- }
-
- return E.right(result.right)
- }
-
- public async duplicateRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- request: HoppRESTRequest
- ): Promise<
- E.Either<
- WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
- HandleRef
- >
- > {
- if (parentCollHandle.value.type === "invalid") {
- return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
- }
-
- const provider = this.registeredProviders.get(
- parentCollHandle.value.data.providerID
- )
-
- if (!provider) {
- return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
- }
-
- const result = await provider.duplicateRESTRequest(
- parentCollHandle,
- collPath,
- request
- )
+ const result = await provider.removeRESTRequest(requestHandle)
if (E.isLeft(result)) {
return E.left({ type: "PROVIDER_ERROR", error: result.left })
@@ -349,34 +454,27 @@ export class NewWorkspaceService extends Service {
}
public async editRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: number,
- request: HoppRESTRequest
+ requestHandle: HandleRef,
+ newRequestName: string
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
- HandleRef
+ HandleRef
>
> {
- if (parentCollHandle.value.type === "invalid") {
+ if (requestHandle.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
- parentCollHandle.value.data.providerID
+ requestHandle.value.data.providerID
)
if (!provider) {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
}
- const result = await provider.editRESTRequest(
- parentCollHandle,
- collPath,
- requestIndex,
- request
- )
+ const result = await provider.editRESTRequest(requestHandle, newRequestName)
if (E.isLeft(result)) {
return E.left({ type: "PROVIDER_ERROR", error: result.left })
@@ -385,6 +483,35 @@ export class NewWorkspaceService extends Service {
return E.right(result.right)
}
+ public async saveRESTRequest(
+ requestHandle: HandleRef,
+ updatedRequest: HoppRESTRequest
+ ): Promise<
+ E.Either<
+ WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
+ HandleRef
+ >
+ > {
+ if (requestHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ requestHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.saveRESTRequest(requestHandle, updatedRequest)
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
public async getRESTCollectionChildrenView(
collectionHandle: HandleRef
diff --git a/packages/hoppscotch-common/src/services/new-workspace/provider.ts b/packages/hoppscotch-common/src/services/new-workspace/provider.ts
index 653626377..309c1d923 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/provider.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/provider.ts
@@ -1,9 +1,19 @@
import { Ref } from "vue"
import * as E from "fp-ts/Either"
import { HandleRef } from "./handle"
-import { Workspace, WorkspaceCollection, WorkspaceDecor } from "./workspace"
+import {
+ Workspace,
+ WorkspaceCollection,
+ WorkspaceDecor,
+ WorkspaceRequest,
+} from "./workspace"
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
-import { HoppRESTRequest } from "@hoppscotch/data"
+import { HoppRESTAuth, HoppRESTHeaders, HoppRESTRequest } from "@hoppscotch/data"
+
+export type UpdatedCollectionProperties = {
+ auth: HoppRESTAuth
+ headers: HoppRESTHeaders
+}
export interface WorkspaceProvider {
providerID: string
@@ -17,6 +27,10 @@ export interface WorkspaceProvider {
workspaceHandle: HandleRef,
collectionID: string
): Promise>>
+ getRequestHandle(
+ parentCollHandle: HandleRef,
+ requestID: string
+ ): Promise>>
getRESTRootCollectionView(
workspaceHandle: HandleRef
@@ -31,34 +45,39 @@ export interface WorkspaceProvider {
): Promise>>
createRESTChildCollection(
parentCollHandle: HandleRef,
- collectionName: string,
- path: string
+ collectionName: string
+ ): Promise>>
+ editRESTRootCollection(
+ collHandle: HandleRef,
+ newCollectionName: string
+ ): Promise>>
+ editRESTChildCollection(
+ parentCollHandle: HandleRef,
+ newCollectionName: string
+ ): Promise>>
+ editRESTCollectionProperties(
+ parentCollHandle: HandleRef,
+ updatedCollProps: UpdatedCollectionProperties
+ ): Promise>>
+ removeRESTRootCollection(
+ collHandle: HandleRef
+ ): Promise>>
+ removeRESTChildCollection(
+ parentCollHandle: HandleRef
): Promise>>
createRESTRequest(
parentCollHandle: HandleRef,
- requestName: string,
- path: string
+ requestName: string
): Promise>>
removeRESTRequest(
- parentCollHandle: HandleRef,
- path: string,
- requestIndex: number
- ): Promise>>
- selectRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: string,
- request: HoppRESTRequest
- ): Promise>>
- duplicateRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- request: HoppRESTRequest
- ): Promise>>
+ requestHandle: HandleRef
+ ): Promise>>
editRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: number,
- request: HoppRESTRequest
- ): Promise>>
+ requestHandle: HandleRef,
+ newRequestName: string
+ ): Promise>>
+ saveRESTRequest(
+ requestHandle: HandleRef,
+ updatedRequest: HoppRESTRequest
+ ): Promise>>
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
index 37850cd9a..31379a230 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
@@ -10,8 +10,12 @@ import {
addRESTCollection,
addRESTFolder,
cascadeParentCollectionForHeaderAuth,
+ editRESTCollection,
+ editRESTFolder,
editRESTRequest,
navigateToFolderWithIndexPath,
+ removeRESTCollection,
+ removeRESTFolder,
removeRESTRequest,
restCollectionStore,
saveRESTRequestAs,
@@ -19,7 +23,10 @@ import {
import { platform } from "~/platform"
import { HandleRef } from "~/services/new-workspace/handle"
-import { WorkspaceProvider } from "~/services/new-workspace/provider"
+import {
+ UpdatedCollectionProperties,
+ WorkspaceProvider,
+} from "~/services/new-workspace/provider"
import {
RESTCollectionChildrenView,
RESTCollectionViewItem,
@@ -29,6 +36,7 @@ import {
Workspace,
WorkspaceCollection,
WorkspaceDecor,
+ WorkspaceRequest,
} from "~/services/new-workspace/workspace"
import { cloneDeep } from "lodash-es"
@@ -40,6 +48,12 @@ import { RESTTabService } from "~/services/tab/rest"
import IconUser from "~icons/lucide/user"
import { NewWorkspaceService } from ".."
import { HoppRESTRequest } from "@hoppscotch/data"
+import path from "path"
+import {
+ resolveSaveContextOnCollectionReorder,
+ getFoldersByPath,
+ updateInheritedPropertiesForAffectedRequests,
+} from "~/helpers/collection/collection"
export class PersonalWorkspaceProviderService
extends Service
@@ -74,68 +88,14 @@ export class PersonalWorkspaceProviderService
this.workspaceService.registerWorkspaceProvider(this)
}
- private navigateToFolderWithIndexPath(
- collections: HoppCollection[],
- indexPaths: number[]
- ) {
- if (indexPaths.length === 0) return null
-
- let target = collections[indexPaths.shift() as number]
-
- while (indexPaths.length > 0)
- target = target?.folders[indexPaths.shift() as number]
-
- return target !== undefined ? target : null
- }
-
- public createRESTChildCollection(
- parentCollHandle: HandleRef,
- collectionName: string,
- path: string
- ): Promise>> {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
- }
-
- return Promise.resolve(
- E.right(
- computed(() => {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return {
- type: "invalid" as const,
- reason: "WORKSPACE_INVALIDATED" as const,
- }
- }
-
- addRESTFolder(collectionName, path)
-
- platform.analytics?.logEvent({
- type: "HOPP_CREATE_COLLECTION",
- workspaceType: "personal",
- isRootCollection: false,
- platform: "rest",
- })
-
- return {
- type: "ok",
- data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.collectionID,
- name: collectionName,
- },
- }
- })
- )
- )
+ /**
+ * Used to get the index of the request from the path
+ * @param path The path of the request
+ * @returns The index of the request
+ */
+ private pathToLastIndex(path: string) {
+ const pathArr = path.split("/")
+ return parseInt(pathArr[pathArr.length - 1])
}
public createRESTRootCollection(
@@ -164,18 +124,17 @@ export class PersonalWorkspaceProviderService
}
}
- addRESTCollection(
- makeCollection({
- name: collectionName,
- folders: [],
- requests: [],
- headers: [],
- auth: {
- authType: "inherit",
- authActive: false,
- },
- })
- )
+ const newRootCollection = makeCollection({
+ name: collectionName,
+ folders: [],
+ requests: [],
+ headers: [],
+ auth: {
+ authType: "inherit",
+ authActive: false,
+ },
+ })
+ addRESTCollection(newRootCollection)
platform.analytics?.logEvent({
type: "HOPP_CREATE_COLLECTION",
@@ -190,7 +149,364 @@ export class PersonalWorkspaceProviderService
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
collectionID: "",
- name: collectionName,
+ collection: newRootCollection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public createRESTChildCollection(
+ parentCollHandle: HandleRef,
+ collectionName: string
+ ): Promise>> {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
+ }
+
+ return Promise.resolve(
+ E.right(
+ computed(() => {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return {
+ type: "invalid" as const,
+ reason: "COLLECTION_INVALIDATED" as const,
+ }
+ }
+
+ const { collectionID, providerID, workspaceID } =
+ parentCollHandle.value.data
+
+ addRESTFolder(collectionName, collectionID)
+
+ platform.analytics?.logEvent({
+ type: "HOPP_CREATE_COLLECTION",
+ workspaceType: "personal",
+ isRootCollection: false,
+ platform: "rest",
+ })
+
+ const newCollection = navigateToFolderWithIndexPath(
+ this.restCollectionState.value.state,
+ collectionID.split("/").map((id) => parseInt(id))
+ ) as HoppCollection
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: newCollection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public editRESTRootCollection(
+ collHandle: HandleRef,
+ newCollectionName: string
+ ): Promise>> {
+ 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 { collection, collectionID, providerID, workspaceID } =
+ collHandle.value.data
+
+ const updatedCollection = {
+ ...(collection as HoppCollection),
+ name: newCollectionName,
+ }
+
+ const collectionIndex = parseInt(collectionID)
+ editRESTCollection(collectionIndex, updatedCollection)
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: updatedCollection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public editRESTChildCollection(
+ collHandle: HandleRef,
+ newCollectionName: string
+ ): Promise>> {
+ 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 { collection, collectionID, providerID, workspaceID } =
+ collHandle.value.data
+
+ const updatedCollection = {
+ ...(collection as HoppCollection),
+ name: newCollectionName,
+ }
+
+ editRESTFolder(collectionID, updatedCollection)
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: updatedCollection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public editRESTCollectionProperties(
+ collHandle: HandleRef,
+ updatedCollProps: UpdatedCollectionProperties
+ ): Promise>> {
+ 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 { collection, collectionID, providerID, workspaceID } =
+ collHandle.value.data
+
+ const { auth, headers } = updatedCollProps
+
+ const updatedCollection = {
+ ...collection,
+ auth,
+ headers,
+ } as HoppCollection
+
+ const isRootCollection = collectionID.split("/").length === 1
+
+ if (isRootCollection) {
+ editRESTCollection(parseInt(collectionID), updatedCollection)
+ } else {
+ editRESTFolder(collectionID, updatedCollection)
+ }
+
+ const { auth: cascadedAuth, headers: cascadedHeaders } =
+ cascadeParentCollectionForHeaderAuth(collectionID, "rest")
+
+ nextTick(() => {
+ updateInheritedPropertiesForAffectedRequests(
+ collectionID,
+ {
+ auth: cascadedAuth,
+ headers: cascadedHeaders,
+ },
+ "rest"
+ )
+ })
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: updatedCollection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public removeRESTRootCollection(
+ collHandle: HandleRef
+ ): Promise>> {
+ 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, providerID, workspaceID } =
+ collHandle.value.data
+
+ const collectionIndex = parseInt(collectionID)
+
+ const collectionToRemove = navigateToFolderWithIndexPath(
+ restCollectionStore.value.state,
+ [collectionIndex]
+ )
+
+ removeRESTCollection(
+ collectionIndex,
+ collectionToRemove ? collectionToRemove.id : undefined
+ )
+
+ resolveSaveContextOnCollectionReorder({
+ lastIndex: collectionIndex,
+ newIndex: -1,
+ folderPath: "", // root collection
+ length: this.restCollectionState.value.state.length,
+ })
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: null,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public removeRESTChildCollection(
+ parentCollHandle: HandleRef
+ ): Promise>> {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
+ }
+
+ return Promise.resolve(
+ E.right(
+ computed(() => {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return {
+ type: "invalid" as const,
+ reason: "COLLECTION_INVALIDATED" as const,
+ }
+ }
+
+ const { collectionID, providerID, workspaceID } =
+ parentCollHandle.value.data
+
+ const folderToRemove = path
+ ? navigateToFolderWithIndexPath(
+ restCollectionStore.value.state,
+ collectionID.split("/").map((i) => parseInt(i))
+ )
+ : undefined
+
+ removeRESTFolder(
+ collectionID,
+ folderToRemove ? folderToRemove.id : undefined
+ )
+
+ const parentFolder = collectionID.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
+ resolveSaveContextOnCollectionReorder({
+ lastIndex: this.pathToLastIndex(collectionID),
+ newIndex: -1,
+ folderPath: parentFolder,
+ length: getFoldersByPath(
+ this.restCollectionState.value.state,
+ parentFolder
+ ).length,
+ })
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: null,
},
}
})
@@ -200,8 +516,7 @@ export class PersonalWorkspaceProviderService
public createRESTRequest(
parentCollHandle: HandleRef,
- requestName: string,
- path: string
+ requestName: string
): Promise>> {
if (
parentCollHandle.value.type !== "ok" ||
@@ -225,15 +540,18 @@ export class PersonalWorkspaceProviderService
}
}
+ const { collectionID, providerID, workspaceID } =
+ parentCollHandle.value.data
+
const newRequest = {
...cloneDeep(this.tabs.currentActiveTab.value.document.request),
name: requestName,
}
- const insertionIndex = saveRESTRequestAs(path, newRequest)
+ const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
- path,
+ collectionID,
"rest"
)
@@ -242,7 +560,7 @@ export class PersonalWorkspaceProviderService
isDirty: false,
saveContext: {
originLocation: "user-collection",
- folderPath: path,
+ folderPath: collectionID,
requestIndex: insertionIndex,
},
inheritedProperties: {
@@ -258,13 +576,18 @@ export class PersonalWorkspaceProviderService
platform: "rest",
})
+ const newCollection = navigateToFolderWithIndexPath(
+ this.restCollectionState.value.state,
+ collectionID.split("/").map((id) => parseInt(id))
+ ) as HoppCollection
+
return {
type: "ok",
data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.collectionID,
- name: requestName,
+ providerID,
+ workspaceID,
+ collectionID,
+ collection: newCollection,
},
}
})
@@ -273,35 +596,37 @@ export class PersonalWorkspaceProviderService
}
public removeRESTRequest(
- parentCollHandle: HandleRef,
- path: string,
- requestIndex: number
- ): Promise>> {
+ requestHandle: HandleRef
+ ): Promise>> {
if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
) {
- return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
+ return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
return Promise.resolve(
E.right(
computed(() => {
if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
) {
return {
type: "invalid" as const,
- reason: "WORKSPACE_INVALIDATED" as const,
+ reason: "REQUEST_INVALIDATED" as const,
}
}
+ const { collectionID, providerID, requestID, workspaceID } =
+ requestHandle.value.data
+ const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
+
const possibleTab = this.tabs.getTabRefWithSaveContext({
originLocation: "user-collection",
- folderPath: path,
+ folderPath: collectionID,
requestIndex,
})
@@ -311,152 +636,32 @@ export class PersonalWorkspaceProviderService
possibleTab.value.document.isDirty = true
}
- console.log(
- `REST collection store state is `,
- restCollectionStore.value.state
- )
-
const requestToRemove = navigateToFolderWithIndexPath(
restCollectionStore.value.state,
- path.split("/").map((i) => parseInt(i))
+ collectionID.split("/").map((i) => parseInt(i))
)?.requests[requestIndex]
- removeRESTRequest(path, requestIndex, requestToRemove?.id)
+ removeRESTRequest(collectionID, requestIndex, requestToRemove?.id)
// the same function is used to reorder requests since after removing, it's basically doing reorder
resolveSaveContextOnRequestReorder({
lastIndex: requestIndex,
newIndex: -1,
- folderPath: path,
+ folderPath: collectionID,
length: getRequestsByPath(
this.restCollectionState.value.state,
- path
+ collectionID
).length,
})
return {
type: "ok",
data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.workspaceID,
- name: "" as const,
- },
- }
- })
- )
- )
- }
-
- public selectRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: string,
- request: HoppRESTRequest
- ): Promise>> {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
- }
-
- return Promise.resolve(
- E.right(
- computed(() => {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return {
- type: "invalid" as const,
- reason: "WORKSPACE_INVALIDATED" as const,
- }
- }
-
- // If there is a request with this save context, switch into it
- let possibleTab = null
-
- const { auth, headers } = cascadeParentCollectionForHeaderAuth(
- collPath,
- "rest"
- )
- possibleTab = this.tabs.getTabRefWithSaveContext({
- originLocation: "user-collection",
- requestIndex: parseInt(requestIndex),
- folderPath: collPath!,
- })
- if (possibleTab) {
- this.tabs.setActiveTab(possibleTab.value.id)
- } else {
- // If not, open the request in a new tab
- this.tabs.createNewTab({
- request: cloneDeep(request),
- isDirty: false,
- saveContext: {
- originLocation: "user-collection",
- folderPath: collPath!,
- requestIndex: parseInt(requestIndex),
- },
- inheritedProperties: {
- auth,
- headers,
- },
- })
- }
-
- return {
- type: "ok",
- data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.workspaceID,
- name: "",
- },
- }
- })
- )
- )
- }
-
- public duplicateRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- request: HoppRESTRequest
- ): Promise>> {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
- }
-
- return Promise.resolve(
- E.right(
- computed(() => {
- if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
- ) {
- return {
- type: "invalid" as const,
- reason: "WORKSPACE_INVALIDATED" as const,
- }
- }
-
- saveRESTRequestAs(collPath, request)
-
- return {
- type: "ok",
- data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.workspaceID,
- name: "",
+ providerID,
+ workspaceID,
+ collectionID,
+ requestID,
+ request: null,
},
}
})
@@ -465,43 +670,52 @@ export class PersonalWorkspaceProviderService
}
public editRESTRequest(
- parentCollHandle: HandleRef,
- collPath: string,
- requestIndex: number,
- request: HoppRESTRequest
- ): Promise>> {
+ requestHandle: HandleRef,
+ newRequestName: string
+ ): Promise>> {
if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
) {
- return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
+ return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
return Promise.resolve(
E.right(
computed(() => {
if (
- parentCollHandle.value.type !== "ok" ||
- parentCollHandle.value.data.providerID !== this.providerID ||
- parentCollHandle.value.data.workspaceID !== "personal"
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
) {
return {
type: "invalid" as const,
- reason: "WORKSPACE_INVALIDATED" as const,
+ reason: "REQUEST_INVALIDATED" as const,
}
}
+ const { collectionID, providerID, request, requestID, workspaceID } =
+ requestHandle.value.data
+ const requestIndexPath = requestID.split("/").slice(-1).join("")
+
+ const requestIndex = parseInt(requestIndexPath)
+
+ const updatedRequest = {
+ ...request,
+ name: newRequestName || request?.name,
+ } as HoppRESTRequest
+
const possibleActiveTab = this.tabs.getTabRefWithSaveContext({
originLocation: "user-collection",
requestIndex,
- collPath,
+ folderPath: collectionID,
})
- editRESTRequest(collPath, requestIndex, request)
+ editRESTRequest(collectionID, requestIndex, updatedRequest)
if (possibleActiveTab) {
- possibleActiveTab.value.document.request.name = request.name
+ possibleActiveTab.value.document.request.name = updatedRequest.name
nextTick(() => {
possibleActiveTab.value.document.isDirty = false
})
@@ -510,10 +724,72 @@ export class PersonalWorkspaceProviderService
return {
type: "ok",
data: {
- providerID: this.providerID,
- workspaceID: parentCollHandle.value.data.workspaceID,
- collectionID: parentCollHandle.value.data.workspaceID,
- name: "",
+ providerID,
+ workspaceID,
+ collectionID,
+ requestID,
+ request: updatedRequest,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public saveRESTRequest(
+ requestHandle: HandleRef,
+ updatedRequest: HoppRESTRequest
+ ): Promise>> {
+ if (
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
+ }
+
+ return Promise.resolve(
+ E.right(
+ computed(() => {
+ if (
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
+ ) {
+ return {
+ type: "invalid" as const,
+ reason: "REQUEST_INVALIDATED" as const,
+ }
+ }
+
+ const { collectionID, providerID, requestID, workspaceID } =
+ requestHandle.value.data
+
+ try {
+ const requestIndex = parseInt(requestID)
+ editRESTRequest(collectionID, requestIndex, updatedRequest)
+
+ platform.analytics?.logEvent({
+ type: "HOPP_SAVE_REQUEST",
+ platform: "rest",
+ createdNow: false,
+ workspaceType: "personal",
+ })
+ } catch (err) {
+ return {
+ type: "invalid" as const,
+ reason: "REQUEST_PATH_NOT_FOUND" as const,
+ }
+ }
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ requestID,
+ request: updatedRequest,
},
}
})
@@ -524,9 +800,7 @@ export class PersonalWorkspaceProviderService
public getCollectionHandle(
workspaceHandle: HandleRef,
collectionID: string
- ): Promise<
- E.Either<"INVALID_WORKSPACE_HANDLE", HandleRef>
- > {
+ ): Promise>> {
if (
workspaceHandle.value.type !== "ok" ||
workspaceHandle.value.data.providerID !== this.providerID ||
@@ -544,18 +818,117 @@ export class PersonalWorkspaceProviderService
workspaceHandle.value.data.workspaceID !== "personal"
) {
return {
- type: "invalid",
+ type: "invalid" as const,
reason: "WORKSPACE_INVALIDATED" as const,
}
}
+ if (!collectionID) {
+ return {
+ type: "invalid" as const,
+ reason: "INVALID_COLLECTION_HANDLE" as const,
+ }
+ }
+
+ const collection = navigateToFolderWithIndexPath(
+ this.restCollectionState.value.state,
+ collectionID.split("/").map((x) => parseInt(x))
+ )
+
+ if (!collection) {
+ return {
+ type: "invalid" as const,
+ reason: "INVALID_COLLECTION_HANDLE" as const,
+ }
+ }
+
+ const { providerID, workspaceID } = workspaceHandle.value.data
+
+ return {
+ type: "ok",
+ data: {
+ providerID,
+ workspaceID,
+ collectionID,
+ collection,
+ },
+ }
+ })
+ )
+ )
+ }
+
+ public getRequestHandle(
+ parentCollHandle: HandleRef,
+ requestID: string
+ ): Promise>> {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
+ }
+
+ return Promise.resolve(
+ E.right(
+ computed(() => {
+ if (
+ parentCollHandle.value.type !== "ok" ||
+ parentCollHandle.value.data.providerID !== this.providerID ||
+ parentCollHandle.value.data.workspaceID !== "personal"
+ ) {
+ return {
+ type: "invalid" as const,
+ reason: "COLLECTION_INVALIDATED" as const,
+ }
+ }
+
+ if (!requestID) {
+ return {
+ type: "invalid" as const,
+ reason: "INVALID_REQUEST_HANDLE" as const,
+ }
+ }
+
+ const { collectionID, providerID, workspaceID } = parentCollHandle.value.data
+
+ const requestIndexPath = requestID.split("/").slice(-1)[0]
+
+ if (!collectionID || !requestIndexPath) {
+ return {
+ type: "invalid" as const,
+ reason: "INVALID_REQUEST_HANDLE" as const,
+ }
+ }
+
+ const requestIndex = parseInt(requestIndexPath)
+
+ // Navigate to the collection containing the request
+ const collection = navigateToFolderWithIndexPath(
+ this.restCollectionState.value.state,
+ collectionID.split("/").map((x) => parseInt(x))
+ )
+
+ // Grab the request with it's index
+ const request = (collection?.requests[requestIndex] ??
+ null) as HoppRESTRequest | null
+
+ if (!request) {
+ return {
+ type: "invalid" as const,
+ reason: "INVALID_REQUEST_HANDLE" as const,
+ }
+ }
+
return {
type: "ok",
data: {
- providerID: this.providerID,
- workspaceID: workspaceHandle.value.data.workspaceID,
+ providerID,
+ workspaceID,
collectionID,
- name: "" as const,
+ requestID,
+ request,
},
}
})
@@ -597,7 +970,7 @@ export class PersonalWorkspaceProviderService
.split("/")
.map((x) => parseInt(x))
- const item = this.navigateToFolderWithIndexPath(
+ const item = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
indexPath
)
@@ -608,7 +981,7 @@ export class PersonalWorkspaceProviderService
type: "collection",
value: {
collectionID: `${collectionID}/${id}`,
- name: childColl.name,
+ collection: childColl,
},
}
})
@@ -618,8 +991,6 @@ export class PersonalWorkspaceProviderService
type: "request",
value: {
requestID: `${collectionID}/${id}`,
- name: req.name,
- method: req.method,
request: req,
},
}
@@ -669,7 +1040,7 @@ export class PersonalWorkspaceProviderService
return this.restCollectionState.value.state.map((coll, id) => {
return {
collectionID: id.toString(),
- name: coll.name,
+ collection: coll,
}
})
}),
@@ -701,7 +1072,6 @@ export class PersonalWorkspaceProviderService
workspaceID: "personal",
name: "Personal Workspace",
- collectionsAreReadonly: false,
},
})
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/view.ts b/packages/hoppscotch-common/src/services/new-workspace/view.ts
index fc9c27260..d54ca7f8e 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/view.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/view.ts
@@ -1,16 +1,16 @@
-import { HoppRESTRequest } from "@hoppscotch/data"
+import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { Ref } from "vue"
export type RESTCollectionViewCollection = {
collectionID: string
- name: string
+
+ collection: HoppCollection
}
export type RESTCollectionViewRequest = {
+ collectionID: string
requestID: string
- name: string
- method: string
request: HoppRESTRequest
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/workspace.ts
index 8eb3043c5..f4da935c8 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/workspace.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/workspace.ts
@@ -1,3 +1,4 @@
+import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { Component } from "vue"
export type Workspace = {
@@ -5,8 +6,6 @@ export type Workspace = {
workspaceID: string
name: string
-
- collectionsAreReadonly: boolean
}
export type WorkspaceCollection = {
@@ -14,7 +13,16 @@ export type WorkspaceCollection = {
workspaceID: string
collectionID: string
- name: string
+ collection: HoppCollection | null
+}
+
+export type WorkspaceRequest = {
+ providerID: string
+ workspaceID: string
+ collectionID: string
+ requestID: string
+
+ request: HoppRESTRequest | null
}
export type WorkspaceDecor = {