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

Feature - Delete operator by keyboard #508

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
saveOperatorPosition,
saveOperatorDependencies,
selectOperatorAndGetData,
removeOperatorRequest,
} from 'store/operator';
import { OPERATORS_TYPES } from 'store/operators';
import { useDeepEqualSelector, useIsLoading } from 'hooks';
Expand All @@ -33,11 +34,16 @@ const numberOfLogsSelector = ({ experimentLogsReducer }) => {
return experimentLogsReducer.logs.length;
};

const operatorSelector = ({ operatorReducer }) => {
return operatorReducer;
};

const ExperimentFlowContainer = () => {
const dispatch = useDispatch();
const { projectId, experimentId } = useParams();

const operators = useDeepEqualSelector(operatorsSelector);
const operator = useDeepEqualSelector(operatorSelector);
const arrowConfigs = useDeepEqualSelector(arrowConfigsSelector);
const numberOfLogs = useDeepEqualSelector(numberOfLogsSelector);
const isShowingLogsPanel = useDeepEqualSelector(isShowingLogsPanelSelector);
Expand All @@ -47,8 +53,10 @@ const ExperimentFlowContainer = () => {
const flowLoading = useIsLoading(OPERATORS_TYPES.FETCH_OPERATORS_REQUEST);
const operatorLoading = useIsLoading(OPERATOR_TYPES.CREATE_OPERATOR_REQUEST);

const selectOperatorHandler = (operator) => {
dispatch(selectOperatorAndGetData(projectId, experimentId, operator));
const selectOperatorHandler = (selectedOperator) => {
dispatch(
selectOperatorAndGetData(projectId, experimentId, selectedOperator)
);
};

const handleSavePosition = (operatorId, position) => {
Expand All @@ -57,6 +65,10 @@ const ExperimentFlowContainer = () => {
);
};

const handleRemoveOperator = () => {
dispatch(removeOperatorRequest(projectId, experimentId, operator));
};

const handleSaveDependencies = (operatorId, dependencies) => {
dispatch(
saveOperatorDependencies(
Expand Down Expand Up @@ -102,6 +114,7 @@ const ExperimentFlowContainer = () => {
handleToggleLogsPanel={handleToggleLogsPanel}
handleSaveDependencies={handleSaveDependencies}
handleDeselectOperator={handleDeselectOperator}
handleRemoveOperator={handleRemoveOperator}
/>
);
};
Expand Down
18 changes: 12 additions & 6 deletions src/pages/Experiments/Experiment/ExperimentFlow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ExperimentFlow = ({
handleToggleLogsPanel,
handleSaveDependencies,
handleDeselectOperator,
handleRemoveOperator,
}) => {
const [connectClass, setConnectClass] = useState('');

Expand Down Expand Up @@ -56,6 +57,15 @@ const ExperimentFlow = ({
handleSaveDependencies(target, filteredDependencies);
};

const handleDeleteOperator = (elements) => {
const element = elements[0];
if (element.type !== 'cardNode') {
handleDeleteConnection(element.target, element.source);
} else if (element.type == 'cardNode') {
handleRemoveOperator();
}
};

const handleDragStop = (_, task) => {
handleSavePosition(task.id, task.position);
};
Expand Down Expand Up @@ -148,12 +158,7 @@ const ExperimentFlow = ({
onSelectionChange={handleDeselectOperator}
onPaneContextMenu={(e) => e.preventDefault()}
onConnectStart={() => setConnectClass('Connecting')}
onElementsRemove={(e) => {
const line = e[0];
if (line.type !== 'cardNode') {
handleDeleteConnection(line.target, line.source);
}
}}
onElementsRemove={handleDeleteOperator}
onlyRenderVisibleElements
>
<Background
Expand Down Expand Up @@ -200,6 +205,7 @@ ExperimentFlow.propTypes = {
handleToggleLogsPanel: PropTypes.func.isRequired,
handleDeselectOperator: PropTypes.func.isRequired,
handleSaveDependencies: PropTypes.func.isRequired,
handleRemoveOperator: PropTypes.func.isRequired,
};

const ExperimentFlowDrop = DropTarget(
Expand Down