diff --git a/app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts b/app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts index 12cbe8e3ab74..b02a03b79f28 100644 --- a/app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts +++ b/app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/helpers.ts @@ -43,7 +43,6 @@ export function getWidgetSessionValues( } for (const key in configMap) { - if (configMap[key] === undefined) continue; let sessionStorageKey = `${widgetType}.${key}`; if (type === "ZONE_WIDGET") { diff --git a/app/client/src/widgets/wds/WDSBaseInputWidget/__tests__/helpers.test.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/__tests__/helpers.test.ts new file mode 100644 index 000000000000..3b58f2a7d466 --- /dev/null +++ b/app/client/src/widgets/wds/WDSBaseInputWidget/__tests__/helpers.test.ts @@ -0,0 +1,64 @@ +import type { WidgetProps } from "widgets/BaseWidget"; +import { isReadOnlyUpdateHook } from "../helpers"; + +describe("isReadOnlyUpdateHook", () => { + it("should return the correct updates for input widget", () => { + const props1 = { + type: "WDS_INPUT_WIDGET", + inputType: "TEXT", + } as unknown as WidgetProps; + + const updates = isReadOnlyUpdateHook(props1, "readOnly", true); + expect(updates).toEqual([ + { propertyPath: "readOnly", propertyValue: true }, + { propertyPath: "type", propertyValue: "WDS_KEY_VALUE_WIDGET" }, + ]); + + const updates2 = isReadOnlyUpdateHook(props1, "readOnly", false); + expect(updates2).toEqual([ + { propertyPath: "readOnly", propertyValue: false }, + { propertyPath: "type", propertyValue: "WDS_INPUT_WIDGET" }, + ]); + + const props2 = { + type: "WDS_EMAIL_INPUT_WIDGET", + inputType: "EMAIL", + } as unknown as WidgetProps; + + const updates3 = isReadOnlyUpdateHook(props2, "readOnly", true); + expect(updates3).toEqual([ + { propertyPath: "readOnly", propertyValue: true }, + { propertyPath: "type", propertyValue: "WDS_KEY_VALUE_WIDGET" }, + ]); + + const updates4 = isReadOnlyUpdateHook(props2, "readOnly", false); + expect(updates4).toEqual([ + { propertyPath: "readOnly", propertyValue: false }, + { propertyPath: "type", propertyValue: "WDS_EMAIL_INPUT_WIDGET" }, + ]); + }); + + it("should not change the type for currency widget", () => { + const props = { + type: "WDS_CURRENCY_INPUT_WIDGET", + inputType: "CURRENCY", + } as unknown as WidgetProps; + + const updates = isReadOnlyUpdateHook(props, "readOnly", true); + expect(updates).toEqual([ + { propertyPath: "readOnly", propertyValue: true }, + ]); + }); + + it("should not change the type for phone widget", () => { + const props = { + type: "WDS_PHONE_INPUT_WIDGET", + inputType: "PHONE", + } as unknown as WidgetProps; + + const updates = isReadOnlyUpdateHook(props, "readOnly", true); + expect(updates).toEqual([ + { propertyPath: "readOnly", propertyValue: true }, + ]); + }); +}); diff --git a/app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts index 25aaeabd6e82..af7adcd8f537 100644 --- a/app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts +++ b/app/client/src/widgets/wds/WDSBaseInputWidget/config/contentConfig.ts @@ -1,5 +1,6 @@ import { ValidationTypes } from "constants/WidgetValidation"; +import { isReadOnlyUpdateHook } from "../helpers"; import type { BaseInputWidgetProps } from "../widget/types"; export const propertyPaneContentConfig = [ @@ -121,6 +122,8 @@ export const propertyPaneContentConfig = [ isJSConvertible: true, isBindProperty: true, isTriggerProperty: false, + dependencies: ["type", "inputType"], + updateHook: isReadOnlyUpdateHook, validation: { type: ValidationTypes.BOOLEAN }, }, { diff --git a/app/client/src/widgets/wds/WDSInputWidget/constants.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/constants.ts similarity index 100% rename from app/client/src/widgets/wds/WDSInputWidget/constants.ts rename to app/client/src/widgets/wds/WDSBaseInputWidget/constants.ts diff --git a/app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts new file mode 100644 index 000000000000..12c1f2e7489a --- /dev/null +++ b/app/client/src/widgets/wds/WDSBaseInputWidget/helpers.ts @@ -0,0 +1,35 @@ +import type { WidgetProps } from "widgets/BaseWidget"; +import type { PropertyUpdates } from "WidgetProvider/constants"; + +import type { InputType } from "./types"; +import { INPUT_TYPE_TO_WIDGET_TYPE_MAP } from "./constants"; + +export function isReadOnlyUpdateHook( + props: WidgetProps, + propertyName: string, + propertyValue: boolean, +) { + const updates: PropertyUpdates[] = [ + { + propertyPath: propertyName, + propertyValue: propertyValue, + }, + ]; + + // if user is marking readOnly as true and if the input type is not INPUT_CURRENCY_WIDGET or INPUT_PHONE_WIDGET, + // then we update the type to WDS_KEY_VALUE_WIDGET, else we update the type based on the input type + if ( + !["WDS_CURRENCY_INPUT_WIDGET", "WDS_PHONE_INPUT_WIDGET"].includes( + props.type, + ) + ) { + updates.push({ + propertyPath: "type", + propertyValue: propertyValue + ? "WDS_KEY_VALUE_WIDGET" + : INPUT_TYPE_TO_WIDGET_TYPE_MAP[props.inputType as InputType], + }); + } + + return updates; +} diff --git a/app/client/src/widgets/wds/WDSBaseInputWidget/index.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/index.ts index f2620b05952d..624925243085 100644 --- a/app/client/src/widgets/wds/WDSBaseInputWidget/index.ts +++ b/app/client/src/widgets/wds/WDSBaseInputWidget/index.ts @@ -1,5 +1,8 @@ import { WDSBaseInputWidget } from "./widget"; export { WDSBaseInputWidget }; + +export * from "./types"; +export * from "./constants"; export type { BaseInputWidgetProps } from "./widget/types"; export type { BaseInputComponentProps } from "./component/types"; diff --git a/app/client/src/widgets/wds/WDSBaseInputWidget/types.ts b/app/client/src/widgets/wds/WDSBaseInputWidget/types.ts new file mode 100644 index 000000000000..81d8cf3e1ba1 --- /dev/null +++ b/app/client/src/widgets/wds/WDSBaseInputWidget/types.ts @@ -0,0 +1,3 @@ +import type { INPUT_TYPES } from "./constants"; + +export type InputType = (typeof INPUT_TYPES)[keyof typeof INPUT_TYPES]; diff --git a/app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx b/app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx index 332d42413c7a..721bb9e0e6ec 100644 --- a/app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx +++ b/app/client/src/widgets/wds/WDSEmailInputWidget/widget/index.tsx @@ -1,7 +1,7 @@ import { WDSInputWidget } from "widgets/wds/WDSInputWidget"; import { EmailInputIcon, EmailInputThumbnail } from "appsmith-icons"; import { WIDGET_TAGS } from "constants/WidgetConstants"; -import { INPUT_TYPES } from "widgets/wds/WDSInputWidget/constants"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget"; import type { WidgetBaseConfiguration } from "WidgetProvider/constants"; class WDSEmailInputWidget extends WDSInputWidget { diff --git a/app/client/src/widgets/wds/WDSInputWidget/component/index.tsx b/app/client/src/widgets/wds/WDSInputWidget/component/index.tsx index c7b16e234a95..2f01a175e887 100644 --- a/app/client/src/widgets/wds/WDSInputWidget/component/index.tsx +++ b/app/client/src/widgets/wds/WDSInputWidget/component/index.tsx @@ -2,10 +2,10 @@ import React from "react"; import { isNil } from "lodash"; import { TextInput } from "@appsmith/wds"; import { Icon, TextArea } from "@appsmith/wds"; +import { useDebouncedValue } from "@mantine/hooks"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget"; -import { INPUT_TYPES } from "../constants"; import type { InputComponentProps } from "./types"; -import { useDebouncedValue } from "@mantine/hooks"; const DEBOUNCE_TIME = 300; diff --git a/app/client/src/widgets/wds/WDSInputWidget/component/types.ts b/app/client/src/widgets/wds/WDSInputWidget/component/types.ts index 547c77e81787..6a254d53fa0f 100644 --- a/app/client/src/widgets/wds/WDSInputWidget/component/types.ts +++ b/app/client/src/widgets/wds/WDSInputWidget/component/types.ts @@ -1,9 +1,7 @@ import type { IconProps } from "@appsmith/wds"; -import type { BaseInputComponentProps } from "../../WDSBaseInputWidget"; - -import type { INPUT_TYPES } from "../constants"; +import type { InputType } from "widgets/wds/WDSBaseInputWidget/types"; -export type InputType = (typeof INPUT_TYPES)[keyof typeof INPUT_TYPES]; +import type { BaseInputComponentProps } from "../../WDSBaseInputWidget"; export interface InputComponentProps extends BaseInputComponentProps { inputType: InputType; diff --git a/app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts b/app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts index acc3392993df..d5799e2d9319 100644 --- a/app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts +++ b/app/client/src/widgets/wds/WDSInputWidget/widget/helper.ts @@ -8,11 +8,14 @@ import { INPUT_INVALID_TYPE_ERROR, INPUT_TEXT_MAX_CHAR_ERROR, } from "ee/constants/messages"; -import type { InputType } from "../component/types"; +import type { InputType } from "widgets/wds/WDSBaseInputWidget"; import type { WidgetProps } from "widgets/BaseWidget"; import type { InputWidgetProps, Validation } from "./types"; -import { INPUT_TYPE_TO_WIDGET_TYPE_MAP, INPUT_TYPES } from "../constants"; +import { + INPUT_TYPE_TO_WIDGET_TYPE_MAP, + INPUT_TYPES, +} from "widgets/wds/WDSBaseInputWidget"; import type { PropertyUpdates } from "WidgetProvider/constants"; import { getDefaultISDCode } from "widgets/wds/WDSPhoneInputWidget/constants"; import { getDefaultCurrency } from "widgets/wds/WDSCurrencyInputWidget/constants"; diff --git a/app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx b/app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx index 71698b222a2f..5d8730189a84 100644 --- a/app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx +++ b/app/client/src/widgets/wds/WDSInputWidget/widget/index.tsx @@ -2,7 +2,6 @@ import React from "react"; import { isNumber, merge, toString } from "lodash"; import * as config from "../config"; import InputComponent from "../component"; -import { INPUT_TYPES } from "../constants"; import type { InputWidgetProps } from "./types"; import { mergeWidgetConfig } from "utils/helpers"; import { parseText, validateInput } from "./helper"; @@ -14,6 +13,7 @@ import type { DerivedPropertiesMap } from "WidgetProvider/factory"; import { EventType } from "constants/AppsmithActionConstants/ActionConstants"; import type { KeyDownEvent } from "widgets/wds/WDSBaseInputWidget/component/types"; import type { WidgetBaseConfiguration } from "WidgetProvider/constants"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget/constants"; class WDSInputWidget extends WDSBaseInputWidget { static type = "WDS_INPUT_WIDGET"; diff --git a/app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx b/app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx index d7174375c8b6..413950312c4a 100644 --- a/app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx +++ b/app/client/src/widgets/wds/WDSMultilineInputWidget/widget/index.tsx @@ -1,8 +1,8 @@ import { WIDGET_TAGS } from "constants/WidgetConstants"; import { WDSInputWidget } from "widgets/wds/WDSInputWidget"; -import { MultilineInputIcon, MultilineInputThumbnail } from "appsmith-icons"; -import { INPUT_TYPES } from "widgets/wds/WDSInputWidget/constants"; import type { WidgetBaseConfiguration } from "WidgetProvider/constants"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget/constants"; +import { MultilineInputIcon, MultilineInputThumbnail } from "appsmith-icons"; class WDSMultilineInputWidget extends WDSInputWidget { static type = "WDS_MULTILINE_INPUT_WIDGET"; diff --git a/app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx b/app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx index f5404cf22d76..0f67165c9c91 100644 --- a/app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx +++ b/app/client/src/widgets/wds/WDSNumberInputWidget/widget/index.tsx @@ -1,8 +1,8 @@ import { WIDGET_TAGS } from "constants/WidgetConstants"; import { WDSInputWidget } from "widgets/wds/WDSInputWidget"; import { NumberInputIcon, NumberInputThumbnail } from "appsmith-icons"; -import { INPUT_TYPES } from "widgets/wds/WDSInputWidget/constants"; import type { WidgetBaseConfiguration } from "WidgetProvider/constants"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget/constants"; class WDSNumberInputWidget extends WDSInputWidget { static type = "WDS_NUMBER_INPUT_WIDGET"; diff --git a/app/client/src/widgets/wds/WDSParagraphWidget/__tests__/helpers.test.ts b/app/client/src/widgets/wds/WDSParagraphWidget/__tests__/helpers.test.ts new file mode 100644 index 000000000000..28d5f818171e --- /dev/null +++ b/app/client/src/widgets/wds/WDSParagraphWidget/__tests__/helpers.test.ts @@ -0,0 +1,38 @@ +import type { WidgetProps } from "widgets/BaseWidget"; +import { fontSizeUpdateHook } from "../helpers"; + +describe("fontSizeUpdateHook", () => { + it("should update the font size and type", () => { + const props = { + type: "WDS_PARAGRAPH_WIDGET", + } as unknown as WidgetProps; + + const updates = fontSizeUpdateHook(props, "fontSize", "heading"); + + expect(updates).toEqual([ + { propertyPath: "fontSize", propertyValue: "heading" }, + { propertyPath: "type", propertyValue: "WDS_HEADING_WIDGET" }, + ]); + + const updates2 = fontSizeUpdateHook(props, "fontSize", "body"); + + expect(updates2).toEqual([ + { propertyPath: "fontSize", propertyValue: "body" }, + { propertyPath: "type", propertyValue: "WDS_PARAGRAPH_WIDGET" }, + ]); + + const updates3 = fontSizeUpdateHook(props, "fontSize", "subtitle"); + + expect(updates3).toEqual([ + { propertyPath: "fontSize", propertyValue: "subtitle" }, + { propertyPath: "type", propertyValue: "WDS_HEADING_WIDGET" }, + ]); + + const updates4 = fontSizeUpdateHook(props, "fontSize", "title"); + + expect(updates4).toEqual([ + { propertyPath: "fontSize", propertyValue: "title" }, + { propertyPath: "type", propertyValue: "WDS_HEADING_WIDGET" }, + ]); + }); +}); diff --git a/app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts b/app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts index e05fd9f14e00..d06d70a414a6 100644 --- a/app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts +++ b/app/client/src/widgets/wds/WDSParagraphWidget/config/defaultsConfig.ts @@ -11,6 +11,7 @@ export const defaultsConfig = { fontSize: "body", textAlign: "left", textColor: "neutral", + fontStyle: undefined, widgetName: "Paragraph", shouldTruncate: false, version: 1, diff --git a/app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts b/app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts index e8aed4f314d6..06df5d9bbf93 100644 --- a/app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts +++ b/app/client/src/widgets/wds/WDSParagraphWidget/config/propertyPaneConfig/styleConfig.ts @@ -1,6 +1,8 @@ import { TYPOGRAPHY_VARIANTS } from "@appsmith/wds-theming"; import { ValidationTypes } from "constants/WidgetValidation"; +import { fontSizeUpdateHook } from "../../helpers"; + export const propertyPaneStyleConfig = [ { sectionName: "General", @@ -32,7 +34,7 @@ export const propertyPaneStyleConfig = [ isJSConvertible: true, isBindProperty: true, isTriggerProperty: false, - isReusable: true, + updateHook: fontSizeUpdateHook, validation: { type: ValidationTypes.TEXT, params: { diff --git a/app/client/src/widgets/wds/WDSParagraphWidget/constants.ts b/app/client/src/widgets/wds/WDSParagraphWidget/constants.ts new file mode 100644 index 000000000000..667d8d10ad14 --- /dev/null +++ b/app/client/src/widgets/wds/WDSParagraphWidget/constants.ts @@ -0,0 +1,6 @@ +export const FONT_SIZE_TO_WIDGET_TYPE_MAP = { + body: "WDS_PARAGRAPH_WIDGET", + subtitle: "WDS_HEADING_WIDGET", + title: "WDS_HEADING_WIDGET", + heading: "WDS_HEADING_WIDGET", +} as const; diff --git a/app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts b/app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts new file mode 100644 index 000000000000..29805cf95fd3 --- /dev/null +++ b/app/client/src/widgets/wds/WDSParagraphWidget/helpers.ts @@ -0,0 +1,24 @@ +import type { PropertyUpdates } from "WidgetProvider/constants"; +import type { WidgetProps } from "widgets/BaseWidget"; + +import { FONT_SIZE_TO_WIDGET_TYPE_MAP } from "./constants"; + +export function fontSizeUpdateHook( + props: WidgetProps, + propertyName: string, + propertyValue: keyof typeof FONT_SIZE_TO_WIDGET_TYPE_MAP, +) { + const updates: PropertyUpdates[] = [ + { + propertyPath: propertyName, + propertyValue: propertyValue, + }, + ]; + + updates.push({ + propertyPath: "type", + propertyValue: FONT_SIZE_TO_WIDGET_TYPE_MAP[propertyValue], + }); + + return updates; +} diff --git a/app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx b/app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx index 69b17b523d81..a47776ab386b 100644 --- a/app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx +++ b/app/client/src/widgets/wds/WDSPasswordInputWidget/widget/index.tsx @@ -1,8 +1,8 @@ import { WIDGET_TAGS } from "constants/WidgetConstants"; import { WDSInputWidget } from "widgets/wds/WDSInputWidget"; -import { PasswordInputIcon, PasswordInputThumbnail } from "appsmith-icons"; -import { INPUT_TYPES } from "widgets/wds/WDSInputWidget/constants"; +import { INPUT_TYPES } from "widgets/wds/WDSBaseInputWidget/constants"; import type { WidgetBaseConfiguration } from "WidgetProvider/constants"; +import { PasswordInputIcon, PasswordInputThumbnail } from "appsmith-icons"; class WDSPasswordInputWidget extends WDSInputWidget { static type = "WDS_PASSWORD_INPUT_WIDGET"; diff --git a/app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts b/app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts index e90ae83f8e38..7b18e9188ff3 100644 --- a/app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts +++ b/app/client/src/widgets/wds/WDSPhoneInputWidget/index.ts @@ -1 +1,2 @@ +export * from "./constants"; export { WDSPhoneInputWidget } from "./widget";