From 1321f9b6c8eb4ef9af9317b41402a54f65db1b91 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 26 Mar 2018 19:11:20 -0700 Subject: [PATCH] Add 'Delete All' option to key/value editors (Closes #803) --- .../app/ui/components/key-value-editor/editor.js | 16 ++++++++++++++++ .../app/ui/components/key-value-editor/row.js | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/insomnia-app/app/ui/components/key-value-editor/editor.js b/packages/insomnia-app/app/ui/components/key-value-editor/editor.js index cbdce1344..3658884a0 100644 --- a/packages/insomnia-app/app/ui/components/key-value-editor/editor.js +++ b/packages/insomnia-app/app/ui/components/key-value-editor/editor.js @@ -6,6 +6,8 @@ import {DEBOUNCE_MILLIS} from '../../../common/constants'; import Lazy from '../base/lazy'; import KeyValueEditorRow from './row'; import {generateId, nullFn} from '../../../common/misc'; +import {Dropdown, DropdownItem, DropdownButton} from '../base/dropdown'; +import PromptButton from '../base/prompt-button'; const NAME = 'name'; const VALUE = 'value'; @@ -56,6 +58,10 @@ class Editor extends PureComponent { this._onChange(pairs); } + _handleDeleteAll () { + this._onChange([]); + } + _handleMove (pairToMove, pairToTarget, targetOffset) { if (pairToMove.id === pairToTarget.id) { // Nothing to do @@ -378,6 +384,16 @@ class Editor extends PureComponent { index={-1} onChange={nullFn} onDelete={nullFn} + renderLeftIcon={() => ( + + + + + + Delete All Items + + + )} className="key-value-editor__row-wrapper--clicker" namePlaceholder={`New ${namePlaceholder}`} valuePlaceholder={`New ${valuePlaceholder}`} diff --git a/packages/insomnia-app/app/ui/components/key-value-editor/row.js b/packages/insomnia-app/app/ui/components/key-value-editor/row.js index cde4a1b82..156fcd35e 100644 --- a/packages/insomnia-app/app/ui/components/key-value-editor/row.js +++ b/packages/insomnia-app/app/ui/components/key-value-editor/row.js @@ -286,6 +286,7 @@ class KeyValueEditorRow extends PureComponent { isDragging, isDraggingOver, noDelete, + renderLeftIcon, connectDragSource, connectDragPreview, connectDropTarget @@ -303,7 +304,11 @@ class KeyValueEditorRow extends PureComponent { let handle = null; if (sortable) { - handle = connectDragSource( + handle = renderLeftIcon ? ( +
+ {renderLeftIcon()} +
+ ) : connectDragSource(
@@ -420,6 +425,7 @@ KeyValueEditorRow.propTypes = { noDropZone: PropTypes.bool, hideButtons: PropTypes.bool, className: PropTypes.string, + renderLeftIcon: PropTypes.func, // For drag-n-drop connectDragSource: PropTypes.func,