Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENGG-1646] feat: collection support for mocks #1634

Merged
merged 102 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
b81beb8
add MockCollectionModal
rohanmathur91 Apr 22, 2024
c77f20b
chore: update types
rohanmathur91 Apr 22, 2024
c7db56e
add `createMockCollection` controller
rohanmathur91 Apr 22, 2024
82c4d95
add create new collection cta
rohanmathur91 Apr 22, 2024
39ebd8c
add collection modal on mocks listing
rohanmathur91 Apr 22, 2024
d56b92a
fix: fetch mocks
rohanmathur91 Apr 22, 2024
38f8331
chore: mock metadata
rohanmathur91 Apr 22, 2024
4e0568c
render collections
rohanmathur91 Apr 22, 2024
21ec893
add `updateMockCollection` controller
rohanmathur91 Apr 22, 2024
46a443b
rename
rohanmathur91 Apr 23, 2024
efae503
add update bulk mock collection id controller
rohanmathur91 Apr 24, 2024
e3168f1
add delete mocks controller
rohanmathur91 Apr 24, 2024
86e249e
cleanup
rohanmathur91 Apr 24, 2024
c47753b
fix: delete mock
rohanmathur91 Apr 24, 2024
b8d0eb9
add deleteMockCollection
rohanmathur91 Apr 24, 2024
b253f3f
add deleteMocks
rohanmathur91 Apr 24, 2024
50604bf
add update and delete collection modals
rohanmathur91 Apr 24, 2024
a457e73
fix
rohanmathur91 Apr 24, 2024
bee0dcd
add row actions
rohanmathur91 Apr 24, 2024
d9ccf9f
fix: toggle modal
rohanmathur91 Apr 24, 2024
84e9ab0
rename createCollection
rohanmathur91 Apr 24, 2024
0fada1a
rename deleteCollectionModal
rohanmathur91 Apr 24, 2024
1303093
rename createCollectionModal
rohanmathur91 Apr 24, 2024
88b709e
rename
rohanmathur91 Apr 24, 2024
ef2c8fc
fix: bulk update collections
rohanmathur91 Apr 24, 2024
adc6d58
add comment
rohanmathur91 Apr 24, 2024
cc7ae38
refactor
rohanmathur91 Apr 24, 2024
3d56fcb
add update mock collection modal
rohanmathur91 Apr 24, 2024
01733c0
fix: row expand
rohanmathur91 Apr 24, 2024
98f040f
chore: add comment
rohanmathur91 Apr 24, 2024
8360e51
fix: style
rohanmathur91 Apr 24, 2024
6ab25c6
refactor: delete mock modal
rohanmathur91 Apr 25, 2024
caa749f
feat: add star mock suuport
rohanmathur91 Apr 26, 2024
f30cb41
fix: style
rohanmathur91 Apr 26, 2024
e216772
chore: fix type
rohanmathur91 Apr 29, 2024
c62c6b3
add table filters
rohanmathur91 Apr 29, 2024
abfe9b0
fix: all filter
rohanmathur91 Apr 29, 2024
6500a28
chore: update analytics
rohanmathur91 Apr 29, 2024
5e93821
[ENGG-1686] refactor: mocks feature (#1648)
rohanmathur91 Apr 30, 2024
939439f
fix: toast
rohanmathur91 Apr 30, 2024
a0c990c
address review comments
rohanmathur91 Apr 30, 2024
0d36818
refactor
rohanmathur91 Apr 30, 2024
0b79ac8
fix: modal header
rohanmathur91 Apr 30, 2024
11d2a00
refactor
rohanmathur91 Apr 30, 2024
550fe4a
refactor
rohanmathur91 Apr 30, 2024
ddebc6b
fix: delete collection
rohanmathur91 Apr 30, 2024
445bb35
fix: select option
rohanmathur91 Apr 30, 2024
f8d89af
fix: style
rohanmathur91 Apr 30, 2024
6b265f3
fix: style
rohanmathur91 Apr 30, 2024
28e5a5b
refactor
rohanmathur91 May 2, 2024
d4b94ed
refactor: mocks -> mockRecords
rohanmathur91 May 2, 2024
405643b
fix: mock description
rohanmathur91 May 2, 2024
7cdf589
add remove mock from collection action
rohanmathur91 May 2, 2024
b1280c8
fix: delete collection
rohanmathur91 May 2, 2024
b1006d2
fix: created by
rohanmathur91 May 2, 2024
b5cb2e2
refactor
rohanmathur91 May 2, 2024
21b1fec
fix: search
rohanmathur91 May 2, 2024
4c276f7
fix: deps
rohanmathur91 May 2, 2024
549ad94
fix: filters
rohanmathur91 May 7, 2024
ba9c134
fix: actions
rohanmathur91 May 7, 2024
6bebb1e
fix: style
rohanmathur91 May 7, 2024
4b92df6
fix: typo
rohanmathur91 May 7, 2024
2c5f048
fix: collection creation
rohanmathur91 May 7, 2024
dcbadad
fix: row style
rohanmathur91 May 7, 2024
0dc958b
fix: action order
rohanmathur91 May 7, 2024
0376cec
cleanup
rohanmathur91 May 8, 2024
fb5ca34
refactor
rohanmathur91 May 1, 2024
6eb175c
fix: collection selection
rohanmathur91 May 1, 2024
aca6b49
chore: add comment
rohanmathur91 May 1, 2024
918ece6
refactor
rohanmathur91 May 1, 2024
b352786
refactor
rohanmathur91 May 1, 2024
aa5ca69
refactor: delete mocks
rohanmathur91 May 1, 2024
fbfd254
chore: fix types
rohanmathur91 May 1, 2024
ab8a2f5
refactor: for bulk onsuccess
rohanmathur91 May 1, 2024
e9f84c1
fix: style
rohanmathur91 May 1, 2024
a0f3b65
add bulk actions
rohanmathur91 May 1, 2024
9226bcb
fix: style
rohanmathur91 May 2, 2024
04c75a1
fix: style
rohanmathur91 May 2, 2024
f7bb630
fix: rerender issue
rohanmathur91 May 2, 2024
74b8996
fix: collection order
rohanmathur91 May 2, 2024
9886277
fix: onSuccess
rohanmathur91 May 3, 2024
b853525
fix: style
rohanmathur91 May 7, 2024
2b33cd2
fix: style
rohanmathur91 May 7, 2024
9959e8c
fix: style
rohanmathur91 May 7, 2024
5156237
Merge pull request #1658 from requestly/ENGG-1671
rohanmathur91 May 10, 2024
dffe9e4
Merge branch 'master' into ENGG-1646
rohanmathur91 May 10, 2024
67a2f87
fix: style
rohanmathur91 May 10, 2024
bc0e4d3
fix: label
rohanmathur91 May 10, 2024
93f8a9d
fix: mock actions
rohanmathur91 May 10, 2024
6ac5380
fix: action
rohanmathur91 May 10, 2024
38553a6
refactor
rohanmathur91 May 10, 2024
6e8fdad
cleanup
rohanmathur91 May 10, 2024
00d1462
refactor: updateMocksCollectionAction
rohanmathur91 May 10, 2024
35bc6e2
refactor: uploadMockAction
rohanmathur91 May 10, 2024
96be53b
refactor: createNewFileAction
rohanmathur91 May 10, 2024
f1b8585
fix: typo
rohanmathur91 May 10, 2024
ee14485
fix: typo
rohanmathur91 May 10, 2024
c5c2709
refactor: delete records action
rohanmathur91 May 10, 2024
daea189
refactor
rohanmathur91 May 10, 2024
006b97f
Merge branch 'master' into ENGG-1646
rohanmathur91 May 10, 2024
671a259
refactor
rohanmathur91 May 10, 2024
4754466
Merge branch 'master' into ENGG-1646
rohanmathur91 May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions app/src/backend/mocks/createCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import firebaseApp from "../../firebase";
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
import { getFirestore, Timestamp, updateDoc, addDoc, collection } from "firebase/firestore";
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
import { getOwnerId } from "backend/utils";
wrongsahil marked this conversation as resolved.
Show resolved Hide resolved
import Logger from "lib/logger";
rohanmathur91 marked this conversation as resolved.
Show resolved Hide resolved
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;
}
};
4 changes: 3 additions & 1 deletion app/src/backend/mocks/createMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import firebaseApp from "../../firebase";
import { getFirestore, Timestamp, updateDoc, addDoc, collection } from "firebase/firestore";
import { RQMockSchema } from "components/features/mocksV2/types";
import { MockRecordType, RQMockSchema } from "components/features/mocksV2/types";
import { getOwnerId } from "backend/utils";
import { updateUserMockSelectorsMap, uploadResponseBodyFiles } from "./common";
import { BODY_IN_BUCKET_ENABLED } from "./constants";
Expand Down Expand Up @@ -48,7 +48,9 @@ const createMockFromFirebase = async (uid: string, mockData: RQMockSchema, teamI
const ownerId = getOwnerId(uid, teamId);

const mockId: string | null = await addDoc(rootMocksCollectionRef, {
collectionId: "",
...mockData,
recordType: MockRecordType.MOCK,
createdBy: uid,
ownerId: ownerId,
deleted: false,
Expand Down
1 change: 1 addition & 0 deletions app/src/backend/mocks/deleteMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const deleteMockFromFirebase = async (mockId: string): Promise<boolean> => {

const success = await updateDoc(docRef, {
deleted: true,
collectionId: "",
updatedTs: Timestamp.now().toMillis(),
})
.then(() => {
Expand Down
47 changes: 47 additions & 0 deletions app/src/backend/mocks/deleteMocks.ts
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;
}
};
36 changes: 36 additions & 0 deletions app/src/backend/mocks/updateCollections.ts
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;
}
};
3 changes: 2 additions & 1 deletion app/src/backend/mocks/updateMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import firebaseApp from "../../firebase";
import { doc, getFirestore, Timestamp, updateDoc } from "firebase/firestore";
import { RQMockSchema } from "components/features/mocksV2/types";
import { MockRecordType, RQMockSchema } from "components/features/mocksV2/types";
import { getOwnerId } from "backend/utils";
import { updateUserMockSelectorsMap, uploadResponseBodyFiles } from "./common";
import { BODY_IN_BUCKET_ENABLED } from "./constants";
Expand Down Expand Up @@ -53,6 +53,7 @@ export const updateMockFromFirebase = async (
const success = await updateDoc(docRef, {
lastUpdatedBy: updaterId,
...mockData,
recordType: MockRecordType.MOCK,
updatedTs: Timestamp.now().toMillis(),
})
.then(() => {
Expand Down
41 changes: 41 additions & 0 deletions app/src/backend/mocks/updateMocksCollectionId.ts
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 app/src/components/features/mocksV2/DeleteMockModal/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const MockEditorIndex: React.FC<Props> = ({
setSavingInProgress(false);
if (success) {
toast.success("Mock Updated Successfully");
trackUpdateMockEvent(mockId, mockType, finalMockData?.fileType);
trackUpdateMockEvent(mockId, mockType, finalMockData?.fileType, finalMockData?.collectionId);
return setMockEditorData(data);
}
toast.error("Mock Update Error");
Expand Down