-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: add code for paragraph-text morphing #36065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
260bfc9
572f5ae
67e8211
68ce8f2
1b1d2ab
e1b3c9f
c8be2f8
395574a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
Comment on lines
+4
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comprehensive Review of Test Cases for General Observations:
Detailed Observations:
Suggestions:
Overall:
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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( | ||
jsartisan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import type { INPUT_TYPES } from "./constants"; | ||
|
|
||
| export type InputType = (typeof INPUT_TYPES)[keyof typeof INPUT_TYPES]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" }, | ||
| ]); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ export const defaultsConfig = { | |
| fontSize: "body", | ||
| textAlign: "left", | ||
| textColor: "neutral", | ||
| fontStyle: undefined, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add this, otherwise when hydrating values from session, we won't be able to get this key if not added here. Ideally |
||
| widgetName: "Paragraph", | ||
| shouldTruncate: false, | ||
| version: 1, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isReusable is not required for fontSize as discussed with taras. |
||
| updateHook: fontSizeUpdateHook, | ||
| validation: { | ||
| type: ValidationTypes.TEXT, | ||
| params: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from "./constants"; | ||
| export { WDSPhoneInputWidget } from "./widget"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required.