fix: Tab Widget Sagas fixed.

This commit is contained in:
Arsalan 2022-03-17 16:28:26 +05:30
parent 87c4645a87
commit 0253019d34
3 changed files with 9 additions and 29 deletions

View File

@ -2,9 +2,8 @@ import React from "react";
import BaseControl, { ControlProps } from "./BaseControl"; import BaseControl, { ControlProps } from "./BaseControl";
import { StyledPropertyPaneButton } from "./StyledControls"; import { StyledPropertyPaneButton } from "./StyledControls";
import styled from "constants/DefaultTheme"; import styled from "constants/DefaultTheme";
import { generateReactKey } from "utils/generators";
import { DroppableComponent } from "components/ads/DraggableListComponent"; import { DroppableComponent } from "components/ads/DraggableListComponent";
import { getNextEntityName, noop } from "utils/AppsmithUtils"; import { noop } from "utils/AppsmithUtils";
import orderBy from "lodash/orderBy"; import orderBy from "lodash/orderBy";
import isString from "lodash/isString"; import isString from "lodash/isString";
import isUndefined from "lodash/isUndefined"; import isUndefined from "lodash/isUndefined";
@ -222,28 +221,6 @@ class TabControl extends BaseControl<ControlProps, State> {
); );
}; };
addOption = () => {
let tabs = this.props.propertyValue;
const tabsArray = this.getTabItems();
const newTabId = generateReactKey({ prefix: "tab" });
const newTabLabel = getNextEntityName(
"Tab ",
tabsArray.map((tab: any) => tab.label),
);
tabs = {
...tabs,
[newTabId]: {
id: newTabId,
index: tabsArray.length,
label: newTabLabel,
widgetId: generateReactKey(),
isVisible: true,
},
};
this.updateProperty(this.props.propertyName, tabs);
};
updateFocus = (index: number, isFocused: boolean) => { updateFocus = (index: number, isFocused: boolean) => {
this.setState({ focusedIndex: isFocused ? index : null }); this.setState({ focusedIndex: isFocused ? index : null });
}; };

View File

@ -33,7 +33,7 @@ import { getDataTree } from "selectors/dataTreeSelectors";
import { generateReactKey } from "utils/generators"; import { generateReactKey } from "utils/generators";
import { WidgetProps } from "widgets/BaseWidget"; import { WidgetProps } from "widgets/BaseWidget";
import WidgetFactory from "utils/WidgetFactory"; import WidgetFactory from "utils/WidgetFactory";
import { omit } from "lodash"; import omit from "lodash/omit";
import produce from "immer"; import produce from "immer";
import { GRID_DENSITY_MIGRATION_V1 } from "widgets/constants"; import { GRID_DENSITY_MIGRATION_V1 } from "widgets/constants";
const WidgetTypes = WidgetFactory.widgetTypes; const WidgetTypes = WidgetFactory.widgetTypes;
@ -405,16 +405,15 @@ function* addNewTabChildSaga(
"Tab ", "Tab ",
tabsArray.map((tab: any) => tab.label), tabsArray.map((tab: any) => tab.label),
); );
const newTabIndex = Object.keys(tabs)?.length - 1;
tabs = { tabs = {
...tabs, ...tabs,
[newTabId]: { [newTabId]: {
id: newTabId, id: newTabId,
index: tabsArray.length,
label: newTabLabel, label: newTabLabel,
widgetId: newTabWidgetId, widgetId: newTabWidgetId,
isVisible: true, isVisible: true,
index: newTabIndex,
}, },
}; };
const newTabProps: any = getChildTabData(tabProps, { const newTabProps: any = getChildTabData(tabProps, {

View File

@ -14,7 +14,7 @@ import {
import { GridDefaults } from "constants/WidgetConstants"; import { GridDefaults } from "constants/WidgetConstants";
import { ENTITY_TYPE } from "entities/AppsmithConsole"; import { ENTITY_TYPE } from "entities/AppsmithConsole";
import LOG_TYPE from "entities/AppsmithConsole/logtype"; import LOG_TYPE from "entities/AppsmithConsole/logtype";
import { flattenDeep, omit } from "lodash"; import { flattenDeep, omit, orderBy } from "lodash";
import { import {
CanvasWidgetsReduxState, CanvasWidgetsReduxState,
FlattenedWidgetProps, FlattenedWidgetProps,
@ -54,7 +54,11 @@ function* deleteTabChildSaga(
const tabWidget = allWidgets[widgetId]; const tabWidget = allWidgets[widgetId];
if (tabWidget && tabWidget.parentId) { if (tabWidget && tabWidget.parentId) {
const tabParentWidget = allWidgets[tabWidget.parentId]; const tabParentWidget = allWidgets[tabWidget.parentId];
const tabsArray: any = Object.values(tabParentWidget.tabsObj); const tabsArray: any = orderBy(
Object.values(tabParentWidget.tabsObj),
"index",
"asc",
);
if (tabsArray && tabsArray.length === 1) return; if (tabsArray && tabsArray.length === 1) return;
const updatedArray = tabsArray.filter((eachItem: any, i: number) => { const updatedArray = tabsArray.filter((eachItem: any, i: number) => {
return i !== index; return i !== index;