Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS-2786 implement delete action in list view #13

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading