Skip to content

Commit

Permalink
fix: check if name is string and use locale
Browse files Browse the repository at this point in the history
  • Loading branch information
aliceoq committed Nov 29, 2023
1 parent da57db3 commit 6185f3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/components/sidebar-elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MethodType } from 'utils/typings/types'
import { LibraryContext } from 'utils/context/libraryContext'

export interface SidebarElement {
name: string
name: string | { en: string; pt: string; es: string }
slug: string
origin: string
type: string
Expand Down Expand Up @@ -108,8 +108,7 @@ const SidebarElements = ({ slugPrefix, items, subItemLevel }: SidebarProps) => {
endpoint,
children,
}: SidebarElement) => {
const localizedName: string =
typeof name === 'string' ? name : name[`${locale}`]
const localizedName: string = typeof name === 'string' ? name : name[locale]
const isExpandable = children.length > 0
const pathSuffix = method ? `#${method.toLowerCase()}-${endpoint}` : ''
const activeItem = method ? `${slug}${pathSuffix}` : slug
Expand Down Expand Up @@ -170,7 +169,7 @@ const SidebarElements = ({ slugPrefix, items, subItemLevel }: SidebarProps) => {
) : checkDocumentationType(sidebarDataMaster, slug, 'link') ? (
<Link href={slug} target="_blank" sx={styles.elementText}>
<IconExternalLink size={16} sx={{ marginRight: '10px' }} />
{name}
{localizedName}
</Link>
) : (
<Box
Expand Down
15 changes: 11 additions & 4 deletions src/components/sidebar-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SidebarSection = ({
sidebarSectionHidden,
setSidebarSectionHidden,
sidebarSections,
locale,
} = useContext(LibraryContext)
const [methodFilterList, setMethodFilterList] = useState([
{ name: 'POST', active: false },
Expand All @@ -44,8 +45,6 @@ const SidebarSection = ({
(methodFilter) => methodFilter.active
)

const { locale } = useContext(LibraryContext)

const filteredResult = useMemo(() => {
if (!filterStatus && searchValue === '') return categories

Expand All @@ -63,7 +62,12 @@ const SidebarSection = ({
)?.active
const hasInputFilter =
searchValue === '' ||
endpoint.name.toLowerCase().includes(searchValue.toLowerCase())
(typeof endpoint.name === 'string'
? endpoint.name
: endpoint.name[locale]
)
.toLowerCase()
.includes(searchValue.toLowerCase())
return hasMethodFilter && hasInputFilter
})
return subcategory
Expand All @@ -72,7 +76,10 @@ const SidebarSection = ({
(subcategory) =>
subcategory.children.length > 0 ||
(subcategory.type === 'markdown' &&
subcategory.name
(typeof subcategory.name === 'string'
? subcategory.name
: subcategory.name[locale]
)
.toLowerCase()
.includes(searchValue.toLowerCase()))
)
Expand Down

0 comments on commit 6185f3b

Please sign in to comment.