From 4a6ade3f0337b930a605ac7f573e57d1dc17dcdd Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Mon, 22 Aug 2022 11:35:39 -0500 Subject: [PATCH] Add section search component for use with directory pages. Add search box component for section search at the top of direcotry landing pages. --- .../marko-web-theme-monorail/browser/index.js | 4 + .../browser/section-search.vue | 89 +++++++++++++++++++ .../components/blocks/marko.json | 3 + .../components/blocks/section-search.marko | 14 +++ .../graphql/fragments/sections-search.js | 46 ++++++++++ .../utils/get-child-sections-by-id.js | 11 +++ 6 files changed, 167 insertions(+) create mode 100644 packages/marko-web-theme-monorail/browser/section-search.vue create mode 100644 packages/marko-web-theme-monorail/components/blocks/section-search.marko create mode 100644 packages/marko-web-theme-monorail/graphql/fragments/sections-search.js create mode 100644 packages/marko-web-theme-monorail/utils/get-child-sections-by-id.js diff --git a/packages/marko-web-theme-monorail/browser/index.js b/packages/marko-web-theme-monorail/browser/index.js index 540b5aec1..aee2dd0e1 100644 --- a/packages/marko-web-theme-monorail/browser/index.js +++ b/packages/marko-web-theme-monorail/browser/index.js @@ -15,6 +15,7 @@ const MenuToggleButton = () => import(/* webpackChunkName: "theme-menu-toggle-bu const NewsletterCloseButton = () => import(/* webpackChunkName: "theme-newsletter-close-button" */ './newsletter-close-button.vue'); const NewsletterToggleButton = () => import(/* webpackChunkName: "theme-newsletter-toggle-button" */ './newsletter-toggle-button.vue'); const CompanySearch = () => import(/* webpackChunkName: "theme-company-search" */ './company-search.vue'); +const SectionSearch = () => import(/* webpackChunkName: "theme-section-search" */ './section-search.vue'); const SiteNewsletterMenu = () => import(/* webpackChunkName: "theme-site-newsletter-menu" */ './site-newsletter-menu.vue'); const WufooForm = () => import(/* webpackChunkName: "theme-wufoo-form" */ './wufoo-form.vue'); const TopStoriesMenu = () => import(/* webpackChunkName: "theme-top-stories-menu" */ './top-stories-menu.vue'); @@ -115,6 +116,9 @@ export default (Browser, config = { Browser.register('ThemeCompanySearch', CompanySearch, { provide: { EventBus }, }); + Browser.register('ThemeSectionSearch', SectionSearch, { + provide: { EventBus }, + }); Browser.register('ThemeTopStoriesMenu', TopStoriesMenu); Browser.register('WufooForm', WufooForm); Browser.register('RevealAdHandler', RevealAdHandler); diff --git a/packages/marko-web-theme-monorail/browser/section-search.vue b/packages/marko-web-theme-monorail/browser/section-search.vue new file mode 100644 index 000000000..e26721932 --- /dev/null +++ b/packages/marko-web-theme-monorail/browser/section-search.vue @@ -0,0 +1,89 @@ + + + diff --git a/packages/marko-web-theme-monorail/components/blocks/marko.json b/packages/marko-web-theme-monorail/components/blocks/marko.json index aa62f8fef..5f3c9719e 100644 --- a/packages/marko-web-theme-monorail/components/blocks/marko.json +++ b/packages/marko-web-theme-monorail/components/blocks/marko.json @@ -145,6 +145,9 @@ "": { "template": "./section-list.marko" }, + "": { + "template": "./section-search.marko" + }, "": { "template": "./section-title-feed.marko", "": {}, diff --git a/packages/marko-web-theme-monorail/components/blocks/section-search.marko b/packages/marko-web-theme-monorail/components/blocks/section-search.marko new file mode 100644 index 000000000..fdf9027b2 --- /dev/null +++ b/packages/marko-web-theme-monorail/components/blocks/section-search.marko @@ -0,0 +1,14 @@ +import queryFragment from "../../graphql/fragments/sections-search" +import { getChildSectionsById } from "../../utils/get-child-sections-by-id"; + +$ const { sectionIds, includeSelf } = input; + + + + $ const nodesById = getChildSectionsById(parent[0], {}, includeSelf); + + + diff --git a/packages/marko-web-theme-monorail/graphql/fragments/sections-search.js b/packages/marko-web-theme-monorail/graphql/fragments/sections-search.js new file mode 100644 index 000000000..07302fd8d --- /dev/null +++ b/packages/marko-web-theme-monorail/graphql/fragments/sections-search.js @@ -0,0 +1,46 @@ +const gql = require('graphql-tag'); + +module.exports = gql` +fragment WebsiteSectionSearchFragment on WebsiteSection { + id + alias + name + children(input: { pagination: { limit: 0 } }) { + edges { + node { + id + alias + name + children(input: { pagination: { limit: 0 } }) { + edges { + node { + id + alias + name + children(input: { pagination: { limit: 0 } }) { + edges { + node { + id + alias + name + children(input: { pagination: { limit: 0 } }) { + edges { + node { + id + alias + name + } + } + } + } + } + } + } + } + } + } + } + } +} + +`; diff --git a/packages/marko-web-theme-monorail/utils/get-child-sections-by-id.js b/packages/marko-web-theme-monorail/utils/get-child-sections-by-id.js new file mode 100644 index 000000000..62a4a7f60 --- /dev/null +++ b/packages/marko-web-theme-monorail/utils/get-child-sections-by-id.js @@ -0,0 +1,11 @@ +const { getAsArray } = require('@parameter1/base-cms-object-path'); + +const getChildSectionsById = (section, childSections = {}, includeSelf = true) => { + const { id } = section; + const children = getAsArray(section, 'children.edges').map(({ node }) => node); + return { + ...children.reduce((obj, child) => getChildSectionsById(child, obj), childSections), + ...(includeSelf && !section[id] && { [id]: section }), + }; +}; +module.exports = { getChildSectionsById };