-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
#962 Bulk connectors ops #3473
Draft
kamsharipova
wants to merge
11
commits into
master
Choose a base branch
from
bulk-connectors-ops
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
#962 Bulk connectors ops #3473
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f9ec61e
962 - bulk connectors operations
cc71300
Merge branch 'master' into bulk-connectors-ops
6cd3a44
962 - bulk connectors operations tests are added
afc016a
962 - bulk connectors operations linters fix
b979837
Merge branch 'master' into bulk-connectors-ops
52fa539
962 - bulk connectors operations linters fix
8a8fedf
Merge branch 'master' into bulk-connectors-ops
Haarolean 19c0b29
962 - bulk connectors operations delete connectors fix
174e4d8
962 - bulk connectors operations permissions for batch actions bar ar…
42eafab
962 - bulk connectors operations: code review fixes
34921e0
Merge branch 'master' into bulk-connectors-ops
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
kafka-ui-react-app/src/components/Connect/List/BatchActionsBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import React from 'react'; | ||
import { | ||
Action, | ||
ResourceType, | ||
ConnectorAction, | ||
Connector, | ||
} from 'generated-sources'; | ||
import useAppParams from 'lib/hooks/useAppParams'; | ||
import { useConfirm } from 'lib/hooks/useConfirm'; | ||
import { RouterParamsClusterConnectConnector } from 'lib/paths'; | ||
import { useIsMutating, useQueryClient } from '@tanstack/react-query'; | ||
import { ActionCanButton } from 'components/common/ActionComponent'; | ||
import { | ||
useDeleteConnector, | ||
useUpdateConnectorState, | ||
} from 'lib/hooks/api/kafkaConnect'; | ||
import { Row } from '@tanstack/react-table'; | ||
import { isPermitted } from 'lib/permissions'; | ||
import { useUserInfo } from 'lib/hooks/useUserInfo'; | ||
|
||
interface BatchActionsBarProps { | ||
rows: Row<Connector>[]; | ||
resetRowSelection(): void; | ||
} | ||
|
||
const BatchActionsBar: React.FC<BatchActionsBarProps> = ({ | ||
rows, | ||
resetRowSelection, | ||
}) => { | ||
const confirm = useConfirm(); | ||
|
||
const selectedConnectors = rows.map(({ original }) => original); | ||
|
||
const mutationsNumber = useIsMutating(); | ||
const isMutating = mutationsNumber > 0; | ||
|
||
const routerProps = useAppParams<RouterParamsClusterConnectConnector>(); | ||
const { clusterName } = routerProps; | ||
const client = useQueryClient(); | ||
const { roles, rbacFlag } = useUserInfo(); | ||
|
||
const canPerformActionOnSelected = (action: Action) => { | ||
return selectedConnectors.every((connector) => | ||
isPermitted({ | ||
roles, | ||
resource: ResourceType.CONNECT, | ||
action, | ||
value: connector.name, | ||
clusterName, | ||
rbacFlag, | ||
}) | ||
); | ||
}; | ||
|
||
const canEdit = canPerformActionOnSelected(Action.EDIT); | ||
const canDelete = canPerformActionOnSelected(Action.DELETE); | ||
|
||
const deleteConnectorMutation = useDeleteConnector(routerProps); | ||
const deleteConnectorsHandler = () => { | ||
confirm( | ||
'Are you sure you want to remove selected connectors?', | ||
async () => { | ||
try { | ||
await Promise.all( | ||
selectedConnectors.map((connector) => | ||
deleteConnectorMutation.mutateAsync({ | ||
clusterName, | ||
connectName: connector.connect, | ||
connectorName: connector.name, | ||
}) | ||
) | ||
); | ||
resetRowSelection(); | ||
} catch (e) { | ||
// do nothing; | ||
} finally { | ||
client.invalidateQueries(['clusters', clusterName, 'connectors']); | ||
} | ||
} | ||
); | ||
}; | ||
|
||
const stateMutation = useUpdateConnectorState(routerProps); | ||
const updateConnector = (action: ConnectorAction, message: string) => { | ||
confirm(message, async () => { | ||
try { | ||
await Promise.all( | ||
selectedConnectors.map((connector) => | ||
stateMutation.mutateAsync({ | ||
clusterName, | ||
connectName: connector.connect, | ||
connectorName: connector.name, | ||
action, | ||
}) | ||
) | ||
); | ||
resetRowSelection(); | ||
} catch (e) { | ||
// do nothing; | ||
} finally { | ||
client.invalidateQueries(['clusters', clusterName, 'connectors']); | ||
} | ||
}); | ||
}; | ||
const restartConnectorHandler = () => { | ||
updateConnector( | ||
ConnectorAction.RESTART, | ||
'Are you sure you want to restart selected connectors?' | ||
); | ||
}; | ||
const restartAllTasksHandler = () => | ||
updateConnector( | ||
ConnectorAction.RESTART_ALL_TASKS, | ||
'Are you sure you want to restart all tasks in selected connectors?' | ||
); | ||
const restartFailedTasksHandler = () => | ||
updateConnector( | ||
ConnectorAction.RESTART_FAILED_TASKS, | ||
'Are you sure you want to restart failed tasks in selected connectors?' | ||
); | ||
const pauseConnectorHandler = () => | ||
updateConnector( | ||
ConnectorAction.PAUSE, | ||
'Are you sure you want to pause selected connectors?' | ||
); | ||
const resumeConnectorHandler = () => | ||
updateConnector( | ||
ConnectorAction.RESUME, | ||
'Are you sure you want to resume selected connectors?' | ||
); | ||
|
||
return ( | ||
<> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={pauseConnectorHandler} | ||
disabled={isMutating} | ||
canDoAction={canEdit} | ||
> | ||
Pause | ||
</ActionCanButton> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={resumeConnectorHandler} | ||
disabled={isMutating} | ||
canDoAction={canEdit} | ||
> | ||
Resume | ||
</ActionCanButton> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={restartConnectorHandler} | ||
disabled={isMutating} | ||
canDoAction={canEdit} | ||
> | ||
Restart Connector | ||
</ActionCanButton> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={restartAllTasksHandler} | ||
disabled={isMutating} | ||
canDoAction={canEdit} | ||
> | ||
Restart All Tasks | ||
</ActionCanButton> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={restartFailedTasksHandler} | ||
disabled={isMutating} | ||
canDoAction={canEdit} | ||
> | ||
Restart Failed Tasks | ||
</ActionCanButton> | ||
<ActionCanButton | ||
buttonSize="M" | ||
buttonType="secondary" | ||
onClick={deleteConnectorsHandler} | ||
disabled={isMutating} | ||
canDoAction={canDelete} | ||
> | ||
Delete | ||
</ActionCanButton> | ||
</> | ||
); | ||
}; | ||
|
||
export default BatchActionsBar; |
29 changes: 29 additions & 0 deletions
29
kafka-ui-react-app/src/components/Connect/List/ConnectorCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { CellContext } from '@tanstack/react-table'; | ||
import { FullConnectorInfo } from 'generated-sources'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { clusterConnectConnectorPath, ClusterNameRoute } from 'lib/paths'; | ||
import useAppParams from 'lib/hooks/useAppParams'; | ||
|
||
const ConnectorCell: React.FC<CellContext<FullConnectorInfo, unknown>> = ({ | ||
row: { original }, | ||
}) => { | ||
const navigate = useNavigate(); | ||
const { name, connect } = original; | ||
const { clusterName } = useAppParams<ClusterNameRoute>(); | ||
const path = clusterConnectConnectorPath(clusterName, connect, name); | ||
const handleOnClick = () => navigate(path); | ||
|
||
return ( | ||
<div | ||
role="link" | ||
tabIndex={0} | ||
onClick={handleOnClick} | ||
onKeyDown={handleOnClick} | ||
> | ||
{name} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConnectorCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<ActionButton
please check this component , because the<ActionCanButton
is just so we would be able to use some very custom selectors together.use
<ActionButton
and it has apermisson
props , please check that.so we will have a uniform way for doing the permission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActionButton is only capable on checking permissions on one entity, but collection. I need either modify the way we operate permissions in ActionButton or use ActionCanButton or I can create new component ActionOnCollectionButton and implement those permissions use there. WDYT is the best way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mgrdich any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will think about it and get back to you.