feat: support searchTerm in Filter Segment (#20526)
* feat: support searchTerm in Filter Segment * update tests * save and load searchTerm * fix types * add missing condition
This commit is contained in:
1 parent
b6aedb830b
commit
703e20a43a
12 files changed
+133
-45
No files matched your search
+14
-2
@@ -2,8 +2,9 @@ import prismock from "../../../../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ColumnFilterType } from "@calcom/features/data-table/lib/types";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { createHandler } from "../create.handler";
|
||||
import { type TCreateFilterSegmentInputSchema } from "../create.schema";
|
||||
@@ -16,11 +17,20 @@ describe("createHandler", () => {
|
||||
|
||||
const baseInput = {
|
||||
tableIdentifier: "bookings",
|
||||
activeFilters: { f: "status" },
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: {
|
||||
type: ColumnFilterType.SINGLE_SELECT,
|
||||
data: "active",
|
||||
},
|
||||
},
|
||||
],
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 10,
|
||||
searchTerm: "test search",
|
||||
};
|
||||
|
||||
it("should create a user-scoped filter segment", async () => {
|
||||
@@ -41,6 +51,7 @@ describe("createHandler", () => {
|
||||
scope: "USER",
|
||||
tableIdentifier: "bookings",
|
||||
name: "My Bookings",
|
||||
searchTerm: "test search",
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -74,6 +85,7 @@ describe("createHandler", () => {
|
||||
scope: "TEAM",
|
||||
tableIdentifier: "bookings",
|
||||
name: "Team Bookings",
|
||||
searchTerm: "test search",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
+81
-37
@@ -2,8 +2,9 @@ import prismock from "../../../../../../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ColumnFilterType } from "@calcom/features/data-table/lib/types";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { updateHandler } from "../update.handler";
|
||||
import { type TUpdateFilterSegmentInputSchema } from "../update.schema";
|
||||
@@ -14,31 +15,50 @@ describe("updateHandler", () => {
|
||||
name: "Test User",
|
||||
} as NonNullable<TrpcSessionUser>;
|
||||
|
||||
const baseInput = {
|
||||
tableIdentifier: "bookings",
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: {
|
||||
type: ColumnFilterType.SINGLE_SELECT,
|
||||
data: "active",
|
||||
},
|
||||
},
|
||||
],
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 10,
|
||||
searchTerm: "test search",
|
||||
};
|
||||
|
||||
it("should update a user-scoped filter segment", async () => {
|
||||
// Create a user-scoped segment first
|
||||
const segment = await prismock.filterSegment.create({
|
||||
data: {
|
||||
...baseInput,
|
||||
userId: mockUser.id,
|
||||
scope: "USER",
|
||||
tableIdentifier: "bookings",
|
||||
name: "My Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 10,
|
||||
},
|
||||
});
|
||||
|
||||
const input: TUpdateFilterSegmentInputSchema = {
|
||||
...baseInput,
|
||||
id: segment.id,
|
||||
scope: "USER",
|
||||
name: "Updated Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 20,
|
||||
searchTerm: "updated search",
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: {
|
||||
type: ColumnFilterType.SINGLE_SELECT,
|
||||
data: "inactive",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = await updateHandler({
|
||||
@@ -48,13 +68,17 @@ describe("updateHandler", () => {
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
id: segment.id,
|
||||
userId: mockUser.id,
|
||||
scope: "USER",
|
||||
tableIdentifier: "bookings",
|
||||
name: "Updated Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 20,
|
||||
searchTerm: "updated search",
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: { type: ColumnFilterType.SINGLE_SELECT, data: "inactive" },
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -81,16 +105,11 @@ describe("updateHandler", () => {
|
||||
// Create a team-scoped segment
|
||||
const segment = await prismock.filterSegment.create({
|
||||
data: {
|
||||
...baseInput,
|
||||
userId: mockUser.id,
|
||||
teamId: team.id,
|
||||
scope: "TEAM",
|
||||
tableIdentifier: "bookings",
|
||||
name: "Team Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 10,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -99,11 +118,16 @@ describe("updateHandler", () => {
|
||||
scope: "TEAM",
|
||||
teamId: team.id,
|
||||
name: "Updated Team Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: false }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 15,
|
||||
searchTerm: "updated search",
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: {
|
||||
type: ColumnFilterType.SINGLE_SELECT,
|
||||
data: "inactive",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = await updateHandler({
|
||||
@@ -114,12 +138,17 @@ describe("updateHandler", () => {
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
id: segment.id,
|
||||
teamId: team.id,
|
||||
scope: "TEAM",
|
||||
tableIdentifier: "bookings",
|
||||
name: "Updated Team Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
sorting: [{ id: "date", desc: false }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
perPage: 15,
|
||||
searchTerm: "updated search",
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: { type: ColumnFilterType.SINGLE_SELECT, data: "inactive" },
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -129,7 +158,12 @@ describe("updateHandler", () => {
|
||||
id: 999,
|
||||
scope: "USER",
|
||||
name: "Updated Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: { type: ColumnFilterType.SINGLE_SELECT, data: "inactive" },
|
||||
},
|
||||
],
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
@@ -171,7 +205,12 @@ describe("updateHandler", () => {
|
||||
scope: "TEAM",
|
||||
tableIdentifier: "bookings",
|
||||
name: "Team Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: { type: ColumnFilterType.SINGLE_SELECT, data: "active" },
|
||||
},
|
||||
],
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
@@ -184,7 +223,12 @@ describe("updateHandler", () => {
|
||||
scope: "TEAM",
|
||||
teamId: team.id,
|
||||
name: "Updated Team Bookings",
|
||||
activeFilters: { f: "status" },
|
||||
activeFilters: [
|
||||
{
|
||||
f: "status",
|
||||
v: { type: ColumnFilterType.SINGLE_SELECT, data: "inactive" },
|
||||
},
|
||||
],
|
||||
sorting: [{ id: "date", desc: true }],
|
||||
columnVisibility: {},
|
||||
columnSizing: {},
|
||||
|
||||
@@ -10,6 +10,7 @@ const baseCreateSchema = {
|
||||
sorting: ZSortingState.optional(),
|
||||
columnVisibility: ZColumnVisibility.optional(),
|
||||
columnSizing: ZColumnSizing.optional(),
|
||||
searchTerm: z.string().nullable().optional(),
|
||||
perPage: z.number().int().min(1),
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export const updateHandler = async ({
|
||||
};
|
||||
input: TUpdateFilterSegmentInputSchema;
|
||||
}) => {
|
||||
const { id, name, activeFilters, sorting, columnVisibility, columnSizing, perPage } = input;
|
||||
const { id, name, activeFilters, sorting, columnVisibility, columnSizing, perPage, searchTerm } = input;
|
||||
const userId = ctx.user.id;
|
||||
|
||||
// First, fetch the existing segment to check permissions
|
||||
@@ -64,6 +64,7 @@ export const updateHandler = async ({
|
||||
columnVisibility,
|
||||
columnSizing,
|
||||
perPage,
|
||||
searchTerm,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ const baseUpdateSchema = {
|
||||
sorting: ZSortingState.optional(),
|
||||
columnVisibility: ZColumnVisibility.optional(),
|
||||
columnSizing: ZColumnSizing.optional(),
|
||||
searchTerm: z.string().nullable().optional(),
|
||||
perPage: z.number().int().min(1).optional(),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user