<commit_before>import camelCase from 'lodash/camelCase';
import mapValues from 'lodash/mapValues';
import { ArgTypesEnhancer, combineParameters } from '@storybook/client-api';
import { ArgTypes } from '@storybook/api';
import { inferArgTypes } from './inferArgTypes';
import { inferControls } from './inferControls';

const isSubset = (kind: string, subset: object, superset: object) => {
  const keys = Object.keys(subset);
  // eslint-disable-next-line no-prototype-builtins
  const overlap = keys.filter((key) => superset.hasOwnProperty(key));
  return overlap.length === keys.length;
};

export const enhanceArgTypes: ArgTypesEnhancer = (context) => {
  const {
    component,
    subcomponents,
    argTypes: userArgTypes = {},
    docs = {},
    args = {},
  } = context.parameters;
  const { extractArgTypes } = docs;

  const namedArgTypes = mapValues(userArgTypes, (val, key) => ({ name: key, ...val }));
  const inferredArgTypes = inferArgTypes(args);
  const components = { Primary: component, ...subcomponents };
  let extractedArgTypes: ArgTypes = {};

  if (extractArgTypes && components) {
    const componentArgTypes = mapValues(components, (comp) => extractArgTypes(comp));
    extractedArgTypes = Object.entries(componentArgTypes).reduce((acc, [label, compTypes]) => {
      if (compTypes) {
        Object.entries(compTypes).forEach(([key, argType]) => {
          const subLabel = label === 'Primary' ? key : camelCase(`${label} ${key}`);
          acc[subLabel] = argType;
        });
      }
      return acc;
    }, {} as ArgTypes);
  }

  if (
    (Object.keys(userArgTypes).length > 0 &&<commit_msg>Addon-docs: Only pass args for the primary component<commit_after>import camelCase from 'lodash/camelCase';
import mapValues from 'lodash/mapValues';
import { ArgTypesEnhancer, combineParameters } from '@storybook/client-api';
import { ArgTypes } from '@storybook/api';
import { inferArgTypes } from './inferArgTypes';
import { inferControls } from './inferControls';

const isSubset = (kind: string, subset: object, superset: object) => {
  const keys = Object.keys(subset);
  // eslint-disable-next-line no-prototype-builtins
  const overlap = keys.filter((key) => superset.hasOwnProperty(key));
  return overlap.length === keys.length;
};

export const enhanceArgTypes: ArgTypesEnhancer = (context) => {
  const {
    component,
    subcomponents,
    argTypes: userArgTypes = {},
    docs = {},
    args = {},
  } = context.parameters;
  const { extractArgTypes } = docs;

  const namedArgTypes = mapValues(userArgTypes, (val, key) => ({ name: key, ...val }));
  const inferredArgTypes = inferArgTypes(args);
  const components = { Primary: component, ...subcomponents };
  let extractedArgTypes: ArgTypes = {};

  if (extractArgTypes && components) {
    const componentArgTypes = mapValues(components, (comp) => extractArgTypes(comp));
    extractedArgTypes = Object.entries(componentArgTypes).reduce((acc, [label, compTypes]) => {
      if (compTypes) {
        Object.entries(compTypes).forEach(([key, argType]) => {
          if (label === 'Primary') {
            acc[key] = argType;
          }
        });
      }
      return acc;
    }, {} as ArgTypes);
  }

  if (
    (Object.keys(userArgTypes).length > 0 &&
{'fraction_non_alphanumeric': 0.14716748768472906, 'fraction_numerical': 0.0006157635467980296, 'mean_word_length': 3.7639296187683287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5707960', 'n_tokens_mistral': 971, 'n_tokens_neox': 952, 'n_words': 227}