-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:magento/pwa-studio into PB-220
- Loading branch information
Showing
74 changed files
with
2,190 additions
and
407 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,18 @@ | ||
# create-pwa | ||
# /packages/create-pwa/lib/ @zetlen | ||
|
||
# peregrine | ||
# /packages/peregrine/lib/ @jimbo | ||
|
||
# pwa-buildpack | ||
# /packages/pwa-buildpack/lib/ @zetlen | ||
|
||
# venia-ui | ||
# /packages/venia-ui/lib/ @jimbo | ||
/packages/venia-ui/lib/components/RichContent/PageBuilder/ @davemacaulay | ||
|
||
# upward-js | ||
# /packages/upward-js/lib/ @zetlen | ||
|
||
# upward-spec | ||
# /packages/upward-spec/suite/ @zetlen |
52 changes: 52 additions & 0 deletions
52
packages/peregrine/lib/talons/Breadcrumbs/useBreadcrumbs.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,52 @@ | ||
import { useMemo } from 'react'; | ||
import { useQuery } from '@apollo/react-hooks'; | ||
|
||
// Just incase the data is unsorted, lets sort it. | ||
const sortCrumbs = (a, b) => a.category_level > b.category_level; | ||
|
||
// Generates the path for the category. | ||
const getPath = (path, suffix) => { | ||
if (path) { | ||
return `/${category_url_path}${suffix}`; | ||
} | ||
|
||
// If there is no path this is just a dead link. | ||
return '#'; | ||
}; | ||
|
||
/** | ||
* Returns props necessary to render a Breadcrumbs component. | ||
* | ||
* @param {object} props | ||
* @param {object} props.query - the breadcrumb query | ||
* @param {string} props.categoryId - the id of the category for which to generate breadcrumbs | ||
* @return {{ currentCategory: string, isLoading: boolean, normalizedData: array }} | ||
*/ | ||
export const useBreadcrumbs = props => { | ||
const { categoryId, query } = props; | ||
|
||
const { data, loading } = useQuery(query, { | ||
variables: { category_id: categoryId } | ||
}); | ||
|
||
// When we have breadcrumb data sort and normalize it for easy rendering. | ||
const normalizedData = useMemo(() => { | ||
if (!loading && data) { | ||
const breadcrumbData = data.category.breadcrumbs; | ||
const categoryUrlSuffix = data.storeConfig.category_url_suffix; | ||
return ( | ||
breadcrumbData && | ||
breadcrumbData.sort(sortCrumbs).map(category => ({ | ||
text: category.category_name, | ||
path: getPath(category.category_url_path, categoryUrlSuffix) | ||
})) | ||
); | ||
} | ||
}, [data, loading]); | ||
|
||
return { | ||
currentCategory: (data && data.category.name) || '', | ||
isLoading: loading, | ||
normalizedData: normalizedData || [] | ||
}; | ||
}; |
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.