Skip to content

fix: add utilizacao do faceLink#1512

Open
DevDaniloSants wants to merge 2 commits intodeco-cx:mainfrom
DevDaniloSants:fix/searchPage
Open

fix: add utilizacao do faceLink#1512
DevDaniloSants wants to merge 2 commits intodeco-cx:mainfrom
DevDaniloSants:fix/searchPage

Conversation

@DevDaniloSants
Copy link

@DevDaniloSants DevDaniloSants commented Jan 15, 2026

um problema no Search Page acontecia quando o usuário pesquisava um produto, a busca era feita da maneira correta .. porém alguns filtros não funcionam da maneira correta.

image

Debugando encontramos um tratamento que estava sendo feito no transform.ts , pelo que vimos por alto ela criava uma nova url e não utilizava o facetLink. Criamos uma versão que preserva a url em questão e o filtro voltou a funcionar nesse caso.

 const getLink = (facet: LegacyFacet, selected: boolean) => {
    const index = pathSegments.findIndex((s) => {
      if (ignoreCaseSelected) {
        return s.toLowerCase() === facet.Value.toLowerCase();
      }

      return s === facet.Value;
    });
    if (!selected && facet.Link && facet.Link.includes("map=")) {
      const vtexLink = new URL(facet.Link, url);

      // Preserva query params existentes (como q=)
      const currentQuery = url.searchParams.get("q");
      if (currentQuery) {
        vtexLink.searchParams.set("q", currentQuery);
      }

      return `${vtexLink.pathname}${vtexLink.search}`;
    }
    const map = hasToBeFullpath
      ? facet.Link.split("map=")[1].split(",")
      : [facet.Map];
    const value = hasToBeFullpath
      ? facet.Link.split("?")[0].slice(1).split("/")
      : [facet.Value];

    const pathSegmentsFiltered = hasProductClusterIds
      ? [pathSegments[mapSegments.indexOf("productClusterIds")]]
      : [];
    const mapSegmentsFiltered = hasProductClusterIds
      ? ["productClusterIds"]
      : [];

    const _mapSegments = hasToBeFullpath ? mapSegmentsFiltered : mapSegments;
    const _pathSegments = hasToBeFullpath ? pathSegmentsFiltered : pathSegments;

    const newMap = selected
      ? [...mapSegments.filter((_, i) => i !== index)]
      : [..._mapSegments, ...map];
    const newPath = selected
      ? [...pathSegments.filter((_, i) => i !== index)]
      : [..._pathSegments, ...value];

    // Insertion-sort like algorithm. Uses the c-continuum theorem
    const zipped: [string, string][] = [];
    for (let it = 0; it < newMap.length; it++) {
      let i = 0;
      while (
        i < zipped.length &&
        (zipped[i][0] === "c" || zipped[i][0] === "C")
      )
        i++;

      zipped.splice(i, 0, [newMap[it], newPath[it]]);
    }

    const link = new URL(`/${zipped.map(([, s]) => s).join("/")}`, url);
    link.searchParams.set("map", zipped.map(([m]) => m).join(","));
    if (behavior === "static") {
      link.searchParams.set(
        "fmap",
        url.searchParams.get("fmap") || mapSegments.join(",")
      );
    }
    const currentQuery = url.searchParams.get("q");
    if (currentQuery) {
      link.searchParams.set("q", currentQuery);
    }

    return `${link.pathname}${link.search}`;
  };

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.133.25 update
  • 🎉 for Minor 0.134.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Enhanced vtex/utils/transform.ts utility functions to preserve query parameters in legacy facet links, add description fields to cluster properties when highlights are present, and refactor the toPlace function for consistent option handling.

Changes

Cohort / File(s) Summary
Query parameter preservation in facet links
vtex/utils/transform.ts
Added logic to preserve existing q query parameter when generating legacy facet links containing map= query by constructing VTEX links with appended current q value
Cluster property enhancements
vtex/utils/transform.ts
Extended toAdditionalPropertyCluster to accept optional highlights?: Set<string> parameter and include description: "highlight" field in returned PropertyValue when applicable
toPlace function refactoring
vtex/utils/transform.ts
Refactored toPlace to consistently derive isActive from options in non-VCS branch, aligning with VCS branch data flow; normalized opening hours and holiday handling
Helper function structural adjustments
vtex/utils/transform.ts
Minor formatting and parameter handling adjustments across toProduct, breadcrumb, and link builder functions with no observable behavior changes

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A carrot-ful of query params saved,
Highlights dancing, descriptions engraved,
toPlace aligned from branch to branch,
Transform utils pack a solid punch! ✨

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The pull request description is incomplete and does not follow the required template structure. While technical details are provided in Portuguese, required template sections (Issue Link, Loom Video, Demonstration Link) are missing or only contain template placeholders. Add the required template sections: fill in the Issue Link with the actual GitHub issue number, provide a Loom video link showing the changes, and include a Demonstration Link to a testable environment or branch.
Title check ❓ Inconclusive The title is partially related to the changeset, referring to facet link functionality which is a real part of the changes, but lacks clarity and uses Portuguese making it unclear to English-speaking reviewers. Clarify the title in English to better describe the main change, such as 'fix: preserve query parameters in facet links' or 'fix: add facet link query parameter handling'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant