From d79533a2df5de941da63e324c930b6865559e2b8 Mon Sep 17 00:00:00 2001 From: mark-tate <143323+mark-tate@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:06:09 +0000 Subject: [PATCH] fix: ensure `initialNamespaceFilters` filter's the initial sitemap (#585) * fix: ensure `initialNamespaceFilters` filter's the initial sitemap * fix: only show filter bar if there are multiple namespaces on sitemap --- .changeset/shy-zoos-suffer.md | 5 +++ .../sitemap-component/src/SitemapToolbar.tsx | 36 ++++++++++--------- .../sitemap-component/src/SitemapTree.tsx | 15 ++++++-- 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 .changeset/shy-zoos-suffer.md diff --git a/.changeset/shy-zoos-suffer.md b/.changeset/shy-zoos-suffer.md new file mode 100644 index 00000000..db84fd9f --- /dev/null +++ b/.changeset/shy-zoos-suffer.md @@ -0,0 +1,5 @@ +--- +'@jpmorganchase/mosaic-sitemap-component': patch +--- + +`initialNamespaceFilters` should filter the initial Sitemap view diff --git a/packages/sitemap-component/src/SitemapToolbar.tsx b/packages/sitemap-component/src/SitemapToolbar.tsx index f8e370be..6f0f3690 100644 --- a/packages/sitemap-component/src/SitemapToolbar.tsx +++ b/packages/sitemap-component/src/SitemapToolbar.tsx @@ -48,23 +48,25 @@ export const SitemapToolbar: React.FC = ({ {!loading ? ( <> Number of pages: {pageCount} - - aria-label={isOpen ? 'close filters menu' : 'open filters menu'} - className={styles.filterDropdown} - onOpenChange={setIsOpen} - onSelectionChange={handleSelect} - selected={filters} - selectionStrategy="multiple" - source={namespaces} - triggerComponent={ - - - - - } - width={200} - {...rest} - /> + {namespaces?.length >= 1 ? ( + + aria-label={isOpen ? 'close filters menu' : 'open filters menu'} + className={styles.filterDropdown} + onOpenChange={setIsOpen} + onSelectionChange={handleSelect} + selected={filters} + selectionStrategy="multiple" + source={namespaces} + triggerComponent={ + + + + + } + width={200} + {...rest} + /> + ) : null} ) : null} diff --git a/packages/sitemap-component/src/SitemapTree.tsx b/packages/sitemap-component/src/SitemapTree.tsx index 17b45a6e..e7305aeb 100644 --- a/packages/sitemap-component/src/SitemapTree.tsx +++ b/packages/sitemap-component/src/SitemapTree.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from 'react'; import { Spinner } from '@salt-ds/core'; -import { useToolbarState } from '@jpmorganchase/mosaic-components'; +import { useToolbarState, ToolbarProvider } from '@jpmorganchase/mosaic-components'; import drawTree from './drawTree'; import styles from './styles.css'; @@ -64,7 +64,7 @@ function getAllNamespaces(routes): string[] { }, []); } -export const SitemapTree: React.FC = ({ +export const Sitemap: React.FC = ({ d3, href = '/sitemap.xml', initialNamespaceFilters = [], @@ -175,3 +175,14 @@ export const SitemapTree: React.FC = ({ ); }; + +export const SitemapTree: React.FC = ({ + initialNamespaceFilters = [], + ...props +}) => { + return ( + + + + ); +};