@c-rex/templates 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-rex/templates",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -34,7 +34,7 @@ export const BlogPageTemplate = async ({ params }: { params: { id: string } }) =
34
34
  const { articleHtml } = extractHtmlContent(htmlContent)
35
35
 
36
36
  return (
37
- <PageWrapper title="">
37
+ <PageWrapper title="" showInput={false}>
38
38
  <SidebarProvider>
39
39
 
40
40
  <CheckArticleLangToast availableVersions={availableVersions} />
@@ -4,11 +4,12 @@ import { PageWrapper } from "@c-rex/components/page-wrapper";
4
4
  import { DOCUMENTS_TYPE_AND_LINK } from "@c-rex/constants";
5
5
 
6
6
  export const DocumentsPageTemplate = async ({ params }: { params: { id: string } }) => {
7
- const { htmlContent, title, lang, availableVersions } = await getPrimaryInfo(params.id, DOCUMENTS_TYPE_AND_LINK);
7
+ const { htmlContent, title, lang, availableVersions, packageId } = await getPrimaryInfo(params.id, DOCUMENTS_TYPE_AND_LINK);
8
8
 
9
9
  return (
10
- <PageWrapper title={title}>
10
+ <PageWrapper title={title} showInput>
11
11
  <ArticleWrapper
12
+ packageId={packageId}
12
13
  title={title}
13
14
  availableVersions={availableVersions}
14
15
  htmlContent={htmlContent}
@@ -31,16 +31,18 @@ export const TopicsPageTemplate = async ({ params }: { params: { id: string } })
31
31
  htmlContent,
32
32
  title,
33
33
  lang,
34
- availableVersions
34
+ availableVersions,
35
+ packageId
35
36
  } = await getInfoWithCache(params.id, TOPICS_TYPE_AND_LINK, infoCache);
36
37
 
37
38
  const { articleHtml } = extractHtmlContent(htmlContent)
38
39
 
39
40
  return (
40
- <PageWrapper title={title}>
41
+ <PageWrapper title={title} showInput>
41
42
  <ArticleWrapper
42
43
  title={title}
43
44
  lang={lang}
45
+ packageId={packageId}
44
46
  availableVersions={availableVersions}
45
47
  htmlContent={articleHtml}
46
48
  id={params.id}
@@ -1,6 +1,6 @@
1
1
  import { DirectoryNodesService, InformationUnitsService, RenditionsService } from "@c-rex/services";
2
2
  import { DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
3
- import { DirectoryNodes, SidebarAvailableVersionsInterface } from "@c-rex/interfaces";
3
+ import { DirectoryNodes, informationUnitsResponseItem, SidebarAvailableVersionsInterface } from "@c-rex/interfaces";
4
4
  import * as cheerio from 'cheerio'
5
5
  import { BLOG_TYPE_AND_LINK } from "@c-rex/constants";
6
6
 
@@ -14,6 +14,7 @@ export const getPrimaryInfo = async (id: string, type: string): Promise<{
14
14
  htmlContent: string,
15
15
  title: string,
16
16
  lang: string,
17
+ packageId: string,
17
18
  availableVersions: SidebarAvailableVersionsInterface[]
18
19
  }> => {
19
20
  const renditionService = new RenditionsService();
@@ -24,22 +25,23 @@ export const getPrimaryInfo = async (id: string, type: string): Promise<{
24
25
  const lang = informationUnitsItem.languages[0];
25
26
  const versionOf = informationUnitsItem.versionOf.shortId
26
27
 
27
- const [versions, rootNode] = await Promise.all([
28
+ const promiseList: any = [
28
29
  informationService.getList({
29
- filters: [`versionOf.shortId=${versionOf}`],
30
+ restrict: [`versionOf.shortId=${versionOf}`], // TODO: replace from filter to restrict
30
31
  fields: ["renditions", "class", "languages", "labels"],
31
32
  }),
32
- getRootNode(informationUnitsItem.directoryNodes),
33
- ])
33
+ ]
34
34
 
35
- let htmlContent = ""
35
+ const rootNode = await getRootNode(informationUnitsItem.directoryNodes)
36
36
 
37
37
  if (rootNode != null) {
38
38
  title = rootNode.informationUnits[0]?.labels[0]?.value;
39
39
  }
40
40
 
41
41
  if ([TOPICS_TYPE_AND_LINK, BLOG_TYPE_AND_LINK].includes(type)) {
42
- htmlContent = await renditionService.getHTMLRendition({ renditions: informationUnitsItem.renditions });
42
+ promiseList.push(
43
+ renditionService.getHTMLRendition({ renditions: informationUnitsItem.renditions })
44
+ )
43
45
 
44
46
  } else if (rootNode != null && type == DOCUMENTS_TYPE_AND_LINK) {
45
47
 
@@ -48,14 +50,19 @@ export const getPrimaryInfo = async (id: string, type: string): Promise<{
48
50
  const directoryId = rootNode.childNodes[0]?.shortId as string;
49
51
 
50
52
  const response = await service.getItem(directoryId);
53
+
51
54
  const infoId = response.informationUnits[0]?.shortId;
52
55
 
53
56
  const childInformationUnit = await informationService.getItem({ id: infoId as string });
54
57
 
55
- htmlContent = await renditionService.getHTMLRendition({ renditions: childInformationUnit.renditions });
58
+ promiseList.push(
59
+ renditionService.getHTMLRendition({ renditions: childInformationUnit.renditions })
60
+ )
56
61
  }
57
62
 
58
- const availableVersions = versions.items.map((item) => {
63
+ const [versions, htmlContent] = await Promise.all(promiseList)
64
+
65
+ const availableVersions = versions.items.map((item: informationUnitsResponseItem) => {
59
66
  return {
60
67
  shortId: item.shortId,
61
68
  link: `/${type}/${item.shortId}`,
@@ -63,15 +70,15 @@ export const getPrimaryInfo = async (id: string, type: string): Promise<{
63
70
  country: item.language.split("-")[1],
64
71
  active: item.language === lang,
65
72
  }
66
- }).sort((a, b) => {
73
+ }).sort((a: SidebarAvailableVersionsInterface, b: SidebarAvailableVersionsInterface) => {
67
74
  if (a.lang < b.lang) return -1;
68
75
  if (a.lang > b.lang) return 1;
69
76
  return 0;
70
- })
71
- .filter(item => item.lang.toLocaleLowerCase() !== "pl-pl") as SidebarAvailableVersionsInterface[];
77
+ }) as SidebarAvailableVersionsInterface[];
72
78
 
73
79
  return {
74
80
  htmlContent,
81
+ packageId: informationUnitsItem.packages[0]?.shortId as string,
75
82
  title: title as string,
76
83
  lang: lang as string,
77
84
  availableVersions
@@ -12,6 +12,7 @@ import { DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants"
12
12
  import { call, generateBreadcrumbItems, generateTreeOfContent, getFileRenditions } from "@c-rex/utils";
13
13
  import { DropdownMenu } from "@c-rex/components/dropdown-menu";
14
14
  import { FileRenditionType } from "@c-rex/types";
15
+ import { useAppConfig } from "@c-rex/contexts/config-provider";
15
16
 
16
17
  type Props = {
17
18
  htmlContent: string,
@@ -20,6 +21,7 @@ type Props = {
20
21
  type: string,
21
22
  lang: string,
22
23
  availableVersions: SidebarAvailableVersionsInterface[],
24
+ packageId: string,
23
25
  }
24
26
 
25
27
  const loadArticleData = async (id: string, type: string, title: string) => {
@@ -68,9 +70,11 @@ const loadArticleData = async (id: string, type: string, title: string) => {
68
70
  }
69
71
  };
70
72
 
71
- export const ArticleWrapper = ({ htmlContent, title, id, type, lang, availableVersions }: Props) => {
73
+ export const ArticleWrapper = ({ htmlContent, title, id, type, lang, availableVersions, packageId }: Props) => {
74
+ const { setPackageID } = useAppConfig()
72
75
  const [loading, setLoading] = useState<boolean>(true)
73
76
 
77
+
74
78
  //set available versions on confgi context so will be possible to get the link when change contant language
75
79
  const [breadcrumbItems, setBreadcrumbItems] = useState<TreeOfContent[]>([])
76
80
  const [treeOfContent, setTreeOfContent] = useState<TreeOfContent[]>([])
@@ -89,6 +93,8 @@ export const ArticleWrapper = ({ htmlContent, title, id, type, lang, availableVe
89
93
  })
90
94
 
91
95
  useEffect(() => {
96
+ setPackageID(packageId)
97
+
92
98
  const fetchData = async () => {
93
99
  const {
94
100
  treeOfContent,
@@ -1,19 +1,23 @@
1
- import React from "react";
2
1
  import { informationUnitsResponse } from "@c-rex/interfaces";
3
2
  import { InformationUnitsService } from "@c-rex/services";
4
3
  import { HomePage } from "./page";
5
4
  import { PageWrapper } from "@c-rex/components/page-wrapper";
5
+ import { WildCardType } from "@c-rex/types";
6
6
 
7
7
  interface HomeProps {
8
8
  searchParams: {
9
9
  search?: string;
10
- page?: string;
11
- language?: string;
10
+ page: string;
11
+ language: string;
12
+ wildcard: string;
13
+ operator: string;
14
+ like: string;
15
+ package?: string;
12
16
  };
13
17
  }
14
18
 
15
19
  export const HomeLayout = async ({ searchParams }: HomeProps) => {
16
- const { search, page, language } = searchParams;
20
+ const { search, page, language, wildcard, operator, like, package: packageParam } = searchParams;
17
21
 
18
22
  let data = {
19
23
  items: [],
@@ -22,35 +26,30 @@ export const HomeLayout = async ({ searchParams }: HomeProps) => {
22
26
  pageNumber: 0
23
27
  }
24
28
  } as unknown as informationUnitsResponse;
25
- let selectedLanguages: string[] = [];
26
29
 
27
30
  if (search !== undefined) {
28
- const pageAux = Number(page);
29
- const searchValue = search;
30
31
 
31
- if (language != undefined) {
32
- const aux = language;
33
- selectedLanguages = aux.split(",");
34
- }
35
-
36
- if (searchValue) {
37
- const service = new InformationUnitsService();
38
-
39
- data = await service.getList({
40
- queries: searchValue.split(" ").join(","),
41
- page: pageAux,
42
- fields: ["renditions", "class", "languages", "labels"],
43
- languages: selectedLanguages
44
- });
32
+ const filters: string[] = []
33
+ if (packageParam && packageParam.length > 0) {
34
+ filters.push(`packages.shortId=${packageParam}`)
45
35
  }
36
+ const service = new InformationUnitsService();
37
+
38
+ data = await service.getList({
39
+ queries: search,
40
+ page: Number(page),
41
+ fields: ["renditions", "class", "languages", "labels"],
42
+ languages: language.split(","),
43
+ wildcard: wildcard as WildCardType,
44
+ operator: operator,
45
+ like: Boolean(like === "true"),
46
+ filters: filters
47
+ });
46
48
  }
47
49
 
48
50
  return (
49
- <PageWrapper title="">
50
- <HomePage
51
- data={data}
52
- selectedLanguages={selectedLanguages}
53
- />
51
+ <PageWrapper title="" showInput={false}>
52
+ <HomePage data={data} />
54
53
  </PageWrapper>
55
54
  );
56
55
  };
package/src/home/page.tsx CHANGED
@@ -1,25 +1,25 @@
1
1
  "use client";
2
2
 
3
- import React, { FC } from "react";
3
+ import React, { FC, useEffect, useState } from "react";
4
4
  import { informationUnitsResponse } from "@c-rex/interfaces";
5
5
  import { call, getFromCookieString } from "@c-rex/utils";
6
6
  import { Button } from "@c-rex/ui/button";
7
- import { AutoComplete } from "@c-rex/components/autocomplete";
8
7
  import { ResultList } from "@c-rex/components/result-list";
9
8
  import { useTranslations } from 'next-intl'
10
- import { parseAsInteger, parseAsString, useQueryStates } from 'nuqs'
9
+ import { parseAsBoolean, parseAsInteger, parseAsString, useQueryStates } from 'nuqs'
11
10
  import { DialogFilter } from "@c-rex/components/dialog-filter";
12
- import { CONTENT_LANG_KEY } from "@c-rex/constants";
11
+ import { CONTENT_LANG_KEY, WILD_CARD_OPTIONS } from "@c-rex/constants";
13
12
  import { useAppConfig } from "@c-rex/contexts/config-provider";
13
+ import { AutoComplete } from "@c-rex/components/autocomplete";
14
14
 
15
15
  interface HomePageProps {
16
16
  data: informationUnitsResponse;
17
- selectedLanguages: string[];
18
17
  }
19
18
 
20
- export const HomePage: FC<HomePageProps> = ({ data, selectedLanguages }) => {
21
- const { configs, availableLanguagesAndCountries: availableLanguages, contentLang } = useAppConfig()
19
+ export const HomePage: FC<HomePageProps> = ({ data }) => {
22
20
  const t = useTranslations();
21
+ const { configs } = useAppConfig()
22
+ const [disabled, setDisabled] = useState<boolean>(false)
23
23
  const [params, setParams] = useQueryStates({
24
24
  search: {
25
25
  defaultValue: "",
@@ -27,50 +27,34 @@ export const HomePage: FC<HomePageProps> = ({ data, selectedLanguages }) => {
27
27
  return value
28
28
  },
29
29
  },
30
- operator: parseAsString,
31
- language: parseAsString,
32
- page: parseAsInteger,
33
30
  }, {
34
31
  history: 'push',
35
32
  shallow: false,
36
33
  });
37
34
 
38
- const { search } = params;
39
-
40
- const onSearch = (value: string): Promise<string[]> => {
41
- return call<string[]>("InformationUnitsService.getSuggestions", { query: value, language: contentLang });
42
- }
43
-
44
- const onSelect = (value: string) => {
45
- //show loading
46
-
47
- const cookie = getFromCookieString(document.cookie, CONTENT_LANG_KEY)
48
-
49
- setParams({
50
- search: value,
51
- operator: "OR",
52
- page: 1,
53
- language: cookie,
54
- });
55
- };
35
+ useEffect(() => {
36
+ if (params.search.length > 0) {
37
+ setDisabled(false)
38
+ } else {
39
+ setDisabled(true)
40
+ }
41
+ }, [params])
56
42
 
57
43
  return (
58
44
  <div className="container">
59
45
  <div className="grid grid-cols-12 gap-4 py-6">
60
- <div className="col-span-12 sm:col-span-9 md:col-span-10">
46
+ <div className="col-span-12 sm:col-span-10 md:col-span-10">
61
47
  <AutoComplete
62
- initialValue={search}
63
- onSearch={onSearch}
64
- onSelect={onSelect}
48
+ embedded={false}
49
+ initialValue={params.search}
50
+ searchByPackage={false}
65
51
  />
66
52
  </div>
67
- <div className="col-span-12 sm:col-span-3 md:col-span-2">
53
+ <div className="col-span-12 sm:col-span-2 md:col-span-2">
68
54
  <div className="flex justify-end">
69
55
  <DialogFilter
70
- startSelectedLanguages={selectedLanguages}
71
- availableLanguages={availableLanguages}
72
56
  trigger={(
73
- <Button variant="default">{t("filters")}</Button>
57
+ <Button variant="default" disabled={disabled}>{t("filter.filters")}</Button>
74
58
  )}
75
59
  />
76
60
  </div>