Where is formatComponentData.js?

I just updated from Strapi 3.5.2 to Strapi 3.6.2 and can’t find file formatComponentData.js

That file was situated in node_modules\strapi-plugin-content-manager\admin\src\utils

I used it file to rename displayed values of components in a specific way (in my custom components).

Now I don’t have that possibility :frowning:

Maybe this logic has been moved to another place?

Old file content looks like this:

  // NOTE: this function is for adding a __temp_key__ key to each object of a repeatable component
// in order to have a unique identifier for the DnD

import { get } from "lodash";
import { getType, getOtherInfos } from "./getAttributeInfos";

const formatComponentData = (data, ct, composSchema) => {
  const recursiveFormatData = (data, schema) => {
    return Object.keys(data).reduce((acc, current) => {
      const type = getType(schema, current);
      const value = get(data, current);
      const compoUid = getOtherInfos(schema, [current, "component"]);
      const isRepeatable = getOtherInfos(schema, [current, "repeatable"]);

      if (!value) {
        acc[current] = value;

        return acc;
      }

      if (type === "dynamiczone") {
        acc[current] = value.map((componentValue) => {
          const formattedData = recursiveFormatData(
            componentValue,
            composSchema[componentValue.__component]
          );

          return formattedData;
        });

        return acc;
      }

      if (type === "component") {
        let formattedValue;

        if (isRepeatable) {
          formattedValue = value.map((obj, i) => {
            const newObj = { ...obj, __temp_key__: i };

            return recursiveFormatData(newObj, composSchema[compoUid]);
          });
        } else {
          formattedValue = recursiveFormatData(value, composSchema[compoUid]);
        }

        acc[current] = formattedValue;

        return acc;
      }

      acc[current] = value;

      return acc;
    }, {});
  };

  return recursiveFormatData(data, ct);
};

export default formatComponentData;

since 3.6.0

Ok, I got it!

For everyone who wondering how to set custom logic for displaying component’s name, you can do it in getTempMaxKey.js file.

1 Like