-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENGG-1646] feat: collection support for mocks (#1634)
* add MockCollectionModal * chore: update types * add `createMockCollection` controller * add create new collection cta * add collection modal on mocks listing * fix: fetch mocks * chore: mock metadata * render collections * add `updateMockCollection` controller * rename * add update bulk mock collection id controller * add delete mocks controller * cleanup * fix: delete mock * add deleteMockCollection * add deleteMocks * add update and delete collection modals * fix * add row actions * fix: toggle modal * rename createCollection * rename deleteCollectionModal * rename createCollectionModal * rename * fix: bulk update collections * add comment * refactor * add update mock collection modal * fix: row expand * chore: add comment * fix: style * refactor: delete mock modal * feat: add star mock suuport * fix: style * chore: fix type * add table filters * fix: all filter * chore: update analytics * [ENGG-1686] refactor: mocks feature (#1648) * fix: mock picker modal * add CreateCollectionModalWrapper * refactor: delete modal * refactor: delete mock modal * rebase * fix: force re-renders * update mock collection modal * cleanup * fix: import * fix: force render * cleanup * fix: empty actions * refactor: mock uploader modal * refactor: new file modal * fix: mock name overflow * fix: star option * cleanup * fix: create mock from picker modal * add comment * fix: toast * address review comments * refactor * fix: modal header * refactor * refactor * fix: delete collection * fix: select option * fix: style * fix: style * refactor * refactor: mocks -> mockRecords * fix: mock description * add remove mock from collection action * fix: delete collection * fix: created by * refactor * fix: search * fix: deps * fix: filters * fix: actions * fix: style * fix: typo * fix: collection creation * fix: row style * fix: action order * cleanup * refactor * fix: collection selection * chore: add comment * refactor * refactor * refactor: delete mocks * chore: fix types * refactor: for bulk onsuccess * fix: style Signed-off-by: rohanmathur91 <mathurrohan04@gmail.com> * add bulk actions Signed-off-by: rohanmathur91 <mathurrohan04@gmail.com> * fix: style * fix: style * fix: rerender issue * fix: collection order * fix: onSuccess * fix: style * fix: style * fix: style * fix: style * fix: label * fix: mock actions * fix: action * refactor * cleanup * refactor: updateMocksCollectionAction * refactor: uploadMockAction * refactor: createNewFileAction * fix: typo * fix: typo * refactor: delete records action * refactor * refactor --------- Signed-off-by: rohanmathur91 <mathurrohan04@gmail.com>
- Loading branch information
1 parent
7ff78a0
commit d1ddf13
Showing
70 changed files
with
2,527 additions
and
2,098 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import firebaseApp from "../../firebase"; | ||
import { getFirestore, Timestamp, updateDoc, addDoc, collection } from "firebase/firestore"; | ||
import { getOwnerId } from "backend/utils"; | ||
import Logger from "lib/logger"; | ||
import { MockRecordType, RQMockCollection } from "components/features/mocksV2/types"; | ||
|
||
type MockCollectionData = Pick<RQMockCollection, "name" | "desc" | "type">; | ||
|
||
export const createCollection = async ( | ||
uid: string, | ||
mockCollectionData: MockCollectionData, | ||
teamId?: string | ||
): Promise<RQMockCollection | null> => { | ||
if (!uid) { | ||
return null; | ||
} | ||
|
||
const mockCollection = await createCollectionInFirebase(uid, mockCollectionData, teamId); | ||
|
||
return mockCollection; | ||
}; | ||
|
||
const createCollectionInFirebase = async ( | ||
uid: string, | ||
mockCollectionData: MockCollectionData, | ||
teamId?: string | ||
): Promise<RQMockCollection | null> => { | ||
const db = getFirestore(firebaseApp); | ||
const mocksRef = collection(db, "mocks"); | ||
const ownerId = getOwnerId(uid, teamId); | ||
|
||
try { | ||
const collectionData: RQMockCollection = { | ||
...mockCollectionData, | ||
recordType: MockRecordType.COLLECTION, | ||
ownerId: ownerId, | ||
deleted: false, | ||
createdBy: uid, | ||
lastUpdatedBy: uid, | ||
createdTs: Timestamp.now().toMillis(), | ||
updatedTs: Timestamp.now().toMillis(), | ||
}; | ||
|
||
const docRef = await addDoc(mocksRef, collectionData); | ||
|
||
Logger.log(`Mock collection document created ${docRef.id}`); | ||
|
||
await updateDoc(docRef, { id: docRef.id }); | ||
|
||
return { ...collectionData, id: docRef.id } as RQMockCollection; | ||
} catch (err) { | ||
Logger.error("Error while creating mock collection", err); | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import firebaseApp from "../../firebase"; | ||
import { doc, getFirestore, Timestamp, writeBatch, collection, deleteField } from "firebase/firestore"; | ||
import { getOwnerId } from "backend/utils"; | ||
|
||
export const deleteMocks = async (uid: string, mockIds: string[], teamId?: string): Promise<boolean> => { | ||
if (!uid) { | ||
return false; | ||
} | ||
|
||
const ownerId = getOwnerId(uid, teamId); | ||
const result = await deleteMocksFromFirebase(uid, ownerId, mockIds); | ||
return result; | ||
}; | ||
|
||
const deleteMocksFromFirebase = async (uid: string, ownerId: string, mockIds: string[]): Promise<boolean> => { | ||
try { | ||
const db = getFirestore(firebaseApp); | ||
const mocksbatch = writeBatch(db); | ||
const userMocksMetadataRef = collection(db, "user-mocks-metadata"); | ||
const userDocRef = doc(userMocksMetadataRef, ownerId); | ||
|
||
mockIds.forEach((mockId) => { | ||
const mockRef = doc(db, "mocks", mockId); | ||
|
||
mocksbatch.set( | ||
mockRef, | ||
{ | ||
deleted: true, | ||
collectionId: "", | ||
lastUpdatedBy: uid, | ||
updatedTs: Timestamp.now().toMillis(), | ||
}, | ||
{ merge: true } | ||
); | ||
|
||
mocksbatch.update(userDocRef, { | ||
[`mockSelectors.${mockId}`]: deleteField(), | ||
}); | ||
}); | ||
|
||
await mocksbatch.commit(); | ||
|
||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import firebaseApp from "../../firebase"; | ||
import { doc, getFirestore, Timestamp, writeBatch } from "firebase/firestore"; | ||
import { RQMockCollection } from "components/features/mocksV2/types"; | ||
|
||
export const updateCollections = async (uid: string, collections: Partial<RQMockCollection>[]): Promise<boolean> => { | ||
if (!uid) { | ||
return null; | ||
} | ||
|
||
const result = await updateCollectionsInFirebase(uid, collections); | ||
|
||
return result; | ||
}; | ||
|
||
const updateCollectionsInFirebase = async (uid: string, collections: Partial<RQMockCollection>[]): Promise<boolean> => { | ||
try { | ||
const db = getFirestore(firebaseApp); | ||
const collectionsBatch = writeBatch(db); | ||
|
||
collections.forEach((collection) => { | ||
const collectionRef = doc(db, "mocks", collection.id); | ||
|
||
collectionsBatch.set( | ||
collectionRef, | ||
{ ...collection, lastUpdatedBy: uid, updatedTs: Timestamp.now().toMillis() }, | ||
{ merge: true } | ||
); | ||
}); | ||
|
||
await collectionsBatch.commit(); | ||
|
||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import firebaseApp from "../../firebase"; | ||
import { Timestamp, doc, getFirestore, writeBatch } from "firebase/firestore"; | ||
|
||
export const updateMocksCollectionId = async ( | ||
uid: string, | ||
mockIds: string[], | ||
updatedCollectionId: string | ||
): Promise<boolean> => { | ||
if (!uid) { | ||
return null; | ||
} | ||
|
||
const result = await updateMocksCollectionIdInFirebase(uid, mockIds, updatedCollectionId); | ||
return result; | ||
}; | ||
|
||
const updateMocksCollectionIdInFirebase = async ( | ||
uid: string, | ||
mockIds: string[], | ||
updatedCollectionId: string | ||
): Promise<boolean> => { | ||
try { | ||
const db = getFirestore(firebaseApp); | ||
const mocksbatch = writeBatch(db); | ||
|
||
mockIds.forEach((id) => { | ||
const mockRef = doc(db, "mocks", id); | ||
mocksbatch.set( | ||
mockRef, | ||
{ collectionId: updatedCollectionId, lastUpdatedBy: uid, updatedTs: Timestamp.now().toMillis() }, | ||
{ merge: true } | ||
); | ||
}); | ||
|
||
await mocksbatch.commit(); | ||
|
||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
102 changes: 0 additions & 102 deletions
102
app/src/components/features/mocksV2/DeleteMockModal/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.