Skip to content

Commit

Permalink
Remove confusing componentManagesLoading control in async story
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron committed Jan 28, 2025
1 parent 7215b43 commit e2b8446
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions packages/react/src/SelectPanel/SelectPanel.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from '@storybook/react'
import Box from '../Box'
import {Button} from '../Button'
import type {ItemInput, GroupedListProps} from '../deprecated/ActionList/List'
import {SelectPanel} from './SelectPanel'
import {SelectPanel, type SelectPanelProps} from './SelectPanel'
import {
FilterIcon,
GearIcon,
Expand All @@ -17,12 +17,10 @@ import {
import useSafeTimeout from '../hooks/useSafeTimeout'
import FormControl from '../FormControl'

type SelectPanelPropsAndCustomArgs = React.ComponentProps<typeof SelectPanel> & {componentManagesLoading?: boolean}

const meta = {
title: 'Components/SelectPanel/Features',
component: SelectPanel,
} satisfies Meta<SelectPanelPropsAndCustomArgs>
} satisfies Meta<SelectPanelProps>

export default meta

Expand Down Expand Up @@ -489,39 +487,29 @@ export const WithLabelInternally = () => {
)
}

export const AsyncFetch: StoryObj<SelectPanelPropsAndCustomArgs> = {
render: ({initialLoadingType, height, componentManagesLoading}: SelectPanelPropsAndCustomArgs) => {
const [loading, setLoading] = React.useState<boolean>(true)
export const AsyncFetch: StoryObj<SelectPanelProps> = {
render: ({initialLoadingType, height}: SelectPanelProps) => {
const [selected, setSelected] = React.useState<ItemInput[]>([])
const [filteredItems, setFilteredItems] = React.useState<ItemInput[]>([])
const [open, setOpen] = useState(false)
const filterTimerId = useRef<number | null>(null)
const {safeSetTimeout, safeClearTimeout} = useSafeTimeout()

const fetchItems = (query: string) => {
setLoading(true)

if (filterTimerId.current) {
safeClearTimeout(filterTimerId.current)
}

filterTimerId.current = safeSetTimeout(() => {
setFilteredItems(items.filter(item => item.text.toLowerCase().startsWith(query.toLowerCase())))
setLoading(false)
}, 2000) as unknown as number
}

const onOpenChange = (value: boolean) => {
setLoading(true)
setOpen(value)
fetchItems('')
}

const loadingProps = {
initialLoadingType,
...(componentManagesLoading ? {} : {loading}),
}

return (
<SelectPanel
title="Select labels"
Expand All @@ -545,14 +533,13 @@ export const AsyncFetch: StoryObj<SelectPanelPropsAndCustomArgs> = {
onFilterChange={fetchItems}
showItemDividers={true}
height={height}
{...loadingProps}
initialLoadingType={initialLoadingType}
/>
)
},
args: {
initialLoadingType: 'spinner',
height: 'medium',
componentManagesLoading: true,
},
argTypes: {
initialLoadingType: {
Expand All @@ -563,10 +550,5 @@ export const AsyncFetch: StoryObj<SelectPanelPropsAndCustomArgs> = {
control: 'select',
options: ['auto', 'xsmall', 'small', 'medium', 'large', 'xlarge'],
},
componentManagesLoading: {
control: {
type: 'boolean',
},
},
},
}

0 comments on commit e2b8446

Please sign in to comment.