<commit_before>import React, { Fragment, useEffect, useMemo } from 'react';
import JSONSchemaBridge from 'uniforms-bridge-json-schema';
import { useIsSmallScreen } from '../../core/components/hooks';
import lazyLoad from '../../core/helper/lazyLoad';

import {
  AutoformControlsDef,
  CellPluginComponentProps,
  JsonSchema,
} from '../../core/types';
import makeUniformsSchema from './makeUniformsSchema';

export const AutoForm = lazyLoad(() =>
  import('uniforms-material').then((c) => c.AutoForm)
);
export const AutoFields = lazyLoad(() =>
  import('uniforms-material').then(
    (c) =>
      c.AutoFields as React.FC<{ element?: React.ReactNode; fields?: string[] }>
  )
);
const getDefaultValue = function (
  bridge: JSONSchemaBridge
): { [key: string]: unknown } {
  return bridge.getSubfields(null).reduce(
    (acc, fieldName) => ({
      ...acc,
      [fieldName]: bridge.getInitialValue(fieldName),
    }),
    {}
  );
};

type Props<T> = CellPluginComponentProps<T> & AutoformControlsDef<T>;
export function AutoformControls<T extends Record<string, unknown> | unknown>({
  onChange,
  data,
  schema,
  columnCount = 2,
}: Props<T>) {
  const bridge = useMemo(() => makeUniformsSchema<T>(schema as JsonSchema<T>), [
    schema,
  ]);
  useEffect(() => {
    const newDefaultData = {
      ...getDefaultValue(bridge),
      ...(data ?? {}),
    };
    onChange(newDefaultData);
  }, [bridge]);
  const isSmall = useIsSmallScreen();
  return (
    <AutoForm model={data} autosave={true} schema={bridge} onSubmit={onChange}>
      <div
        style={{
          columnCount: isSmall ? 1 : columnCount,
          columnRule: '1px solid #E0E0E0',
          columnGap: 48,
        }}
      >
        <AutoFields element={Fragment} />
      </div>
    </AutoForm>
  );
}
<commit_msg>fix: type problem<commit_after>import React, { Fragment, useEffect, useMemo } from 'react';
import JSONSchemaBridge from 'uniforms-bridge-json-schema';
import { useIsSmallScreen } from '../../core/components/hooks';
import lazyLoad from '../../core/helper/lazyLoad';

import {
  AutoformControlsDef,
  CellPluginComponentProps,
  JsonSchema,
} from '../../core/types';
import makeUniformsSchema from './makeUniformsSchema';

export const AutoForm = lazyLoad(() =>
  import('uniforms-material').then((c) => c.AutoForm)
);
export const AutoFields = lazyLoad(() =>
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  import('uniforms-material').then((c) => c.AutoFields as any)
) as React.FC<{
  element?: React.ReactNode;
  fields?: string[];
  omitFields?: string[];
}>;
const getDefaultValue = function (
  bridge: JSONSchemaBridge
): { [key: string]: unknown } {
  return bridge.getSubfields(null).reduce(
    (acc, fieldName) => ({
      ...acc,
      [fieldName]: bridge.getInitialValue(fieldName),
    }),
    {}
  );
};

type Props<T> = CellPluginComponentProps<T> & AutoformControlsDef<T>;
export function AutoformControls<T extends Record<string, unknown> | unknown>({
  onChange,
  data,
  schema,
  columnCount = 2,
}: Props<T>) {
  const bridge = useMemo(() => makeUniformsSchema<T>(schema as JsonSchema<T>), [
    schema,
  ]);
  useEffect(() => {
    const newDefaultData = {
      ...getDefaultValue(bridge),
      ...(data ?? {}),
    };
    onChange(newDefaultData);
  }, [bridge]);
  const isSmall = useIsSmallScreen();
  return (
    <AutoForm model={data} autosave={true} schema={bridge} onSubmit={onChange}>
      <div
        style={{
          columnCount: isSmall ? 1 : columnCount,
          columnRule: '1px solid #E0E0E0',
          columnGap: 48,
        }}
      >
        <AutoFields element={Fragment} />
      </div>
    </AutoForm>
  );
}

{'fraction_non_alphanumeric': 0.1639477977161501, 'fraction_numerical': 0.004350190320826536, 'mean_word_length': 3.4165666266506602, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6882062', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1162, 'n_words': 245}