Repository: appsmithorg/appsmith
File: app/client/src/components/editorComponents/WidgetQueryGeneratorForm/CommonControls/DatasourceDropdown/useSource/useConnectToOptions.tsx (TypeScript)

Code before:
        score.A += SORT_INCREAMENT << SortingWeights.execution;
      } else {
        score.B += SORT_INCREAMENT << SortingWeights.execution;
      }
    } else if (A.data?.request?.requestedAt) {
      score.A += SORT_INCREAMENT << SortingWeights.execution;
    } else if (B.data?.request?.requestedAt) {
      score.B += SORT_INCREAMENT << SortingWeights.execution;
    }

    if (getDatatype(A.data?.body) === expectedDatatype) {
      score.A += SORT_INCREAMENT << SortingWeights.datatype;
    }

    if (getDatatype(B.data?.body) === expectedDatatype) {
      score.B += SORT_INCREAMENT << SortingWeights.datatype;
    }

    return score.A > score.B ? -1 : 1;
  });
}

export function getBindingValue(
  widget: WidgetProps,
  query: ActionData | ModuleInstanceData,
  getQueryBindingValue: (query: ActionData | ModuleInstanceData) => string = (
    query,
  ) => `{{${query.config.name}.data}}`,
) {
  const querySuggestedWidgets = query.data?.suggestedWidgets;

  if (!querySuggestedWidgets) return getQueryBindingValue(query);

  const suggestedWidget = querySuggestedWidgets.find(
    (suggestedWidget) => suggestedWidget.type === widget.type,
  );

  if (!suggestedWidget) return getQueryBindingValue(query);

  return `{{${query.config.name}.${suggestedWidget.bindingQuery}}}`;
}
interface ConnectToOptionsProps {
  pluginImages: Record<string, string>;
  widget: WidgetProps;
}

export const getQueryIcon = (
  query: ActionData | ModuleInstanceData,
  pluginImages: Record<string, string>,
  modules: Record<string, Module>,
) => {

Review comment (suggestion):
For chat widget, we don't want `${query.config.name}.data`, we just want `${query.config.name}`. So updated this function so that binding can be controlled by widget.

Code after:
        score.A += SORT_INCREAMENT << SortingWeights.execution;
      } else {
        score.B += SORT_INCREAMENT << SortingWeights.execution;
      }
    } else if (A.data?.request?.requestedAt) {
      score.A += SORT_INCREAMENT << SortingWeights.execution;
    } else if (B.data?.request?.requestedAt) {
      score.B += SORT_INCREAMENT << SortingWeights.execution;
    }

    if (getDatatype(A.data?.body) === expectedDatatype) {
      score.A += SORT_INCREAMENT << SortingWeights.datatype;
    }

    if (getDatatype(B.data?.body) === expectedDatatype) {
      score.B += SORT_INCREAMENT << SortingWeights.datatype;
    }

    return score.A > score.B ? -1 : 1;
  });
}

export const getDefaultQueryBindingValue = (
  query: ActionData | ModuleInstanceData,
) => `{{${query.config.name}.data}}`;

export function getBindingValue(
  widget: WidgetProps,
  query: ActionData | ModuleInstanceData,
  getQueryBindingValue: (
    query: ActionData | ModuleInstanceData,
  ) => string = getDefaultQueryBindingValue,
) {
  const querySuggestedWidgets = query.data?.suggestedWidgets;

  if (!querySuggestedWidgets) return getQueryBindingValue(query);

  const suggestedWidget = querySuggestedWidgets.find(
    (suggestedWidget) => suggestedWidget.type === widget.type,
  );

  if (!suggestedWidget) return getQueryBindingValue(query);

  return `{{${query.config.name}.${suggestedWidget.bindingQuery}}}`;
}
interface ConnectToOptionsProps {
  pluginImages: Record<string, string>;
  widget: WidgetProps;
}

export const getQueryIcon = (