feat : smart tree component (#2865)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Nivedin
2023-01-31 17:15:03 +05:30
committed by GitHub
parent b95e2b365a
commit 2910164d5a
39 changed files with 4483 additions and 4142 deletions

View File

@@ -12,6 +12,7 @@ import { TeamCollection } from "../teams/TeamCollection"
import { TeamRequest } from "../teams/TeamRequest"
import { GQLError, runGQLQuery } from "./GQLClient"
import {
ExportAsJsonDocument,
GetCollectionChildrenIDsDocument,
GetCollectionRequestsDocument,
GetCollectionTitleDocument,
@@ -125,3 +126,23 @@ export const teamCollToHoppRESTColl = (
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],
requests: coll.requests?.map((x) => x.request) ?? [],
})
/**
* Get the JSON string of all the collection of the specified team
* @param teamID - ID of the team
* @returns Either of the JSON string of the collection or the error
*/
export const getTeamCollectionJSON = async (teamID: string) => {
const data = await runGQLQuery({
query: ExportAsJsonDocument,
variables: {
teamID,
},
})
if (E.isLeft(data)) {
return E.left(data.left)
}
return E.right(data.right)
}

View File

@@ -0,0 +1,76 @@
import { runMutation } from "../GQLClient"
import {
CreateChildCollectionDocument,
CreateChildCollectionMutation,
CreateChildCollectionMutationVariables,
CreateNewRootCollectionDocument,
CreateNewRootCollectionMutation,
CreateNewRootCollectionMutationVariables,
DeleteCollectionDocument,
DeleteCollectionMutation,
DeleteCollectionMutationVariables,
ImportFromJsonDocument,
ImportFromJsonMutation,
ImportFromJsonMutationVariables,
RenameCollectionDocument,
RenameCollectionMutation,
RenameCollectionMutationVariables,
} from "../graphql"
type CreateNewRootCollectionError = "team_coll/short_title"
type CreateChildCollectionError = "team_coll/short_title"
type RenameCollectionError = "team_coll/short_title"
type DeleteCollectionError = "team/invalid_coll_id"
export const createNewRootCollection = (title: string, teamID: string) =>
runMutation<
CreateNewRootCollectionMutation,
CreateNewRootCollectionMutationVariables,
CreateNewRootCollectionError
>(CreateNewRootCollectionDocument, {
title,
teamID,
})
export const createChildCollection = (
childTitle: string,
collectionID: string
) =>
runMutation<
CreateChildCollectionMutation,
CreateChildCollectionMutationVariables,
CreateChildCollectionError
>(CreateChildCollectionDocument, {
childTitle,
collectionID,
})
/** Can be used to rename both collection and folder (considered same in BE) */
export const renameCollection = (collectionID: string, newTitle: string) =>
runMutation<
RenameCollectionMutation,
RenameCollectionMutationVariables,
RenameCollectionError
>(RenameCollectionDocument, {
collectionID,
newTitle,
})
/** Can be used to delete both collection and folder (considered same in BE) */
export const deleteCollection = (collectionID: string) =>
runMutation<
DeleteCollectionMutation,
DeleteCollectionMutationVariables,
DeleteCollectionError
>(DeleteCollectionDocument, {
collectionID,
})
export const importJSONToTeam = (collectionJSON: string, teamID: string) =>
runMutation<ImportFromJsonMutation, ImportFromJsonMutationVariables, "">(
ImportFromJsonDocument,
{
jsonString: collectionJSON,
teamID,
}
)

View File

@@ -1,14 +1,66 @@
import { runMutation } from "../GQLClient"
import {
CreateRequestInCollectionDocument,
CreateRequestInCollectionMutation,
CreateRequestInCollectionMutationVariables,
DeleteRequestDocument,
DeleteRequestMutation,
DeleteRequestMutationVariables,
MoveRestTeamRequestDocument,
MoveRestTeamRequestMutation,
MoveRestTeamRequestMutationVariables,
UpdateRequestDocument,
UpdateRequestMutation,
UpdateRequestMutationVariables,
} from "../graphql"
type MoveRestTeamRequestErrors =
| "team_req/not_found"
| "team_req/invalid_target_id"
type DeleteRequestErrors = "team_req/not_found"
export const createRequestInCollection = (
collectionID: string,
data: {
request: string
teamID: string
title: string
}
) =>
runMutation<
CreateRequestInCollectionMutation,
CreateRequestInCollectionMutationVariables,
""
>(CreateRequestInCollectionDocument, {
collectionID,
data,
})
export const updateTeamRequest = (
requestID: string,
data: {
request: string
title: string
}
) =>
runMutation<UpdateRequestMutation, UpdateRequestMutationVariables, "">(
UpdateRequestDocument,
{
requestID,
data,
}
)
export const deleteTeamRequest = (requestID: string) =>
runMutation<
DeleteRequestMutation,
DeleteRequestMutationVariables,
DeleteRequestErrors
>(DeleteRequestDocument, {
requestID,
})
export const moveRESTTeamRequest = (requestID: string, collectionID: string) =>
runMutation<
MoveRestTeamRequestMutation,