forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating name: sublanding to guides and using DropdownMenu for type/t…
…opics filter (github#23290) * updating sublanding to guides page and using DropdownMenu primer component * fix linting error * remove unnecessary import * updating translation files * move data-testid * trying to fix test * fix browser tests * Update content/README.md Co-authored-by: Francis <15894826+francisfuzz@users.noreply.github.com> Co-authored-by: Francis <15894826+francisfuzz@users.noreply.github.com>
- Loading branch information
1 parent
5983137
commit 4ff5167
Showing
48 changed files
with
192 additions
and
219 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
2 changes: 1 addition & 1 deletion
2
components/sublanding/ArticleCard.tsx → components/guides/ArticleCard.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
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,108 @@ | ||
import React, { useEffect, useState } from 'react' | ||
|
||
import { | ||
ArticleGuide, | ||
useProductGuidesContext, | ||
} from 'components/context/ProductGuidesContext' | ||
import { useTranslation } from 'components/hooks/useTranslation' | ||
import { ArticleCard } from './ArticleCard' | ||
import { DropdownMenu } from '@primer/components' | ||
import { ItemInput } from '@primer/components/lib/ActionList/List' | ||
|
||
const PAGE_SIZE = 9 | ||
export const ArticleCards = () => { | ||
const { t } = useTranslation('product_guides') | ||
const guideTypes: Record<string, string> = t('guide_types') | ||
const { allTopics, includeGuides } = useProductGuidesContext() | ||
const [numVisible, setNumVisible] = useState(PAGE_SIZE) | ||
const [typeFilter, setTypeFilter] = useState<ItemInput | undefined>() | ||
const [topicFilter, setTopicFilter] = useState<ItemInput | undefined>() | ||
const [filteredResults, setFilteredResults] = useState<Array<ArticleGuide>>([]) | ||
|
||
useEffect(() => { | ||
setNumVisible(PAGE_SIZE) | ||
setFilteredResults( | ||
(includeGuides || []).filter((card) => { | ||
const matchesType = card.type === typeFilter?.key | ||
const matchesTopic = card.topics.some((key) => key === topicFilter?.key) | ||
return (typeFilter?.key ? matchesType : true) && (topicFilter?.key ? matchesTopic : true) | ||
}) | ||
) | ||
}, [typeFilter, topicFilter]) | ||
|
||
const isUserFiltering = typeFilter !== undefined || topicFilter !== undefined | ||
|
||
const guides = isUserFiltering ? filteredResults : includeGuides || [] | ||
|
||
const types = Object.entries(guideTypes).map(([key, val]) => { | ||
return ( | ||
{text: val, key: key} | ||
) | ||
}) as ItemInput[] | ||
|
||
types.unshift({text: t('filters.all'), key: undefined}) | ||
|
||
const topics = allTopics?.map((topic) => { | ||
return ( | ||
{text: topic, key: topic} | ||
) | ||
}) as ItemInput[] | ||
|
||
topics.unshift({text: t('filters.all'), key: undefined}) | ||
|
||
return ( | ||
<div> | ||
<label htmlFor="guide-filter-form">{t('filter_instructions')}</label> | ||
<form name="guide-filter-form" className="mt-2 mb-5 d-flex d-flex"> | ||
<div data-testid="card-filter-types"> | ||
<label htmlFor="type" className="text-uppercase f6 color-fg-muted d-block"> | ||
{t('filters.type')} | ||
</label> | ||
<DropdownMenu | ||
aria-label="guide types" | ||
data-testid="types-dropdown" | ||
placeholder={t('filters.all')} | ||
items={types} | ||
selectedItem={typeFilter} | ||
onChange={setTypeFilter} /> | ||
</div> | ||
|
||
<div data-testid="card-filter-topics" className="mx-4"> | ||
<label htmlFor="topic" className="text-uppercase f6 color-fg-muted d-block"> | ||
{t('filters.topic')} | ||
</label> | ||
<DropdownMenu | ||
aria-label="guide topics" | ||
data-testid="topics-dropdown" | ||
placeholder={t('filters.all')} | ||
items={topics} | ||
selectedItem={topicFilter} | ||
onChange={setTopicFilter} /> | ||
</div> | ||
</form> | ||
|
||
<div role="status" className="color-fg-muted"> | ||
{guides.length === 0 | ||
? t('guides_found.none') | ||
: guides.length === 1 | ||
? t('guides_found.one') | ||
: t('guides_found.multiple').replace('{n}', guides.length)} | ||
</div> | ||
|
||
<div className="d-flex flex-wrap mr-0 mr-md-n6 mr-lg-n8"> | ||
{guides.slice(0, numVisible).map((card) => { | ||
return <ArticleCard key={card.href} card={card} typeLabel={guideTypes[card.type]} /> | ||
})} | ||
</div> | ||
|
||
{guides.length > numVisible && ( | ||
<button | ||
className="col-12 mt-5 text-center text-bold color-fg-accent btn-link" | ||
onClick={() => setNumVisible(numVisible + PAGE_SIZE)} | ||
> | ||
{t('load_more')} | ||
</button> | ||
)} | ||
</div> | ||
) | ||
} |
File renamed without changes.
10 changes: 5 additions & 5 deletions
10
components/sublanding/SubLandingHero.tsx → components/guides/GuidesHero.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
File renamed without changes.
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
6 changes: 3 additions & 3 deletions
6
components/sublanding/LearningTracks.tsx → components/guides/LearningTracks.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
14 changes: 7 additions & 7 deletions
14
components/sublanding/ProductSubLanding.tsx → components/guides/ProductGuides.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
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
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.