Repository: appsmithorg/appsmith
File: app/client/src/components/propertyControls/TableComputeValue.tsx (TypeScript)

Code before:
    }

    // Convert string to JavaScript expression
    const stringToEvaluate = stringToJS(value);

    // Return empty if the evaluated string is empty
    if (stringToEvaluate === "") {
      return stringToEvaluate;
    }

    // Handle specific cases with "currentIndex" or "currentRow"
    if (this.containsTableSpecificBindings(stringToEvaluate)) {
      return this.buildTableSpecificBinding(stringToEvaluate, tableName);
    }

    // Wrap the evaluated string in double curly braces for binding
    return this.wrapInDoubleCurlyBraces(stringToEvaluate);
  };

  shouldReturnValueDirectly = (value: string) => {
    return (
      !isDynamicValue(value) && !this.props.additionalControlData?.isArrayValue
    );
  };

  containsTableSpecificBindings = (stringToEvaluate: string) => {
    return (
      stringToEvaluate.includes("currentIndex") ||
      stringToEvaluate.includes("currentRow")
    );
  };

  buildTableSpecificBinding = (stringToEvaluate: string, tableName: string) => {
    return `${ComputeTablePropertyControlV2.getBindingPrefix(
      tableName,
    )}${stringToEvaluate}${ComputeTablePropertyControlV2.bindingSuffix}`;
  };

  wrapInDoubleCurlyBraces = (stringToEvaluate: string) => {
    return `{{${stringToEvaluate}}}`;
  };

  onTextChange = (event: React.ChangeEvent<HTMLTextAreaElement> | string) => {
    let value = "";

    if (typeof event !== "string") {
      value = event.target?.value;
    } else {
      value = event;
    }


Review comment (refactor):
The functions that are extracted are just too shallow. I would do such abstractions only if they are used at atleast 3 places or doing something complex. But in this case, it is very straight forward, so extracting thesr won't help much, insteads, makes the code a little complex.



Code after:
  };

  getComputedValue = (value: string, tableName: string) => {
    // Return raw value if:
    // 1. The value is not a dynamic binding (not wrapped in {{...}})
    // 2. AND this control is not configured to handle array values via additionalControlData
    // This allows single values to be returned without table binding computation
    if (
      !isDynamicValue(value) &&
      !this.props.additionalControlData?.isArrayValue
    ) {
      return value;
    }

    const stringToEvaluate = stringToJS(value);

    if (stringToEvaluate === "") {
      return stringToEvaluate;
    }

    return ComputeTablePropertyControlV2.getTableComputeBinding(
      tableName,
      stringToEvaluate,
    );
  };

  onTextChange = (event: React.ChangeEvent<HTMLTextAreaElement> | string) => {
    let value = "";

    if (typeof event !== "string") {
      value = event.target?.value;
    } else {
      value = event;
    }

    if (isString(value)) {
      const output = this.getComputedValue(
        value,
        this.props.widgetProperties.widgetName,
      );

      this.updateProperty(this.props.propertyName, output);
    } else {
      this.updateProperty(this.props.propertyName, value);
    }
  };

  static getControlType() {
    return "TABLE_COMPUTE_VALUE";
  }
}