Skip to content

Commit

Permalink
Fix/app components (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sodik authored Sep 9, 2024
1 parent fdd9d27 commit 6ad2c91
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/ui/__tests__/AppSidebar/AppSidebarFavorites.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import { render, screen } from '@testing-library/react'

import { AppSidebarFavorites } from '../../src/AppSidebar'

describe('AppSidebarFavorites', () => {
it('shows no favorites if empty', () => {
render(<AppSidebarFavorites>{() => null}</AppSidebarFavorites>)

expect(screen.getByTestId('sidebar-menu-no-favorites')).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
}
}

&:hover {
&:hover,
&:active {
color: inherit;

.favorite {
display: block;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/AppSidebar/AppSidebarItem/AppSidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactElement, ReactNode, useContext } from 'react'
import cn from 'classnames'
import { Icon as FeatherIcon } from 'react-feather'
import { DataTestProp } from '@hazelcast/helpers'

import { Icon } from '../../Icon'
import { Tooltip } from '../../Tooltip'
Expand All @@ -10,7 +11,6 @@ import { AppSidebarFavoriteButton } from '../AppSidebarFavoriteButton'
import { appSidebarSectionContext } from '../AppSidebarSection/appSidebarSectionContext'

import styles from './AppSidebarItem.module.scss'
import { DataTestProp } from '@hazelcast/helpers'

const Component = ({ children }: { children: ReactNode }) => <>{children}</>

Expand Down Expand Up @@ -60,6 +60,7 @@ export const AppSidebarItem = ({
disabled={disabled as boolean}
disabledTooltip={disabledTooltip}
bodyClassName={styles.content}
data-test="sidebar-menu-item-title"
className={cn(styles.button, { [styles.active]: active }, className)}
>
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ $sideBarMenuSectionTransitionMaxHeight: 1000px;
display: flex;
flex-direction: column;
gap: c.$grid;
padding: 0 c.$grid 0 0;
}

.icon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactNode, useContext } from 'react'
import cn from 'classnames'
import { DataTestProp } from '@hazelcast/helpers'

import { appSidebarContext } from '../appSidebarContext'
import { AppSidebarSectionExpandable, AppSidebarSectionExpandableProps } from './AppSidebarSectionExpandable'
Expand All @@ -9,21 +10,22 @@ import styles from './AppSidebarSection.module.scss'
export type AppSidebarSectionProps = {
title: string
children: ReactNode
} & ({ id?: never; active?: never; icon?: never; ariaLabel?: never } | AppSidebarSectionExpandableProps)
} & DataTestProp &
({ id?: never; active?: never; icon?: never; ariaLabel?: never } | AppSidebarSectionExpandableProps)

export const AppSidebarSection = ({ id, icon, active, title, children, ariaLabel }: AppSidebarSectionProps) => {
export const AppSidebarSection = ({ id, icon, active, title, children, ariaLabel, 'data-test': dataTest }: AppSidebarSectionProps) => {
const { isOpen } = useContext(appSidebarContext)

if (id) {
return (
<AppSidebarSectionExpandable id={id} icon={icon} title={title} active={active} ariaLabel={ariaLabel}>
<AppSidebarSectionExpandable data-test={dataTest} id={id} icon={icon} title={title} active={active} ariaLabel={ariaLabel}>
{children}
</AppSidebarSectionExpandable>
)
}

return (
<section className={cn(styles.root, { [styles.collapsed]: !isOpen })}>
<section data-test={dataTest} className={cn(styles.root, { [styles.collapsed]: !isOpen })}>
<h3>{title}</h3>
{children}
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { ReactNode, useContext, useEffect } from 'react'
import cn from 'classnames'
import { ChevronDown, ChevronUp, Icon as FeatherIcon } from 'react-feather'
import createPersistedState from 'use-persisted-state'
import { DataTestProp } from '@hazelcast/helpers'

import { useRefValue } from '../../hooks'
import { Icon, IconProps } from '../../Icon'
Expand All @@ -11,18 +12,26 @@ import { appSidebarSectionContext } from './appSidebarSectionContext'

import styles from './AppSidebarSection.module.scss'

export interface AppSidebarSectionExpandableProps {
export type AppSidebarSectionExpandableProps = {
id: string
title: string
active: boolean
icon: FeatherIcon
ariaLabel: string
children: ReactNode
}
} & DataTestProp

const kebabCase = (str: string) => str.toLowerCase().split(' ').join('-')

export const AppSidebarSectionExpandable = ({ id, active, icon, title, ariaLabel, children }: AppSidebarSectionExpandableProps) => {
export const AppSidebarSectionExpandable = ({
id,
active,
icon,
title,
ariaLabel,
children,
'data-test': dataTest = 'sidebar-menu-section-title',
}: AppSidebarSectionExpandableProps) => {
const { isOpen, open: openSidebar } = useContext(appSidebarContext)
const usePersistedMenuStorageState = createPersistedState<boolean>(`isOpen::${title}`)

Expand Down Expand Up @@ -63,7 +72,7 @@ export const AppSidebarSectionExpandable = ({ id, active, icon, title, ariaLabel
active={active}
className={styles.toggle}
adornment={<Icon data-test="sidebar-menu-section-chevron" size="medium" containerClassName={styles.icon} {...chevronButtonProps} />}
data-test="sidebar-menu-section-title"
data-test={dataTest}
/>
{/* detect whether an item is in an expandable section or not. */}
<appSidebarSectionContext.Provider value={{}}>
Expand Down

0 comments on commit 6ad2c91

Please sign in to comment.