From 5c43f5d18dd236ec7bbe4827f6908ceff2363e7e Mon Sep 17 00:00:00 2001 From: Abhinav Jha Date: Mon, 19 Oct 2020 14:26:04 +0530 Subject: [PATCH] Update widgetId references to a copied tabs widget's tabs (#1273) --- app/client/src/sagas/WidgetOperationSagas.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/client/src/sagas/WidgetOperationSagas.tsx b/app/client/src/sagas/WidgetOperationSagas.tsx index dcf9a5e7a2..f161c10875 100644 --- a/app/client/src/sagas/WidgetOperationSagas.tsx +++ b/app/client/src/sagas/WidgetOperationSagas.tsx @@ -42,7 +42,7 @@ import { } from "actions/controlActions"; import { isDynamicValue } from "utils/DynamicBindingUtils"; import { WidgetProps } from "widgets/BaseWidget"; -import _ from "lodash"; +import _, { isString } from "lodash"; import WidgetFactory from "utils/WidgetFactory"; import { buildWidgetBlueprint, @@ -867,6 +867,26 @@ function* pasteWidgetSaga() { } }); } + + // Update the tabs for the tabs widget. + if (widget.tabs && widget.type === WidgetTypes.TABS_WIDGET) { + try { + const tabs = isString(widget.tabs) + ? JSON.parse(widget.tabs) + : widget.tabs; + if (Array.isArray(tabs)) { + widget.tabs = JSON.stringify( + tabs.map(tab => { + tab.widgetId = widgetIdMap[tab.widgetId]; + return tab; + }), + ); + } + } catch (error) { + log.debug("Error updating tabs", error); + } + } + // If it is the copied widget, update position properties if (widget.widgetId === widgetIdMap[copiedWidget.widgetId]) { newWidgetId = widget.widgetId;