Skip to content

Commit

Permalink
fix: ensure initialNamespaceFilters filter's the initial sitemap (#585
Browse files Browse the repository at this point in the history
)

* fix: ensure `initialNamespaceFilters` filter's the initial sitemap

* fix: only show filter bar if there are multiple namespaces on sitemap
  • Loading branch information
mark-tate authored Mar 14, 2024
1 parent 8ba714e commit d79533a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-zoos-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jpmorganchase/mosaic-sitemap-component': patch
---

`initialNamespaceFilters` should filter the initial Sitemap view
36 changes: 19 additions & 17 deletions packages/sitemap-component/src/SitemapToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ export const SitemapToolbar: React.FC<SitemapToolbarProps> = ({
{!loading ? (
<>
<Caption2 className={styles.pageCount}>Number of pages: {pageCount}</Caption2>
<Dropdown<string, 'multiple'>
aria-label={isOpen ? 'close filters menu' : 'open filters menu'}
className={styles.filterDropdown}
onOpenChange={setIsOpen}
onSelectionChange={handleSelect}
selected={filters}
selectionStrategy="multiple"
source={namespaces}
triggerComponent={
<span className={styles.filterDropdownTriggerRoot}>
<Icon name="filter" />
<DropdownButton label={defaultButtonLabel(filters)} />
</span>
}
width={200}
{...rest}
/>
{namespaces?.length >= 1 ? (
<Dropdown<string, 'multiple'>
aria-label={isOpen ? 'close filters menu' : 'open filters menu'}
className={styles.filterDropdown}
onOpenChange={setIsOpen}
onSelectionChange={handleSelect}
selected={filters}
selectionStrategy="multiple"
source={namespaces}
triggerComponent={
<span className={styles.filterDropdownTriggerRoot}>
<Icon name="filter" />
<DropdownButton label={defaultButtonLabel(filters)} />
</span>
}
width={200}
{...rest}
/>
) : null}
</>
) : null}
</div>
Expand Down
15 changes: 13 additions & 2 deletions packages/sitemap-component/src/SitemapTree.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,7 +64,7 @@ function getAllNamespaces(routes): string[] {
}, []);
}

export const SitemapTree: React.FC<SitemapTreeProps> = ({
export const Sitemap: React.FC<SitemapTreeProps> = ({
d3,
href = '/sitemap.xml',
initialNamespaceFilters = [],
Expand Down Expand Up @@ -175,3 +175,14 @@ export const SitemapTree: React.FC<SitemapTreeProps> = ({
</div>
);
};

export const SitemapTree: React.FC<SitemapTreeProps> = ({
initialNamespaceFilters = [],
...props
}) => {
return (
<ToolbarProvider initialState={{ filters: initialNamespaceFilters }}>
<Sitemap {...props} />
</ToolbarProvider>
);
};

0 comments on commit d79533a

Please sign in to comment.