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 committed Oct 17, 2023
1 parent 3a43655 commit 2242463
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 (let domain of domains) {

Check failure on line 136 in src/Components/DomainList/DomainList.tsx

View workflow job for this annotation

GitHub Actions / validate

'domain' is never reassigned. Use 'const' instead
if (domain.domain_id !== uuid) {
newDomains.push(domain);

Check failure on line 138 in src/Components/DomainList/DomainList.tsx

View workflow job for this annotation

GitHub Actions / validate

Delete `··`
}
}
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) {
let domainId = domain.domain_id;

Check failure on line 167 in src/Components/DomainList/DomainList.tsx

View workflow job for this annotation

GitHub Actions / validate

'domainId' is never reassigned. Use 'const' instead
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 2242463

Please sign in to comment.