directus-extension-api-trigger-interface
directus-extension-api-trigger-interface copied to clipboard
some improvements
- adds system-display-template interface to url-properties
- adds the ability to return a custom popup-title and popup-text
- adds the ability to return a custom url to jump to after api-call
- adds the ability to show popup as dialog
example for endpoint that returns custom popup-title, popup-text, a custom url to jump to and showing a dialog instead of the notification:
module.exports = (router, { services, exceptions, database }) => {
const { ItemsService } = services;
const { ServiceUnavailableException } = exceptions;
router.get("/cancel/:id", async (req, res, next) => {
const id = req.params.id;
try {
res.json({
title: "Success",
text: "Event canceled",
goto: "/content/event",
dialog: true,
});
} catch (error) {
return next(new ServiceUnavailableException(error.message));
}
});
}
Hi @kamil-malinski
Thanks for your contributions.
Your improvements are very nice but I think some unintended behaviors might happen with custom title & text. For example, you call a GET to an item that contains one of these fields but you don't want them to be displayed on the popup. I suggest that you can add a boolean props to enable/disable custom popup content.
Hi @duydvu
I don’t use the text field or the title field of the item for the popup. The text and the title are from the response of the endpoint.
If you don’t want custom text and title just don’t put them into the response.
For example, the button triggers a request to a 3rd-party API and it returns the data that contains title or text, it will be displayed even if I don't want to.
We cannot control the data of the response returned from the API so I just want to have a way to control whether it should use the data as the dialog title & text.
ok, I understand what you mean
I'm going to add a switch as suggested
How is it going, @kamil-malinski. Is there anything I can help?
@kamil-malinski I just raised an issue #3 for navigating the browser to another page after the API call. Checking your pull request, there is already:
if (result.data?.goto) router.push(result.data.goto);
I believe the directus APP will ask for user confirmation for unsaved changes? this is a little bit annoying regarding user experience. I am wondering do you have a solution or workaround for this?