diff --git a/packages/nodes-base/credentials/FileMaker.credentials.ts b/packages/nodes-base/credentials/FileMaker.credentials.ts index 1d8e4cf55c..443e87d115 100644 --- a/packages/nodes-base/credentials/FileMaker.credentials.ts +++ b/packages/nodes-base/credentials/FileMaker.credentials.ts @@ -6,7 +6,7 @@ import { export class FileMaker implements ICredentialType { name = 'fileMaker'; - displayName = 'FileMaker'; + displayName = 'FileMaker API'; properties = [ { displayName: 'Host', diff --git a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts index d210e40f3b..fc41b3dac3 100644 --- a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts +++ b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts @@ -676,20 +676,14 @@ export class FileMaker implements INodeType { // Get all the available topics to display them to user so that he can // select them easily async getLayouts(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; + let returnData: INodePropertyOptions[]; - let layouts; try { - layouts = await layoutsApiRequest.call(this); + returnData = await layoutsApiRequest.call(this); } catch (err) { throw new Error(`FileMaker Error: ${err}`); } - for (const layout of layouts) { - returnData.push({ - name: layout.name, - value: layout.name, - }); - } + return returnData; }, async getResponseLayouts(this: ILoadOptionsFunctions): Promise { diff --git a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts index 9c7ac7740f..d28d10486f 100644 --- a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts +++ b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts @@ -5,7 +5,7 @@ import { } from 'n8n-core'; import { - IDataObject, + IDataObject, INodePropertyOptions, } from 'n8n-workflow'; import {OptionsWithUri} from 'request'; @@ -19,6 +19,11 @@ interface ScriptsOptions { 'script.presort'?: any; //tslint:disable-line:no-any 'script.presort.param'?: any; //tslint:disable-line:no-any } +interface LayoutObject { + name: string; + isFolder?: boolean; + folderLayoutNames?:LayoutObject[]; +} /** * Make an API request to ActiveCampaign @@ -27,7 +32,7 @@ interface ScriptsOptions { * @param {string} method * @returns {Promise} */ -export async function layoutsApiRequest(this: ILoadOptionsFunctions | IExecuteFunctions | IExecuteSingleFunctions): Promise { // tslint:disable-line:no-any +export async function layoutsApiRequest(this: ILoadOptionsFunctions | IExecuteFunctions | IExecuteSingleFunctions): Promise { // tslint:disable-line:no-any const token = await getToken.call(this); const credentials = this.getCredentials('fileMaker'); @@ -49,14 +54,30 @@ export async function layoutsApiRequest(this: ILoadOptionsFunctions | IExecuteFu try { const responseData = await this.helpers.request!(options); - return responseData.response.layouts; - + const items = parseLayouts(responseData.response.layouts); + items.sort((a, b) => a.name > b.name ? 0 : 1); + return items; } catch (error) { // If that data does not exist for some reason return the actual error throw error; } } +function parseLayouts(layouts: LayoutObject[]): INodePropertyOptions[] { + const returnData: INodePropertyOptions[] = []; + for (const layout of layouts) { + if (layout.isFolder!) { + returnData.push(...parseLayouts(layout.folderLayoutNames!)); + } else { + returnData.push({ + name: layout.name, + value: layout.name, + }); + } + } + return returnData; +} + /** * Make an API request to ActiveCampaign * @@ -138,7 +159,6 @@ export async function getPortals(this: ILoadOptionsFunctions): Promise { // export async function getScripts(this: ILoadOptionsFunctions): Promise { // tslint:disable-line:no-any const token = await getToken.call(this); const credentials = this.getCredentials('fileMaker'); - const layout = this.getCurrentNodeParameter('layout') as string; if (credentials === undefined) { throw new Error('No credentials got returned!');