refactor: import-export team coll in new schema
This commit is contained in:
@@ -108,6 +108,27 @@ const importToPersonalWorkspace = (collections: HoppCollection[]) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function translateToTeamCollectionFormat(x: HoppCollection) {
|
||||||
|
const folders: HoppCollection[] = (x.folders ?? []).map(
|
||||||
|
translateToTeamCollectionFormat
|
||||||
|
)
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
auth: x.auth,
|
||||||
|
headers: x.headers,
|
||||||
|
}
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
...x,
|
||||||
|
folders,
|
||||||
|
data,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.id) obj.id = x.id
|
||||||
|
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
const importToTeamsWorkspace = async (collections: HoppCollection[]) => {
|
const importToTeamsWorkspace = async (collections: HoppCollection[]) => {
|
||||||
if (!hasTeamWriteAccess.value || !selectedTeamID.value) {
|
if (!hasTeamWriteAccess.value || !selectedTeamID.value) {
|
||||||
return E.left({
|
return E.left({
|
||||||
@@ -115,8 +136,12 @@ const importToTeamsWorkspace = async (collections: HoppCollection[]) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const transformedCollection = collections.map((collection) =>
|
||||||
|
translateToTeamCollectionFormat(collection)
|
||||||
|
)
|
||||||
|
|
||||||
const res = await toTeamsImporter(
|
const res = await toTeamsImporter(
|
||||||
JSON.stringify(collections),
|
JSON.stringify(transformedCollection),
|
||||||
selectedTeamID.value
|
selectedTeamID.value
|
||||||
)()
|
)()
|
||||||
|
|
||||||
@@ -400,7 +425,6 @@ const HoppTeamCollectionsExporter: ImporterOrExporter = {
|
|||||||
},
|
},
|
||||||
action: async () => {
|
action: async () => {
|
||||||
isHoppTeamCollectionExporterInProgress.value = true
|
isHoppTeamCollectionExporterInProgress.value = true
|
||||||
|
|
||||||
if (
|
if (
|
||||||
props.collectionsType.type === "team-collections" &&
|
props.collectionsType.type === "team-collections" &&
|
||||||
props.collectionsType.selectedTeam
|
props.collectionsType.selectedTeam
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
query GetCollectionTitle($collectionID: ID!) {
|
|
||||||
collection(collectionID: $collectionID) {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
query GetCollectionTitleAndData($collectionID: ID!) {
|
||||||
|
collection(collectionID: $collectionID) {
|
||||||
|
title
|
||||||
|
data
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ query GetSingleCollection($collectionID: ID!) {
|
|||||||
collection(collectionID: $collectionID) {
|
collection(collectionID: $collectionID) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
|
data
|
||||||
parent {
|
parent {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ subscription TeamCollectionAdded($teamID: ID!) {
|
|||||||
teamCollectionAdded(teamID: $teamID) {
|
teamCollectionAdded(teamID: $teamID) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
|
data
|
||||||
parent {
|
parent {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
ExportAsJsonDocument,
|
ExportAsJsonDocument,
|
||||||
GetCollectionChildrenIDsDocument,
|
GetCollectionChildrenIDsDocument,
|
||||||
GetCollectionRequestsDocument,
|
GetCollectionRequestsDocument,
|
||||||
GetCollectionTitleDocument,
|
GetCollectionTitleAndDataDocument,
|
||||||
} from "./graphql"
|
} from "./graphql"
|
||||||
|
|
||||||
export const BACKEND_PAGE_SIZE = 10
|
export const BACKEND_PAGE_SIZE = 10
|
||||||
@@ -84,16 +84,19 @@ export const getCompleteCollectionTree = (
|
|||||||
pipe(
|
pipe(
|
||||||
TE.Do,
|
TE.Do,
|
||||||
|
|
||||||
TE.bind("title", () =>
|
TE.bind("titleAndData", () =>
|
||||||
pipe(
|
pipe(
|
||||||
() =>
|
() =>
|
||||||
runGQLQuery({
|
runGQLQuery({
|
||||||
query: GetCollectionTitleDocument,
|
query: GetCollectionTitleAndDataDocument,
|
||||||
variables: {
|
variables: {
|
||||||
collectionID: collID,
|
collectionID: collID,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
TE.map((x) => x.collection!.title)
|
TE.map((result) => ({
|
||||||
|
title: result.collection!.title,
|
||||||
|
data: result.collection!.data,
|
||||||
|
}))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
TE.bind("children", () =>
|
TE.bind("children", () =>
|
||||||
@@ -107,22 +110,36 @@ export const getCompleteCollectionTree = (
|
|||||||
TE.bind("requests", () => () => getCollectionRequests(collID)),
|
TE.bind("requests", () => () => getCollectionRequests(collID)),
|
||||||
|
|
||||||
TE.map(
|
TE.map(
|
||||||
({ title, children, requests }) =>
|
({ titleAndData, children, requests }) =>
|
||||||
<TeamCollection>{
|
<TeamCollection>{
|
||||||
id: collID,
|
id: collID,
|
||||||
children,
|
children,
|
||||||
requests,
|
requests,
|
||||||
title,
|
title: titleAndData.title,
|
||||||
|
data: titleAndData.data,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
export const teamCollToHoppRESTColl = (coll: TeamCollection): HoppCollection =>
|
export const teamCollToHoppRESTColl = (
|
||||||
makeCollection({
|
coll: TeamCollection
|
||||||
|
): HoppCollection => {
|
||||||
|
const data =
|
||||||
|
coll.data && coll.data !== "null"
|
||||||
|
? JSON.parse(coll.data)
|
||||||
|
: {
|
||||||
|
auth: { authType: "inherit", authActive: true },
|
||||||
|
headers: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
return makeCollection({
|
||||||
name: coll.title,
|
name: coll.title,
|
||||||
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],
|
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],
|
||||||
requests: coll.requests?.map((x) => x.request) ?? [],
|
requests: coll.requests?.map((x) => x.request) ?? [],
|
||||||
|
auth: data.auth ?? { authType: "inherit", authActive: true },
|
||||||
|
headers: data.headers ?? [],
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JSON string of all the collection of the specified team
|
* Get the JSON string of all the collection of the specified team
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const isPlainObject = (value: any): value is object => _isPlainObject(value)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if a collection matches the schema for a hoppscotch collection.
|
* checks if a collection matches the schema for a hoppscotch collection.
|
||||||
|
* here 2 is the latest version of the schema.
|
||||||
*/
|
*/
|
||||||
const isValidCollection = (collection: unknown): collection is HoppCollection =>
|
const isValidCollection = (collection: unknown): collection is HoppCollection =>
|
||||||
isPlainObject(collection) && "v" in collection && collection.v === 2
|
isPlainObject(collection) && "v" in collection && collection.v === 2
|
||||||
|
|||||||
@@ -699,7 +699,7 @@ export default class NewTeamCollectionAdapter {
|
|||||||
children: null,
|
children: null,
|
||||||
requests: null,
|
requests: null,
|
||||||
title: result.right.teamCollectionAdded.title,
|
title: result.right.teamCollectionAdded.title,
|
||||||
data: null,
|
data: result.right.teamCollectionAdded.data ?? null,
|
||||||
},
|
},
|
||||||
result.right.teamCollectionAdded.parent?.id ?? null
|
result.right.teamCollectionAdded.parent?.id ?? null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function exportedCollectionToHoppCollection(
|
|||||||
if (collectionType == "REST") {
|
if (collectionType == "REST") {
|
||||||
const restCollection = collection as ExportedUserCollectionREST
|
const restCollection = collection as ExportedUserCollectionREST
|
||||||
const data =
|
const data =
|
||||||
restCollection.data && restCollection.data != "null"
|
restCollection.data && restCollection.data !== "null"
|
||||||
? JSON.parse(restCollection.data)
|
? JSON.parse(restCollection.data)
|
||||||
: {
|
: {
|
||||||
auth: { authType: "inherit", authActive: false },
|
auth: { authType: "inherit", authActive: false },
|
||||||
@@ -115,7 +115,7 @@ function exportedCollectionToHoppCollection(
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id: restCollection.id,
|
id: restCollection.id,
|
||||||
v: 1,
|
v: 2,
|
||||||
name: restCollection.name,
|
name: restCollection.name,
|
||||||
folders: restCollection.folders.map((folder) =>
|
folders: restCollection.folders.map((folder) =>
|
||||||
exportedCollectionToHoppCollection(folder, collectionType)
|
exportedCollectionToHoppCollection(folder, collectionType)
|
||||||
@@ -162,7 +162,7 @@ function exportedCollectionToHoppCollection(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: gqlCollection.id,
|
id: gqlCollection.id,
|
||||||
v: 1,
|
v: 2,
|
||||||
name: gqlCollection.name,
|
name: gqlCollection.name,
|
||||||
folders: gqlCollection.folders.map((folder) =>
|
folders: gqlCollection.folders.map((folder) =>
|
||||||
exportedCollectionToHoppCollection(folder, collectionType)
|
exportedCollectionToHoppCollection(folder, collectionType)
|
||||||
@@ -324,7 +324,7 @@ function setupUserCollectionCreatedSubscription() {
|
|||||||
name: res.right.userCollectionCreated.title,
|
name: res.right.userCollectionCreated.title,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
v: 1,
|
v: 2,
|
||||||
auth: data.auth,
|
auth: data.auth,
|
||||||
headers: data.headers,
|
headers: data.headers,
|
||||||
})
|
})
|
||||||
@@ -332,7 +332,7 @@ function setupUserCollectionCreatedSubscription() {
|
|||||||
name: res.right.userCollectionCreated.title,
|
name: res.right.userCollectionCreated.title,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
v: 1,
|
v: 2,
|
||||||
auth: data.auth,
|
auth: data.auth,
|
||||||
headers: data?.headers,
|
headers: data?.headers,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user