refactor: updates based on the provider methods signature changes

This commit is contained in:
jamesgeorge007
2024-02-09 22:49:38 +05:30
parent c1a8a871d2
commit 392b2fc48d
8 changed files with 476 additions and 432 deletions

View File

@@ -292,20 +292,19 @@ const saveRequestAs = async () => {
return
}
const resultHandle = await workspaceService.updateRESTRequest(
const updateRequestResult = await workspaceService.updateRESTRequest(
requestHandle,
updatedRequest
)
if (E.isLeft(resultHandle)) {
if (E.isLeft(updateRequestResult)) {
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
return
}
const result = resultHandle.right
if (updateRequestResult.right.type === "invalid") {
// REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND
if (result.value.type === "invalid") {
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
return
}

View File

@@ -544,9 +544,18 @@ const saveRequest = async () => {
if (E.isLeft(updateRequestResult)) {
// INVALID_REQUEST_HANDLE
showSaveRequestModal.value = true
return
}
if (!tab.value.document.isDirty) {
tab.value.document.isDirty = true
const resultHandle = updateRequestResult.right
if (resultHandle.type === "invalid") {
// REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND
if (resultHandle.reason === "REQUEST_PATH_NOT_FOUND") {
// REQUEST_PATH_NOT_FOUND
tab.value.document.saveContext = undefined
await saveRequest()
}
return
}

View File

@@ -139,9 +139,7 @@ import IconImport from "~icons/lucide/folder-down"
import IconHelpCircle from "~icons/lucide/help-circle"
import IconPlus from "~icons/lucide/plus"
import {
cascadeParentCollectionForHeaderAuth,
navigateToFolderWithIndexPath,
restCollectionStore,
restCollections$,
saveRESTRequestAs,
} from "~/newstore/collections"
@@ -256,12 +254,9 @@ const displayConfirmModal = (show: boolean) => {
const addNewRootCollection = async (name: string) => {
modalLoadingState.value = true
const newCollectionID = restCollectionState.value.length.toString()
const result = await workspaceService.createRESTRootCollection(
props.workspaceHandle,
name,
newCollectionID
{ name }
)
if (E.isLeft(result)) {
@@ -306,19 +301,13 @@ const onRemoveRootCollection = async () => {
return
}
const result =
await workspaceService.removeRESTRootCollection(collectionHandle)
const result = await workspaceService.removeRESTCollection(collectionHandle)
if (E.isLeft(result)) {
// INVALID_COLLECTION_HANDLE
return
}
if (result.right.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
toast.success(t("state.deleted"))
displayConfirmModal(false)
}
@@ -370,10 +359,24 @@ const onAddRequest = async (requestName: string) => {
return
}
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
requestHandle.value.data.collectionID,
"rest"
)
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
collectionHandle
)
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
// INVALID_COLLECTION_HANDLE
return
}
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
if (cascadingAuthHeadersHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const { auth, headers } = cascadingAuthHeadersHandle.value.data
tabs.createNewTab({
request: newRequest,
@@ -396,7 +399,7 @@ const addChildCollection = (parentCollectionIndexPath: string) => {
displayModalAddChildColl(true)
}
const onAddChildCollection = async (childCollectionName: string) => {
const onAddChildCollection = async (newChildCollectionName: string) => {
const parentCollectionIndexPath = editingCollectionIndexPath.value
const collectionHandleResult = await workspaceService.getCollectionHandle(
@@ -418,7 +421,7 @@ const onAddChildCollection = async (childCollectionName: string) => {
const result = await workspaceService.createRESTChildCollection(
collectionHandle,
childCollectionName
{ name: newChildCollectionName }
)
if (E.isLeft(result)) {
@@ -466,29 +469,15 @@ const onEditRootCollection = async (newCollectionName: string) => {
return
}
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
const updatedCollection = navigateToFolderWithIndexPath(
restCollectionStore.value.state,
collectionIndexPath.split("/").map((id) => parseInt(id))
) as HoppCollection
updatedCollection.name = newCollectionName
const result = await workspaceService.editRESTCollection(
collectionHandle,
updatedCollection
)
const result = await workspaceService.updateRESTCollection(collectionHandle, {
name: 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"))
}
@@ -505,7 +494,7 @@ const editChildCollection = (payload: {
displayModalEditChildCollection(true)
}
const onEditChildCollection = async (newCollectionName: string) => {
const onEditChildCollection = async (newChildCollectionName: string) => {
const collectionIndexPath = editingChildCollectionIndexPath.value
const collectionHandleResult = await workspaceService.getCollectionHandle(
@@ -525,29 +514,15 @@ const onEditChildCollection = async (newCollectionName: string) => {
return
}
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
const updatedCollection = navigateToFolderWithIndexPath(
restCollectionStore.value.state,
collectionIndexPath.split("/").map((id) => parseInt(id))
) as HoppCollection
updatedCollection.name = newCollectionName
const result = await workspaceService.editRESTCollection(
collectionHandle,
updatedCollection
)
const result = await workspaceService.updateRESTCollection(collectionHandle, {
name: newChildCollectionName,
})
if (E.isLeft(result)) {
// INVALID_COLLECTION_HANDLE
return
}
if (result.right.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
displayModalEditChildCollection(false)
toast.success(t("collection.renamed"))
}
@@ -580,7 +555,7 @@ const onRemoveChildCollection = async () => {
return
}
const result = await workspaceService.removeRESTChildCollection(
const result = await workspaceService.removeRESTCollection(
parentCollectionHandle
)
@@ -589,11 +564,6 @@ const onRemoveChildCollection = async () => {
return
}
if (result.right.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
toast.success(t("state.deleted"))
displayConfirmModal(false)
}
@@ -635,11 +605,6 @@ const onRemoveRequest = async () => {
return
}
if (result.right.value.type === "invalid") {
// WORKSPACE_INVALIDATED
return
}
const possibleTab = tabs.getTabRefWithSaveContext({
originLocation: "workspace-user-collection",
requestHandle,
@@ -669,6 +634,23 @@ const onRemoveRequest = async () => {
const selectRequest = async (requestIndexPath: string) => {
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
const collectionHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
collectionIndexPath
)
if (E.isLeft(collectionHandleResult)) {
// INVALID_WORKSPACE_HANDLE
return
}
const collectionHandle = collectionHandleResult.right
if (collectionHandle.value.type === "invalid") {
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
const requestHandleResult = await workspaceService.getRequestHandle(
props.workspaceHandle,
requestIndexPath
@@ -686,15 +668,30 @@ const selectRequest = async (requestIndexPath: string) => {
return
}
const request = requestHandle.value.data.request as HoppRESTRequest
const request = requestHandle.value.data.request
// If there is a request with this save context, switch into it
let possibleTab = null
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
collectionIndexPath,
"rest"
)
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
collectionHandle
)
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
// INVALID_COLLECTION_HANDLE
return
}
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
if (cascadingAuthHeadersHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const { auth, headers } = cascadingAuthHeadersHandle.value.data
possibleTab = tabs.getTabRefWithSaveContext({
originLocation: "workspace-user-collection",
requestHandle,
@@ -766,7 +763,7 @@ const editRequest = (payload: {
displayModalEditRequest(true)
}
const onEditRequest = async (newReqName: string) => {
const onEditRequest = async (newRequestName: string) => {
const requestID = editingRequestIndexPath.value
const requestHandleResult = await workspaceService.getRequestHandle(
@@ -786,22 +783,16 @@ const onEditRequest = async (newReqName: string) => {
return
}
const updatedRequest = {
...requestHandle.value.data.request,
name: newReqName,
} as HoppRESTRequest
const result = await workspaceService.updateRESTRequest(
requestHandle,
updatedRequest
)
const result = await workspaceService.updateRESTRequest(requestHandle, {
name: newRequestName,
})
if (E.isLeft(result)) {
// INVALID_REQUEST_HANDLE
return
}
if (result.right.value.type === "invalid") {
if (result.right.type === "invalid") {
// REQUEST_INVALIDATED
return
}
@@ -830,18 +821,6 @@ const editCollectionProperties = async (collectionIndexPath: string) => {
},
],
} as HoppInheritedProperty
// Have a provider level implementation that returns a view that says what the headesd and auth are
if (parentIndex) {
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
parentIndex,
"rest"
)
inheritedProperties = {
auth,
headers,
}
}
const collectionHandleResult = await workspaceService.getCollectionHandle(
props.workspaceHandle,
@@ -860,6 +839,32 @@ const editCollectionProperties = async (collectionIndexPath: string) => {
return
}
if (parentIndex) {
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
collectionHandle
)
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
// INVALID_COLLECTION_HANDLE
return
}
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
if (cascadingAuthHeadersHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const { auth, headers } = cascadingAuthHeadersHandle.value.data
inheritedProperties = {
auth,
headers,
}
}
const collection = navigateToFolderWithIndexPath(
restCollectionState.value,
collectionIndexPath.split("/").map((id) => parseInt(id))
@@ -899,35 +904,35 @@ const setCollectionProperties = async (updatedCollectionProps: {
return
}
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
const collection = navigateToFolderWithIndexPath(
restCollectionStore.value.state,
collectionIndexPath.split("/").map((id) => parseInt(id))
) as HoppCollection
const updatedCollection = {
...collection,
const result = await workspaceService.updateRESTCollection(collectionHandle, {
auth,
headers,
}
const result = await workspaceService.editRESTCollection(
collectionHandle,
updatedCollection
)
})
if (E.isLeft(result)) {
// INVALID_COLLECTION_HANDLE
return
}
if (result.right.value.type === "invalid") {
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
collectionHandle
)
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
// INVALID_COLLECTION_HANDLE
return
}
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
if (cascadingAuthHeadersHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const { auth: cascadedAuth, headers: cascadedHeaders } =
cascadeParentCollectionForHeaderAuth(collectionIndexPath, "rest")
cascadingAuthHeadersHandle.value.data
nextTick(() => {
updateInheritedPropertiesForAffectedRequests(