Suite8 Possible bug in base-line-items.component.ts, checking here before I log

Hi,

Being relatively new to Angular etc, I thought I would check here before logging this as a bug. So I was looking at the line-items field type and noticed that there is a trigger when adding/removing a line, to allow custom code to hook into these events (ie on removal this gets sent: onLineItemRemove).

This gets tied up with Field Logic definitions and a custom Angular action (similar to the existing field logic), so theoretcally you can wait for a line to be deleted and then trigger an action that also deletes an entry in a remote table (for example). This is the (eventual) code that does this:

 protected triggerLineActionEvents(lineActionEvent: LineActionEvent): void {

        const fieldLogics = this.field?.logic || {} as FieldLogicMap;

        if (emptyObject(fieldLogics)) {
            return;
        }

        Object.keys(fieldLogics).forEach(logicKey => {

            const fieldLogic = fieldLogics[logicKey] || null;

            const onEvent = fieldLogic?.params?.triggerOnEvents?.[lineActionEvent];

            if (isTrue(onEvent)) {
                this.logic.runLogic(this.field, this.mode as ViewMode, this.record);
            }
        });
    }

So as far as I can see you would add an entry in the ‘logic’ settings for the field, with params of

'triggerOnEvents'=>['onLineItemRemove'=>true]

which would trigger the events to run (great). However the this.runLogic has an additional parameter (triggeringStatus), which is then used to determine precisely which actions to run, in this case I would expect something like onLineItemRemove to be sent through so we can seperate the actions to run between onLineItemRemove/onLineItemAdd, the way it is I believe that all registered actions will run everytime.

Hopefully this is me reading this incorrectly, if not let me know and I will raise a bug.

Regards

Mark

When that function is called, it’s called with one of the two event types, either onLineItemRemoveor onLineItemAdd :

    removeItem(index: number): void {

        this.fieldManager.removeLineItem(
            this.field,
            index
        );

        this.updateItems(this.field.items);

        this.triggerLineActionEvents(LineActionEvent.onLineItemRemove);
    }

    addEmptyItem(): void {
        const itemDefinition: FieldDefinition = this.field?.definition?.lineItems?.definition || {};

        this.fieldManager.addLineItem(
            itemDefinition,
            this.record,
            this.field
        );

        this.triggerLineActionEvents(LineActionEvent.onLineItemAdd);
    }

I am not sure this is meant (yet) to allow custom code… it’s true that the basic Angular concepts in this app (events, actions, etc) are all quite similar… and if you’re customizing by adding and compiling actual TypeScript code, then it’s all there for you to use. But if you’re thinking of extensibility through metadata files, then much of it is not available yet.

Am I understanding your intent correctly? If not, please explain a bit more