pankod/refine

View on GitHub
packages/inferencer/src/utilities/get-option-label/index.ts

Summary

Maintainability
A
55 mins
Test Coverage
import { InferField } from "../../types";

export const getOptionLabel = (field: InferField) => {
  if (!field.relationInfer) return "";

  if (field.relationInfer?.accessor) {
    if (Array.isArray(field.relationInfer.accessor)) {
      return `optionLabel: "${field.relationInfer.accessor[0]}",`;
    }
    if (field.relationInfer.accessor !== "title") {
      return `optionLabel: "${field.relationInfer.accessor}",`;
    }
    return "";
  }

  return "";
};