-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move disk source outside the add disk modal dialog
Signed-off-by: Aviv Turgeman <[email protected]>
- Loading branch information
Showing
17 changed files
with
215 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/utils/components/DiskModal/components/DiskSourceSelect/DiskSourceSelect.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/utils/components/DiskModal/components/DiskSourceSelect/utils/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { SourceTypes } from '@kubevirt-utils/components/DiskModal/utils/types'; | ||
|
||
export type DiskSourceOptionGroupItem = { | ||
description?: string; | ||
id: SourceTypes; | ||
label: string; | ||
label: ReactNode | string; | ||
}; | ||
|
||
export type DiskSourceOptionGroup = { | ||
description?: string; | ||
groupLabel?: string; | ||
items: DiskSourceOptionGroupItem[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/utils/components/DiskSourceFlyoutMenu/DiskSourceFlyoutMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { FC, useRef, useState } from 'react'; | ||
|
||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { | ||
Menu, | ||
MenuContainer, | ||
MenuContent, | ||
MenuItem, | ||
MenuList, | ||
MenuToggle, | ||
} from '@patternfly/react-core'; | ||
|
||
import { getDiskSourceOptionGroups } from '../DiskModal/components/DiskSourceSelect/utils/utils'; | ||
import { SourceTypes } from '../DiskModal/utils/types'; | ||
|
||
import FlyoutItem from './FlyoutItem/FlyoutItem'; | ||
|
||
export type DiskSourceFlyoutMenuProps = { | ||
className?: string; | ||
isTemplate?: boolean; | ||
onSelect: (value: SourceTypes) => void; | ||
}; | ||
|
||
const DiskSourceFlyoutMenu: FC<DiskSourceFlyoutMenuProps> = ({ | ||
className, | ||
isTemplate = false, | ||
onSelect, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const menuRef = useRef<HTMLDivElement>(null); | ||
const toggleRef = useRef<HTMLButtonElement>(null); | ||
|
||
const options = getDiskSourceOptionGroups(isTemplate); | ||
|
||
const onToggleClick = () => { | ||
setIsOpen((open) => !open); | ||
}; | ||
|
||
const onSelectSource = (value: SourceTypes) => { | ||
onSelect(value); | ||
setIsOpen(false); | ||
}; | ||
|
||
const toggle = ( | ||
<MenuToggle | ||
className={className} | ||
isExpanded={isOpen} | ||
onClick={onToggleClick} | ||
ref={toggleRef} | ||
variant="primary" | ||
> | ||
{t('Add disk')} | ||
</MenuToggle> | ||
); | ||
|
||
const menu = ( | ||
<Menu containsFlyout ref={menuRef}> | ||
<MenuContent> | ||
<MenuList> | ||
{options?.map(({ description, groupLabel, items }) => { | ||
const isFlyout = items?.length > 1; | ||
return isFlyout ? ( | ||
<MenuItem | ||
description={description} | ||
flyoutMenu={<FlyoutItem items={items} onSelect={onSelectSource} />} | ||
itemId={groupLabel} | ||
> | ||
{groupLabel} | ||
</MenuItem> | ||
) : ( | ||
<MenuItem | ||
description={description} | ||
itemId={items?.[0]?.id} | ||
onClick={() => onSelectSource(items?.[0]?.id)} | ||
> | ||
{items?.[0]?.label} | ||
</MenuItem> | ||
); | ||
})} | ||
</MenuList> | ||
</MenuContent> | ||
</Menu> | ||
); | ||
|
||
return ( | ||
<MenuContainer | ||
isOpen={isOpen} | ||
menu={menu} | ||
menuRef={menuRef} | ||
onOpenChange={(open) => setIsOpen(open)} | ||
popperProps={{ width: '250px' }} | ||
toggle={toggle} | ||
toggleRef={toggleRef} | ||
/> | ||
); | ||
}; | ||
|
||
export default DiskSourceFlyoutMenu; |
3 changes: 3 additions & 0 deletions
3
src/utils/components/DiskSourceFlyoutMenu/FlyoutItem/FlyoutItem.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.flyout-item { | ||
min-width: 250px; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/utils/components/DiskSourceFlyoutMenu/FlyoutItem/FlyoutItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { DiskSourceOptionGroupItem } from '@kubevirt-utils/components/DiskModal/components/DiskSourceSelect/utils/types'; | ||
import { Menu, MenuContent, MenuItem, MenuList } from '@patternfly/react-core'; | ||
|
||
import { DiskSourceFlyoutMenuProps } from '../DiskSourceFlyoutMenu'; | ||
|
||
import './FlyoutItem.scss'; | ||
|
||
type FlyoutItemProps = { | ||
items: DiskSourceOptionGroupItem[]; | ||
onSelect: DiskSourceFlyoutMenuProps['onSelect']; | ||
}; | ||
const FlyoutItem: FC<FlyoutItemProps> = ({ items, onSelect }) => ( | ||
<Menu className="flyout-item"> | ||
<MenuContent> | ||
<MenuList> | ||
{items?.map(({ description, id, label }) => ( | ||
<MenuItem description={description} itemId={id} key={id} onClick={() => onSelect(id)}> | ||
{label} | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</MenuContent> | ||
</Menu> | ||
); | ||
|
||
export default FlyoutItem; |
Oops, something went wrong.