Skip to content

Commit

Permalink
962 - bulk connectors operations delete connectors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamila Alekbaeva committed Apr 17, 2023
1 parent 8a8fedf commit 19c0b29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 17 additions & 6 deletions kafka-ui-react-app/src/components/Connect/List/BatchActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const BatchActionsBar: React.FC<BatchActionsBarProps> = ({
const isMutating = mutationsNumber > 0;

const routerProps = useAppParams<RouterParamsClusterConnectConnector>();
const clusterName = routerProps.clusterName;
const { clusterName } = routerProps;
const client = useQueryClient();

const canEdit = usePermission(
Expand All @@ -49,18 +49,29 @@ const BatchActionsBar: React.FC<BatchActionsBarProps> = ({
);

const deleteConnectorMutation = useDeleteConnector(routerProps);
const deleteConnectorsHandler = () =>
const deleteConnectorsHandler = () => {
confirm(
<>Are you sure you want to remove selected connectors?</>,
'Are you sure you want to remove selected connectors?',
async () => {
try {
await deleteConnectorMutation.mutateAsync();
await Promise.all(
selectedConnectors.map((connector) => {
deleteConnectorMutation.mutateAsync({
clusterName,
connectName: connector.connect,
connectorName: connector.name,
});
})
);
resetRowSelection();
} catch {
// do not redirect
} catch (e) {
// do nothing;
} finally {
client.invalidateQueries(['clusters', clusterName, 'connectors']);
}
}
);
};

const stateMutation = useUpdateConnectorState(routerProps);
const updateConnector = (action: ConnectorAction, message: string) => {
Expand Down
9 changes: 6 additions & 3 deletions kafka-ui-react-app/src/lib/hooks/api/kafkaConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export function useCreateConnector(clusterName: ClusterName) {
export function useDeleteConnector(props: UseConnectorProps) {
const client = useQueryClient();

return useMutation(() => api.deleteConnector(props), {
onSuccess: () => client.invalidateQueries(connectorsKey(props.clusterName)),
});
return useMutation(
(message: UseConnectorProps) => api.deleteConnector(message),
{
onSuccess: () => client.invalidateQueries(connectorKey(props)),
}
);
}

0 comments on commit 19c0b29

Please sign in to comment.