From b5d7794a869f73d7c7d235126b69e4d1f9f35f3b Mon Sep 17 00:00:00 2001 From: David Klages Date: Mon, 27 Apr 2020 08:50:23 -0400 Subject: [PATCH] Fix recent FAQ sort --- src/components/Sidebar/RecentFAQs.js | 4 ++-- src/components/Sidebar/RelatedFAQs.js | 4 ++-- src/pages/Home/FAQPreview/FAQPreview.js | 4 ++-- src/pages/Home/Sidebar/RecentFAQs.js | 24 ++++++++++++------------ src/utils/helpers.js | 3 +++ 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/Sidebar/RecentFAQs.js b/src/components/Sidebar/RecentFAQs.js index 312c92c..9fa4174 100644 --- a/src/components/Sidebar/RecentFAQs.js +++ b/src/components/Sidebar/RecentFAQs.js @@ -14,14 +14,14 @@ import { DOMAIN_NAME } from 'api/endpoints'; import './styles.scss'; import { useSearch } from 'utils/hooks'; import { types, searchKeys } from 'api/content'; -import { sortMapper, documentsSelector } from 'utils/helpers'; +import { faqSortMapper, documentsSelector } from 'utils/helpers'; import { HashLink as Link } from 'react-router-hash-link'; const RecentFAQs = ({ styleGuide }) => { const documents = useSearch( { - sort: sortMapper(searchKeys.displayOrder), + sort: faqSortMapper(searchKeys.displayOrder), fq: `type:(${types.faqItem})`, fl: 'document:[json]&rows=5', }, diff --git a/src/components/Sidebar/RelatedFAQs.js b/src/components/Sidebar/RelatedFAQs.js index d6c9bac..f681a77 100644 --- a/src/components/Sidebar/RelatedFAQs.js +++ b/src/components/Sidebar/RelatedFAQs.js @@ -14,7 +14,7 @@ import { DOMAIN_NAME } from 'api/endpoints'; import './styles.scss'; import { useSearch } from 'utils/hooks'; import { types, searchKeys } from 'api/content'; -import { sortMapper, documentsSelector } from 'utils/helpers'; +import { faqSortMapper, documentsSelector } from 'utils/helpers'; import { HashLink as Link } from 'react-router-hash-link'; const RelatedFAQs = ({ categories, styleGuide }) => { @@ -34,7 +34,7 @@ const RelatedFAQs = ({ categories, styleGuide }) => { const documents = useSearch( { - sort: sortMapper(searchKeys.displayOrder), + sort: faqSortMapper(searchKeys.displayOrder), fq: `type:(${types.faqItem}) AND ( ${query} )`, fl: 'document:[json]&rows=5', }, diff --git a/src/pages/Home/FAQPreview/FAQPreview.js b/src/pages/Home/FAQPreview/FAQPreview.js index 14ab029..067253c 100644 --- a/src/pages/Home/FAQPreview/FAQPreview.js +++ b/src/pages/Home/FAQPreview/FAQPreview.js @@ -13,14 +13,14 @@ import { useRouteMatch } from 'react-router-dom'; import ArticlesPreviewCard from 'components/ArticlesPreviewCard/ArticlesPreviewCard'; import FAQItem from 'components/FAQItem/FAQItem' -import { sortMapper, documentsSelector } from 'utils/helpers'; +import { faqSortMapper, documentsSelector } from 'utils/helpers'; import { useSearch } from 'utils/hooks'; import { types, searchKeys } from 'api/content'; const FAQPreview = ({ styleGuide }) => { const documents = useSearch( { - sort: sortMapper(searchKeys.displayOrder), + sort: faqSortMapper(searchKeys.displayOrder), fq: `type:(${types.faqItem}) AND ${searchKeys.topUpdate}:true`, fl: 'document:[json]', }, diff --git a/src/pages/Home/Sidebar/RecentFAQs.js b/src/pages/Home/Sidebar/RecentFAQs.js index e4070d9..f0ac6c9 100644 --- a/src/pages/Home/Sidebar/RecentFAQs.js +++ b/src/pages/Home/Sidebar/RecentFAQs.js @@ -14,30 +14,30 @@ import { DOMAIN_NAME } from 'api/endpoints'; import './styles.scss'; import { useSearch } from 'utils/hooks'; import { types, searchKeys } from 'api/content'; -import { sortMapper, documentsSelector } from 'utils/helpers'; +import { faqSortMapper, documentsSelector } from 'utils/helpers'; -const RecentFAQs = ({styleGuide}) => { +const RecentFAQs = ({ styleGuide }) => { const documents = useSearch( { - sort: sortMapper(searchKeys.displayOrder), - fq: `type:(${types.faqItem})`, - fl: 'document:[json]&rows=5', + sort: faqSortMapper(searchKeys.displayOrder), + fq: `type:(${types.faqItem})`, + fl: 'document:[json]&rows=5', }, documentsSelector - ); + ); - if(!documents?.length){ + if (!documents?.length) { return null; } - return( + return (
-
Recently added FAQs
-
) diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 09a5c2d..277497a 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -96,6 +96,9 @@ export const removeDuplicates = array => Array.from(new Set(array)); export const sortMapper = value => `sortableDate1 ${value === 'Most Recent' ? 'desc' : 'asc'}`; +export const faqSortMapper = value => + `lastModified ${value === 'Most Recent' ? 'desc' : 'asc'}`; + //get Date string in MMM DD YYYY format const getFormattedDate = dateString => dateString