Skip to content

Commit

Permalink
Extract the subtitle for filter tags
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanFengYeh committed Dec 29, 2024
1 parent 3fd6bdb commit cd6b761
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/search/HierarchicalMenuWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
(renderFn, unmountFn = () => {}) => {
return widgetParams => {
const { attributes, separator } = widgetParams

console.log(attributes)
// Store information that needs to be shared across multiple method calls.
const connectorState: MultiselectHierarchicalMenuState = {
levels: [],
Expand All @@ -69,7 +69,7 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
if (!results) return { levels: [], widgetParams }

// Get the last refinement.
const lastRefinement = results.getRefinements().pop()?.attributeName
// const lastRefinement = results.getRefinements().pop()?.attributeName

// Merge the results items with the initial ones.
const getItems = (
Expand All @@ -95,8 +95,8 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
}))
: []

if (lastRefinement && !attributes.includes(lastRefinement))
return resultsItems
// if (lastRefinement && !attributes.includes(lastRefinement))
// return resultsItems

const level = connectorState.levels.find(
level => level.attribute === attribute
Expand Down Expand Up @@ -131,6 +131,7 @@ export const connectMultiselectHierarchicalMenu: MultiselectHierarchicalMenuConn
)
helper.clearRefinements(attr)
}

const refinement = helper
.getRefinements(attribute)
.find(ref => ref.value === value)
Expand Down
26 changes: 26 additions & 0 deletions components/search/bills/BillSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ const searchClient = new TypesenseInstantSearchAdapter({
}
}).searchClient

const extractLastSegmentOfRefinements = (items: any[]) => {
return items.map(item => {
console.log(item)
if (item.label != "topics.lvl1") return item
const newRefinements = item.refinements.map(
(refinement: { label: string }) => {
// Split the label to extract the last part of the hierarchy
const lastPartOfLabel = refinement.label.split(" > ").pop()

return {
...refinement,
// Update label to only show the last part
label: lastPartOfLabel
}
}
)

return {
...item,
label: "Tags",
refinements: newRefinements
}
})
}

export const BillSearch = () => {
const items = useBillSort()
const initialSortByValue = items[0].value
Expand Down Expand Up @@ -99,6 +124,7 @@ const Layout: FC<
<CurrentRefinements
className="mt-2 mb-2"
excludedAttributes={["nextHearingAt"]}
transformItems={extractLastSegmentOfRefinements}
/>
{status === "empty" ? (
<NoResults>
Expand Down

0 comments on commit cd6b761

Please sign in to comment.