-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2061 from avivtur/move-disk-source
Move disk source outside the add disk modal dialog
- Loading branch information
Showing
18 changed files
with
213 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
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
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 './components/FlyoutItem/FlyoutItem'; | ||
import { DiskSourceFlyoutMenuProps } from './utils/types'; | ||
|
||
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 onSelectSource = (value: SourceTypes) => { | ||
onSelect(value); | ||
setIsOpen(false); | ||
}; | ||
|
||
const toggle = ( | ||
<MenuToggle | ||
className={className} | ||
isExpanded={isOpen} | ||
onClick={() => setIsOpen((open) => !open)} | ||
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/components/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/components/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 '../../utils/types'; | ||
|
||
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; |
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,7 @@ | ||
import { SourceTypes } from '@kubevirt-utils/components/DiskModal/utils/types'; | ||
|
||
export type DiskSourceFlyoutMenuProps = { | ||
className?: string; | ||
isTemplate?: boolean; | ||
onSelect: (value: SourceTypes) => void; | ||
}; |
Oops, something went wrong.