mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add resource loaders for picklists
This commit is contained in:
parent
32f0a3af85
commit
07881b1385
|
@ -26,6 +26,7 @@ import {
|
|||
GetAllFilterOptions,
|
||||
IdType,
|
||||
LoadedFields,
|
||||
LoadedLayouts,
|
||||
LocationType,
|
||||
NameType,
|
||||
ProductDetails,
|
||||
|
@ -327,19 +328,7 @@ export async function getFields(
|
|||
resource: SnakeCaseResource,
|
||||
{ onlyCustom } = { onlyCustom: false },
|
||||
) {
|
||||
const moduleMap: { [resource: string]: string } = {
|
||||
account: 'Accounts',
|
||||
contact: 'Contacts',
|
||||
deal: 'Deals',
|
||||
invoice: 'Invoices',
|
||||
lead: 'Leads',
|
||||
product: 'Products',
|
||||
purchaseOrder: 'Purchase_Orders',
|
||||
salesOrder: 'Sales_Orders',
|
||||
vendor: 'Vendors',
|
||||
};
|
||||
|
||||
const qs = { module: moduleMap[resource] };
|
||||
const qs = { module: getModuleName(resource) };
|
||||
|
||||
let { fields } = await zohoApiRequest.call(this, 'GET', '/settings/fields', {}, qs) as LoadedFields;
|
||||
|
||||
|
@ -352,6 +341,49 @@ export async function getFields(
|
|||
return sortBy(options, o => o.name);
|
||||
}
|
||||
|
||||
function getModuleName(resource: string) {
|
||||
return {
|
||||
account: 'Accounts',
|
||||
contact: 'Contacts',
|
||||
deal: 'Deals',
|
||||
invoice: 'Invoices',
|
||||
lead: 'Leads',
|
||||
product: 'Products',
|
||||
purchaseOrder: 'Purchase_Orders',
|
||||
salesOrder: 'Sales_Orders',
|
||||
vendor: 'Vendors',
|
||||
quote: 'Quotes',
|
||||
}[resource];
|
||||
}
|
||||
|
||||
export async function getPicklistOptions(
|
||||
this: ILoadOptionsFunctions,
|
||||
resource: string,
|
||||
targetField: string,
|
||||
) {
|
||||
const qs = { module: getModuleName(resource) };
|
||||
const responseData = await zohoApiRequest.call(this, 'GET', '/settings/layouts', {}, qs) as LoadedLayouts;
|
||||
|
||||
const pickListOptions = responseData.layouts[0]
|
||||
.sections.find(section => section.api_name === getSectionApiName(resource))
|
||||
?.fields.find(f => f.api_name === targetField)
|
||||
?.pick_list_values;
|
||||
|
||||
if (!pickListOptions) return [];
|
||||
|
||||
return pickListOptions.map(
|
||||
(option) => ({ name: option.display_value, value: option.actual_value }),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function getSectionApiName(resource: string) {
|
||||
if (resource === 'purchaseOrder') return 'Purchase Order Information';
|
||||
if (resource === 'salesOrder') return 'Sales Order Information';
|
||||
|
||||
return `${capitalizeInitial(resource)} Information`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add filter options to a query string object.
|
||||
*/
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
adjustSalesOrderPayload,
|
||||
adjustVendorPayload,
|
||||
getFields,
|
||||
getPicklistOptions,
|
||||
handleListing,
|
||||
throwOnEmptyUpdate,
|
||||
toLoadOptions,
|
||||
|
@ -194,7 +195,7 @@ export class ZohoCrm implements INodeType {
|
|||
// resource fields
|
||||
// ----------------------------------------
|
||||
|
||||
// standard fields
|
||||
// standard fields - called from `makeGetAllFields`
|
||||
|
||||
async getAccountFields(this: ILoadOptionsFunctions) {
|
||||
return getFields.call(this, 'account');
|
||||
|
@ -285,6 +286,30 @@ export class ZohoCrm implements INodeType {
|
|||
async getCustomVendorFields(this: ILoadOptionsFunctions) {
|
||||
return getFields.call(this, 'vendor', { onlyCustom: true });
|
||||
},
|
||||
|
||||
// ----------------------------------------
|
||||
// resource picklist options
|
||||
// ----------------------------------------
|
||||
|
||||
async getAccountType(this: ILoadOptionsFunctions) {
|
||||
return getPicklistOptions.call(this, 'account', 'Account_Type');
|
||||
},
|
||||
|
||||
async getDealStage(this: ILoadOptionsFunctions) {
|
||||
return getPicklistOptions.call(this, 'deal', 'Stage');
|
||||
},
|
||||
|
||||
async getPurchaseOrderStatus(this: ILoadOptionsFunctions) {
|
||||
return getPicklistOptions.call(this, 'purchaseOrder', 'Status');
|
||||
},
|
||||
|
||||
async getSalesOrderStatus(this: ILoadOptionsFunctions) {
|
||||
return getPicklistOptions.call(this, 'salesOrder', 'Status');
|
||||
},
|
||||
|
||||
async getQuoteStage(this: ILoadOptionsFunctions) {
|
||||
return getPicklistOptions.call(this, 'quote', 'Quote_Stage');
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -135,8 +135,11 @@ export const accountFields = [
|
|||
{
|
||||
displayName: 'Account Type',
|
||||
name: 'Account_Type',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getAccountType',
|
||||
},
|
||||
default: [],
|
||||
},
|
||||
{
|
||||
displayName: 'Annual Revenue',
|
||||
|
@ -323,8 +326,11 @@ export const accountFields = [
|
|||
{
|
||||
displayName: 'Account Type',
|
||||
name: 'Account_Type',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getAccountType',
|
||||
},
|
||||
default: [],
|
||||
},
|
||||
{
|
||||
displayName: 'Annual Revenue',
|
||||
|
|
|
@ -102,9 +102,12 @@ export const dealFields = [
|
|||
{
|
||||
displayName: 'Stage',
|
||||
name: 'stage',
|
||||
type: 'string',
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getDealStage',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
|
@ -367,8 +370,11 @@ export const dealFields = [
|
|||
{
|
||||
displayName: 'Stage',
|
||||
name: 'Stage',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getDealStage',
|
||||
},
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -284,8 +284,11 @@ export const purchaseOrderFields = [
|
|||
{
|
||||
displayName: 'Status',
|
||||
name: 'Status',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPurchaseOrderStatus',
|
||||
},
|
||||
description: 'Status of the purchase order.',
|
||||
},
|
||||
{
|
||||
|
@ -508,8 +511,11 @@ export const purchaseOrderFields = [
|
|||
{
|
||||
displayName: 'Status',
|
||||
name: 'Status',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPurchaseOrderStatus',
|
||||
},
|
||||
description: 'Status of the purchase order.',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -177,8 +177,12 @@ export const quoteFields = [
|
|||
{
|
||||
displayName: 'Quote Stage',
|
||||
name: 'Quote_Stage',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getQuoteStage',
|
||||
},
|
||||
description: 'Stage of the quote.',
|
||||
},
|
||||
shippingAddress,
|
||||
{
|
||||
|
@ -367,8 +371,12 @@ export const quoteFields = [
|
|||
{
|
||||
displayName: 'Quote Stage',
|
||||
name: 'Quote_Stage',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getQuoteStage',
|
||||
},
|
||||
description: 'Stage of the quote.',
|
||||
},
|
||||
shippingAddress,
|
||||
{
|
||||
|
|
|
@ -255,8 +255,11 @@ export const salesOrderFields = [
|
|||
{
|
||||
displayName: 'Status',
|
||||
name: 'Status',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSalesOrderStatus',
|
||||
},
|
||||
description: 'Status of the sales order.',
|
||||
},
|
||||
{
|
||||
|
@ -493,8 +496,11 @@ export const salesOrderFields = [
|
|||
{
|
||||
displayName: 'Status',
|
||||
name: 'Status',
|
||||
type: 'string',
|
||||
default: '',
|
||||
type: 'options',
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSalesOrderStatus',
|
||||
},
|
||||
description: 'Status of the sales order.',
|
||||
},
|
||||
{
|
||||
|
|
15
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
15
packages/nodes-base/nodes/Zoho/types.d.ts
vendored
|
@ -85,3 +85,18 @@ export type LoadedProducts = Array<{
|
|||
Product_Name: string;
|
||||
id: string;
|
||||
}>;
|
||||
|
||||
export type LoadedLayouts = {
|
||||
layouts: Array<{
|
||||
sections: Array<{
|
||||
api_name: string;
|
||||
fields: Array<{
|
||||
api_name: string;
|
||||
pick_list_values: Array<{
|
||||
display_value: string;
|
||||
actual_value: string;
|
||||
}>
|
||||
}>
|
||||
}>
|
||||
}>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue