Skip to content

Commit

Permalink
refactor derived properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jsartisan committed Nov 14, 2024
1 parent f088f14 commit 3347af1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { WidgetState } from "widgets/BaseWidget";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";

import { CurrencyInputComponent } from "../component";
import derivedProperties from "./parsedDerivedProperties";

import {
formatCurrencyNumber,
limitDecimalValue,
Expand All @@ -19,7 +19,9 @@ import {
import {
getLocaleDecimalSeperator,
getLocaleThousandSeparator,
parseDerivedProperties,
} from "widgets/WidgetUtils";
import derivedPropertyFns from "./derived";
import type { SetterConfig, Stylesheet } from "entities/AppTheming";
import type {
AnvilConfig,
Expand Down Expand Up @@ -120,8 +122,10 @@ class WDSCurrencyInputWidget extends WDSBaseInputWidget<
}

static getDerivedPropertiesMap() {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
isValid: `{{(() => {${derivedProperties.isValid}})()}}`,
isValid: `{{(() => {${parsedDerivedProperties.isValid}})()}}`,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { mergeWidgetConfig } from "utils/helpers";
import { parseText, validateInput } from "./helper";
import type { WidgetState } from "widgets/BaseWidget";
import type { SetterConfig } from "entities/AppTheming";
import derivedProperties from "./parsedDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";
import { WDSBaseInputWidget } from "../../WDSBaseInputWidget";
import type { DerivedPropertiesMap } from "WidgetProvider/factory";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
Expand Down Expand Up @@ -52,8 +53,10 @@ class WDSInputWidget extends WDSBaseInputWidget<InputWidgetProps, WidgetState> {
}

static getDerivedPropertiesMap(): DerivedPropertiesMap {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return merge(super.getDerivedPropertiesMap(), {
isValid: `{{(() => {${derivedProperties.isValid}})()}}`,
isValid: `{{(() => {${parsedDerivedProperties.isValid}})()}}`,
});
}

Expand Down
9 changes: 6 additions & 3 deletions app/client/src/widgets/CurrencyInputWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
} from "../component/CurrencyCodeDropdown";
import { AutocompleteDataType } from "utils/autocomplete/AutocompleteDataType";
import _ from "lodash";
import derivedProperties from "./parsedDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";
import BaseInputWidget from "widgets/BaseInputWidget";
import type { BaseInputWidgetProps } from "widgets/BaseInputWidget/widget";
import * as Sentry from "@sentry/react";
Expand Down Expand Up @@ -422,9 +423,11 @@ class CurrencyInputWidget extends BaseInputWidget<
}

static getDerivedPropertiesMap(): DerivedPropertiesMap {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
isValid: `{{(()=>{${derivedProperties.isValid}})()}}`,
value: `{{(()=>{${derivedProperties.value}})()}}`,
isValid: `{{(()=>{${parsedDerivedProperties.isValid}})()}}`,
value: `{{(()=>{${parsedDerivedProperties.value}})()}}`,
};
}

Expand Down
7 changes: 5 additions & 2 deletions app/client/src/widgets/InputWidgetV2/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
import type { InputComponentProps } from "../component";
import InputComponent from "../component";
import { getParsedText, isInputTypeEmailOrPassword } from "./Utilities";
import derivedProperties from "./parsedDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";

import IconSVG from "../icon.svg";
import ThumbnailSVG from "../thumbnail.svg";
Expand Down Expand Up @@ -640,8 +641,10 @@ class InputWidget extends BaseInputWidget<InputWidgetProps, WidgetState> {
}

static getDerivedPropertiesMap(): DerivedPropertiesMap {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return merge(super.getDerivedPropertiesMap(), {
isValid: `{{(() => {${derivedProperties.isValid}})()}}`,
isValid: `{{(() => {${parsedDerivedProperties.isValid}})()}}`,
});
}

Expand Down
7 changes: 5 additions & 2 deletions app/client/src/widgets/PhoneInputWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
import { AutocompleteDataType } from "utils/autocomplete/AutocompleteDataType";
import _ from "lodash";
import BaseInputWidget from "widgets/BaseInputWidget";
import derivedProperties from "./parsedDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";
import type { BaseInputWidgetProps } from "widgets/BaseInputWidget/widget";
import { mergeWidgetConfig } from "utils/helpers";
import type { CountryCode } from "libphonenumber-js";
Expand Down Expand Up @@ -295,8 +296,10 @@ class PhoneInputWidget extends BaseInputWidget<
}

static getDerivedPropertiesMap(): DerivedPropertiesMap {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
isValid: `{{(() => {${derivedProperties.isValid}})()}}`,
isValid: `{{(() => {${parsedDerivedProperties.isValid}})()}}`,
};
}

Expand Down

0 comments on commit 3347af1

Please sign in to comment.