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

Flow multi select to delete #6021

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/src/js/components/FlowTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FlowTable extends React.Component {

render() {
const { vScroll, viewportTop } = this.state;
const { flows, selected, highlight } = this.props;
const { flows, highlight, selectedRows } = this.props;
const isHighlighted = highlight ? Filt.parse(highlight) : () => false;

return (
Expand All @@ -124,7 +124,7 @@ class FlowTable extends React.Component {
<FlowRow
key={flow.id}
flow={flow}
selected={flow === selected}
selected={selectedRows.includes(flow.id)}
highlighted={isHighlighted(flow)}
/>
))}
Expand All @@ -141,5 +141,5 @@ export const PureFlowTable = AutoScroll(FlowTable);
export default connect((state) => ({
flows: state.flows.view,
highlight: state.flows.highlight,
selected: state.flows.byId[state.flows.selected[0]],
selectedRows: state.flows.selected,
}))(PureFlowTable);
9 changes: 7 additions & 2 deletions web/src/js/components/FlowTable/FlowRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback } from "react";
import classnames from "classnames";
import { Flow } from "../../flow";
import { useAppDispatch, useAppSelector } from "../../ducks";
import { select } from "../../ducks/flows";
import { multiSelect, select } from "../../ducks/flows";
import * as columns from "./FlowColumns";

type FlowRowProps = {
Expand Down Expand Up @@ -36,7 +36,12 @@ export default React.memo(function FlowRow({
if (node.classList.contains("col-quickactions")) return;
node = node.parentNode;
}
dispatch(select(flow.id));
if (e.ctrlKey) {
dispatch(multiSelect(flow.id));
}
if (!e.ctrlKey) {
dispatch(select(flow.id));
}
},
[flow]
);
Expand Down
33 changes: 28 additions & 5 deletions web/src/js/components/Header/FlowMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
replay as replayFlow,
resume as resumeFlow,
revert as revertFlow,
removeMultiple as removeMultipleFlows,
} from "../../ducks/flows";
import Dropdown, { MenuItem } from "../common/Dropdown";
import { copy } from "../../flow/export";
Expand All @@ -23,6 +24,7 @@ export default function FlowMenu(): JSX.Element {
flow = useAppSelector(
(state) => state.flows.byId[state.flows.selected[0]]
);
const selectedRows = useAppSelector((state) => state.flows.selected);

if (!flow) return <div />;
return (
Expand All @@ -34,19 +36,26 @@ export default function FlowMenu(): JSX.Element {
title="[r]eplay flow"
icon="fa-repeat text-primary"
onClick={() => dispatch(replayFlow(flow))}
disabled={!canReplay(flow)}
disabled={
!canReplay(flow) || selectedRows.length > 1
}
>
Replay
</Button>
<Button
title="[D]uplicate flow"
icon="fa-copy text-info"
onClick={() => dispatch(duplicateFlow(flow))}
disabled={selectedRows.length > 1}
>
Duplicate
</Button>
<Button
disabled={!flow || !flow.modified}
disabled={
!flow ||
!flow.modified ||
selectedRows.length > 1
}
title="revert changes to flow [V]"
icon="fa-history text-warning"
onClick={() => dispatch(revertFlow(flow))}
Expand All @@ -56,7 +65,13 @@ export default function FlowMenu(): JSX.Element {
<Button
title="[d]elete flow"
icon="fa-trash text-danger"
onClick={() => dispatch(removeFlow(flow))}
onClick={() =>
selectedRows.length === 1
? dispatch(removeFlow(flow))
: dispatch(
removeMultipleFlows(selectedRows)
)
}
>
Delete
</Button>
Expand All @@ -78,15 +93,23 @@ export default function FlowMenu(): JSX.Element {
<div className="menu-group">
<div className="menu-content">
<Button
disabled={!flow || !flow.intercepted}
disabled={
!flow ||
!flow.intercepted ||
selectedRows.length > 1
}
title="[a]ccept intercepted flow"
icon="fa-play text-success"
onClick={() => dispatch(resumeFlow(flow))}
>
Resume
</Button>
<Button
disabled={!flow || !flow.intercepted}
disabled={
!flow ||
!flow.intercepted ||
selectedRows.length > 1
}
title="kill intercepted flow [x]"
icon="fa-times text-danger"
onClick={() => dispatch(killFlow(flow))}
Expand Down
22 changes: 22 additions & 0 deletions web/src/js/ducks/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const UPDATE = "FLOWS_UPDATE";
export const REMOVE = "FLOWS_REMOVE";
export const RECEIVE = "FLOWS_RECEIVE";
export const SELECT = "FLOWS_SELECT";
export const MULTI_SELECT = "FLOWS_MULTI_SELECT";
export const SET_FILTER = "FLOWS_SET_FILTER";
export const SET_SORT = "FLOWS_SET_SORT";
export const SET_HIGHLIGHT = "FLOWS_SET_HIGHLIGHT";
Expand Down Expand Up @@ -111,6 +112,11 @@ export default function reducer(
selected: action.flowIds,
};

case MULTI_SELECT:
return {
...state,
selected: [...state.selected, ...action.flowIds],
};
default:
return state;
}
Expand Down Expand Up @@ -196,6 +202,15 @@ export function remove(flow: Flow) {
return (dispatch) => fetchApi(`/flows/${flow.id}`, { method: "DELETE" });
}

export function removeMultiple(flowIds: string[]) {
const promises: Promise<Response>[] = [];
flowIds.forEach((id) =>
promises.push(fetchApi(`/flows/${id}`, { method: "DELETE" }))
);
return (dispatch) => Promise.all(promises);
// return (dispatch) => fetchApi(`/flows/${flow.id}`, { method: "DELETE" });
}

export function duplicate(flow: Flow) {
return (dispatch) =>
fetchApi(`/flows/${flow.id}/duplicate`, { method: "POST" });
Expand Down Expand Up @@ -242,3 +257,10 @@ export function select(id?: string) {
flowIds: id ? [id] : [],
};
}

export function multiSelect(id?: string) {
return {
type: MULTI_SELECT,
flowIds: id ? [id] : [],
};
}