From 0fe4dffb3b6ea817e514d15077fb5f3f99a939aa Mon Sep 17 00:00:00 2001 From: MarBert <41899883+MarBert@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:10:32 +0100 Subject: [PATCH 01/10] [DEV-1962] implement urlreplacemap (#1180) * add url replace map single type * add changeset * refactor for linting * add codec, fetch and make for urlreplacemap * add required to url * test, populate, refactor * add dictionary merge, replace old map with new one * fixes required by review * Delete .changeset/healthy-cobras-type.md * fix issue with populate * fix issue with generated path * add changeset * fix tests * fixes requested by review * rename urlreplacesmap to urlreplacemap * refactor as requested * Update apps/nextjs-website/src/lib/cmsApi.ts Co-authored-by: marcobottaro <39835990+marcobottaro@users.noreply.github.com> --------- Co-authored-by: t Co-authored-by: tommaso1 Co-authored-by: marcobottaro <39835990+marcobottaro@users.noreply.github.com> --- .changeset/orange-beans-drop.md | 5 ++++ apps/nextjs-website/src/_contents/products.ts | 2 +- .../guides/[...productGuidePage]/page.tsx | 12 +++----- .../[...productTutorialPage]/page.tsx | 10 +++---- .../[...solutionSubPathSlugs]/page.tsx | 11 +++---- apps/nextjs-website/src/lib/cmsApi.ts | 16 ++++++++++ .../strapi/__tests__/urlReplaceMap.test.ts | 6 ++-- .../lib/strapi/fetches/fetchUrlReplaceMap.ts | 30 ++++++++++++------- .../lib/strapi/makeProps/makeUrlReplaceMap.ts | 5 ++-- 9 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 .changeset/orange-beans-drop.md diff --git a/.changeset/orange-beans-drop.md b/.changeset/orange-beans-drop.md new file mode 100644 index 0000000000..bac38c1251 --- /dev/null +++ b/.changeset/orange-beans-drop.md @@ -0,0 +1,5 @@ +--- +"nextjs-website": minor +--- + +Update url mapping for documentation diff --git a/apps/nextjs-website/src/_contents/products.ts b/apps/nextjs-website/src/_contents/products.ts index 398dcbb44c..8af34d91c1 100644 --- a/apps/nextjs-website/src/_contents/products.ts +++ b/apps/nextjs-website/src/_contents/products.ts @@ -97,7 +97,7 @@ export const spaceToPrefixMap = pipe( /** * Contains the mapping between the docs.pagopa.it url and the developer portal url. */ -export const urlReplacesMap: { readonly [url: string]: string } = { +export const staticUrlReplaceMap: { readonly [url: string]: string } = { // App IO 'https://docs.pagopa.it/io-guida-tecnica-1.3/': '/app-io/guides/io-guida-tecnica/v1.3', diff --git a/apps/nextjs-website/src/app/[productSlug]/guides/[...productGuidePage]/page.tsx b/apps/nextjs-website/src/app/[productSlug]/guides/[...productGuidePage]/page.tsx index fed4e565cd..e8d8e3b9de 100644 --- a/apps/nextjs-website/src/app/[productSlug]/guides/[...productGuidePage]/page.tsx +++ b/apps/nextjs-website/src/app/[productSlug]/guides/[...productGuidePage]/page.tsx @@ -4,11 +4,7 @@ import ProductLayout, { import { getGuide, getProductGuidePath } from '@/lib/api'; import { Product } from '@/lib/types/product'; import React from 'react'; -import { - gitBookPagesWithTitle, - spaceToPrefixMap, - urlReplacesMap, -} from '@/_contents/products'; +import { gitBookPagesWithTitle, spaceToPrefixMap } from '@/_contents/products'; import { ParseContentConfig } from 'gitbook-docs/parseContent'; import { Metadata } from 'next'; import { @@ -17,7 +13,7 @@ import { } from '@/helpers/metadata.helpers'; import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate'; import { productPageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers'; -import { getGuidesProps } from '@/lib/cmsApi'; +import { getGuidesProps, getUrlReplaceMapProps } from '@/lib/cmsApi'; import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers'; import { breadcrumbItemByProduct, @@ -81,7 +77,7 @@ const Page = async ({ params }: { params: Params }) => { params?.productSlug, params?.productGuidePage ?? [''] ); - + const urlReplaceMap = await getUrlReplaceMapProps(); const { product, page, guide, version, versions, source, bannerLinks, seo } = guideProps; const props: ProductGuidePageProps = { @@ -98,7 +94,7 @@ const Page = async ({ params }: { params: Params }) => { assetsPrefix: source.assetsPrefix, gitBookPagesWithTitle, spaceToPrefix: spaceToPrefixMap, - urlReplaces: urlReplacesMap, + urlReplaces: urlReplaceMap, }, }; diff --git a/apps/nextjs-website/src/app/[productSlug]/tutorials/[...productTutorialPage]/page.tsx b/apps/nextjs-website/src/app/[productSlug]/tutorials/[...productTutorialPage]/page.tsx index 5645e925e6..72d47f22ce 100644 --- a/apps/nextjs-website/src/app/[productSlug]/tutorials/[...productTutorialPage]/page.tsx +++ b/apps/nextjs-website/src/app/[productSlug]/tutorials/[...productTutorialPage]/page.tsx @@ -9,11 +9,7 @@ import { import { Product } from '@/lib/types/product'; import GitBookContent from '@/components/organisms/GitBookContent/GitBookContent'; import { Box } from '@mui/material'; -import { - gitBookPagesWithTitle, - spaceToPrefixMap, - urlReplacesMap, -} from '@/_contents/products'; +import { gitBookPagesWithTitle, spaceToPrefixMap } from '@/_contents/products'; import { ParseContentConfig } from 'gitbook-docs/parseContent'; import { Metadata } from 'next'; import { @@ -34,6 +30,7 @@ import { breadcrumbItemByProduct, productToBreadcrumb, } from '@/helpers/structuredData.helpers'; +import { getUrlReplaceMapProps } from '@/lib/cmsApi'; type Params = { productSlug: string; @@ -124,6 +121,7 @@ const Page = async ({ params }: { params: Params }) => { ); } + const urlReplaceMap = await getUrlReplaceMapProps(); const tutorialProps = await getStaticTutorial(productSlug, [tutorialPath]); const { product, page, bannerLinks, source, relatedLinks } = tutorialProps; const props: ProductTutorialPageProps = { @@ -137,7 +135,7 @@ const Page = async ({ params }: { params: Params }) => { assetsPrefix: source.assetsPrefix, gitBookPagesWithTitle, spaceToPrefix: spaceToPrefixMap, - urlReplaces: urlReplacesMap, + urlReplaces: urlReplaceMap, }, }; diff --git a/apps/nextjs-website/src/app/solutions/[solutionSlug]/[...solutionSubPathSlugs]/page.tsx b/apps/nextjs-website/src/app/solutions/[solutionSlug]/[...solutionSubPathSlugs]/page.tsx index 213f3b3cc4..b833b9a97c 100644 --- a/apps/nextjs-website/src/app/solutions/[solutionSlug]/[...solutionSubPathSlugs]/page.tsx +++ b/apps/nextjs-website/src/app/solutions/[solutionSlug]/[...solutionSubPathSlugs]/page.tsx @@ -1,16 +1,12 @@ import React from 'react'; -import { - gitBookPagesWithTitle, - spaceToPrefixMap, - urlReplacesMap, -} from '@/_contents/products'; +import { gitBookPagesWithTitle, spaceToPrefixMap } from '@/_contents/products'; import { Metadata } from 'next'; import { makeMetadata } from '@/helpers/metadata.helpers'; import { getSolutionDetail, getSolutionSubPaths } from '@/lib/api'; import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate'; import { pageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers'; import { ParseContentConfig } from 'gitbook-docs/parseContent'; -import { getSolutionsProps } from '@/lib/cmsApi'; +import { getSolutionsProps, getUrlReplaceMapProps } from '@/lib/cmsApi'; import { SolutionTemplateProps } from '@/components/templates/SolutionTemplate/SolutionTemplate'; import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers'; import { getItemFromPaths } from '@/helpers/structuredData.helpers'; @@ -64,6 +60,7 @@ const Page = async ({ params }: { params: Params }) => { params?.solutionSubPathSlugs ); + const urlReplaceMap = await getUrlReplaceMapProps(); if (!solutionProps) { return null; } @@ -79,7 +76,7 @@ const Page = async ({ params }: { params: Params }) => { assetsPrefix: source.assetsPrefix, gitBookPagesWithTitle, spaceToPrefix: spaceToPrefixMap, - urlReplaces: urlReplacesMap, + urlReplaces: urlReplaceMap, }, }; diff --git a/apps/nextjs-website/src/lib/cmsApi.ts b/apps/nextjs-website/src/lib/cmsApi.ts index 95173d9817..71201bffbe 100644 --- a/apps/nextjs-website/src/lib/cmsApi.ts +++ b/apps/nextjs-website/src/lib/cmsApi.ts @@ -24,6 +24,7 @@ import { overviews, products, quickStartGuides, + staticUrlReplaceMap, tutorialLists, } from '@/_contents/products'; import { makeCaseHistoriesProps } from './strapi/makeProps/makeCaseHistories'; @@ -47,6 +48,9 @@ import { fetchOverviews } from '@/lib/strapi/fetches/fetchOverviews'; import { makeOverviewsProps } from '@/lib/strapi/makeProps/makeOverviews'; import { fetchTutorialListPages } from './strapi/fetches/fetchTutorialListPages'; import { makeTutorialListPagesProps } from './strapi/makeProps/makeTutorialListPages'; +import { fetchUrlReplaceMap } from './strapi/fetches/fetchUrlReplaceMap'; +import build from 'next/dist/build'; +import { makeUrlReplaceMap } from './strapi/makeProps/makeUrlReplaceMap'; // a BuildEnv instance ready to be used const buildEnv = pipe( @@ -136,6 +140,18 @@ export const getQuickStartGuidesProps = async () => { } }; +export const getUrlReplaceMapProps = async () => { + const { + config: { FETCH_FROM_STRAPI: fetchFromStrapi }, + } = buildEnv; + + if (fetchFromStrapi) { + const urlReplaceMap = await fetchUrlReplaceMap(buildEnv); + return { ...staticUrlReplaceMap, ...makeUrlReplaceMap(urlReplaceMap) }; + } + return staticUrlReplaceMap; +}; + export const getApiDataListPagesProps = async () => { const { config: { FETCH_FROM_STRAPI: fetchFromStrapi }, diff --git a/apps/nextjs-website/src/lib/strapi/__tests__/urlReplaceMap.test.ts b/apps/nextjs-website/src/lib/strapi/__tests__/urlReplaceMap.test.ts index 14436aaa42..218ef4e89a 100644 --- a/apps/nextjs-website/src/lib/strapi/__tests__/urlReplaceMap.test.ts +++ b/apps/nextjs-website/src/lib/strapi/__tests__/urlReplaceMap.test.ts @@ -1,8 +1,8 @@ -import { UrlReplaceMapCodec } from '../codecs/UrlReplaceMapCodec'; import * as Either from 'fp-ts/lib/Either'; +import { pipe } from 'fp-ts/lib/function'; +import { UrlReplaceMapCodec } from '../codecs/UrlReplaceMapCodec'; import { productJson } from './fixtures/product'; import { makeUrlReplaceMap } from '../makeProps/makeUrlReplaceMap'; -import { pipe } from 'fp-ts/lib/function'; import { mediaRasterJson } from './fixtures/media'; const strapiResponse = { @@ -73,7 +73,7 @@ describe('UrlReplaceMapCodec', () => { const urlReplaceMap = makeUrlReplaceMap(result!); expect(urlReplaceMap).toEqual({ - aaaa: 'firma-con-io/guides/aaaa/2', + aaaa: '/firma-con-io/guides/aaaa/2', }); }); }); diff --git a/apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts b/apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts index 5d163c2fce..1db7b7298f 100644 --- a/apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts +++ b/apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts @@ -4,17 +4,25 @@ import qs from 'qs'; const makeStrapiUrlReplaceMapPopulate = () => qs.stringify({ - populate: [ - 'urlToGuide.guide.*', - 'urlToGuide.guide.image', - 'urlToGuide.guide.mobileImage', - 'urlToGuide.guide.listItems', - 'urlToGuide.guide.product.*', - 'urlToGuide.guide.versions.*', - 'urlToGuide.guide.seo.*', - 'urlToGuide.guide.product.bannerLinks.*', - 'urlToGuide.guide.product.bannerLinks.icon', - ], + populate: { + urlToGuide: { + populate: { + guide: { + populate: [ + 'image', + 'mobileImage', + 'listItems', + 'versions', + 'bannerLinks.icon', + 'seo', + 'seo.metaSocial.image', + 'product.logo', + 'product.bannerLinks.icon', + ], + }, + }, + }, + }, }); export const fetchUrlReplaceMap = fetchFromStrapi( diff --git a/apps/nextjs-website/src/lib/strapi/makeProps/makeUrlReplaceMap.ts b/apps/nextjs-website/src/lib/strapi/makeProps/makeUrlReplaceMap.ts index 764aa09a07..fdeb5bdce8 100644 --- a/apps/nextjs-website/src/lib/strapi/makeProps/makeUrlReplaceMap.ts +++ b/apps/nextjs-website/src/lib/strapi/makeProps/makeUrlReplaceMap.ts @@ -5,15 +5,14 @@ export type UrlReplaceMap = Record; export function makeUrlReplaceMap( urlReplacemap: StrapiUrlReplaceMap ): UrlReplaceMap { - const map = urlReplacemap.data.attributes.urlToGuide.reduce((map, obj) => { + return urlReplacemap.data.attributes.urlToGuide.reduce((map, obj) => { return { ...map, - [obj.url]: `${ + [obj.url]: `/${ obj.guide.data?.attributes.product.data.attributes.slug }/guides/${obj.guide.data?.attributes.slug}${ obj.version ? `/${obj.version}` : '' }`, }; }, {} as UrlReplaceMap); - return map; } From d572be41652cdc05d5a0346573679d5ba6e5399c Mon Sep 17 00:00:00 2001 From: MarBert <41899883+MarBert@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:38:43 +0100 Subject: [PATCH 02/10] [CAI-178] Fix chatbot tab reposition (#1197) * fix ref in anchorEl * add changeset --------- Co-authored-by: marcobottaro <39835990+marcobottaro@users.noreply.github.com> --- .changeset/clever-mirrors-carry.md | 5 +++++ .../organisms/ChatbotLayout/ChatbotLayout.tsx | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/clever-mirrors-carry.md diff --git a/.changeset/clever-mirrors-carry.md b/.changeset/clever-mirrors-carry.md new file mode 100644 index 0000000000..775c973229 --- /dev/null +++ b/.changeset/clever-mirrors-carry.md @@ -0,0 +1,5 @@ +--- +"nextjs-website": patch +--- + +fix reference in anchorEl for chatbot diff --git a/apps/nextjs-website/src/components/organisms/ChatbotLayout/ChatbotLayout.tsx b/apps/nextjs-website/src/components/organisms/ChatbotLayout/ChatbotLayout.tsx index f9f3ac93b9..91bbe13fb7 100644 --- a/apps/nextjs-website/src/components/organisms/ChatbotLayout/ChatbotLayout.tsx +++ b/apps/nextjs-website/src/components/organisms/ChatbotLayout/ChatbotLayout.tsx @@ -35,17 +35,18 @@ const ChatbotLayout = ({ }: ChatbotLayoutProps) => { const t = useTranslations(); const { palette } = useTheme(); - const [anchorEl, setAnchorEl] = React.useState( - null + const ref = React.useRef(); + const [anchorEl, setAnchorEl] = React.useState( + undefined ); - const handleClick = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget); + const handleClick = () => { + setAnchorEl(ref.current); return null; }; const handleClose = () => { - setAnchorEl(null); + setAnchorEl(undefined); }; const open = Boolean(anchorEl); @@ -53,6 +54,7 @@ const ChatbotLayout = ({ return ( Date: Mon, 14 Oct 2024 14:55:33 +0200 Subject: [PATCH 03/10] Remove subtitle attribute from bannerLink component (#1190) --- .changeset/fuzzy-buttons-sing.md | 5 +++++ apps/strapi-cms/src/components/common/banner-link.json | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .changeset/fuzzy-buttons-sing.md diff --git a/.changeset/fuzzy-buttons-sing.md b/.changeset/fuzzy-buttons-sing.md new file mode 100644 index 0000000000..d8f1ffa863 --- /dev/null +++ b/.changeset/fuzzy-buttons-sing.md @@ -0,0 +1,5 @@ +--- +"strapi-cms": minor +--- + +Remove subtitle attribute from bannerLink component diff --git a/apps/strapi-cms/src/components/common/banner-link.json b/apps/strapi-cms/src/components/common/banner-link.json index d046f1397b..ed4cca6da5 100644 --- a/apps/strapi-cms/src/components/common/banner-link.json +++ b/apps/strapi-cms/src/components/common/banner-link.json @@ -10,9 +10,6 @@ "title": { "type": "string" }, - "subtitle": { - "type": "string" - }, "content": { "type": "blocks" }, From 23f27b82cb5dc79d5ee086f16bc27a49bfc41fcf Mon Sep 17 00:00:00 2001 From: marcobottaro <39835990+marcobottaro@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:11:20 +0200 Subject: [PATCH 04/10] [DEV-1969] Remove subtitle from banner link codec (#1191) * Remove subtitle from BannerLink codec * Remove subtitle from features items in Overview page * Fix StrapiBaseProduct, StrapiProduct and StrapiProducts type names * Add changeset --- .changeset/fuzzy-bags-yawn.md | 5 +++++ .../src/lib/strapi/codecs/BannerLinkCodec.ts | 3 +-- .../src/lib/strapi/codecs/ProductCodec.ts | 6 +++--- .../src/lib/strapi/makeProps/makeBannerLink.ts | 4 ++-- .../src/lib/strapi/makeProps/makeOverviews.ts | 1 - .../src/lib/strapi/makeProps/makeProducts.ts | 11 ++++++----- 6 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 .changeset/fuzzy-bags-yawn.md diff --git a/.changeset/fuzzy-bags-yawn.md b/.changeset/fuzzy-bags-yawn.md new file mode 100644 index 0000000000..507aeeb4ae --- /dev/null +++ b/.changeset/fuzzy-bags-yawn.md @@ -0,0 +1,5 @@ +--- +"nextjs-website": patch +--- + +Remove subtitle from banner link codec diff --git a/apps/nextjs-website/src/lib/strapi/codecs/BannerLinkCodec.ts b/apps/nextjs-website/src/lib/strapi/codecs/BannerLinkCodec.ts index b7c03652bd..fe7073482c 100644 --- a/apps/nextjs-website/src/lib/strapi/codecs/BannerLinkCodec.ts +++ b/apps/nextjs-website/src/lib/strapi/codecs/BannerLinkCodec.ts @@ -6,10 +6,9 @@ import { MediaCodec } from './MediaCodec'; export const BannerLinkCodec = t.strict({ id: t.number, title: t.union([NullToUndefinedCodec, t.string]), - subtitle: t.union([NullToUndefinedCodec, t.string]), content: t.union([NullToUndefinedCodec, BlocksContentCodec]), icon: t.strict({ data: MediaCodec }), theme: t.union([t.literal('light'), t.literal('dark')]), }); -export type BannerLink = t.TypeOf; +export type StrapiBannerLink = t.TypeOf; diff --git a/apps/nextjs-website/src/lib/strapi/codecs/ProductCodec.ts b/apps/nextjs-website/src/lib/strapi/codecs/ProductCodec.ts index 084879ebe6..c133ce9842 100644 --- a/apps/nextjs-website/src/lib/strapi/codecs/ProductCodec.ts +++ b/apps/nextjs-website/src/lib/strapi/codecs/ProductCodec.ts @@ -103,6 +103,6 @@ export const ProductsCodec = t.strict({ data: t.array(ProductCodec), }); -export type BaseProduct = t.TypeOf; -export type Product = t.TypeOf; -export type Products = t.TypeOf; +export type StrapiBaseProduct = t.TypeOf; +export type StrapiProduct = t.TypeOf; +export type StrapiProducts = t.TypeOf; diff --git a/apps/nextjs-website/src/lib/strapi/makeProps/makeBannerLink.ts b/apps/nextjs-website/src/lib/strapi/makeProps/makeBannerLink.ts index 59229e3175..8429cc840e 100644 --- a/apps/nextjs-website/src/lib/strapi/makeProps/makeBannerLink.ts +++ b/apps/nextjs-website/src/lib/strapi/makeProps/makeBannerLink.ts @@ -1,8 +1,8 @@ import { BannerLinkProps } from '@/components/atoms/BannerLink/BannerLink'; -import { BannerLink } from '@/lib/strapi/codecs/BannerLinkCodec'; +import { StrapiBannerLink } from '@/lib/strapi/codecs/BannerLinkCodec'; export function makeBannerLinkProps( - strapiBannerLink: BannerLink + strapiBannerLink: StrapiBannerLink ): BannerLinkProps { return { content: strapiBannerLink.content, diff --git a/apps/nextjs-website/src/lib/strapi/makeProps/makeOverviews.ts b/apps/nextjs-website/src/lib/strapi/makeProps/makeOverviews.ts index aba5a98205..42753f457b 100644 --- a/apps/nextjs-website/src/lib/strapi/makeProps/makeOverviews.ts +++ b/apps/nextjs-website/src/lib/strapi/makeProps/makeOverviews.ts @@ -33,7 +33,6 @@ export function makeOverviewsProps( items: attributes.features.items.map((item) => ({ iconUrl: item.icon.data?.attributes.url, - subtitle: item.subtitle, content: item.content, title: item.title || '', })) || [], diff --git a/apps/nextjs-website/src/lib/strapi/makeProps/makeProducts.ts b/apps/nextjs-website/src/lib/strapi/makeProps/makeProducts.ts index a9db81004f..e9b35b1a86 100644 --- a/apps/nextjs-website/src/lib/strapi/makeProps/makeProducts.ts +++ b/apps/nextjs-website/src/lib/strapi/makeProps/makeProducts.ts @@ -1,14 +1,15 @@ import { products } from '@/_contents/products'; import { - Products, - Product as ApiProduct, - BaseProduct, + StrapiProducts, + StrapiProduct, + StrapiBaseProduct, } from '../codecs/ProductCodec'; import { Product } from '../../types/product'; import { makeBannerLinkProps } from '@/lib/strapi/makeProps/makeBannerLink'; export function mergeProductWithStaticContent( - attributes: Partial & BaseProduct['attributes'] + attributes: Partial & + StrapiBaseProduct['attributes'] ): Product { const staticProduct = products.find((product) => product.slug === attributes.slug) || products[0]; @@ -21,7 +22,7 @@ export function mergeProductWithStaticContent( } export function makeProductsProps( - products: Products, + products: StrapiProducts, staticProducts: ReadonlyArray ): ReadonlyArray { return [ From e6b7263685cf886da4c622b9895fb4bee10b0737 Mon Sep 17 00:00:00 2001 From: marcobottaro <39835990+marcobottaro@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:35:18 +0200 Subject: [PATCH 05/10] Remove warnings from build output (#1192) --- .changeset/curly-geese-attend.md | 6 ++++++ .../components/atoms/MobileUserInfo/MobileUserInfo.tsx | 1 - .../organisms/GitBookContent/components/CodeBlock.tsx | 1 - packages/gitbook-docs/src/markdoc/schema/code.ts | 1 + packages/gitbook-docs/src/markdoc/schema/swagger.ts | 9 +++++---- 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changeset/curly-geese-attend.md diff --git a/.changeset/curly-geese-attend.md b/.changeset/curly-geese-attend.md new file mode 100644 index 0000000000..ad96d36c8a --- /dev/null +++ b/.changeset/curly-geese-attend.md @@ -0,0 +1,6 @@ +--- +"gitbook-docs": patch +"nextjs-website": patch +--- + +Remove warnings from build output diff --git a/apps/nextjs-website/src/components/atoms/MobileUserInfo/MobileUserInfo.tsx b/apps/nextjs-website/src/components/atoms/MobileUserInfo/MobileUserInfo.tsx index d381cfdcc6..c11a5805ee 100644 --- a/apps/nextjs-website/src/components/atoms/MobileUserInfo/MobileUserInfo.tsx +++ b/apps/nextjs-website/src/components/atoms/MobileUserInfo/MobileUserInfo.tsx @@ -8,7 +8,6 @@ import Link from 'next/link'; import { useTranslations } from 'next-intl'; import { usePathname, useRouter } from 'next/navigation'; import { MobileSiteHeaderStyledTreeItem } from '@/components/molecules/MobileSiteHeader/MobileSiteHeader'; -import { ButtonNaked } from '@pagopa/mui-italia'; type MobileUserInfoProps = { // eslint-disable-next-line functional/no-return-void diff --git a/apps/nextjs-website/src/components/organisms/GitBookContent/components/CodeBlock.tsx b/apps/nextjs-website/src/components/organisms/GitBookContent/components/CodeBlock.tsx index 524b5f25f1..e848803b6c 100644 --- a/apps/nextjs-website/src/components/organisms/GitBookContent/components/CodeBlock.tsx +++ b/apps/nextjs-website/src/components/organisms/GitBookContent/components/CodeBlock.tsx @@ -1,7 +1,6 @@ import { CodeBlockProps } from 'gitbook-docs/markdoc/schema/code'; import { ReactNode } from 'react'; import CodeBlockPart from '@/components/molecules/CodeBlockPart/CodeBlockPart'; -import MermaidDiagram from '@/components/atoms/MermaidDiagram/MermaidDiagram'; import dynamic from 'next/dynamic'; const NoSSRMermaidDiagram = dynamic( diff --git a/packages/gitbook-docs/src/markdoc/schema/code.ts b/packages/gitbook-docs/src/markdoc/schema/code.ts index 78c720361e..25e00fbd00 100644 --- a/packages/gitbook-docs/src/markdoc/schema/code.ts +++ b/packages/gitbook-docs/src/markdoc/schema/code.ts @@ -43,6 +43,7 @@ export const code: Schema = { 'CodeBlock', { ...Object.fromEntries( + // eslint-disable-next-line @typescript-eslint/no-unused-vars Object.entries(attrs).filter(([_, value]) => value !== null) ), ...fenceAttr, diff --git a/packages/gitbook-docs/src/markdoc/schema/swagger.ts b/packages/gitbook-docs/src/markdoc/schema/swagger.ts index c14cb546aa..b0e13d50c9 100644 --- a/packages/gitbook-docs/src/markdoc/schema/swagger.ts +++ b/packages/gitbook-docs/src/markdoc/schema/swagger.ts @@ -1,4 +1,4 @@ -import Markdoc, { Schema } from '@markdoc/markdoc'; +import Markdoc, { RenderableTreeNode, Schema } from '@markdoc/markdoc'; import { SrcAttr } from '../attributes'; export type SwaggerProps = { @@ -19,9 +19,10 @@ export const swagger: Schema = { baseUrl: { type: String }, }, transform: (node, config) => { - const attrs = node.transformAttributes(config); - const children = node.transformChildren(config); - return new Markdoc.Tag('Swagger', attrs, children); + const attrs: Record = node.transformAttributes(config); + const children: readonly RenderableTreeNode[] = + node.transformChildren(config); + return new Markdoc.Tag('Swagger', attrs, [...children]); }, }; From 5e07dbe24c821340cfdb2a07a1d5b35f0c2fcf66 Mon Sep 17 00:00:00 2001 From: mdciri Date: Wed, 16 Oct 2024 11:36:35 +0200 Subject: [PATCH 06/10] Update modules --- apps/chatbot/src/modules/chatbot.py | 17 +++++++++++------ apps/chatbot/src/modules/presidio.py | 28 ++++++++++++---------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apps/chatbot/src/modules/chatbot.py b/apps/chatbot/src/modules/chatbot.py index a187968503..5b361e949d 100644 --- a/apps/chatbot/src/modules/chatbot.py +++ b/apps/chatbot/src/modules/chatbot.py @@ -16,10 +16,7 @@ from src.modules.presidio import PresidioPII -AWS_S3_BUCKET = os.getenv("CHB_AWS_S3_BUCKET") -ITALIAN_THRESHOLD = 0.85 -NUM_MIN_WORDS_QUERY = 3 -NUM_MIN_REFERENCES = 1 +USE_PRESIDIO = True if os.getenv("CHB_USE_PRESIDIO", "True") == "True" else False RESPONSE_TYPE = Union[ Response, StreamingResponse, AsyncStreamingResponse, PydanticResponse ] @@ -36,7 +33,9 @@ def __init__( self.params = params self.prompts = prompts - self.pii = PresidioPII(config=params["config_presidio"]) + if USE_PRESIDIO: + self.pii = PresidioPII(config=params["config_presidio"]) + self.model = get_llm() self.embed_model = get_embed_model() self.index = load_automerging_index_redis( @@ -111,6 +110,9 @@ def _get_response_str(self, engine_response: RESPONSE_TYPE) -> str: """ else: response_str = self._unmask_reference(response_str, nodes) + + if "Step 2:" in response_str: + response_str = response_str.split("Step 2:")[1].strip() return response_str @@ -142,7 +144,10 @@ def _unmask_reference(self, response_str: str, nodes) -> str: def mask_pii(self, message: str) -> str: - return self.pii.mask_pii(message) + if USE_PRESIDIO: + return self.pii.mask_pii(message) + else: + return message def generate(self, query_str: str) -> str: diff --git a/apps/chatbot/src/modules/presidio.py b/apps/chatbot/src/modules/presidio.py index 7de5560873..65e7f114e1 100644 --- a/apps/chatbot/src/modules/presidio.py +++ b/apps/chatbot/src/modules/presidio.py @@ -12,7 +12,7 @@ # see supported entities by Presidio with their description at: https://microsoft.github.io/presidio/supported_entities/ -ENTITIES = [ +GLOBAL_ENTITIES = [ "CREDIT_CARD", "CRYPTO", "DATE_TIME", @@ -23,21 +23,16 @@ "LOCATION", "PERSON", "PHONE_NUMBER", - "MEDICAL_LICENSE", + "MEDICAL_LICENSE" +] + +IT_ENTITIES = [ "IT_FISCAL_CODE", "IT_DRIVER_LICENSE", "IT_VAT_CODE", "IT_PASSPORT", "IT_IDENTITY_CARD", - "IT_PHYSICAL_ADDRESS", # this is a custom entity added to the analyzer registry - # "ES_NIF", - # "ES_NIE", - # "US_BANK_NUMBER", - # "US_DRIVER_LICENSE", - # "US_ITIN", - # "US_PASSPORT", - # "US_SSN", - # "UK_NHS" + "IT_PHYSICAL_ADDRESS" ] ALLOW_LIST = [ @@ -102,9 +97,10 @@ def __init__( analyzer_threshold: float = 0.4 ): self.config = config + self.languages = [item["lang_code"] for item in config["models"]] self.entity_mapping = entity_mapping self.mapping = mapping - self.entities = entities if entities else ENTITIES + self.entities = entities if entities else GLOBAL_ENTITIES self.analyzer_threshold = analyzer_threshold if isinstance(self.config, (Path, str)): @@ -117,7 +113,7 @@ def __init__( self.nlp_engine = nlp_engine self.analyzer = AnalyzerEngine( nlp_engine = self.nlp_engine, - supported_languages = ["it", "en"], # "es", "fr", "de" + supported_languages = self.languages, default_score_threshold = analyzer_threshold ) self._add_italian_physical_address_entity() @@ -136,7 +132,7 @@ def detect_language(self, text: str) -> str: detected_languages = detect_langs(text) lang_list = [] for detected_lang in detected_languages: - if detected_lang.lang in ["it", "en", "es", "fr", "de"]: + if detected_lang.lang in self.languages: lang_list.append(detected_lang.lang) if not lang_list: @@ -145,7 +141,7 @@ def detect_language(self, text: str) -> str: elif "it" in lang_list: lang = "it" else: - lang = "en" # lang_list[0].lang + lang = lang_list[0] except: logging.warning("No detected language.") lang = "it" @@ -160,7 +156,7 @@ def detect_pii(self, text: str) -> List[RecognizerResult]: results = self.analyzer.analyze( text=text, language=lang, - entities=self.entities, + entities=self.entities + IT_ENTITIES if lang == "it" else self.entities, allow_list=ALLOW_LIST ) From da8a41cd43e382c31bcecd45813df73c7326e0ba Mon Sep 17 00:00:00 2001 From: mdciri Date: Wed, 16 Oct 2024 11:36:54 +0200 Subject: [PATCH 07/10] Update config prompts --- apps/chatbot/config/prompts.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/chatbot/config/prompts.yaml b/apps/chatbot/config/prompts.yaml index daf7b34161..61b4f4f51e 100644 --- a/apps/chatbot/config/prompts.yaml +++ b/apps/chatbot/config/prompts.yaml @@ -12,7 +12,6 @@ qa_prompt_str: | - the answer must be clear, non-redundant, and have not repeated sentences. - the answer must not include the query. - If your answer is based on this retrieved context, include a "Rif" section at the end of the response, listing the titles and filenames from the source nodes used. If no context is used, do not include a reference. - - the answer must be with the same language of the query. -------------------- Output Examples: Query: Cos'รจ il nodo dei pagamenti? @@ -38,7 +37,14 @@ qa_prompt_str: | -------------------- Task: Given the query: {query_str} - Answer the query according to the `Chatbot Policy` listed above. + + Reply to the user following these two steps: + Step 1: + Pay great attention in detail on the query's language and determine if it is formulated in Italian, English, Spanish, French, German, Greek, Croatian, or Slovenian ('yes' or 'no'). + Step 2: + If Step 1 returns 'yes': reply always in Italian, regardless of the input language, according to the `Chatbot Policy` listed above. + Otherwise: reply you cannot speak that language and ask for a new query written in an accepted language. + Answer: From b57d55c42619369143722978db7d31a4cecc2ed6 Mon Sep 17 00:00:00 2001 From: mdciri Date: Wed, 16 Oct 2024 11:37:11 +0200 Subject: [PATCH 08/10] Update env example --- apps/chatbot/.env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/chatbot/.env.example b/apps/chatbot/.env.example index 9dbd012ac8..3d9cbb938c 100644 --- a/apps/chatbot/.env.example +++ b/apps/chatbot/.env.example @@ -13,6 +13,7 @@ CHB_WEBSITE_URL=... CHB_REDIS_INDEX_NAME=... CHB_LLAMAINDEX_INDEX_ID=... CHB_DOCUMENTATION_DIR=... +CHB_USE_PRESIDIO=... CHB_GOOGLE_API_KEY=... CHB_PROVIDER=... CHB_MODEL_ID=... From 278d56df6eaa80cbded42b59139a00966e19c3cc Mon Sep 17 00:00:00 2001 From: Devis Battisti Date: Wed, 16 Oct 2024 17:32:44 +0200 Subject: [PATCH 09/10] redis admin port --- apps/chatbot/docker/compose.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/chatbot/docker/compose.yaml b/apps/chatbot/docker/compose.yaml index e720460e45..349c715027 100644 --- a/apps/chatbot/docker/compose.yaml +++ b/apps/chatbot/docker/compose.yaml @@ -32,6 +32,7 @@ services: image: redis/redis-stack:7.2.0-v13 ports: - "6379:6379" + - "8001:8001" networks: - ntw From 91c782a73c77ab59299078dd9c64380dd7067b6a Mon Sep 17 00:00:00 2001 From: Devis Battisti Date: Wed, 16 Oct 2024 17:36:27 +0200 Subject: [PATCH 10/10] chore: add env example var --- apps/chatbot/.env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/chatbot/.env.example b/apps/chatbot/.env.example index c7e15cf1d3..cf45f3da0b 100644 --- a/apps/chatbot/.env.example +++ b/apps/chatbot/.env.example @@ -26,3 +26,4 @@ CHB_ENGINE_USE_ASYNC=True CHB_ENGINE_USE_STREAMING=... CHB_QUERY_TABLE_PREFIX=chatbot-local CHB_DYNAMODB_URL=http://locahost:8080 +CHB_USE_PRESIDIO=True