This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96b1471
commit ec67fb0
Showing
38 changed files
with
2,606 additions
and
2,657 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ jobs: | |
- name: Cypress run | ||
uses: cypress-io/[email protected] | ||
with: | ||
start: yarn dev, yarn start-console | ||
start: yarn serve-build, yarn start-console | ||
wait-on: "http://localhost:9001" | ||
browser: chrome | ||
headed: false | ||
|
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
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
37 changes: 37 additions & 0 deletions
37
src/utils/components/ActionDropdownItem/ActionDropdownItem.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,37 @@ | ||
import React, { Dispatch, FC, SetStateAction } from 'react'; | ||
|
||
import { Action, useAccessReview } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { DropdownItem } from '@patternfly/react-core'; | ||
|
||
import './action-dropdown-item.scss'; | ||
|
||
type ActionDropdownItemProps = { | ||
action: Action; | ||
setIsOpen: Dispatch<SetStateAction<boolean>>; | ||
}; | ||
|
||
const ActionDropdownItem: FC<ActionDropdownItemProps> = ({ action, setIsOpen }) => { | ||
const [actionAllowed] = useAccessReview(action?.accessReview); | ||
|
||
const handleClick = () => { | ||
if (typeof action?.cta === 'function') { | ||
action?.cta(); | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<DropdownItem | ||
data-test-id={`${action?.id}`} | ||
description={action?.description} | ||
isDisabled={action?.disabled || !actionAllowed} | ||
key={action?.id} | ||
onClick={handleClick} | ||
> | ||
{action?.label} | ||
{action?.icon && <span className="text-muted">{action.icon}</span>} | ||
</DropdownItem> | ||
); | ||
}; | ||
|
||
export default ActionDropdownItem; |
6 changes: 6 additions & 0 deletions
6
src/utils/components/ActionDropdownItem/action-dropdown-item.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,6 @@ | ||
.ActionDropdownItem { | ||
&__disabled { | ||
cursor: unset; | ||
color: var(--pf-global--disabled-color--100); | ||
} | ||
} |
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,63 @@ | ||
import React, { FC, memo, useState } from 'react'; | ||
|
||
import { Action } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Dropdown, DropdownList } from '@patternfly/react-core'; | ||
import DropdownToggle from '@utils/components/Toggles/DropdownToggle'; | ||
import KebabToggle from '@utils/components/Toggles/KebabToggle'; | ||
import { useNMStateTranslation } from '@utils/hooks/useNMStateTranslation'; | ||
|
||
import ActionDropdownItem from '../ActionDropdownItem/ActionDropdownItem'; | ||
|
||
type ActionsDropdownProps = { | ||
actions: Action[]; | ||
className?: string; | ||
id?: string; | ||
isKebabToggle?: boolean; | ||
onLazyClick?: () => void; | ||
}; | ||
|
||
const ActionsDropdown: FC<ActionsDropdownProps> = ({ | ||
actions = [], | ||
className, | ||
id, | ||
isKebabToggle, | ||
onLazyClick, | ||
}) => { | ||
const { t } = useNMStateTranslation(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const onToggle = () => { | ||
setIsOpen((prevIsOpen) => { | ||
if (onLazyClick && !prevIsOpen) onLazyClick(); | ||
|
||
return !prevIsOpen; | ||
}); | ||
}; | ||
|
||
const Toggle = isKebabToggle | ||
? KebabToggle({ isExpanded: isOpen, onClick: onToggle }) | ||
: DropdownToggle({ | ||
children: t('Actions'), | ||
isExpanded: isOpen, | ||
onClick: onToggle, | ||
}); | ||
|
||
return ( | ||
<Dropdown | ||
className={className} | ||
data-test-id={id} | ||
isOpen={isOpen} | ||
onOpenChange={(open: boolean) => setIsOpen(open)} | ||
popperProps={{ enableFlip: true, position: 'right' }} | ||
toggle={Toggle} | ||
> | ||
<DropdownList> | ||
{actions?.map((action) => ( | ||
<ActionDropdownItem action={action} key={action?.id} setIsOpen={setIsOpen} /> | ||
))} | ||
</DropdownList> | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
export default memo(ActionsDropdown); |
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
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
Oops, something went wrong.