feat: multi Select for "Event Type" in Insights (#23173)
* Multi select event type in insights * Fixing multi select query generation * Added null check for eventType filters * Updated test to support multiselect * Type fix --------- Co-authored-by: Devanshu Sharma <[email protected]>
This commit is contained in:
1 parent
0ea673e507
commit
cafecad8ae
3 files changed
+25
-11
No files matched your search
@@ -35,7 +35,7 @@ export const useInsightsBookings = () => {
|
|||||||
size: 200,
|
size: 200,
|
||||||
meta: {
|
meta: {
|
||||||
filter: {
|
filter: {
|
||||||
type: ColumnFilterType.SINGLE_SELECT,
|
type: ColumnFilterType.MULTI_SELECT,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
|
|||||||
@@ -298,8 +298,16 @@ export class InsightsBookingBaseService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id === "eventTypeId" && isSingleSelectFilterValue(value) && typeof value.data === "number") {
|
if (id === "eventTypeId" && isMultiSelectFilterValue(value)) {
|
||||||
return Prisma.sql`("eventTypeId" = ${value.data}) OR ("eventParentId" = ${value.data})`;
|
const eventTypeIds = value.data.map((id) => Number(id));
|
||||||
|
|
||||||
|
if (eventTypeIds.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Prisma.sql`("eventTypeId" IN (${Prisma.join(eventTypeIds)}) OR "eventParentId" IN (${Prisma.join(
|
||||||
|
eventTypeIds
|
||||||
|
)}))`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id === "userId" && isSingleSelectFilterValue(value) && typeof value.data === "number") {
|
if (id === "userId" && isSingleSelectFilterValue(value) && typeof value.data === "number") {
|
||||||
|
|||||||
@@ -381,8 +381,8 @@ describe("InsightsBookingService Integration Tests", () => {
|
|||||||
{
|
{
|
||||||
id: "eventTypeId",
|
id: "eventTypeId",
|
||||||
value: {
|
value: {
|
||||||
type: ColumnFilterType.SINGLE_SELECT,
|
type: ColumnFilterType.MULTI_SELECT,
|
||||||
data: testData.eventType.id,
|
data: [testData.eventType.id],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -391,7 +391,9 @@ describe("InsightsBookingService Integration Tests", () => {
|
|||||||
|
|
||||||
const conditions = await service.getFilterConditions();
|
const conditions = await service.getFilterConditions();
|
||||||
expect(conditions).toEqual(
|
expect(conditions).toEqual(
|
||||||
Prisma.sql`("eventTypeId" = ${testData.eventType.id}) OR ("eventParentId" = ${testData.eventType.id})`
|
Prisma.sql`("eventTypeId" IN (${Prisma.join([
|
||||||
|
testData.eventType.id,
|
||||||
|
])}) OR "eventParentId" IN (${Prisma.join([testData.eventType.id])}))`
|
||||||
);
|
);
|
||||||
|
|
||||||
await testData.cleanup();
|
await testData.cleanup();
|
||||||
@@ -441,8 +443,8 @@ describe("InsightsBookingService Integration Tests", () => {
|
|||||||
{
|
{
|
||||||
id: "eventTypeId",
|
id: "eventTypeId",
|
||||||
value: {
|
value: {
|
||||||
type: ColumnFilterType.SINGLE_SELECT,
|
type: ColumnFilterType.MULTI_SELECT,
|
||||||
data: testData.eventType.id,
|
data: [testData.eventType.id],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -458,7 +460,11 @@ describe("InsightsBookingService Integration Tests", () => {
|
|||||||
|
|
||||||
const conditions = await service.getFilterConditions();
|
const conditions = await service.getFilterConditions();
|
||||||
expect(conditions).toEqual(
|
expect(conditions).toEqual(
|
||||||
Prisma.sql`(("eventTypeId" = ${testData.eventType.id}) OR ("eventParentId" = ${testData.eventType.id})) AND ("userId" = ${testData.user.id})`
|
Prisma.sql`(("eventTypeId" IN (${Prisma.join([
|
||||||
|
testData.eventType.id,
|
||||||
|
])}) OR "eventParentId" IN (${Prisma.join([testData.eventType.id])}))) AND ("userId" = ${
|
||||||
|
testData.user.id
|
||||||
|
})`
|
||||||
);
|
);
|
||||||
|
|
||||||
await testData.cleanup();
|
await testData.cleanup();
|
||||||
@@ -542,8 +548,8 @@ describe("InsightsBookingService Integration Tests", () => {
|
|||||||
{
|
{
|
||||||
id: "eventTypeId",
|
id: "eventTypeId",
|
||||||
value: {
|
value: {
|
||||||
type: ColumnFilterType.SINGLE_SELECT,
|
type: ColumnFilterType.MULTI_SELECT,
|
||||||
data: userEventType.id,
|
data: [userEventType.id],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in new issue
Block a user