SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.07k stars 650 forks source link

[Bug]: Bulk action doesn't trigger a list refresh #1624

Open bogmihut8 opened 5 months ago

bogmihut8 commented 5 months ago

Contact Details

No response

What happened?

I have implemented a bulk action that should just update a flag in the db object. Everything works as expected, but after action returns the success, it doesn't trigger a list refresh. Any idea what is missing here?

Thanks!

Bug prevalence

While developing the bulk action

AdminJS dependencies version

"@adminjs/express": "^6.1.0", "@adminjs/mongoose": "^4.0.0", "@adminjs/themes": "^1.0.1", "@adminjs/upload": "^4.0.1", "adminjs": "^7.4.1",

What browsers do you see the problem on?

No response

Relevant log output

No response

Relevant code that's giving you issues

updateMultipleDiscount15: {
    actionType: 'bulk',
    method: 'post',
    icon: 'Percent',
    label: 'Set selected discount 15%',
    component: false,
    handler: async (request, response, data) => {
      const { records, currentAdmin } = data;

      try {
        await Product.updateMany(
          { _id: { $in: request.query.recordIds.split(',') } },
          { $set: { discount15: true, discount25: false, discount50: false } },
          { new: true }
        );

        return {
          records: records.map(record => record.toJSON(currentAdmin)),
          notice: {
            message: 'Discount updated successfully',
            type: 'success',
          },
          redirectUrl: '/admin/resources/Produse',
        };
      } catch (error) {
        return {
          records,
          notice: {
            message: `Error updating discount: ${error.message}`,
            type: 'error',
          },
        };
      }
    },
  },
tamertwitter commented 4 months ago

maybe you imagine a new idea https://github.com/SoftwareBrothers/adminjs/issues/1634