From 4343d7bdd853585611941cee157977a26b8c3f63 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Fri, 14 Feb 2020 07:48:33 +0000 Subject: [PATCH] Dropdown widget fixes --- .../editorComponents/ContextDropdown.tsx | 2 +- .../editorComponents/ErrorBoundry.tsx | 2 ++ .../propertyControls/OptionControl.tsx | 5 ++--- app/client/src/constants/ActionConstants.tsx | 2 +- .../mockResponses/WidgetConfigResponse.tsx | 10 ++++----- .../pages/Applications/ApplicationCard.tsx | 3 --- app/client/src/pages/Editor/EditorSidebar.tsx | 3 --- .../pages/Editor/PageListSidebar/index.tsx | 2 -- app/client/src/utils/Validators.ts | 21 +++++++------------ app/client/src/widgets/DropdownWidget.tsx | 6 +++--- 10 files changed, 21 insertions(+), 35 deletions(-) diff --git a/app/client/src/components/editorComponents/ContextDropdown.tsx b/app/client/src/components/editorComponents/ContextDropdown.tsx index d31c7dff5f..9e8e20f353 100644 --- a/app/client/src/components/editorComponents/ContextDropdown.tsx +++ b/app/client/src/components/editorComponents/ContextDropdown.tsx @@ -83,7 +83,7 @@ export const ContextDropdown = (props: ContextDropdownProps) => { const renderer: ItemRenderer = ( option: ContextDropdownOption, - ) => ; + ) => ; return ( { componentDidCatch(error: any, errorInfo: any) { console.error({ error, errorInfo }); + Sentry.captureException(error); } render() { diff --git a/app/client/src/components/propertyControls/OptionControl.tsx b/app/client/src/components/propertyControls/OptionControl.tsx index c6a0cc128b..733fb4d3da 100644 --- a/app/client/src/components/propertyControls/OptionControl.tsx +++ b/app/client/src/components/propertyControls/OptionControl.tsx @@ -7,7 +7,6 @@ import { } from "./StyledControls"; import { DropdownOption } from "widgets/DropdownWidget"; import { ControlType } from "constants/PropertyControlConstants"; -import { generateReactKey } from "utils/generators"; import styled from "constants/DefaultTheme"; import { FormIcons } from "icons/FormIcons"; import { AnyStyledComponent } from "styled-components"; @@ -39,7 +38,7 @@ class OptionControl extends BaseControl { return ( { const options: DropdownOption[] = this.props.propertyValue ? this.props.propertyValue.slice() : []; - options.push({ label: "", value: "", id: generateReactKey() }); + options.push({ label: "", value: "" }); this.updateProperty("options", options); }; diff --git a/app/client/src/constants/ActionConstants.tsx b/app/client/src/constants/ActionConstants.tsx index 8641519418..f459c3c47e 100644 --- a/app/client/src/constants/ActionConstants.tsx +++ b/app/client/src/constants/ActionConstants.tsx @@ -23,7 +23,7 @@ export type ActionType = | "DOWNLOAD"; export const PropertyPaneActionDropdownOptions: DropdownOption[] = [ - { label: "Call API", value: "API", id: "API" }, + { label: "Call API", value: "API" }, // { label: "Run Query", value: "QUERY" }, ]; diff --git a/app/client/src/mockResponses/WidgetConfigResponse.tsx b/app/client/src/mockResponses/WidgetConfigResponse.tsx index 8c6027ad9f..022a378768 100644 --- a/app/client/src/mockResponses/WidgetConfigResponse.tsx +++ b/app/client/src/mockResponses/WidgetConfigResponse.tsx @@ -112,11 +112,11 @@ const WidgetConfigResponse: WidgetConfigReducerState = { selectionType: "SINGLE_SELECT", label: "Select", options: [ - { id: "1", label: "Option 1", value: "1" }, - { id: "2", label: "Option 2", value: "2" }, - { id: "3", label: "Option 3", value: "3" }, - { id: "4", label: "Option 4", value: "4" }, - { id: "5", label: "Option 5", value: "5" }, + { label: "Option 1", value: "1" }, + { label: "Option 2", value: "2" }, + { label: "Option 3", value: "3" }, + { label: "Option 4", value: "4" }, + { label: "Option 5", value: "5" }, ], widgetName: "Dropdown", selectedIndex: 0, diff --git a/app/client/src/pages/Applications/ApplicationCard.tsx b/app/client/src/pages/Applications/ApplicationCard.tsx index bd5a588b9e..2bc79aa76b 100644 --- a/app/client/src/pages/Applications/ApplicationCard.tsx +++ b/app/client/src/pages/Applications/ApplicationCard.tsx @@ -150,7 +150,6 @@ export const ApplicationCard = (props: ApplicationCardProps) => { const moreActionItems: ContextDropdownOption[] = []; if (props.share) { moreActionItems.push({ - id: "share", value: "share", onSelect: shareApp, label: "Share", @@ -158,7 +157,6 @@ export const ApplicationCard = (props: ApplicationCardProps) => { } if (props.duplicate) { moreActionItems.push({ - id: "duplicate", value: "duplicate", onSelect: duplicateApp, label: "Duplicate", @@ -166,7 +164,6 @@ export const ApplicationCard = (props: ApplicationCardProps) => { } if (props.delete) { moreActionItems.push({ - id: "delete", value: "delete", onSelect: deleteApp, label: "Delete", diff --git a/app/client/src/pages/Editor/EditorSidebar.tsx b/app/client/src/pages/Editor/EditorSidebar.tsx index f62aaa0db2..999f9dc231 100644 --- a/app/client/src/pages/Editor/EditorSidebar.tsx +++ b/app/client/src/pages/Editor/EditorSidebar.tsx @@ -349,7 +349,6 @@ class EditorSidebar extends React.Component { null, label: "Copy to", @@ -367,7 +366,6 @@ class EditorSidebar extends React.Component { ), }, { - id: "move", value: "move", onSelect: () => null, label: "Move to", @@ -387,7 +385,6 @@ class EditorSidebar extends React.Component { })), }, { - id: "delete", value: "delete", onSelect: () => this.props.deleteItem( diff --git a/app/client/src/pages/Editor/PageListSidebar/index.tsx b/app/client/src/pages/Editor/PageListSidebar/index.tsx index 614332edf7..05701b3c38 100644 --- a/app/client/src/pages/Editor/PageListSidebar/index.tsx +++ b/app/client/src/pages/Editor/PageListSidebar/index.tsx @@ -111,13 +111,11 @@ const PageListSidebar = () => { return pages.map(page => { const pageActions: ContextDropdownOption[] = [ { - id: "setdefault", value: "setdefault", onSelect: () => setPageAsDefault(page.pageId, applicationId), label: "Set as Home Page", }, { - id: "delete", value: "delete", onSelect: () => deletePage(page.pageId), intent: "danger", diff --git a/app/client/src/utils/Validators.ts b/app/client/src/utils/Validators.ts index 14205893c5..b9d3287c0b 100644 --- a/app/client/src/utils/Validators.ts +++ b/app/client/src/utils/Validators.ts @@ -176,20 +176,13 @@ export const VALIDATORS: Record = { message: `${WIDGET_TYPE_VALIDATION_ERROR}: Options Data`, }; } - const hasOptions = _.every( - parsed, - (datum: { label: any; id: any; value: any }) => { - if (_.isObject(datum)) { - return ( - _.isString(datum.label) && - _.isString(datum.id) && - _.isString(datum.value) - ); - } else { - return false; - } - }, - ); + const hasOptions = _.every(parsed, (datum: { label: any; value: any }) => { + if (_.isObject(datum)) { + return _.isString(datum.label) && _.isString(datum.value); + } else { + return false; + } + }); if (!hasOptions) { return { isValid: false, diff --git a/app/client/src/widgets/DropdownWidget.tsx b/app/client/src/widgets/DropdownWidget.tsx index ea40253b18..dd82ac0ade 100644 --- a/app/client/src/widgets/DropdownWidget.tsx +++ b/app/client/src/widgets/DropdownWidget.tsx @@ -40,9 +40,10 @@ class DropdownWidget extends BaseWidget { }; } - componentDidUpdate(nextProps: DropdownWidgetProps) { + componentDidUpdate(prevProps: DropdownWidgetProps) { + super.componentDidUpdate(prevProps); if ( - JSON.stringify(nextProps.options) !== JSON.stringify(this.props.options) + JSON.stringify(prevProps.options) !== JSON.stringify(this.props.options) ) { this.updateWidgetMetaProperty("selectedIndex", undefined); this.updateWidgetMetaProperty("selectedIndexArr", []); @@ -124,7 +125,6 @@ export type SelectionType = "SINGLE_SELECT" | "MULTI_SELECT"; export interface DropdownOption { label: string; value: string; - id: string; } export interface DropdownWidgetProps extends WidgetProps {