From 797300b2bcc1843b4da5b8756c9e3f2c8c16a3f9 Mon Sep 17 00:00:00 2001 From: irismarie Date: Tue, 17 Nov 2020 16:47:09 +0100 Subject: [PATCH] duplicate widget via context menu, closes #184 --- src/dashboard/dashboard.js | 14 ++++++++++++++ src/widget/widget-context-menu.js | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index 60e271a..032791d 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -268,6 +268,19 @@ class Dashboard extends Component { this.setState({ editModal: true, modalData: widget, modalIndex: index }); }; + duplicateWidget(widget) { + let widgetCopy = JSON.parse(JSON.stringify(widget)); + delete widgetCopy.id; + widgetCopy.x = widgetCopy.x + 50; + widgetCopy.y = widgetCopy.y + 50; + + AppDispatcher.dispatch({ + type: 'widgets/start-add', + token: this.state.sessionToken, + data: widgetCopy + }); + }; + startEditFiles() { let tempFiles = []; this.state.files.forEach(file => { @@ -505,6 +518,7 @@ class Dashboard extends Component { index={parseInt(widgetKey, 10)} widget={this.state.widgets[widgetKey]} onEdit={this.editWidget.bind(this)} + onDuplicate={this.duplicateWidget.bind(this)} onDelete={this.deleteWidget.bind(this)} onChange={this.widgetChange.bind(this)} diff --git a/src/widget/widget-context-menu.js b/src/widget/widget-context-menu.js index 197abf0..fd8f5c5 100644 --- a/src/widget/widget-context-menu.js +++ b/src/widget/widget-context-menu.js @@ -27,6 +27,12 @@ class WidgetContextMenu extends React.Component { } }; + duplicateWidget = event => { + if (this.props.onDuplicate != null) { + this.props.onDuplicate(this.props.widget); + } + }; + deleteWidget = event => { if (this.props.onDelete != null) { this.props.onDelete(this.props.widget, this.props.index); @@ -92,6 +98,7 @@ class WidgetContextMenu extends React.Component { const ContextMenu = () => ( Edit + Duplicate Delete