Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(piece-sets): the Set Name filter searches every set, not only the loaded page (#16612)

lina-alomariedee8894357e
diff --git a/packages/core/shared/package.json b/packages/core/shared/package.json
index d2ad105f6c0..e5ff0ad0d43 100644
--- a/packages/core/shared/package.json
+++ b/packages/core/shared/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/shared",
- "version": "0.202.0",
+ "version": "0.202.1",
"type": "commonjs",
"sideEffects": false,
"main": "./dist/src/index.js",
diff --git a/packages/core/shared/src/lib/ee/piece-set/index.ts b/packages/core/shared/src/lib/ee/piece-set/index.ts
index 55035574e2b..2590de29f0b 100644
--- a/packages/core/shared/src/lib/ee/piece-set/index.ts
+++ b/packages/core/shared/src/lib/ee/piece-set/index.ts
@@ -93,5 +93,6 @@ export type AssignProjectsRequestBody = z.infer<typeof AssignProjectsRequestBody
export const ListPieceSetsRequestQuery = z.object({
cursor: z.string().optional(),
limit: z.number().int().min(1).max(100).optional().default(10),
+ name: z.string().optional(),
})
export type ListPieceSetsRequestQuery = z.infer<typeof ListPieceSetsRequestQuery>
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
index cda92a348db..30cd4b48d27 100644
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
@@ -16,6 +16,7 @@ export const pieceSetController: FastifyPluginAsyncZod = async (app) => {
platformId: req.principal.platform.id,
cursor: req.query.cursor,
limit: req.query.limit,
+ name: req.query.name,
})
})
@@ -83,6 +84,7 @@ const ListPieceSets = {
querystring: z.object({
cursor: z.string().optional(),
limit: z.coerce.number().int().min(1).max(100).optional().default(10),
+ name: z.string().optional(),
}),
},
}
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
index 12d36b8e4bf..6ae035112e8 100644
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
@@ -19,6 +19,7 @@ type ListParams = {
platformId: string
cursor?: string
limit?: number
+ name?: string
}
type GetOneParams = {
@@ -88,7 +89,7 @@ export const pieceSetService = (log: FastifyBaseLogger) => ({
return isNil(assigned) ? this.getOrCreateDefaultPieceSet(platformId) : assigned
},
- async list({ platformId, cursor, limit = 10 }: ListParams): Promise<SeekPage<PieceSet>> {
+ async list({ platformId, cursor, limit = 10, name }: ListParams): Promise<SeekPage<PieceSet>> {
const boundedLimit = Math.min(limit, MAX_PIECE_SET_PAGE_SIZE)
const decodedCursor = paginationHelper.decodeCursor(cursor ?? null)
const paginator = buildPaginator({
@@ -100,9 +101,11 @@ export const pieceSetService = (log: FastifyBaseLogger) => ({
beforeCursor: decodedCursor.previousCursor,
},
})
- const { data, cursor: newCursor } = await paginator.paginate(
- pieceSetRepo().createQueryBuilder('piece_set').where({ platformId }),
- )
+ const queryBuilder = pieceSetRepo().createQueryBuilder('piece_set').where({ platformId })
+ if (name) {
+ queryBuilder.andWhere('piece_set.name ILIKE :name', { name: `%${escapeLikeBackslashes(name)}%` })
+ }
+ const { data, cursor: newCursor } = await paginator.paginate(queryBuilder)
return paginationHelper.createPage<PieceSet>(data, newCursor)
},
@@ -239,6 +242,10 @@ function resolveKey({ key, name }: { key?: string | null, name: string }): strin
return `${kebabCase(name)}-${apId().slice(0, 8)}`
}
+function escapeLikeBackslashes(value: string): string {
+ return value.replace(/\\/g, '\\\\')
+}
+
function rethrowKeyConflict(error: unknown): never {
if (isUniqueViolation(error)) {
throw new ActivepiecesError({
diff --git a/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts b/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
index 6a23063ce8e..44b1d417b6a 100644
--- a/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
+++ b/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
@@ -130,6 +130,75 @@ describe('Piece Sets API', () => {
const backBody = backToFirstPage.json()
expect(backBody.data.map((s: PieceSet) => s.id)).toEqual(firstBody.data.map((s: PieceSet) => s.id))
})
+
+ it('filters by name across all sets, not only the first page', async () => {
+ const { token } = await setupPlatformWithPieceSets()
+ for (const name of ['Set 0', 'Set 1', 'Set 2', 'Set 3', 'Finance Tools']) {
+ await app!.inject({
+ method: 'POST',
+ url: '/api/v1/piece-sets',
+ headers: { authorization: `Bearer ${token}` },
+ body: { name },
+ })
+ }
+
+ const response = await app!.inject({
+ method: 'GET',
+ url: '/api/v1/piece-sets?limit=2&name=finance',
+ headers: { authorization: `Bearer ${token}` },
+ })
+ expect(response.statusCode).toBe(StatusCodes.OK)
+ const body = response.json()
+ expect(body.data.map((s: PieceSet) => s.name)).toEqual(['Finance Tools'])
+ expect(body.next).toBeNull()
+ })
+
+ it('matches a backslash in the name literally and keeps % and _ as wildcards', async () => {
+ const { token } = await setupPlatformWithPieceSets()
+ for (const name of ['Ops\\Finance', 'OpsFinance', 'Set-1', 'set_1']) {
+ await app!.inject({
+ method: 'POST',
+ url: '/api/v1/piece-sets',
+ headers: { authorization: `Bearer ${token}` },
+ body: { name },
+ })
+ }
+
+ const backslashSearch = await app!.inject({
+ method: 'GET',
+ url: `/api/v1/piece-sets?name=${encodeURIComponent('ops\\f')}`,
+ headers: { authorization: `Bearer ${token}` },
+ })
+ expect(backslashSearch.statusCode).toBe(StatusCodes.OK)
+ expect(backslashSearch.json().data.map((s: PieceSet) => s.name)).toEqual(['Ops\\Finance'])
+
+ const wildcardSearch = await app!.inject({
+ method: 'GET',
+ url: `/api/v1/piece-sets?name=${encodeURIComponent('set_1')}`,
+ headers: { authorization: `Bearer ${token}` },
+ })
+ expect(wildcardSearch.statusCode).toBe(StatusCodes.OK)
+ expect(wildcardSearch.json().data.map((s: PieceSet) => s.name).sort()).toEqual(['Set-1', 'set_1'])
+ })
+
+ it('does not return matching sets from another platform', async () => {
+ const { token: otherToken } = await setupPlatformWithPieceSets()
+ await app!.inject({
+ method: 'POST',
+ url: '/api/v1/piece-sets',
+ headers: { authorization: `Bearer ${otherToken}` },
+ body: { name: 'Finance Tools' },
+ })
+ const { token } = await setupPlatformWithPieceSets()
+
+ const response = await app!.inject({
+ method: 'GET',
+ url: '/api/v1/piece-sets?name=finance',
+ headers: { authorization: `Bearer ${token}` },
+ })
+ expect(response.statusCode).toBe(StatusCodes.OK)
+ expect(response.json().data).toEqual([])
+ })
})
describe('Create', () => {
diff --git a/packages/web/src/app/routes/platform/setup/pieces/piece-sets/piece-sets-tab.tsx b/packages/web/src/app/routes/platform/setup/pieces/piece-sets/piece-sets-tab.tsx
index 21f3496a093..ede4918b4bf 100644
--- a/packages/web/src/app/routes/platform/setup/pieces/piece-sets/piece-sets-tab.tsx
+++ b/packages/web/src/app/routes/platform/setup/pieces/piece-sets/piece-sets-tab.tsx
@@ -51,13 +51,14 @@ export const PieceSetsTab = () => {
const cursor = searchParams.get(CURSOR_QUERY_PARAM) ?? undefined;
const limitParam = searchParams.get('limit');
const limit = limitParam ? parseInt(limitParam, 10) : undefined;
+ const name = searchParams.get('name') ?? undefined;
const {
data: pieceSetsPage,
isLoading,
isError,
refetch,
- } = pieceSetQueries.usePieceSets({ cursor, limit });
+ } = pieceSetQueries.usePieceSets({ cursor, limit, name });
const { mutate: deleteSet } = pieceSetMutations.useDeletePieceSet();
const pieceSets = useMemo(() => pieceSetsPage?.data ?? [], [pieceSetsPage]);
@@ -209,7 +210,6 @@ export const PieceSetsTab = () => {
isError={isError}
errorStateEntity={t('piece sets')}
onRetry={refetch}
- clientFiltering={true}
onRowClick={(pieceSet) =>
navigate(`/platform/pieces/piece-sets/${pieceSet.id}`)
}
diff --git a/packages/web/src/features/piece-sets/hooks/piece-sets-hooks.ts b/packages/web/src/features/piece-sets/hooks/piece-sets-hooks.ts
index 7068f08d558..25b3a740d03 100644
--- a/packages/web/src/features/piece-sets/hooks/piece-sets-hooks.ts
+++ b/packages/web/src/features/piece-sets/hooks/piece-sets-hooks.ts
@@ -22,8 +22,14 @@ import { pieceSetsApi } from '../api/piece-sets-api';
export const pieceSetKeys = {
all: ['piece-sets'] as const,
- page: (cursor: string | undefined, limit: number | undefined) =>
- ['piece-sets', 'page', cursor ?? null, limit ?? null] as const,
+ page: ({ cursor, limit, name }: PieceSetsPageParams) =>
+ [
+ 'piece-sets',
+ 'page',
+ cursor ?? null,
+ limit ?? null,
+ name ?? null,
+ ] as const,
one: (id: string) => ['piece-sets', id] as const,
project: (projectId: string) => ['piece-sets', 'project', projectId] as const,
update: ['piece-sets', 'update'] as const,
@@ -37,14 +43,11 @@ export const pieceSetQueryOptions = {
};
export const pieceSetQueries = {
- usePieceSets: ({
- cursor,
- limit,
- }: { cursor?: string; limit?: number } = {}) => {
+ usePieceSets: ({ cursor, limit, name }: PieceSetsPageParams = {}) => {
const { platform } = platformHooks.useCurrentPlatform();
return useQuery({
- queryKey: pieceSetKeys.page(cursor, limit),
- queryFn: () => pieceSetsApi.list({ cursor, limit }),
+ queryKey: pieceSetKeys.page({ cursor, limit, name }),
+ queryFn: () => pieceSetsApi.list({ cursor, limit, name }),
enabled: platform.plan.managePiecesEnabled,
});
},
@@ -218,3 +221,9 @@ const UpdatePieceSetVariables = z.object({
id: z.string(),
request: UpdatePieceSetRequestBody,
});
+
+type PieceSetsPageParams = {
+ cursor?: string;
+ limit?: number;
+ name?: string;
+};