adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Handle click on custom resourece action button

Open b-des opened this issue 3 years ago • 5 comments

Hello. I've created new action with `actionType: 'resource' but I want to intercept the click before go to the page with component. For example I need to collect all the query parameters before open new custom action page. Please, advise how can I do it?

P.S. before and after hooks are not triggered for resource action.

b-des avatar Jul 20 '22 16:07 b-des

In general how can I add click handler for custom action? For example I don't want to open new page by click but perform API call

b-des avatar Jul 20 '22 18:07 b-des

If you share your code it would be a little easier to help you, but something like this should work.

 CustomAction: {
        actionType: "resource",
        icon: "Renew",
        component: false,
        handler: async (req, res, context) => {
          //Do whatever you want
          return {
            notice: { message: "Done" },
          }
        },
      }

AshotN avatar Jul 20 '22 19:07 AshotN

Thank you @AshotN for the response. It works but seems handler function is triggered only when component: false. Let me explain what is my goal. image I want to download some CSV file based on the query parameters when click on action button I understand that downloading can be started only from component. So it's vicious circle, on the one hand downloading can be started from component, on the other hand - handler function can't be triggered when component is set. It's obviously that query parameter must be passed somehow to component and use them to make API call and return attachment to browser. Please, advise how can I solve this issue

b-des avatar Jul 21 '22 05:07 b-des

Why before, after and handler functions isn't triggered for new action with actionType: 'resource', when component is set? How it can be fixed? image image

b-des avatar Jul 22 '22 08:07 b-des

Any new update about this one ?

chadybadour avatar Mar 17 '23 14:03 chadybadour