diff --git a/.idea/formula-evaluator.iml b/.idea/formula-evaluator.iml index 5bcabc71..b25edf75 100644 --- a/.idea/formula-evaluator.iml +++ b/.idea/formula-evaluator.iml @@ -8,7 +8,7 @@ diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index cc3da93f..00000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/expression-components/main/ui/components/base/lwc/baseButton/baseButton.js b/expression-components/main/ui/components/base/lwc/baseButton/baseButton.js index 759ca8e1..9e435a60 100644 --- a/expression-components/main/ui/components/base/lwc/baseButton/baseButton.js +++ b/expression-components/main/ui/components/base/lwc/baseButton/baseButton.js @@ -1,6 +1,7 @@ import {api} from 'lwc'; import TwElement from "c/twElement"; import {NavigationMixin} from "lightning/navigation"; +import {RefreshEvent} from "lightning/refresh"; import execute from '@salesforce/apex/FormulaEvaluatorUiController.execute'; import {classNames} from 'c/utils'; @@ -13,7 +14,7 @@ export default class BaseButton extends NavigationMixin(TwElement) { /** * @typedef ApexFunctionCallback - * @property { "navigate__namedPage" | "navigate__url" } type + * @property { "navigate__namedPage" | "navigate__url", "reload", "refresh" } type * @property { string } name * @property { Object } args */ @@ -21,7 +22,7 @@ export default class BaseButton extends NavigationMixin(TwElement) { /** * The action to execute when the button is clicked * @property {string} label - * @property {"action" | "navigation_namedPage" | "navigation_url" } type + * @property {"action", "submit" | "navigation_namedPage" | "navigation_url" } type * @property {string | ApexFunction} src * @property {ApexFunctionCallback} callback */ @@ -32,6 +33,7 @@ export default class BaseButton extends NavigationMixin(TwElement) { @api variant = "primary"; disabled = false; + get btnClasses() { switch (this.variant) { case "primary": @@ -62,7 +64,12 @@ export default class BaseButton extends NavigationMixin(TwElement) { const evt = new CustomEvent('submit', { bubbles: true, - detail: {action: execute, fnReference: this.action.src, callback: this.actionCallback}, + detail: { + action: execute, fnReference: this.action.src, callback: () => { + this.actionCallback(); + this.disabled = false; + } + }, composed: true }); this.dispatchEvent(evt); @@ -70,6 +77,7 @@ export default class BaseButton extends NavigationMixin(TwElement) { try { const result = await execute({fnReference: this.action.src}); this.actionCallback(result); + this.disabled = false; } catch (e) { console.error(e); } @@ -99,16 +107,28 @@ export default class BaseButton extends NavigationMixin(TwElement) { get displayAsButton() { return this.action.type === "submit" || this.action.type === "action"; } + actionCallback = (result) => { - if (this.action.callback.type === 'reload') { - // Reload is not handled by the navigation mixin, so we handle it here - // as a special case. - location.reload(); - } else { - this[NavigationMixin.Navigate](this._getNavigationObjectFromActionResult(result)); + switch (this.action.callback.type) { + case "reload": + this.dispatchEvent(new RefreshEvent()); + break; + case "refresh": + this.dispatchEvent(new CustomEvent('expression_refresh', {bubbles: true, composed: true})); + break; + case "navigate__namedPage": + case "navigate__url": + this._navigate(result); + break; + default: + throw new Error(`Unknown callback type: ${this.action.callback.type}`); } } + _navigate(result) { + this[NavigationMixin.Navigate](this._getNavigationObjectFromActionResult(result)); + } + _getNavigationObjectFromActionResult = (result) => { return { type: this._mapApexCallbackToNavigationMixinType(this.action.callback.type), diff --git a/expression-components/main/ui/components/base/lwc/expressionElementContainer/expressionElementContainer.html b/expression-components/main/ui/components/base/lwc/expressionElementContainer/expressionElementContainer.html index 83d2a0e4..abda2eea 100644 --- a/expression-components/main/ui/components/base/lwc/expressionElementContainer/expressionElementContainer.html +++ b/expression-components/main/ui/components/base/lwc/expressionElementContainer/expressionElementContainer.html @@ -1,5 +1,5 @@