Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

SCLNG-341 New "before delete" hook in Smart Data Source

Description:

The use case for a beforeDelete hook will most often be displaying a confirmation prompt. Displaying dialogs is always async and as such, the BeforeDeleteCallback type should be ammended to accept both Promises and boolean values (the latter so as to not break existing behavior):

src/core/data-source/crudhookable.ts

Code Block
export type BeforeEventCallback = (changeType: ChangeType, ev: any) => boolean;

// the above should become:
export type BeforeEventCallback = (
	changeType: ChangeType,
	ev: any
) => boolean | Promise<boolean>;

To accommodate this change, a few changes must be made in existing Smart Data Source code to check if the beforeSaveChanges callback result is a Promise, and if so, await the result.

public deleteRecord(): Promise<void> must now become public async deleteRecord(): Promise<void>. Within this method, it should be checked whether there is a beforeDelete callback provided and if so, either await the result or accept a boolean result directly. If the result is false, return Promise.resolve() and stop.

Sample usage:We have implemented a new hook for the Smart Data Source that can be used to perform certain operations before a record is deleted. The event raised is also cancellable.

JSON

Code Block
{
  "dataSources": {
    "CustomerDataSource": {
        "beforeDelete": "BeforeCustomerDelete"
    }
  }
}

...