Skip to content

Commit 860a215

Browse files
authored
feat: add search in actor dropdown (#46)
* feat: add search in actor dropdown * feat: add search in task dropdown * feat: increase limit for recent-actors
1 parent 791adea commit 860a215

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

nodes/Apify/resources/actorResourceLocator.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const resourceLocatorProperty: INodeProperties = {
1515
typeOptions: {
1616
searchListMethod: 'listActors',
1717
searchFilterRequired: false,
18-
searchable: false,
18+
searchable: true,
1919
},
2020
},
2121
{
@@ -108,7 +108,10 @@ export function overrideActorProperties(properties: INodeProperties[]): INodePro
108108
return result;
109109
}
110110

111-
export async function listActors(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
111+
export async function listActors(
112+
this: ILoadOptionsFunctions,
113+
searchTerm?: string,
114+
): Promise<INodeListSearchResult> {
112115
const actorSource = this.getNodeParameter('actorSource', 'recentlyUsed') as string;
113116

114117
const mapToN8nResult = (actor: any) => ({
@@ -124,12 +127,21 @@ export async function listActors(this: ILoadOptionsFunctions): Promise<INodeList
124127
method: 'GET',
125128
uri: '/v2/acts',
126129
qs: {
127-
limit: 200,
130+
limit: 1000,
128131
offset: 0,
129132
},
130133
});
131134

132135
if (actorSource === 'recentlyUsed') {
136+
if (searchTerm) {
137+
const regex = new RegExp(searchTerm, 'i');
138+
const filteredActors = recentActors.filter(
139+
(actor: any) => regex.test(actor.title || '') || regex.test(actor.name || ''),
140+
);
141+
return {
142+
results: filteredActors.map(mapToN8nResult),
143+
};
144+
}
133145
return {
134146
results: recentActors.map(mapToN8nResult),
135147
};
@@ -143,6 +155,7 @@ export async function listActors(this: ILoadOptionsFunctions): Promise<INodeList
143155
qs: {
144156
limit: 200,
145157
offset: 0,
158+
search: searchTerm,
146159
},
147160
});
148161

nodes/Apify/resources/actorTaskResourceLocator.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const resourceLocatorProperty: INodeProperties = {
1515
typeOptions: {
1616
searchListMethod: 'listActorTasks',
1717
searchFilterRequired: false,
18-
searchable: false,
18+
searchable: true,
1919
},
2020
},
2121
{
@@ -75,7 +75,10 @@ export function overrideActorTaskProperties(properties: INodeProperties[]) {
7575
});
7676
}
7777

78-
export async function listActorTasks(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
78+
export async function listActorTasks(
79+
this: ILoadOptionsFunctions,
80+
searchTerm?: string,
81+
): Promise<INodeListSearchResult> {
7982
const searchResults = await apiRequestAllItems.call(this, {
8083
method: 'GET',
8184
uri: '/v2/actor-tasks',
@@ -85,11 +88,18 @@ export async function listActorTasks(this: ILoadOptionsFunctions): Promise<INode
8588
},
8689
});
8790

88-
const { data } = searchResults;
89-
const { items } = data;
91+
const {
92+
data: { items },
93+
} = searchResults;
94+
95+
let filteredItems = [...items];
96+
if (searchTerm) {
97+
const regex = new RegExp(searchTerm, 'i');
98+
filteredItems = items.filter((b: any) => regex.test(b.title || '') || regex.test(b.name || ''));
99+
}
90100

91101
return {
92-
results: items.map((b: any) => ({
102+
results: filteredItems.map((b: any) => ({
93103
name: b.title || b.name,
94104
value: b.id,
95105
url: `https://console.apify.com/actors/tasks/${b.id}/input`,

0 commit comments

Comments
 (0)