diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/Interfaces.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/Interfaces.ts index 50af0f7b6f..35c44eec0c 100644 --- a/packages/nodes-base/nodes/SeaTable/v2/actions/Interfaces.ts +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/Interfaces.ts @@ -1,7 +1,7 @@ import type { AllEntities, Entity, PropertiesOf } from 'n8n-workflow'; type SeaTableMap = { - row: 'create' | 'get' | 'search' | 'update' | 'remove' | 'lock' | 'unlock'; + row: 'create' | 'get' | 'search' | 'update' | 'remove' | 'lock' | 'unlock' | 'list'; base: 'snapshot' | 'metadata' | 'apiCall' | 'collaborator'; link: 'add' | 'remove'; asset: 'upload' | 'getPublicURL'; diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/index.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/index.ts index b6453601f9..a78e54f528 100644 --- a/packages/nodes-base/nodes/SeaTable/v2/actions/row/index.ts +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/index.ts @@ -1,5 +1,6 @@ import * as create from './create'; import * as get from './get'; +import * as list from './list'; import * as search from './search'; import * as update from './update'; import * as remove from './remove'; @@ -7,7 +8,7 @@ import * as lock from './lock'; import * as unlock from './unlock'; import type { INodeProperties } from 'n8n-workflow'; -export { create, get, search, update, remove, lock, unlock }; +export { create, get, search, update, remove, lock, unlock, list }; export const descriptions: INodeProperties[] = [ { @@ -33,6 +34,12 @@ export const descriptions: INodeProperties[] = [ description: 'Get the content of a row', action: 'Get a row', }, + { + name: 'Get Many', + value: 'list', + description: 'Get many rows from a table of view', + action: 'Get many rows', + }, { name: 'Search', value: 'search', @@ -68,6 +75,7 @@ export const descriptions: INodeProperties[] = [ }, ...create.description, ...get.description, + ...list.description, ...search.description, ...update.description, ...remove.description, diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/description.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/description.ts new file mode 100644 index 0000000000..3d1360cf0f --- /dev/null +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/description.ts @@ -0,0 +1,55 @@ +import type { RowProperties } from '../../Interfaces'; + +export const rowListDescription: RowProperties = [ + { + displayName: 'Table Name', + name: 'tableName', + type: 'options', + placeholder: 'Select a table', + required: true, + typeOptions: { + loadOptionsMethod: 'getTableNames', + }, + displayOptions: { + show: { + resource: ['row'], + operation: ['list'], + }, + }, + default: '', + description: + 'The name of SeaTable table to access. Choose from the list, or specify a name using an expression.', + }, + { + displayName: 'View Name or ID (optional)', + name: 'viewName', + type: 'options', + required: false, + displayOptions: { + show: { + resource: ['row'], + operation: ['list'], + }, + }, + typeOptions: { + loadOptionsDependsOn: ['tableName'], + loadOptionsMethod: 'getTableViews', + }, + default: '', + description: 'The name of SeaTable view to access. Choose from the list, or specify ...', + }, + { + displayName: 'Simplify output', + name: 'simple', + type: 'boolean', + displayOptions: { + show: { + resource: ['row'], + operation: ['list'], + }, + }, + default: true, + description: + 'Simplified returns only the columns of your base. Non-simplified will return additional columns like _ctime (=creation time), _mtime (=modification time) etc.', + }, +]; diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/execute.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/execute.ts new file mode 100644 index 0000000000..c46cd4639e --- /dev/null +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/execute.ts @@ -0,0 +1,54 @@ +import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow'; +import type { IRow } from './../../Interfaces'; +import { + seaTableApiRequest, + enrichColumns, + simplify_new, + getBaseCollaborators, +} from '../../../GenericFunctions'; + +export async function list(this: IExecuteFunctions, index: number): Promise { + // get parameters + const tableName = this.getNodeParameter('tableName', index) as string; + const viewName = this.getNodeParameter('viewName', index) as string; + const simple = this.getNodeParameter('simple', index) as boolean; + + // get collaborators + const collaborators = await getBaseCollaborators.call(this); + + // get rows + let requestMeta = await seaTableApiRequest.call( + this, + {}, + 'GET', + '/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata/', + ); + + let requestRows = await seaTableApiRequest.call( + this, + {}, + 'GET', + '/dtable-server/api/v1/dtables/{{dtable_uuid}}/rows/', + {}, + { + table_name: tableName, + view_name: viewName, + limit: 1000, + }, + ); + + let metadata = + requestMeta.metadata.tables.find((table: { name: string }) => table.name === tableName) + ?.columns ?? []; + let rows = requestRows.rows as IRow[]; + + // hide columns like button + rows.map((row) => enrichColumns(row, metadata, collaborators)); + + // remove columns starting with _ if simple; + if (simple) { + rows.map((row) => simplify_new(row)); + } + + return this.helpers.returnJsonArray(rows as IDataObject[]); +} diff --git a/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/index.ts b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/index.ts new file mode 100644 index 0000000000..ab055196fd --- /dev/null +++ b/packages/nodes-base/nodes/SeaTable/v2/actions/row/list/index.ts @@ -0,0 +1,4 @@ +import { list as execute } from './execute'; +import { rowListDescription as description } from './description'; + +export { description, execute };