Skip to content

Commit

Permalink
HMS-2786 implement delete action in list view
Browse files Browse the repository at this point in the history
Implement the delete action in the list view kebab menu.  There is
no confirmation dialog yet (to be implemented later; see HMS-2787).
  • Loading branch information
frasertweedale authored and avisiedo committed Oct 17, 2023
1 parent 3a43655 commit 7642a0f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Components/DomainList/DomainList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ export const DomainList = () => {
setDomains(newDomains);
};

// remove domain(s) matching the given uuid from the `domains` state
const removeDomain = (uuid: string): void => {
const newDomains: Domain[] = [];
for (const domain of domains) {
if (domain.domain_id !== uuid) {
newDomains.push(domain);
}
}
setDomains(newDomains);
};

const onEnableDisable = (domain: Domain) => {
console.log(`clicked on Enable/Disable, on row ${domain.title}`);
if (domain.domain_id) {
Expand All @@ -151,6 +162,25 @@ export const DomainList = () => {
}
};

const onDelete = (domain: Domain) => {
if (domain.domain_id !== undefined) {
const domainId = domain.domain_id;
resources_api
.deleteDomain(domainId)
.then((response) => {
if (response.status == 204) {
removeDomain(domainId);
} else {
// TODO show-up notification with error message
}
})
.catch((error) => {
// TODO show-up notification with error message
console.log('error onClose: ' + error);
});
}
};

const defaultActions = (domain: Domain): IAction[] => [
{
title: 'Enable/Disable',
Expand All @@ -162,7 +192,7 @@ export const DomainList = () => {
},
{
title: 'Delete',
onClick: () => console.log(`clicked on Delete, on row ${domain.title}`),
onClick: () => onDelete(domain),
},
];

Expand Down

0 comments on commit 7642a0f

Please sign in to comment.