This topic follows Smart collection hooks routes
Today I updated forest-express-sequelize to v7.6.3
As for now, this is my smart collection forest/ file :
const { collection } = require('forest-express-sequelize');
collection('categories', {
actions: [{
name: 'Ajouter un nouveau contrat',
type: 'single',
fields: [{
field: 'Clef de repartition',
type: 'Enum',
enums: []
}, {
field: 'Référence',
type: 'String'
}, {
field: 'Date de début',
type: 'Date'
}, {
field: 'Date de fin',
type: 'Date'
}, {
field: 'Préavis en jours',
type: 'Number'
}, {
field: 'Tacite reconduction',
type: 'Boolean'
}, {
field: 'Montant annuel',
type: 'Number'
}, {
field: 'comment',
type: 'String'
}, {
field: 'Échéance du contrat assurance',
type: 'Enum',
enums: [
'Mensuelle',
'Trimestrielle',
'Annuelle'
]
}, {
field: 'Type de contrat',
type: 'Enum',
enums: [
'Maintenance',
'Assurance'
]
// }, {
// "provider_matricule": "TYMATE_12"
}],
hooks: {
load: ({ fields, record }) => {
console.log(record);
return fields;
}
}
}, {
name: 'Mise à jour (avenant) d\'un contrat',
type: 'single',
fields: [{
field: 'Date de fin',
type: 'String'
}, {
field: 'Préavis en jours',
type: 'String'
}, {
field: 'Tacite reconduction',
type: 'Boolean'
}, {
field: 'Montant',
type: 'Number'
}, {
field: 'PJ du contrat',
type: 'File'
}, {
field: 'Échéances',
type: 'String'
}],
}],
fields: [{
field: 'id',
type: 'String'
}, {
field: 'display_name',
type: 'String'
}, {
field: 'created_at',
type: 'Date'
}, {
field: 'updated_at',
type: 'Date'
}, {
field: 'sergic_slug',
type: 'String'
}, {
field: 'sergic_update_time',
type: 'Date'
}, {
field: 'mandatory',
type: 'Boolean'
}, {
field: 'default',
type: 'Boolean'
}]
});
As you can see, the whole point of upgrading forest-express-sequelize was in order to use hooks load method in the smart action of a smart collection. I’m about to write the load method in order to init the dropdowns in my form.
But I’m really puzzled about one thing :
load: ({ fields, record }) => {
console.log(record);
return fields;
}
This console.log simply displays :
{ id: '101' }
but this is FAR from what I need in my load method :
I should have the display_name, mandatory and all additional fields that might come in the future (the API providing me data for this collection will soon be enriched).
If the “record” contains the id only, it might be a major issue for me.
I should specify that i’m calling the smart action from the table view and I do not have a GET method for a unique record (hense no summary view).