Skip to content

Commit

Permalink
fix(sidebar): render schema index in sidebar with node_key fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoaibdev7 committed Nov 17, 2024
1 parent 2b66a82 commit e1392d7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/App/SideBar/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import ChevronDownIcon from '~/components/Icons/ChevronDownIcon'
import ChevronUpIcon from '~/components/Icons/ChevronUpIcon'
import { Flex } from '~/components/common/Flex'
import { useDataStore } from '~/stores/useDataStore'
import { useSchemaStore } from '~/stores/useSchemaStore'
import { colors } from '~/utils/colors'

export const SelectWithPopover = () => {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null)
const { sidebarFilter, setSidebarFilter, sidebarFilterCounts = [] } = useDataStore((s) => s)
const { getSchemaByType } = useSchemaStore()

const currentFilter = (sidebarFilter ?? '').toLowerCase()
const currentFilterCount = sidebarFilterCounts.find((f) => f.name === currentFilter)?.count || 0

Expand All @@ -39,12 +42,18 @@ export const SelectWithPopover = () => {
handleClosePopover()
}

const getDisplayName = (type: string) => {
const schema = getSchemaByType(type)

return schema?.index || schema?.node_key || capitalizeFirstLetter(type)
}

return (
<div>
<Action onClick={handleOpenPopover}>
<div className="text">Show</div>
<div className="value" data-testid="value">
{`${capitalizeFirstLetter(currentFilter)} (${currentFilterCount})`}
{`${getDisplayName(currentFilter)} (${currentFilterCount})`}
</div>
{currentFilterCount >= 1 && <div className="icon">{!anchorEl ? <ChevronDownIcon /> : <ChevronUpIcon />}</div>}
</Action>
Expand Down Expand Up @@ -78,7 +87,7 @@ export const SelectWithPopover = () => {
}}
>
<span className="icon">{name === sidebarFilter ? <CheckIcon /> : null}</span>
<span>{`${capitalizeFirstLetter(name)} (${count})`}</span>
<span>{`${getDisplayName(name)} (${count})`}</span>
</MenuItem>
))}
</FormControl>
Expand Down

0 comments on commit e1392d7

Please sign in to comment.