From 0300a0028cba5bde6b6877fa87482c9d319b962c Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 10 Apr 2024 16:34:05 +1000 Subject: [PATCH 1/2] Updated limitedForm to allow FormOptions to be used --- src/API.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/API.ts b/src/API.ts index 3a7db195..d1e9e2a2 100644 --- a/src/API.ts +++ b/src/API.ts @@ -102,28 +102,36 @@ export class API { } } - public limitedForm(name: string, opts: limitOptions): Promise { + /** + * Opens a named form, limiting/filtering the fields included + * @param {string} name - The name of the form to open + * @param {limitOptions} limitOpts - The options to apply when filtering fields + * @param {FormOptions} formOpts - Form options to use when opening the form once filtered + * @returns {Promise} - A promise that resolves with the form result + * @throws {ModalFormError} - Throws an error if the form definition is not found + */ + public limitedForm(name: string, limitOpts: limitOptions, formOpts?: FormOptions): Promise { const formDefinition = this.getFormByName(name); let newFormDefinition: FormDefinition; if (formDefinition) { - if (isOmitOption(opts)) { - const omit = opts.omit; + if (isOmitOption(limitOpts)) { + const omit = limitOpts.omit; newFormDefinition = { ...formDefinition, fields: formDefinition.fields.filter((field) => !omit.includes(field.name)), }; - } else if (isPickOption(opts)) { + } else if (isPickOption(limitOpts)) { newFormDefinition = { ...formDefinition, fields: formDefinition.fields.filter((field) => opts.pick.includes(field.name)), }; } else { throw new ModalFormError( - "Invalid options provided to limitedForm", - `GOT: ${JSON.stringify(opts)}`, + "Invalid limit options provided to limitedForm", + `GOT: ${JSON.stringify(limitOpts)}`, ); } - return this.openModalForm(newFormDefinition); + return this.openModalForm(newFormDefinition, formOpts); } else { const error = new ModalFormError(`Form definition ${name} not found`); log_error(error); From 56073bb9951ce98cfa125cecbfcd03350890ebf5 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 11 Apr 2024 14:25:18 +1000 Subject: [PATCH 2/2] Bugfix - missed rename when renaming opts to limitOpts in API.ts --- src/API.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API.ts b/src/API.ts index d1e9e2a2..f7991539 100644 --- a/src/API.ts +++ b/src/API.ts @@ -123,7 +123,7 @@ export class API { } else if (isPickOption(limitOpts)) { newFormDefinition = { ...formDefinition, - fields: formDefinition.fields.filter((field) => opts.pick.includes(field.name)), + fields: formDefinition.fields.filter((field) => limitOpts.pick.includes(field.name)), }; } else { throw new ModalFormError(