-
Notifications
You must be signed in to change notification settings - Fork 76
AWX Dashboard update to use Count Bar designed by UXD #824
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
Merged
jamestalton
merged 15 commits into
main
from
AWX-Dashboard-update-to-use-Count-Bar-designed-by-UXD
Sep 1, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4684e0e
AWX Dashboard update to use Count Bar designed by UXD
jamestalton b65797a
spacing tweak
jamestalton 8c0ee43
update manage view
jamestalton ee1aacd
Add links for projects from dashboard
jamestalton a6ee845
fixes
jamestalton c71c14f
Merge branch 'main' into AWX-Dashboard-update-to-use-Count-Bar-design…
jamestalton 433c646
component tests
jamestalton d82a59c
fix
jamestalton 7b3e1ed
e2e fix
jamestalton 08adfb9
Merge remote-tracking branch 'origin/main' into AWX-Dashboard-update-…
jamestalton b3b457b
fix tests
jamestalton 5c5ce3a
fix tests
jamestalton adb75a3
Merge branch 'main' into AWX-Dashboard-update-to-use-Count-Bar-design…
jamestalton 8ed15e6
fixes
jamestalton 7cc4e17
code comments
jamestalton 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 hidden or 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 hidden or 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 hidden or 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,49 +1,159 @@ | ||
| import { CardBody, Flex, FlexItem, Title } from '@patternfly/react-core'; | ||
| import { ArrowRightIcon } from '@patternfly/react-icons'; | ||
| import { ChartDonut, ChartLabel, ChartLabelProps } from '@patternfly/react-charts'; | ||
| import { CardBody, Title } from '@patternfly/react-core'; | ||
| import { CSSProperties } from 'react'; | ||
| import { Link } from 'react-router-dom'; | ||
| import { PageDashboardCard } from './PageDashboardCard'; | ||
|
|
||
| export type PageDashboardCountBarProps = { | ||
| counts: { | ||
| title: string; | ||
| count: number; | ||
| total?: number; | ||
| to: string; | ||
| counts?: { label: string; count: number; color: string; link?: string }[]; | ||
| }[]; | ||
| }; | ||
|
|
||
| export function PageDashboardCountBar(props: PageDashboardCountBarProps) { | ||
| return ( | ||
| <PageDashboardCard width="xxl" isCompact> | ||
| <CardBody> | ||
| <Flex | ||
| spaceItems={{ default: 'spaceItems2xl' }} | ||
| style={{ rowGap: 16 }} | ||
| justifyContent={{ default: 'justifyContentSpaceEvenly' }} | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexWrap: 'wrap', | ||
| justifyContent: 'space-evenly', | ||
| paddingLeft: 8, | ||
| paddingRight: 8, | ||
| gap: 16, | ||
| }} | ||
| > | ||
| {props.counts.map((item) => ( | ||
| <FlexItem key={item.title}> | ||
| <Flex | ||
| alignItems={{ default: 'alignItemsCenter' }} | ||
| spaceItems={{ default: 'spaceItemsMd' }} | ||
| > | ||
| <FlexItem> | ||
| <Title headingLevel="h3" size="xl"> | ||
| {props.counts.map((item, index) => { | ||
| const id = item.title.toLowerCase().replace(/ /g, '-'); | ||
| const total: number = | ||
| item.total ?? | ||
| item.counts?.reduce<number>((acc: number, curr) => acc + (curr.count ?? 0), 0) ?? | ||
| 0; | ||
| return ( | ||
| <div id={id} key={index} style={{ display: 'flex', gap: 12, alignItems: 'center' }}> | ||
| <Link to={item.to} style={{ color: 'var(--pf-global--text--Color)' }}> | ||
| <Title | ||
| headingLevel="h3" | ||
| size="xl" | ||
| style={{ whiteSpace: 'nowrap', textDecoration: 'none' }} | ||
| > | ||
| {item.title} | ||
| </Title> | ||
| </FlexItem> | ||
| <FlexItem> | ||
| <span style={{ fontSize: 'xx-large', lineHeight: 1 }}>{item.count}</span> | ||
| </FlexItem> | ||
| <FlexItem> | ||
| <Link to={item.to}> | ||
| <ArrowRightIcon /> | ||
| </Link> | ||
| </FlexItem> | ||
| </Flex> | ||
| </FlexItem> | ||
| ))} | ||
| </Flex> | ||
| </Link> | ||
|
|
||
| {/* if there is a total and the item has counts and counts is not undefined */} | ||
| {/* then we want to show the donut chart instead of just a count whisch is in the else */} | ||
| {/* Note: even if there is counts but total is 0 we want to just render the count */} | ||
| {total && 'counts' in item && item.counts ? ( | ||
| <> | ||
| <div | ||
| id={`${id}-chart`} | ||
| style={{ maxHeight: 64, marginTop: -4, marginBottom: -4 }} | ||
| > | ||
| <ChartDonut | ||
| title={item.counts | ||
| .reduce<number>((acc, curr) => acc + curr.count, 0) | ||
| .toString()} | ||
| titleComponent={<PageChartLabel to={item.to} />} | ||
| padding={{ top: 0, left: 0, right: 0, bottom: 0 }} | ||
| width={64} | ||
| height={64} | ||
| data={item.counts.map((count) => ({ x: count.label, y: count.count }))} | ||
| colorScale={item.counts.map((count) => count.color)} | ||
| cornerRadius={3} | ||
| allowTooltip={false} | ||
| /> | ||
| </div> | ||
| <PageChartLegend id={`${id}-legend`} legend={item.counts} /> | ||
| </> | ||
| ) : ( | ||
| // This renders the total if there are no counts or total is zero | ||
| <span style={{ fontSize: 'xx-large', lineHeight: 1 }}>{total}</span> | ||
| )} | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| </CardBody> | ||
| </PageDashboardCard> | ||
| ); | ||
| } | ||
|
|
||
| export function PageChartLegend(props: { | ||
| id: string; | ||
| legend: { label: string; count: number; color: string; link?: string }[]; | ||
| }) { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'grid', | ||
| gridTemplateColumns: 'auto auto auto', | ||
| columnGap: 6, | ||
| alignItems: 'center', | ||
| }} | ||
| > | ||
| {props.legend.map((item, index) => { | ||
| if (item.count === 0) return <></>; | ||
| return ( | ||
| <> | ||
| <div | ||
| key={index * 3 + 0} | ||
| style={{ width: 10, height: 10, backgroundColor: item.color, borderRadius: 2 }} | ||
| /> | ||
| <div | ||
| id={`${props.id}-${item.label.toLowerCase().replace(/ /g, '-')}-count`} | ||
| key={index * 3 + 1} | ||
| style={{ fontSize: 'small', textAlign: 'center' }} | ||
| > | ||
| {item.count} | ||
| </div> | ||
| <div key={index * 3 + 2} style={{ fontSize: 'small' }}> | ||
| {item.link ? ( | ||
| <Link to={item.link} style={{ textDecoration: 'none' }}> | ||
| {item.label} | ||
| </Link> | ||
| ) : ( | ||
| item.label | ||
| )} | ||
| </div> | ||
| </> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function PageChartLabel(props: ChartLabelProps & { to?: string }) { | ||
| if (props.to) { | ||
| return ( | ||
| <Link to={props.to} style={{ textDecoration: 'none' }}> | ||
| <ChartLabel | ||
| {...props} | ||
| style={ | ||
| { | ||
| ...props.style, | ||
| fill: 'var(--pf-global--link--Color)', | ||
| stroke: 'var(--pf-global--link--Color)', | ||
| } as CSSProperties | ||
| } | ||
| /> | ||
| </Link> | ||
| ); | ||
| } | ||
| return ( | ||
| <ChartLabel | ||
| {...props} | ||
| style={ | ||
| { | ||
| ...props.style, | ||
| fill: 'var(--pf-global--text--Color)', | ||
| stroke: 'var(--pf-global--text--Color)', | ||
| } as CSSProperties | ||
| } | ||
| /> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.