-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor header components and add talons #1793
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3491f58
Refactor header components and add talons
sirugh 8cbcdce
delete unused test
sirugh b09cd92
Merge branch 'develop' into rugh/talon-header
sirugh 0c1cac4
Remove snap and use prettier after merge
sirugh 8d92bb8
Merge branch 'develop' into rugh/talon-header
dpatil-magento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { useCartContext } from '@magento/peregrine/lib/context/cart'; | ||
|
||
export const useCartTrigger = () => { | ||
const [{ details }, { getCartDetails, toggleCart }] = useCartContext(); | ||
const { items_qty: itemCount } = details; | ||
|
||
useEffect(() => { | ||
getCartDetails(); | ||
}, [getCartDetails]); | ||
|
||
const handleClick = useCallback(() => { | ||
toggleCart(); | ||
}, [toggleCart]); | ||
|
||
return { | ||
handleClick, | ||
itemCount | ||
}; | ||
}; |
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,20 @@ | ||
import { useCallback } from 'react'; | ||
import { useAppContext } from '@magento/peregrine/lib/context/app'; | ||
|
||
export const useHeader = () => { | ||
const [ | ||
{ hasBeenOffline, isOnline, searchOpen }, | ||
{ toggleSearch } | ||
] = useAppContext(); | ||
|
||
const handleSearchTriggerClick = useCallback(() => { | ||
toggleSearch(); | ||
}, [toggleSearch]); | ||
|
||
return { | ||
handleSearchTriggerClick, | ||
hasBeenOffline, | ||
isOnline, | ||
searchOpen | ||
}; | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/peregrine/lib/talons/Header/useNavigationTrigger.js
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,14 @@ | ||
import { useCallback } from 'react'; | ||
import { useAppContext } from '@magento/peregrine/lib/context/app'; | ||
|
||
export const useNavigationTrigger = () => { | ||
const [, { toggleDrawer }] = useAppContext(); | ||
|
||
const handleOpenNavigation = useCallback(() => { | ||
toggleDrawer('nav'); | ||
}, [toggleDrawer]); | ||
|
||
return { | ||
handleOpenNavigation | ||
}; | ||
}; |
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,10 @@ | ||
import { useCallback } from 'react'; | ||
export const useSearchTrigger = props => { | ||
const { onClick } = props; | ||
const handleClick = useCallback(() => { | ||
onClick(); | ||
}, [onClick]); | ||
return { | ||
handleClick | ||
}; | ||
}; |
13 changes: 0 additions & 13 deletions
13
packages/venia-ui/lib/components/Header/__tests__/__snapshots__/cartCounter.spec.js.snap
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
34 changes: 0 additions & 34 deletions
34
packages/venia-ui/lib/components/Header/__tests__/cartCounter.spec.js
This file was deleted.
Oops, something went wrong.
51 changes: 34 additions & 17 deletions
51
packages/venia-ui/lib/components/Header/__tests__/cartTrigger.spec.js
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,44 +1,61 @@ | ||
import React from 'react'; | ||
import { createTestInstance } from '@magento/peregrine'; | ||
import { useCartContext } from '@magento/peregrine/lib/context/cart'; | ||
|
||
import Trigger from '../cartTrigger'; | ||
import CartTrigger from '../cartTrigger'; | ||
|
||
jest.mock('@magento/peregrine/lib/context/cart', () => { | ||
const state = { | ||
details: {} | ||
}; | ||
const api = { | ||
getCartDetails: jest.fn(), | ||
toggleCart: jest.fn() | ||
}; | ||
|
||
const useCartContext = jest.fn(() => [state, api]); | ||
|
||
return { useCartContext }; | ||
}); | ||
|
||
const classes = { | ||
root: 'a' | ||
}; | ||
const getCartDetails = jest.fn(); | ||
const toggleCart = jest.fn(); | ||
|
||
test('Cart icon svg has no fill when cart is empty', () => { | ||
const props = { | ||
cart: { | ||
const [cartState, cartApi] = useCartContext(); | ||
useCartContext.mockReturnValueOnce([ | ||
{ | ||
...cartState, | ||
details: { | ||
items_qty: 0 | ||
} | ||
}, | ||
classes, | ||
getCartDetails, | ||
toggleCart | ||
}; | ||
{ | ||
...cartApi | ||
} | ||
]); | ||
|
||
const component = createTestInstance(<Trigger {...props} />); | ||
const component = createTestInstance(<CartTrigger classes={classes} />); | ||
|
||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Cart icon svg has fill and correct value when cart contains items', () => { | ||
const props = { | ||
cart: { | ||
const [cartState, cartApi] = useCartContext(); | ||
useCartContext.mockReturnValueOnce([ | ||
{ | ||
...cartState, | ||
details: { | ||
items_qty: 10 | ||
} | ||
}, | ||
classes, | ||
getCartDetails, | ||
toggleCart | ||
}; | ||
{ | ||
...cartApi | ||
} | ||
]); | ||
|
||
const component = createTestInstance(<Trigger {...props} />); | ||
const component = createTestInstance(<CartTrigger classes={classes} />); | ||
|
||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
height: 3rem; | ||
min-width: 3rem; | ||
} | ||
|
||
.counter { | ||
font-weight: 600; | ||
margin-left: 0.3rem; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused classes.