From 03594050f1fe625f6bc16ed7a04188ea7aaeec4f Mon Sep 17 00:00:00 2001 From: Christoph Dyllick-Brenzinger Date: Fri, 15 Dec 2023 15:55:19 +0100 Subject: [PATCH] add case insensitive search to "search" action --- .../v2/actions/row/search/description.ts | 14 ++++++++++++ .../SeaTable/v2/actions/row/search/execute.ts | 22 ++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/description.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/description.ts index ce94fa6ca8..666197f14a 100644 --- a/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/description.ts +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/description.ts @@ -52,6 +52,20 @@ export const rowSearchDescription: RowProperties = [ default: '', description: 'What to look for?', }, + { + displayName: 'Case Insensitive Search', + name: 'insensitive', + type: 'boolean', + displayOptions: { + show: { + resource: ['row'], + operation: ['search'], + }, + }, + default: false, + description: + 'FALSE: The search distinguish between uppercase and lowercase characters. TRUE: Search ignores case sensitivity.', + }, { displayName: 'Activate wildcard search', name: 'wildcard', diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/execute.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/execute.ts index 816d9c5107..f9de6940b1 100644 --- a/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/execute.ts +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/search/execute.ts @@ -13,30 +13,22 @@ export async function search( ): Promise { const tableName = this.getNodeParameter('tableName', index) as string; const searchColumn = this.getNodeParameter('searchColumn', index) as string; - const searchTerm = this.getNodeParameter('searchTerm', index) as any; // string or integer + let searchTerm = this.getNodeParameter('searchTerm', index) as any; // string or integer + const insensitive = this.getNodeParameter('insensitive', index) as boolean; const wildcard = this.getNodeParameter('wildcard', index) as boolean; const simple = this.getNodeParameter('simple', index) as boolean; // get collaborators const collaborators = await getBaseCollaborators.call(this); - //let metadata: IDtableMetadataColumn[] = []; - //let rows: IRow[]; - //let sqlResult: IRowResponse; - - // get the collaborators (avoid executing this multiple times !!!!) - /*let collaboratorsResult: ICollaboratorsResult = await seaTableApiRequest.call( - this, - {}, - 'GET', - '/dtable-server/api/v1/dtables/{{dtable_uuid}}/related-users/', - ); - let collaborators: ICollaborator[] = collaboratorsResult.user_list || []; - */ - // this is the base query. The WHERE has to be finalized... let sqlQuery = `SELECT * FROM \`${tableName}\` WHERE \`${searchColumn}\``; + if (insensitive) { + searchTerm = searchTerm.toLowerCase(); + sqlQuery = `SELECT * FROM \`${tableName}\` WHERE lower(\`${searchColumn}\`)`; + } + if (wildcard && isNaN(searchTerm)) sqlQuery = sqlQuery + ' LIKE "%' + searchTerm + '%"'; else if (!wildcard && isNaN(searchTerm)) sqlQuery = sqlQuery + ' = "' + searchTerm + '"'; else if (wildcard && !isNaN(searchTerm)) sqlQuery = sqlQuery + ' LIKE %' + searchTerm + '%';