Repository: twentyhq/twenty
File: packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/find-records-action/components/WorkflowObjectDropdownContent.tsx (TypeScript)

Code before:

  const matchesSearchFilter = (
    objectMetadataItem: (typeof objectMetadataItems)[number],
    searchInputLowerCase: string,
  ) => {
    return (
      objectMetadataItem.nameSingular
        .toLowerCase()
        .includes(searchInputLowerCase) ||
      objectMetadataItem.labelSingular
        .toLowerCase()
        .includes(searchInputLowerCase) ||
      objectMetadataItem.labelPlural
        .toLowerCase()
        .includes(searchInputLowerCase)
    );
  };

  const shouldShowAdvanced =
    showAdvancedOption &&
    !isSystemObjectsOpen &&
    (!isNonEmptyString(searchInputValue) ||
      searchInputValue.toLowerCase().includes('advanced'));

  const searchInputLowerCase = searchInputValue.toLowerCase();

  const filteredNonSystemObjects = nonSystemObjectMetadataItems.filter(
    (objectMetadataItem) =>
      matchesSearchFilter(objectMetadataItem, searchInputLowerCase),
  );

  const filteredSystemObjects = systemObjectMetadataItems.filter(
    (objectMetadataItem) =>
      matchesSearchFilter(objectMetadataItem, searchInputLowerCase),
  );

  const filteredObjects = isSystemObjectsOpen
    ? filteredSystemObjects
    : filteredNonSystemObjects;

  const filteredOptions = filteredObjects.map((objectMetadataItem) => ({
    Icon: getIcon(objectMetadataItem.icon),
    label: objectMetadataItem.labelPlural,
    value: objectMetadataItem.nameSingular,
  }));

  const handleSystemObjectsClick = () => {
    setIsSystemObjectsOpen(true);
    setSearchInputValue('');
  };


Review comment (suggestion):
The `searchInputValue.toLowerCase()` is computed twice - once on line 59 for the `shouldShowAdvanced` check and once on line 61 to create `searchInputLowerCase`. Consider moving the `searchInputLowerCase` variable declaration before line 55 and reusing it in the `shouldShowAdvanced` condition to avoid redundant computation.
```suggestion
  const searchInputLowerCase = searchInputValue.toLowerCase();

  const shouldShowAdvanced =
    showAdvancedOption &&
    !isSystemObjectsOpen &&
    (!isNonEmptyString(searchInputValue) ||
      searchInputLowerCase.includes('advanced'));
```

Code after:

  const matchesSearchFilter = (
    objectMetadataItem: (typeof objectMetadataItems)[number],
    searchInputLowerCase: string,
  ) => {
    return (
      objectMetadataItem.nameSingular
        .toLowerCase()
        .includes(searchInputLowerCase) ||
      objectMetadataItem.labelSingular
        .toLowerCase()
        .includes(searchInputLowerCase) ||
      objectMetadataItem.labelPlural
        .toLowerCase()
        .includes(searchInputLowerCase)
    );
  };

  const searchInputLowerCase = searchInputValue.toLowerCase();

  const shouldShowAdvanced =
    showAdvancedOption &&
    !isSystemObjectsOpen &&
    (!isNonEmptyString(searchInputValue) ||
      searchInputLowerCase.includes('advanced'));

  const filteredNonSystemObjects = nonSystemObjectMetadataItems.filter(
    (objectMetadataItem) =>
      matchesSearchFilter(objectMetadataItem, searchInputLowerCase),
  );

  const filteredSystemObjects = systemObjectMetadataItems.filter(
    (objectMetadataItem) =>
      matchesSearchFilter(objectMetadataItem, searchInputLowerCase),
  );

  const filteredObjects = isSystemObjectsOpen
    ? filteredSystemObjects
    : filteredNonSystemObjects;

  const filteredOptions = filteredObjects.map((objectMetadataItem) => ({
    Icon: getIcon(objectMetadataItem.icon),
    label: objectMetadataItem.labelPlural,
    value: objectMetadataItem.nameSingular,
  }));

  const handleSystemObjectsClick = () => {
    setIsSystemObjectsOpen(true);
    setSearchInputValue('');
  };