-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(25464): Improver visual identity of the workspace * refactor(25464): export visual mapping for adapter status * refactor(25464): export zoom selectors * refactor(25464): add glue to adapter and bridge nodes * refactor(25464): add style to the minimap * refactor(25464): change icon * refactor(25464): refactor nodes to introduce skeleton rendering * refactor(25464): hide toolbars when nodes are being dragged * refactor(25464): add devices to the group when adapters are added * test(25464): fix tests * fix(25464): change theme to match data hub reactflow * refactor(25464): refactor the toolbar button group for reuse * test(25464): add tests * fix(25464): fix edge markers * test(25464): fix tests * fix(25464): fix review issues
- Loading branch information
Showing
20 changed files
with
426 additions
and
167 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
59 changes: 59 additions & 0 deletions
59
hivemq-edge/src/frontend/src/components/react-flow/ToolbarButtonGroup.spec.cy.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,59 @@ | ||
import { ReactFlowProvider } from 'reactflow' | ||
import { Icon } from '@chakra-ui/react' | ||
import { LuAlbum, LuBaby } from 'react-icons/lu' | ||
|
||
import IconButton from '@/components/Chakra/IconButton.tsx' | ||
import ToolbarButtonGroup from '@/components/react-flow/ToolbarButtonGroup.tsx' | ||
|
||
describe('ToolbarButtonGroup', () => { | ||
beforeEach(() => { | ||
cy.viewport(800, 250) | ||
}) | ||
|
||
it('should renders properly', () => { | ||
cy.mountWithProviders( | ||
<ToolbarButtonGroup> | ||
<IconButton icon={<Icon as={LuAlbum} />} aria-label="first button" onClick={cy.stub().as('button1')} /> | ||
<IconButton icon={<Icon as={LuBaby} />} aria-label="second button" onClick={cy.stub().as('button2')} /> | ||
</ToolbarButtonGroup>, | ||
{ | ||
wrapper: ({ children }) => <ReactFlowProvider>{children}</ReactFlowProvider>, | ||
} | ||
) | ||
|
||
cy.get('[role="group"]').should('have.attr', 'data-orientation', 'vertical') | ||
cy.getByAriaLabel('second button').should('be.visible') | ||
cy.getByAriaLabel('first button').should('be.visible') | ||
}) | ||
|
||
it('should renders props', () => { | ||
cy.mountWithProviders( | ||
<ToolbarButtonGroup orientation="horizontal"> | ||
<IconButton icon={<Icon as={LuAlbum} />} aria-label="first button" onClick={cy.stub().as('button1')} /> | ||
<IconButton icon={<Icon as={LuBaby} />} aria-label="second button" onClick={cy.stub().as('button2')} /> | ||
</ToolbarButtonGroup>, | ||
{ | ||
wrapper: ({ children }) => <ReactFlowProvider>{children}</ReactFlowProvider>, | ||
} | ||
) | ||
|
||
cy.get('[role="group"]').should('have.attr', 'data-orientation', 'horizontal') | ||
cy.getByAriaLabel('second button').should('be.visible') | ||
cy.getByAriaLabel('first button').should('be.visible') | ||
}) | ||
|
||
it('should be accessible', () => { | ||
cy.injectAxe() | ||
cy.mountWithProviders( | ||
<ToolbarButtonGroup> | ||
<IconButton icon={<Icon as={LuAlbum} />} aria-label="first button" /> | ||
<IconButton icon={<Icon as={LuBaby} />} aria-label="second button" /> | ||
</ToolbarButtonGroup>, | ||
{ | ||
wrapper: ({ children }) => <ReactFlowProvider>{children}</ReactFlowProvider>, | ||
} | ||
) | ||
cy.checkAccessibility() | ||
cy.percySnapshot('The login page on loading') | ||
}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
hivemq-edge/src/frontend/src/components/react-flow/ToolbarButtonGroup.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,34 @@ | ||
import { FC, useMemo } from 'react' | ||
import { useStore } from 'reactflow' | ||
import { ButtonGroup, ButtonGroupProps } from '@chakra-ui/react' | ||
|
||
// TODO[NVL] ChakraUI Theme doesn't support ButtonGroup | ||
const ToolbarButtonGroup: FC<ButtonGroupProps> = ({ children, ...rest }) => { | ||
const zoomFactor = useStore((s) => s.transform[2]) | ||
|
||
const getToolbarSize = useMemo<string>(() => { | ||
if (zoomFactor >= 1.5) return 'lg' | ||
if (zoomFactor >= 1) return 'md' | ||
if (zoomFactor >= 0.75) return 'sm' | ||
return 'xs' | ||
}, [zoomFactor]) | ||
|
||
return ( | ||
<ButtonGroup | ||
size={getToolbarSize} | ||
variant="solid" | ||
colorScheme="gray" | ||
orientation="vertical" | ||
isAttached | ||
sx={{ | ||
boxShadow: '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)', | ||
backgroundColor: 'rgba(0, 0, 0, 0.19)', | ||
}} | ||
{...rest} | ||
> | ||
{children} | ||
</ButtonGroup> | ||
) | ||
} | ||
|
||
export default ToolbarButtonGroup |
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.