Skip to content

Commit

Permalink
Merge branch 'master' into davidh/eng-527-dropdown-interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dherault committed Aug 24, 2022
2 parents a409d79 + 767e6e5 commit 8484391
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 120 deletions.
2 changes: 2 additions & 0 deletions www/src/components/marketplace/MarketplaceRepositories.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ function MarketplaceRepositories({ installed }) {
>
<LinkTabWrap
key="marketplace"
textValue="Marketplace"
to="/marketplace"
>
<Tab>Marketplace</Tab>
</LinkTabWrap>
<LinkTabWrap
key="installed"
textValue="Installed"
to="/installed"
>
<Tab>Installed</Tab>
Expand Down
108 changes: 68 additions & 40 deletions www/src/components/marketplace/MarketplaceSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,30 @@ import { capitalize } from '../../utils/string'

import { CATEGORIES_QUERY, TAGS_QUERY } from './queries'

function MarketplaceSidebarCheckbox({ toggled, onClick, label }) {
function AccordionWithExpanded({ children, ...props }) {
const [expanded, setExpanded] = useState(false)

return (
<Accordion
expanded={expanded}
onExpand={() => setExpanded(!expanded)}
{...props}
>
{children(expanded)}
</Accordion>
)
}

function MarketplaceSidebarCheckbox({
toggled, onClick, label, trapFocus = false,
}) {
return (
<Checkbox
mb={0.25}
small
checked={toggled}
onChange={onClick}
tabIndex={trapFocus ? 0 : -1}
>
<P
body2
Expand Down Expand Up @@ -77,42 +94,44 @@ function MarketplaceSidebar(props) {
const sortedCategories = filteredCategories.slice().sort((a, b) => a.category.localeCompare(b.category))

return (
<Accordion
<AccordionWithExpanded
ghost
defaultExpanded
title={`Categories (${sortedCategories.length})`}
borderBottom="1px solid border !important"
>
{sortedCategories.map(({ category }) => (
{expanded => sortedCategories.map(({ category }) => (
<MarketplaceSidebarCheckbox
key={category}
toggled={isToggled('category', category)}
onClick={() => handleToggle('category', category)}
label={capitalize(category)}
trapFocus={expanded}
/>
))}
</Accordion>
</AccordionWithExpanded>
)
}

function renderPublishers() {
const sortedPublishers = ['Plural']

return (
<Accordion
<AccordionWithExpanded
ghost
title={`Publisher (${sortedPublishers.length})`}
borderBottom="1px solid border !important"
>
{sortedPublishers.map(publisher => (
{expanded => sortedPublishers.map(publisher => (
<MarketplaceSidebarCheckbox
key={publisher}
toggled={isToggled('publisher', publisher)}
onClick={() => handleToggle('publisher', publisher)}
label={capitalize(publisher)}
trapFocus={expanded}
/>
))}
</Accordion>
</AccordionWithExpanded>
)
}

Expand All @@ -122,45 +141,54 @@ function MarketplaceSidebar(props) {
const resultTags = search ? fuse.search(search).map(({ item }) => item) : sortedTags.filter((x, i) => i < nDisplayedTags)

return (
<Accordion
<AccordionWithExpanded
ghost
defaultExpanded
title={`Tags (${sortedTags.length}${((nDisplayedTags < tags.length) || hasMoreTags) ? '+' : ''})`}
>
<Input
medium
width="100%"
placeholder="Filter"
value={search}
onChange={event => setSearch(event.target.value)}
endIcon={search ? (
<CloseIcon
size={8}
mt={0.2}
cursor="pointer"
onClick={() => setSearch('')}
{expanded => (
<>
<Input
medium
width="100%"
placeholder="Filter"
value={search}
onChange={event => setSearch(event.target.value)}
inputProps={{
tabIndex: expanded ? 0 : -1,
}}
endIcon={search ? (
<CloseIcon
size={8}
mt={0.2}
cursor="pointer"
onClick={() => setSearch('')}
/>
) : null}
/>
) : null}
/>
{resultTags.map(({ tag, count }) => (
<MarketplaceSidebarCheckbox
key={tag}
toggled={isToggled('tag', tag)}
onClick={() => handleToggle('tag', tag)}
label={`${tag} (${count})`}
/>
))}
{((nDisplayedTags < tags.length) || hasMoreTags) && !search && (
<A
mt={0.5}
ml="22px"
color="text-light"
onClick={handleMoreTagsClick}
>
See More +
</A>
{resultTags.map(({ tag, count }) => (
<MarketplaceSidebarCheckbox
key={tag}
toggled={isToggled('tag', tag)}
onClick={() => handleToggle('tag', tag)}
label={`${tag} (${count})`}
trapFocus={expanded}
/>
))}
{((nDisplayedTags < tags.length) || hasMoreTags) && !search && (
<A
mt={0.5}
ml="22px"
color="text-light"
onClick={handleMoreTagsClick}
tabIndex={expanded ? 0 : -1}
>
See More +
</A>
)}
</>
)}
</Accordion>
</AccordionWithExpanded>
)
}

Expand Down
12 changes: 7 additions & 5 deletions www/src/components/profile/MyProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function MyProfile() {
{DIRECTORY.map(({ label, path }) => (
<LinkTabWrap
key={path}
textValue={label}
to={path}
>
<Tab>{label}</Tab>
Expand All @@ -79,11 +80,12 @@ export function MyProfile() {
</TabList>
</ResponsiveLayoutSidenavContainer>
<ResponsiveLayoutSpacer />
<ResponsiveLayoutContentContainer>
<TabPanel stateRef={tabStateRef}>
<Outlet />
</TabPanel>
</ResponsiveLayoutContentContainer>
<TabPanel
as={<ResponsiveLayoutContentContainer />}
stateRef={tabStateRef}
>
<Outlet />
</TabPanel>
<ResponsiveLayoutSpacer />
</Flex>
)
Expand Down
15 changes: 8 additions & 7 deletions www/src/components/repos/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,14 @@ export default function Chart() {
</TabList>
</ResponsiveLayoutSidenavContainer>
<ResponsiveLayoutSpacer />
<ResponsiveLayoutContentContainer>
<TabPanel stateRef={tabStateRef}>
<Outlet
context={{ helmChart: chart, currentHelmChart: currentVersion }}
/>
</TabPanel>
</ResponsiveLayoutContentContainer>
<TabPanel
as={<ResponsiveLayoutContentContainer />}
stateRef={tabStateRef}
>
<Outlet
context={{ helmChart: chart, currentHelmChart: currentVersion }}
/>
</TabPanel>
<ResponsiveLayoutSidecarContainer width="200px">
<Box
direction="column"
Expand Down
11 changes: 6 additions & 5 deletions www/src/components/repos/Docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ export function Docker() {
</TabList>
</ResponsiveLayoutSidenavContainer>
<ResponsiveLayoutSpacer />
<ResponsiveLayoutContentContainer>
<TabPanel stateRef={tabStateRef}>
<Outlet context={{ image, filter, setFilter }} />
</TabPanel>
</ResponsiveLayoutContentContainer>
<TabPanel
as={<ResponsiveLayoutContentContainer />}
stateRef={tabStateRef}
>
<Outlet context={{ image, filter, setFilter }} />
</TabPanel>
<ResponsiveLayoutSidecarContainer width="200px">
<Codeline marginBottom="xlarge">{`docker pull ${imageName}`}</Codeline>
<DetailContainer
Expand Down
21 changes: 11 additions & 10 deletions www/src/components/repos/Terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,17 @@ export default function Terraform() {
</TabList>
</ResponsiveLayoutSidenavContainer>
<ResponsiveLayoutSpacer />
<ResponsiveLayoutContentContainer>
<TabPanel stateRef={tabStateRef}>
<Outlet
context={{
terraformChart: terraformModule,
currentTerraformChart: currentVersion,
}}
/>
</TabPanel>
</ResponsiveLayoutContentContainer>
<TabPanel
as={<ResponsiveLayoutContentContainer />}
stateRef={tabStateRef}
>
<Outlet
context={{
terraformChart: terraformModule,
currentTerraformChart: currentVersion,
}}
/>
</TabPanel>
<ResponsiveLayoutSidecarContainer width="200px">
<Box
direction="column"
Expand Down
54 changes: 40 additions & 14 deletions www/src/components/repos/common/ImagePullMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,39 @@ import { Box } from 'grommet'
import { useOutletContext } from 'react-router-dom'

import { DURATIONS, Graph } from 'components/utils/Graph'
import { useMemo } from 'react'
import { useMemo, useRef } from 'react'
import moment from 'moment'
import { PageTitle, SubTab } from 'pluralsh-design-system'
import {
PageTitle, SubTab, TabList, TabPanel,
} from 'pluralsh-design-system'
import { generateColor } from 'components/utils/colors'

function RangePicker({ duration, setDuration }) {
const tabStateRef = useRef()
const selectedKey = `${duration.offset}+${duration.step}`

return (
<Box direction="row">
{DURATIONS.map((d, i) => (
<TabList
stateRef={tabStateRef}
stateProps={{
orientation: 'horizontal',
selectedKey,
onSelectionChange: key => {
const dur = DURATIONS.find(d => key === `${d.offset}+${d.step}`)

if (dur) setDuration(dur)
},
}}
>
{DURATIONS.map(d => (
<SubTab
key={i}
active={duration.step === d.step && duration.offset === d.offset}
onClick={() => setDuration(d)}
key={`${d.offset}+${d.step}`}
textValue={d.label}
>
{d.label}
</SubTab>
))}
</Box>
</TabList>
)
}

Expand All @@ -34,7 +49,9 @@ export default function ImagePullMetrics() {
data: values.map(({ time, value }) => ({ x: moment(time).toDate(), y: value })),
color: generateColor(i),
}
}), [dockerRepository.metrics, dockerRepository.name])
}),
[dockerRepository.metrics, dockerRepository.name])
const tabStateRef = useRef()

return (
<Box
Expand All @@ -44,23 +61,32 @@ export default function ImagePullMetrics() {
>
<PageTitle heading="Pull metrics">
<RangePicker
tabStateRef={tabStateRef}
duration={{ offset: filter.offset, step: filter.precision }}
setDuration={({ offset, step, tick }) => setFilter({
...filter, offset, precision: step, tick,
...filter,
offset,
precision: step,
tick,
})}
/>
</PageTitle>
<Box
overflow={{ vertical: 'hidden' }}
height="350px"
<TabPanel
stateRef={tabStateRef}
as={(
<Box
overflow={{ vertical: 'hidden' }}
height="350px"
/>
)}
>
<Graph
data={data}
precision={filter.precision}
offset={filter.offset}
tick={filter.tick}
/>
</Box>
</TabPanel>
</Box>
)
}
Loading

0 comments on commit 8484391

Please sign in to comment.