Page 1 of 1

How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 9:41 am
by suhas.kachare

Hi Team ,

I am implementing a Bryntum Taskboard in react . I want to make a api call and fetch menuItem data from backend on taskMenu (...) click

Can you please guide me on this.

Thanks.


Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 11:32 am
by tasnim

Hello,

You could listen to taskMenuItem
It will fire when you click on a task menu item

new TaskBoard({
	listeners : {
		taskMenuItem : () => {
			// put your logic here
		}
	}
});

Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 11:41 am
by suhas.kachare

I want to make a api call on click of taskMenu (i.e 3 dot icon) and not on click of taskMenuItem


Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 11:45 am
by Animal

Could be that what you need is the taskmenubeforeshow event

https://bryntum.com/products/taskboard/docs/api/TaskBoard/view/TaskBoard#event-taskMenuBeforeShow

Screenshot 2023-02-23 at 10.43.20.png
Screenshot 2023-02-23 at 10.43.20.png (249.72 KiB) Viewed 924 times

Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 11:51 am
by Animal

I recommend experimenting with the catchAllevent to see what significant events are emitted. That's how I found this solution :)

Screenshot 2023-02-23 at 10.49.56.png
Screenshot 2023-02-23 at 10.49.56.png (470.46 KiB) Viewed 922 times

Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 12:03 pm
by suhas.kachare

Can I make api call inside this ? and where should I write this code inside or outside of listener block

  taskboard.on('taskmenubeforeshow' ,({items})=>{
          console.log('taskMenu click')
    }),

Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 2:39 pm
by suhas.kachare

I tried above code but it's not working as I have to make an api call . taskmenubeforeshow is not an async function.

listeners: {
 taskMenuBeforeShow: async({ items }) => {
        let response = await axiosWrapper.get("task.Actions.wm", { id: 17354 }, dispatch);
        let menuItems = response.data.items;
        menuItems.forEach((item) => {
          return (items[item.key] = item.text);
        });
      },
}

Can you please guide me with any other solution


Re: How to make a api call on taskMenu click

Posted: Thu Feb 23, 2023 4:30 pm
by Animal

The event does not currently allow async event handlers. This could be added. Here is a ticket : https://github.com/bryntum/support/issues/6249


Re: How to make a api call on taskMenu click

Posted: Wed Mar 01, 2023 10:07 am
by Animal

I have the fix for this, but it will not make it into the 5.3.0 release. Minor releases are very regular though, the 5.3.1 release will allow you to use an async handler for the taskMenuBeforeShow event and mutate the items object to change the menu content.