Feature(s) impacted
Hooks don’t work on bulk type smart actions despite documentation: Use a Smart Action Form - Developer Guide
Observed behavior
Unless I specify type: 'single'
for the action type, the following produces no response:
hooks: {
change: {
Message: async ({ fields, record }) => {
console.log(`load: / fields`, fields);
console.log(`load: / request`, record);
return fields;
},
Recruiter: async ({ fields, record }) => {
console.log(`load: / fields`, fields);
console.log(`load: / request`, record);
return fields;
}
}
},
Expected behavior
As noted in the documentation, the following should work just fine:
const { collection, RecordsGetter } = require('forest-express-sequelize');
const { customers } = require('../models');
const customersHaveSameCountry = require('../services/customers-have-same-country');
collection('customers', {
actions: [{
name: 'Some action',
type: 'bulk',
fields: [
{
field: 'country',
type: 'String',
isReadOnly: true
},
{
field: 'city',
type: 'String'
},
],
hooks: {
load: async ({ fields, request }) => {
const country = fields.find(field => field.field === 'country');
const ids = await new RecordsGetter(forest, request.user, request.query)
.getIdsFromRequest(request);
const customers = await customers.findAll({ where: { id }});
country.value = '';
country.isReadOnly = false;
// If customers have the same country, set field to this country and make it not editable
if (customersHaveSameCountry(customers)) {
country.value = customers.country;
country.isReadOnly = true;
}
return fields;
},
},
}],
fields: [],
segments: [],
});
Can this be retested to make sure it does in fact work? I am not able to get load
or change
hooks to produce any response.
According to this older post, load
hooks do not work for bulk actions:
But again, the documentation says otherwise.
Context
"meta": {
"liana": "forest-express-sequelize",
"liana_version": "7.12.3",
"stack": {
"database_type": "postgres",
"engine": "nodejs",
"engine_version": "17.9.0",
"orm_version": "6.11.0"
}
}