refactor: update coll properties when syncing
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
mutation UpdateUserCollection(
|
||||||
|
$userCollectionID: ID!
|
||||||
|
$newTitle: String
|
||||||
|
$data: String
|
||||||
|
) {
|
||||||
|
updateUserCollection(
|
||||||
|
userCollectionID: $userCollectionID
|
||||||
|
newTitle: $newTitle
|
||||||
|
data: $data
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
data
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@ query GetUserRootCollections {
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
type
|
type
|
||||||
|
data
|
||||||
childrenREST {
|
childrenREST {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
type
|
type
|
||||||
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ subscription UserCollectionCreated {
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
type
|
type
|
||||||
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ subscription userCollectionUpdated {
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
type
|
type
|
||||||
|
data
|
||||||
parent {
|
parent {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ import {
|
|||||||
GetGqlRootUserCollectionsQueryVariables,
|
GetGqlRootUserCollectionsQueryVariables,
|
||||||
GetGqlRootUserCollectionsDocument,
|
GetGqlRootUserCollectionsDocument,
|
||||||
ReqType,
|
ReqType,
|
||||||
|
UpdateUserCollectionMutation,
|
||||||
|
UpdateUserCollectionMutationVariables,
|
||||||
|
UpdateUserCollectionDocument,
|
||||||
} from "../../api/generated/graphql"
|
} from "../../api/generated/graphql"
|
||||||
|
|
||||||
export const createRESTRootUserCollection = (title: string) =>
|
export const createRESTRootUserCollection = (title: string) =>
|
||||||
@@ -160,6 +163,17 @@ export const renameUserCollection = (
|
|||||||
""
|
""
|
||||||
>(RenameUserCollectionDocument, { userCollectionID, newTitle })()
|
>(RenameUserCollectionDocument, { userCollectionID, newTitle })()
|
||||||
|
|
||||||
|
export const updateUserCollection = (
|
||||||
|
userCollectionID: string,
|
||||||
|
newTitle?: string,
|
||||||
|
data?: string
|
||||||
|
) =>
|
||||||
|
runMutation<
|
||||||
|
UpdateUserCollectionMutation,
|
||||||
|
UpdateUserCollectionMutationVariables,
|
||||||
|
""
|
||||||
|
>(UpdateUserCollectionDocument, { userCollectionID, newTitle, data })()
|
||||||
|
|
||||||
export const moveUserCollection = (
|
export const moveUserCollection = (
|
||||||
sourceCollectionID: string,
|
sourceCollectionID: string,
|
||||||
destinationCollectionID?: string
|
destinationCollectionID?: string
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ type ExportedUserCollectionREST = {
|
|||||||
folders: ExportedUserCollectionREST[]
|
folders: ExportedUserCollectionREST[]
|
||||||
requests: Array<HoppRESTRequest & { id: string }>
|
requests: Array<HoppRESTRequest & { id: string }>
|
||||||
name: string
|
name: string
|
||||||
auth: HoppRESTRequest["auth"]
|
data: string
|
||||||
headers: HoppRESTRequest["headers"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExportedUserCollectionGQL = {
|
type ExportedUserCollectionGQL = {
|
||||||
@@ -98,8 +97,7 @@ type ExportedUserCollectionGQL = {
|
|||||||
folders: ExportedUserCollectionGQL[]
|
folders: ExportedUserCollectionGQL[]
|
||||||
requests: Array<HoppGQLRequest & { id: string }>
|
requests: Array<HoppGQLRequest & { id: string }>
|
||||||
name: string
|
name: string
|
||||||
auth: HoppGQLRequest["auth"]
|
data: string
|
||||||
headers: HoppGQLRequest["headers"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportedCollectionToHoppCollection(
|
function exportedCollectionToHoppCollection(
|
||||||
@@ -108,6 +106,8 @@ function exportedCollectionToHoppCollection(
|
|||||||
): HoppCollection<HoppRESTRequest | HoppGQLRequest> {
|
): HoppCollection<HoppRESTRequest | HoppGQLRequest> {
|
||||||
if (collectionType == "REST") {
|
if (collectionType == "REST") {
|
||||||
const restCollection = collection as ExportedUserCollectionREST
|
const restCollection = collection as ExportedUserCollectionREST
|
||||||
|
const data = restCollection.data ? JSON.parse(restCollection.data) : null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: restCollection.id,
|
id: restCollection.id,
|
||||||
v: 1,
|
v: 1,
|
||||||
@@ -142,11 +142,12 @@ function exportedCollectionToHoppCollection(
|
|||||||
testScript,
|
testScript,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
auth: restCollection.auth,
|
auth: data.auth ?? { authType: "inherit", authActive: false },
|
||||||
headers: restCollection.headers,
|
headers: data.headers ?? [],
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const gqlCollection = collection as ExportedUserCollectionGQL
|
const gqlCollection = collection as ExportedUserCollectionGQL
|
||||||
|
const data = gqlCollection.data ? JSON.parse(gqlCollection.data) : null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: gqlCollection.id,
|
id: gqlCollection.id,
|
||||||
@@ -164,8 +165,8 @@ function exportedCollectionToHoppCollection(
|
|||||||
name,
|
name,
|
||||||
})
|
})
|
||||||
) as HoppGQLRequest[],
|
) as HoppGQLRequest[],
|
||||||
auth: gqlCollection.auth,
|
auth: data.auth,
|
||||||
headers: gqlCollection.headers,
|
headers: data.headers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,6 +298,9 @@ function setupUserCollectionCreatedSubscription() {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// root collections won't have parentCollectionID
|
// root collections won't have parentCollectionID
|
||||||
|
const data = res.right.userCollectionCreated.data
|
||||||
|
? JSON.parse(res.right.userCollectionCreated.data)
|
||||||
|
: null
|
||||||
runDispatchWithOutSyncing(() => {
|
runDispatchWithOutSyncing(() => {
|
||||||
collectionType == "GQL"
|
collectionType == "GQL"
|
||||||
? addGraphqlCollection({
|
? addGraphqlCollection({
|
||||||
@@ -304,22 +308,19 @@ function setupUserCollectionCreatedSubscription() {
|
|||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
v: 1,
|
v: 1,
|
||||||
auth: {
|
auth: data?.auth ?? { authType: "inherit", authActive: false },
|
||||||
authType: "none",
|
headers: data?.headers ?? [],
|
||||||
authActive: false,
|
|
||||||
},
|
|
||||||
headers: [],
|
|
||||||
})
|
})
|
||||||
: addRESTCollection({
|
: addRESTCollection({
|
||||||
name: res.right.userCollectionCreated.title,
|
name: res.right.userCollectionCreated.title,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
v: 1,
|
v: 1,
|
||||||
auth: {
|
auth: data?.auth ?? {
|
||||||
authType: "none",
|
authType: "inherit",
|
||||||
authActive: false,
|
authActive: false,
|
||||||
},
|
},
|
||||||
headers: [],
|
headers: data?.headers ?? [],
|
||||||
})
|
})
|
||||||
|
|
||||||
const localIndex = collectionStore.value.state.length - 1
|
const localIndex = collectionStore.value.state.length - 1
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
editUserRequest,
|
editUserRequest,
|
||||||
moveUserCollection,
|
moveUserCollection,
|
||||||
moveUserRequest,
|
moveUserRequest,
|
||||||
renameUserCollection,
|
updateUserCollection,
|
||||||
updateUserCollectionOrder,
|
updateUserCollectionOrder,
|
||||||
} from "./collections.api"
|
} from "./collections.api"
|
||||||
|
|
||||||
@@ -155,8 +155,13 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
|
|||||||
[collectionIndex]
|
[collectionIndex]
|
||||||
)?.id
|
)?.id
|
||||||
|
|
||||||
if (collectionID && collection.name) {
|
const data = {
|
||||||
renameUserCollection(collectionID, collection.name)
|
auth: collection.auth,
|
||||||
|
headers: collection.headers,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collectionID) {
|
||||||
|
updateUserCollection(collectionID, collection.name, JSON.stringify(data))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async addFolder({ name, path }) {
|
async addFolder({ name, path }) {
|
||||||
@@ -195,9 +200,12 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
|
|||||||
)?.id
|
)?.id
|
||||||
|
|
||||||
const folderName = folder.name
|
const folderName = folder.name
|
||||||
|
const data = {
|
||||||
if (folderID && folderName) {
|
auth: folder.auth,
|
||||||
renameUserCollection(folderID, folderName)
|
headers: folder.headers,
|
||||||
|
}
|
||||||
|
if (folderID) {
|
||||||
|
updateUserCollection(folderID, folderName, JSON.stringify(data))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async removeFolder({ folderID }) {
|
async removeFolder({ folderID }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user