-
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.
feat(#71): add accordion item content
- Loading branch information
Showing
9 changed files
with
373 additions
and
92 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
156 changes: 156 additions & 0 deletions
156
dashboard/src/components/Accordion/BuildAccordionContent.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { MdFolderOpen } from 'react-icons/md'; | ||
|
||
import { useMemo } from 'react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { AccordionItemBuilds } from '@/types/tree/TreeDetails'; | ||
|
||
import StatusChartMemoized, { Colors } from '../StatusChart/StatusCharts'; | ||
|
||
import LinksGroup from '../LinkGroup/LinkGroup'; | ||
|
||
import { IAccordionItems } from './Accordion'; | ||
|
||
export interface IBuildAccordionContent { | ||
testStatus: { | ||
failTests: number; | ||
errorTests: number; | ||
passTests: number; | ||
skipTests: number; | ||
}; | ||
kernelImage?: string; | ||
buildLogs?: string; | ||
kernelConfig?: string; | ||
dtb?: string; | ||
systemMap?: string; | ||
modules?: string; | ||
} | ||
|
||
export interface ILinksGroup { | ||
kernelImage?: string; | ||
buildLogs?: string; | ||
kernelConfig?: string; | ||
dtb?: string; | ||
systemMap?: string; | ||
modules?: string; | ||
} | ||
|
||
const AccordionBuildContent = ({ | ||
accordionData, | ||
}: IAccordionItems): JSX.Element => { | ||
const contentData = accordionData as AccordionItemBuilds; | ||
const chartElements = useMemo(() => { | ||
return contentData.testStatus?.passTests || | ||
contentData.testStatus?.skipTests || | ||
contentData.testStatus?.errorTests || | ||
contentData.testStatus?.failTests | ||
? [ | ||
{ | ||
value: contentData.testStatus?.passTests ?? 0, | ||
label: <FormattedMessage id="buildAccordion.testSuccess" />, | ||
color: Colors.Green, | ||
}, | ||
{ | ||
value: | ||
(contentData.testStatus?.failTests ?? 0) + | ||
(contentData.testStatus?.errorTests ?? 0), | ||
label: <FormattedMessage id="buildAccordion.testFailed" />, | ||
color: Colors.Red, | ||
}, | ||
{ | ||
value: contentData.testStatus?.skipTests ?? 0, | ||
label: <FormattedMessage id="buildAccordion.testSkiped" />, | ||
color: Colors.Gray, | ||
}, | ||
] | ||
: [ | ||
{ | ||
value: 1, | ||
label: <FormattedMessage id="global.none" />, | ||
color: Colors.Gray, | ||
showValue: false, | ||
}, | ||
]; | ||
}, [ | ||
contentData.testStatus?.errorTests, | ||
contentData.testStatus?.failTests, | ||
contentData.testStatus?.passTests, | ||
contentData.testStatus?.skipTests, | ||
]); | ||
|
||
const links = useMemo( | ||
() => [ | ||
contentData.kernelImage | ||
? { | ||
title: <FormattedMessage id="buildAccordion.kernelImage" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
linkText: <span>{`kernel/${contentData.kernelImage}`}</span>, | ||
} | ||
: undefined, | ||
contentData.kernelConfig | ||
? { | ||
title: <FormattedMessage id="buildAccordion.kernelConfig" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
link: contentData.kernelConfig, | ||
linkText: <FormattedMessage id="buildAccordion.kernelConfigPath" />, | ||
} | ||
: undefined, | ||
contentData.dtb | ||
? { | ||
title: <FormattedMessage id="buildAccordion.dtb" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
link: contentData.dtb, | ||
linkText: <FormattedMessage id="buildAccordion.dtbs" />, | ||
} | ||
: undefined, | ||
contentData.buildLogs | ||
? { | ||
title: <FormattedMessage id="buildAccordion.buildLogs" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
link: contentData.buildLogs, | ||
linkText: <FormattedMessage id="buildAccordion.logs" />, | ||
} | ||
: undefined, | ||
contentData.systemMap | ||
? { | ||
title: <FormattedMessage id="buildAccordion.systemMap" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
link: contentData.systemMap, | ||
linkText: <FormattedMessage id="buildAccordion.systemMapPath" />, | ||
} | ||
: undefined, | ||
contentData.modules | ||
? { | ||
title: <FormattedMessage id="buildAccordion.modules" />, | ||
icon: <MdFolderOpen className="text-lightBlue" />, | ||
link: contentData.modules, | ||
linkText: <FormattedMessage id="buildAccordion.modulesZip" />, | ||
} | ||
: undefined, | ||
], | ||
[ | ||
contentData.buildLogs, | ||
contentData.dtb, | ||
contentData.kernelConfig, | ||
contentData.kernelImage, | ||
contentData.modules, | ||
contentData.systemMap, | ||
], | ||
); | ||
|
||
return ( | ||
<div className="flex flex-row justify-between"> | ||
<div className="min-w-[400px]"> | ||
<StatusChartMemoized | ||
type="chart" | ||
title={<FormattedMessage id="buildAccordion.testStatus" />} | ||
elements={chartElements} | ||
/> | ||
</div> | ||
<LinksGroup links={links} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AccordionBuildContent; |
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,35 @@ | ||
import { ReactElement, useMemo } from 'react'; | ||
|
||
import LinkWithIcon from '../LinkWithIcon/LinkWithIcon'; | ||
|
||
interface ILinkGroup { | ||
links: (ILink | undefined)[]; | ||
} | ||
|
||
interface ILink { | ||
linkText: JSX.Element; | ||
title?: ReactElement; | ||
link?: string; | ||
icon?: ReactElement; | ||
} | ||
|
||
const LinksGroup = ({ links }: ILinkGroup): JSX.Element => { | ||
const linkGroup = useMemo(() => { | ||
return links?.map( | ||
link => | ||
link && ( | ||
<LinkWithIcon | ||
title={link.title} | ||
icon={link.icon} | ||
linkText={link.linkText} | ||
key={link.link} | ||
/> | ||
), | ||
); | ||
}, [links]); | ||
return ( | ||
<div className="grid grid-cols-3 gap-4 min-w-[350px]">{linkGroup}</div> | ||
); | ||
}; | ||
|
||
export default LinksGroup; |
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,27 @@ | ||
import { ReactElement } from 'react'; | ||
|
||
interface ILinkWithIcon { | ||
title?: string | ReactElement; | ||
linkText?: string | ReactElement; | ||
link?: string; | ||
icon?: ReactElement; | ||
} | ||
|
||
const LinkWithIcon = ({ | ||
title, | ||
linkText, | ||
icon, | ||
link, | ||
}: ILinkWithIcon): JSX.Element => { | ||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<span className="font-bold">{title}</span> | ||
<a className="flex flex-row gap-1 items-center" href={link}> | ||
{linkText} | ||
{icon} | ||
</a> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LinkWithIcon; |
Oops, something went wrong.