Skip to content

Commit b684dcd

Browse files
feat(Eliminar namespace): Eliminar namespace (#85)
1 parent 6859342 commit b684dcd

File tree

14 files changed

+81
-217
lines changed

14 files changed

+81
-217
lines changed

src/main/java/io/github/project/openubl/ublhub/models/jpa/entities/NamespaceEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class NamespaceEntity extends PanacheEntityBase {
6060
@OneToMany(fetch = FetchType.LAZY, mappedBy = "namespace", orphanRemoval = true)
6161
public List<CompanyEntity> companies = new ArrayList<>();
6262

63+
@OnDelete(action = OnDeleteAction.CASCADE)
64+
@OneToMany(fetch = FetchType.LAZY, mappedBy = "namespace", orphanRemoval = true)
65+
public List<ComponentEntity> components = new ArrayList<>();
66+
6367
@Version
6468
@Column(name = "version")
6569
public int version;

src/main/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@konveyor/lib-ui": "^5.2.0",
77
"@patternfly/react-core": "^4.168.8",
88
"@patternfly/react-table": "^4.44.4",
9-
"@project-openubl/lib-ui": "1.6.0",
9+
"@project-openubl/lib-ui": "1.7.0",
1010
"@redhat-cloud-services/frontend-components-notifications": "^3.2.4",
1111
"@testing-library/jest-dom": "^5.11.4",
1212
"@testing-library/react": "^11.1.0",

src/main/webapp/src/App.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import { DefaultLayout } from "./shared/components";
99
import NotificationsPortal from "@redhat-cloud-services/frontend-components-notifications/NotificationPortal";
1010
import "@redhat-cloud-services/frontend-components-notifications/index.css";
1111

12-
import DeleteDialog from "./shared/containers/delete-dialog";
12+
import { ConfirmationContextProvider } from "@project-openubl/lib-ui";
1313

1414
const App: React.FC = () => {
1515
return (
1616
<HashRouter>
17-
<DefaultLayout>
18-
<AppRoutes />
19-
</DefaultLayout>
20-
<NotificationsPortal />
21-
<DeleteDialog />
17+
<ConfirmationContextProvider>
18+
<DefaultLayout>
19+
<AppRoutes />
20+
</DefaultLayout>
21+
<NotificationsPortal />
22+
</ConfirmationContextProvider>
2223
</HashRouter>
2324
);
2425
};

src/main/webapp/src/pages/namespaces/namespaces-list/namespaces-list.tsx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useState } from "react";
22

33
import {
44
useTableControls,
55
SimpleTableWithToolbar,
66
useTable,
77
useModal,
8+
useConfirmationContext,
89
} from "@project-openubl/lib-ui";
910

1011
import {
@@ -24,7 +25,13 @@ import {
2425
sortable,
2526
} from "@patternfly/react-table";
2627

27-
import { useNamespacesQuery } from "queries/namespaces";
28+
import { useDispatch } from "react-redux";
29+
import { alertActions } from "store/alert";
30+
31+
import {
32+
useNamespacesQuery,
33+
useDeleteNamespaceMutation,
34+
} from "queries/namespaces";
2835

2936
import {
3037
SearchInput,
@@ -33,6 +40,7 @@ import {
3340
} from "shared/components";
3441

3542
import { Namespace } from "api/models";
43+
import { getAxiosErrorMessage } from "utils/modelUtils";
3644

3745
const ROW_FIELD = "row_field";
3846
const getRow = (rowData: IRowData): Namespace => {
@@ -73,6 +81,10 @@ export const filterByText = (filterText: string, item: Namespace) => {
7381
};
7482

7583
export const NamespacesList: React.FC = () => {
84+
const dispatch = useDispatch();
85+
const confirmationModal = useConfirmationContext();
86+
87+
//
7688
const namespaceModal = useModal<Namespace>();
7789

7890
//
@@ -86,10 +98,7 @@ export const NamespacesList: React.FC = () => {
8698

8799
//
88100
const namespaces = useNamespacesQuery();
89-
90-
useEffect(() => {
91-
console.log(namespaces);
92-
}, [namespaces]);
101+
const deleteNamespace = useDeleteNamespaceMutation();
93102

94103
const { pageItems, filteredItems } = useTable<Namespace>({
95104
items: namespaces.data || [],
@@ -117,7 +126,37 @@ export const NamespacesList: React.FC = () => {
117126
extraData: IExtraData
118127
) => {
119128
const row: Namespace = getRow(rowData);
120-
console.log("Write code to delete the row", row);
129+
130+
confirmationModal.open({
131+
title: `Eliminar ${row.name}`,
132+
titleIconVariant: "warning",
133+
message: (
134+
<span>
135+
¿Estas seguro de querer eliminar este namespace? Esta acción
136+
eliminará el namespace <b>{row.name}</b> permanentemente.`
137+
</span>
138+
),
139+
confirmBtnVariant: ButtonVariant.danger,
140+
confirmBtnLabel: "Eliminar",
141+
cancelBtnLabel: "Cancelar",
142+
onConfirm: () => {
143+
confirmationModal.enableProcessing();
144+
deleteNamespace
145+
.mutateAsync(row)
146+
.catch((error) => {
147+
dispatch(
148+
alertActions.addAlert(
149+
"danger",
150+
"Error",
151+
getAxiosErrorMessage(error)
152+
)
153+
);
154+
})
155+
.finally(() => {
156+
confirmationModal.close();
157+
});
158+
},
159+
});
121160
},
122161
},
123162
];
@@ -167,7 +206,7 @@ export const NamespacesList: React.FC = () => {
167206
variant={ButtonVariant.primary}
168207
onClick={() => namespaceModal.open("add")}
169208
>
170-
Nuevo Namespace
209+
Crear nuevo
171210
</Button>
172211
</ToolbarItem>
173212
</ToolbarGroup>

src/main/webapp/src/queries/namespaces.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ export const useCreateNamespaceMutation = (
5757
);
5858
};
5959

60+
export const useDeleteNamespaceMutation = (
61+
onSuccess?: () => void
62+
): UseMutationResult<void, ApiClientError, Namespace, unknown> => {
63+
const client = useUblhubClient();
64+
const queryClient = useQueryClient();
65+
return useMutation<void, ApiClientError, Namespace>(
66+
async (ns: Namespace) => {
67+
await client.delete<void>(resource, `${ns.id}`);
68+
},
69+
{
70+
onSuccess: () => {
71+
queryClient.invalidateQueries("namespaces");
72+
onSuccess && onSuccess();
73+
},
74+
}
75+
);
76+
};
77+
6078
export const getNamespaceNameSchema = (
6179
namespacesQuery: UseQueryResult<Namespace[]>,
6280
namespaceBeingPrefilled: Namespace | null

src/main/webapp/src/shared/containers/delete-dialog/delete-dialog.tsx

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/webapp/src/shared/containers/delete-dialog/index.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/webapp/src/shared/containers/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/webapp/src/store/deleteDialog/actions.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/webapp/src/store/deleteDialog/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)