Repository: twentyhq/twenty
File: packages/twenty-front/src/modules/page-layout/widgets/graph/utils/generateGroupByQueryVariablesFromBarOrLineChartConfiguration.ts (TypeScript)

Code before:
    groupBy.push(
      buildGroupByFieldObject({
        field: groupByFieldY,
        subFieldName: groupBySubFieldNameY,
        dateGranularity: shouldApplyDateGranularityY
          ? (chartConfiguration.secondaryAxisGroupByDateGranularity ??
            GRAPH_DEFAULT_DATE_GRANULARITY)
          : undefined,
        firstDayOfTheWeek,
        isNestedDateField: isFieldYNestedDate,
      }),
    );
  }

  const orderBy: Array<
    | AggregateOrderByWithGroupByField
    | ObjectRecordOrderByForScalarField
    | ObjectRecordOrderByWithGroupByDateField
    | ObjectRecordOrderByForCompositeField
    | ObjectRecordOrderByForRelationField
  > = [];

  orderBy.push(
    getGroupByOrderBy({
      graphOrderBy:
        chartConfiguration.primaryAxisOrderBy ?? GraphOrderBy.FIELD_ASC,
      groupByField: groupByFieldX,
      groupBySubFieldName: chartConfiguration.primaryAxisGroupBySubFieldName,
      aggregateOperation,
      dateGranularity: shouldApplyDateGranularityX
        ? (chartConfiguration.primaryAxisDateGranularity ??
          GRAPH_DEFAULT_DATE_GRANULARITY)
        : undefined,
    }),
  );

  if (isDefined(groupByFieldY)) {
    const isFieldYDateForOrderBy = isFieldMetadataDateKind(groupByFieldY.type);

    const isFieldYNestedDateForOrderBy = isRelationNestedFieldDateKind({
      relationField: groupByFieldY,
      relationNestedFieldName: groupBySubFieldNameY,
      objectMetadataItems,
    });

    const shouldApplyDateGranularityYForOrderBy =
      isFieldYDateForOrderBy || isFieldYNestedDateForOrderBy;

    orderBy.push(
      getGroupByOrderBy({
        graphOrderBy:

Review comment (suggestion):
the best thing here would be to have a `const DEFAULT_ORDER_BY = GraphOrderBy.FIELD_ASC;`
and use it here

Code after:
    groupBy.push(
      buildGroupByFieldObject({
        field: groupByFieldY,
        subFieldName: groupBySubFieldNameY,
        dateGranularity: shouldApplyDateGranularityY
          ? (chartConfiguration.secondaryAxisGroupByDateGranularity ??
            GRAPH_DEFAULT_DATE_GRANULARITY)
          : undefined,
        firstDayOfTheWeek,
        isNestedDateField: isFieldYNestedDate,
      }),
    );
  }

  const orderBy: Array<
    | AggregateOrderByWithGroupByField
    | ObjectRecordOrderByForScalarField
    | ObjectRecordOrderByWithGroupByDateField
    | ObjectRecordOrderByForCompositeField
    | ObjectRecordOrderByForRelationField
  > = [];

  orderBy.push(
    getGroupByOrderBy({
      graphOrderBy:
        chartConfiguration.primaryAxisOrderBy ?? GRAPH_DEFAULT_ORDER_BY,
      groupByField: groupByFieldX,
      groupBySubFieldName: chartConfiguration.primaryAxisGroupBySubFieldName,
      aggregateOperation,
      dateGranularity: shouldApplyDateGranularityX
        ? (chartConfiguration.primaryAxisDateGranularity ??
          GRAPH_DEFAULT_DATE_GRANULARITY)
        : undefined,
    }),
  );

  if (isDefined(groupByFieldY)) {
    const isFieldYDateForOrderBy = isFieldMetadataDateKind(groupByFieldY.type);

    const isFieldYNestedDateForOrderBy = isRelationNestedFieldDateKind({
      relationField: groupByFieldY,
      relationNestedFieldName: groupBySubFieldNameY,
      objectMetadataItems,
    });

    const shouldApplyDateGranularityYForOrderBy =
      isFieldYDateForOrderBy || isFieldYNestedDateForOrderBy;

    orderBy.push(
      getGroupByOrderBy({
        graphOrderBy: