refactor: store changes for collections (#2947)

This commit is contained in:
Akash K
2023-03-14 14:16:45 +05:30
committed by GitHub
parent 2179ce6fff
commit 1372681b87

View File

@@ -31,7 +31,7 @@ const defaultGraphqlCollectionState = {
type RESTCollectionStoreType = typeof defaultRESTCollectionState type RESTCollectionStoreType = typeof defaultRESTCollectionState
type GraphqlCollectionStoreType = typeof defaultGraphqlCollectionState type GraphqlCollectionStoreType = typeof defaultGraphqlCollectionState
function navigateToFolderWithIndexPath( export function navigateToFolderWithIndexPath(
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
indexPaths: number[] indexPaths: number[]
) { ) {
@@ -97,12 +97,15 @@ const restCollectionDispatchers = defineDispatchers({
{ state }: RESTCollectionStoreType, { state }: RESTCollectionStoreType,
{ {
collectionIndex, collectionIndex,
collection, partialCollection,
}: { collectionIndex: number; collection: HoppCollection<any> } }: {
collectionIndex: number
partialCollection: Partial<HoppCollection<any>>
}
) { ) {
return { return {
state: state.map((col, index) => state: state.map((col, index) =>
index === collectionIndex ? collection : col index === collectionIndex ? { ...col, ...partialCollection } : col
), ),
} }
}, },
@@ -824,13 +827,13 @@ export function getRESTCollection(collectionIndex: number) {
export function editRESTCollection( export function editRESTCollection(
collectionIndex: number, collectionIndex: number,
collection: HoppCollection<HoppRESTRequest> partialCollection: Partial<HoppCollection<HoppRESTRequest>>
) { ) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "editCollection", dispatcher: "editCollection",
payload: { payload: {
collectionIndex, collectionIndex,
collection, partialCollection: partialCollection,
}, },
}) })
} }