ForestAdmin / forest-express-mongoose

🌱 ExpressJS/Mongoose agent for Forest Admin to integrate directly to your existing ExpressJS/Mongoose backend application.
https://www.forestadmin.com
GNU General Public License v3.0
193 stars 28 forks source link

Smart Action values not working #168

Closed ChrisLahaye closed 5 years ago

ChrisLahaye commented 5 years ago

Expected behavior

When opening a Smart Action I would expect the field to be filled in with the value denoted under values.

Actual behavior

There is no default value

Failure Logs

forest.collection('Payment', {
    actions: [{
            endpoint: 'forest/payment/refund',
            name: 'Refund payment',
            fields: [{
                    description: 'The amount to be refunded',
                    field: 'amount',
                    isRequired: true,
                    type: 'Number',
                }],
            values: (context) => ({ amount: 50 }),
        }],
});

translates into

    "actions": [{
      "name": "Refund payment",
      "type": "bulk",
      "baseUrl": null,
      "endpoint": "forest/payment/refund",
      "httpMethod": "POST",
      "redirect": null,
      "download": false,
      "fields": [{
        "field": "amount",
        "type": "Number",
        "defaultValue": null,
        "enums": null,
        "isRequired": true,
        "reference": null,
        "description": "The amount to be refunded",
        "position": 0,
        "widget": null
      }]
    }]

Context

ChrisLahaye commented 5 years ago

https://github.com/ForestAdmin/forest-express/pull/231 fix proposed

arnaudbesnier commented 5 years ago

Hi @ChrisLahaye, I am not sure we have a bug here.

If you want to specify a custom endpoint for your Smart Action, you must start your endpoint with a / character. By default (if you don't specify a custom endpoint), the endpoint generated will be correctly prefixed with a / character.

(I think that the fix you proposed could generate regressions for Smart Actions declared without custom endpoint)

ChrisLahaye commented 5 years ago

@arnaudbesnier You are right... Thanks for having a look though