SUSI Skill CMS has evolved drastically over the past few months with not only the introduction of skill metrics, skill analytics and powerful sorting features and interactive skill view types we needed the SUSI admins to be able to delete skills directly from the skills page and hence the skill can be deleted without visiting the admin service and then locating the skill and deleting it. This feature can be useful when a skill live on the system needs to be removed instantaneously for any reason like the API used by the skill going down or if it is a redundant skill or anything else. This feature was much needed for the admins and thus it was implemented.
About the API
An API is developed at the server so from the client we call this API to fetch data from the server and plug this data into the chart we wish to render.
- Access token (taken from the session of the logged in user)
Sample API call :
Displaying a button with delete icon on skill page
The option to delete skill should be available at the skill page for each skill so we add a button with a delete icon for this in the group of edit skills and skill version buttons, clicking over this button will open up a confirmation dialog with two actions notable the delete/confirm button which deletes the skills and the cancel button which can be useful in case the user changes their mind. On clicking the delete button the request to delete the skill is sent to the server and thus the skill is deleted.
Import some required components
Adding some variables to the component state which will help us decide when the delete skill dialog is to be shown.
Display the delete skill button only when the user is logged in user has admin rights.
Adding some JSX to the component’s render function which includes a div in the skill page section and the Dialog component for the delete skill and some actions which in our case is the the confirmation to delete skill and to cancel the skill deletion in case the user changes their mind. Also a tooltip is shown which appears on hovering over the delete skill button.
Clicking the delete skill button will change the state variable which decides whether the dialog is to be shown or not.
Adding submit and cancel actions for the dialog menu and send them to the dialog as a prop.
Hitting the endpoint for skill deletion.
Adding onClick event handlers for dialog actions, for the cancel button we simply toggle the view of the delete skill dialog and for the submit button hits the endpoint for skill deletion and then we display a snack bar message about the status of request we submit if it succeeded or failed. Once the submit button is clicked we hit the delete skill endpoint by supplying appropriate params and post the request for skill deletion by calling the API through AJAX with appropriate params and thus this concludes the skill deletion workflow.
Build the URL for the AJAX request.
Make an AJAX request to the built API URL and in case the request is successful we set the conditional for displaying the snackbar to true and set the snackbar message depending on whether the skill was deleted successfully or it failed.
This concludes the workflow of how the skill deletion feature was implemented on the CMS skill page for admins. I hope you found this useful.
- David Gilbertson, Icons as react components: https://firstname.lastname@example.org/icons-as-react-components-de3e33cb8792
- Guide to use material icons, https://material-ui.com/style/icons/