Skip to content

Commit

Permalink
fix missing product category filtering query param, omit envId from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyd committed Nov 6, 2023
1 parent 0681430 commit f746907
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/shared/ui/appPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FC, ReactNode } from "react";
import { perCollectionSEOTitle } from "../../../lib/constants/labels";
import { ValidCollectionCodename } from "../../../lib/types/perCollection";
import { useSmartLink } from "../../../lib/useSmartLink";
import { Stringified, parseFlatted } from "../../../lib/utils/circularityUtils";
import { parseFlatted,Stringified } from "../../../lib/utils/circularityUtils";
import { siteCodename } from "../../../lib/utils/env";
import { createItemSmartLink } from "../../../lib/utils/smartLinkUtils";
import { Article, contentTypes, Metadata, Nav_NavigationItem, Product, Solution, WSL_Page, WSL_WebSpotlightRoot } from "../../../models";
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/changeUrlQueryString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ import { NextRouter } from "next/router";
import { ParsedUrlQueryInput } from "querystring";

export const changeUrlQueryString = (query: ParsedUrlQueryInput, router: NextRouter) => {
router.replace({ query: query }, undefined, { scroll: false, shallow: true });
const asPath = {
pathname: router.asPath.split('?')[0], // getting rid of envId
query
};

router.replace({ query: query }, asPath, { scroll: false, shallow: true });
}
2 changes: 1 addition & 1 deletion lib/utils/circularityUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringify, parse } from "flatted";
import { parse,stringify } from "flatted";

/**
* Helper methods for managing circular references.
Expand Down
7 changes: 5 additions & 2 deletions pages/[envId]/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Content } from "../../components/shared/Content";
import { AppPage } from "../../components/shared/ui/appPage";
import { getDefaultMetadata, getItemBySlug, getPagesSlugs, getSiteMenu } from "../../lib/kontentClient";
import { reservedListingSlugs } from "../../lib/routing";
import { Stringified, parseFlatted, stringifyAsType } from "../../lib/utils/circularityUtils";
import { parseFlatted, Stringified, stringifyAsType } from "../../lib/utils/circularityUtils";
import { defaultEnvId } from "../../lib/utils/env";
import { getEnvIdFromRouteParams, getPreviewApiKeyFromPreviewData } from "../../lib/utils/pageUtils";
import { createElementSmartLink, createFixedAddSmartLink } from "../../lib/utils/smartLinkUtils";
Expand Down Expand Up @@ -83,7 +83,10 @@ const TopLevelPage: FC<Props> = (props) => {
{...createFixedAddSmartLink("end")}
>
{page.elements.content.linkedItems.map((piece) => (
<Content key={piece.system.id} item={piece} />
<Content
key={piece.system.id}
item={piece}
/>
))}
</div>
</AppPage>
Expand Down
2 changes: 1 addition & 1 deletion pages/[envId]/articles/category/[category]/page/[page].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ArticlePageSize } from "../../../../../../lib/constants/paging";
import { getArticlesCountByCategory, getArticlesForListing, getDefaultMetadata, getItemBySlug, getItemsTotalCount, getSiteMenu } from "../../../../../../lib/kontentClient";
import { ResolutionContext, resolveUrlPath } from "../../../../../../lib/routing";
import { ArticleListingUrlQuery, ArticleTypeWithAll, categoryFilterSource, isArticleType } from "../../../../../../lib/utils/articlesListing";
import { Stringified, parseFlatted, stringifyAsType } from "../../../../../../lib/utils/circularityUtils";
import { parseFlatted, Stringified, stringifyAsType } from "../../../../../../lib/utils/circularityUtils";
import { defaultEnvId, siteCodename } from "../../../../../../lib/utils/env";
import { getEnvIdFromRouteParams, getPreviewApiKeyFromPreviewData } from "../../../../../../lib/utils/pageUtils";
import { Article, contentTypes, Metadata, Nav_NavigationItem, taxonomies, WSL_Page } from "../../../../../../models";
Expand Down
2 changes: 1 addition & 1 deletion pages/[envId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Content } from '../../components/shared/Content';
import { AppPage } from '../../components/shared/ui/appPage';
import { getHomepage, getSiteMenu } from '../../lib/kontentClient';
import { useSmartLink } from '../../lib/useSmartLink';
import { Stringified, parseFlatted, stringifyAsType } from '../../lib/utils/circularityUtils';
import { parseFlatted, Stringified, stringifyAsType } from '../../lib/utils/circularityUtils';
import { defaultEnvId } from '../../lib/utils/env';
import { getEnvIdFromRouteParams, getPreviewApiKeyFromPreviewData } from '../../lib/utils/pageUtils';
import { Metadata, Nav_NavigationItem, WSL_WebSpotlightRoot } from '../../models';
Expand Down
4 changes: 2 additions & 2 deletions pages/[envId]/products/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ProductsPageSize } from "../../../lib/constants/paging";
import { getDefaultMetadata, getItemBySlug, getProductsForListing, getSiteMenu } from "../../../lib/kontentClient";
import { createQueryString, reservedListingSlugs, resolveUrlPath } from "../../../lib/routing";
import { changeUrlQueryString } from "../../../lib/utils/changeUrlQueryString";
import { Stringified, parseFlatted, stringifyAsType } from "../../../lib/utils/circularityUtils";
import { parseFlatted, Stringified, stringifyAsType } from "../../../lib/utils/circularityUtils";
import { defaultEnvId, siteCodename } from "../../../lib/utils/env";
import { getEnvIdFromRouteParams, getPreviewApiKeyFromPreviewData } from "../../../lib/utils/pageUtils";
import { contentTypes, Metadata, Nav_NavigationItem, Product, WSL_Page } from "../../../models";
Expand Down Expand Up @@ -123,7 +123,7 @@ export const Products: FC<Props> = props => {
? [...categories, term.codename, ...term.terms.map((t) => t.codename)]
: categories.filter((c) => c !== term.codename && !term.terms.map((t) => t.codename).includes(c));

changeUrlQueryString({ category: newCategories }, router);
changeUrlQueryString({ ...router.query, category: newCategories }, router);
};

return (
Expand Down

0 comments on commit f746907

Please sign in to comment.