Fix: Set a default option in select widget while adding from suggested widgets (#6236)
This commit is contained in:
parent
c1b815ff45
commit
c0364d747b
|
|
@ -1,6 +1,6 @@
|
||||||
import { getTypographyByKey } from "constants/DefaultTheme";
|
import { getTypographyByKey } from "constants/DefaultTheme";
|
||||||
import { WidgetTypes } from "constants/WidgetConstants";
|
import { WidgetTypes } from "constants/WidgetConstants";
|
||||||
import React from "react";
|
import React, { memo } from "react";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { generateReactKey } from "utils/generators";
|
import { generateReactKey } from "utils/generators";
|
||||||
|
|
@ -15,6 +15,10 @@ import {
|
||||||
SUGGESTED_WIDGET_TOOLTIP,
|
SUGGESTED_WIDGET_TOOLTIP,
|
||||||
} from "constants/messages";
|
} from "constants/messages";
|
||||||
import { SuggestedWidget } from "api/ActionAPI";
|
import { SuggestedWidget } from "api/ActionAPI";
|
||||||
|
import { useSelector } from "store";
|
||||||
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
||||||
|
import { getWidgets } from "sagas/selectors";
|
||||||
|
import { getNextWidgetName } from "sagas/WidgetOperationSagas";
|
||||||
|
|
||||||
const WidgetList = styled.div`
|
const WidgetList = styled.div`
|
||||||
${(props) => getTypographyByKey(props, "p1")}
|
${(props) => getTypographyByKey(props, "p1")}
|
||||||
|
|
@ -107,6 +111,7 @@ function getWidgetProps(
|
||||||
suggestedWidget: SuggestedWidget,
|
suggestedWidget: SuggestedWidget,
|
||||||
widgetInfo: WidgetBindingInfo,
|
widgetInfo: WidgetBindingInfo,
|
||||||
actionName: string,
|
actionName: string,
|
||||||
|
widgetName?: string,
|
||||||
) {
|
) {
|
||||||
const fieldName = widgetInfo.propertyName;
|
const fieldName = widgetInfo.propertyName;
|
||||||
switch (suggestedWidget.type) {
|
switch (suggestedWidget.type) {
|
||||||
|
|
@ -134,6 +139,18 @@ function getWidgetProps(
|
||||||
dynamicBindingPathList: [{ key: `chartData.${reactKey}.data` }],
|
dynamicBindingPathList: [{ key: `chartData.${reactKey}.data` }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
case WidgetTypes.DROP_DOWN_WIDGET:
|
||||||
|
return {
|
||||||
|
type: suggestedWidget.type,
|
||||||
|
props: {
|
||||||
|
[fieldName]: `{{${actionName}.${suggestedWidget.bindingQuery}}}`,
|
||||||
|
defaultOptionValue: `{{${widgetName}.options[0].value}}`,
|
||||||
|
dynamicBindingPathList: [
|
||||||
|
{ key: widgetInfo.propertyName },
|
||||||
|
{ key: "defaultOptionValue" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
type: suggestedWidget.type,
|
type: suggestedWidget.type,
|
||||||
|
|
@ -153,15 +170,23 @@ type SuggestedWidgetProps = {
|
||||||
|
|
||||||
function SuggestedWidgets(props: SuggestedWidgetProps) {
|
function SuggestedWidgets(props: SuggestedWidgetProps) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const dataTree = useSelector(getDataTree);
|
||||||
|
const canvasWidgets = useSelector(getWidgets);
|
||||||
|
|
||||||
const addWidget = (
|
const addWidget = (
|
||||||
suggestedWidget: SuggestedWidget,
|
suggestedWidget: SuggestedWidget,
|
||||||
widgetInfo: WidgetBindingInfo,
|
widgetInfo: WidgetBindingInfo,
|
||||||
) => {
|
) => {
|
||||||
|
const widgetName = getNextWidgetName(
|
||||||
|
canvasWidgets,
|
||||||
|
suggestedWidget.type,
|
||||||
|
dataTree,
|
||||||
|
);
|
||||||
const payload = getWidgetProps(
|
const payload = getWidgetProps(
|
||||||
suggestedWidget,
|
suggestedWidget,
|
||||||
widgetInfo,
|
widgetInfo,
|
||||||
props.actionName,
|
props.actionName,
|
||||||
|
widgetName,
|
||||||
);
|
);
|
||||||
|
|
||||||
AnalyticsUtil.logEvent("SUGGESTED_WIDGET_CLICK", {
|
AnalyticsUtil.logEvent("SUGGESTED_WIDGET_CLICK", {
|
||||||
|
|
@ -204,4 +229,5 @@ function SuggestedWidgets(props: SuggestedWidgetProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SuggestedWidgets;
|
const MemoizedSuggestedWidgets = memo(SuggestedWidgets);
|
||||||
|
export default MemoizedSuggestedWidgets;
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ import {
|
||||||
import { getSelectedWidgets } from "selectors/ui";
|
import { getSelectedWidgets } from "selectors/ui";
|
||||||
import { getParentWithEnhancementFn } from "./WidgetEnhancementHelpers";
|
import { getParentWithEnhancementFn } from "./WidgetEnhancementHelpers";
|
||||||
import { widgetSelectionSagas } from "./WidgetSelectionSagas";
|
import { widgetSelectionSagas } from "./WidgetSelectionSagas";
|
||||||
|
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
||||||
|
|
||||||
function* getChildWidgetProps(
|
function* getChildWidgetProps(
|
||||||
parent: FlattenedWidgetProps,
|
parent: FlattenedWidgetProps,
|
||||||
|
|
@ -1463,15 +1464,10 @@ function* getEntityNames() {
|
||||||
return Object.keys(evalTree);
|
return Object.keys(evalTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextWidgetName(
|
export function getNextWidgetName(
|
||||||
widgets: CanvasWidgetsReduxState,
|
widgets: CanvasWidgetsReduxState,
|
||||||
type: WidgetType,
|
type: WidgetType,
|
||||||
evalTree: {
|
evalTree: DataTree,
|
||||||
bottomRow: any;
|
|
||||||
leftColumn: any;
|
|
||||||
rightColumn: any;
|
|
||||||
topRow: any;
|
|
||||||
},
|
|
||||||
options?: Record<string, unknown>,
|
options?: Record<string, unknown>,
|
||||||
) {
|
) {
|
||||||
// Compute the new widget's name
|
// Compute the new widget's name
|
||||||
|
|
@ -1580,7 +1576,7 @@ function* pasteWidgetSaga() {
|
||||||
// goToNextAvailableRow = true,
|
// goToNextAvailableRow = true,
|
||||||
// persistColumnPosition = false,
|
// persistColumnPosition = false,
|
||||||
|
|
||||||
const evalTree = yield select(getDataTree);
|
const evalTree: DataTree = yield select(getDataTree);
|
||||||
|
|
||||||
// Get a flat list of all the widgets to be updated
|
// Get a flat list of all the widgets to be updated
|
||||||
const widgetList = copiedWidgets.list;
|
const widgetList = copiedWidgets.list;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user