-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group licenses detected in the same file (#126)
Signed-off-by: Damian Stasik <[email protected]> Co-authored-by: abstractionfactory <[email protected]>
- Loading branch information
1 parent
eea8e73
commit 7b1da90
Showing
9 changed files
with
159 additions
and
133 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
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,72 @@ | ||
import { SidebarBlock } from "../SidebarBlock"; | ||
import { Fragment, ReactNode } from "react"; | ||
import { definitions } from "@/api"; | ||
import { Icon } from "../Icon"; | ||
import { info } from "@/icons/info"; | ||
|
||
interface BlockProps { | ||
license?: definitions["LicenseList"]; | ||
} | ||
|
||
function LicenseSidebarBlockTitle() { | ||
return ( | ||
<> | ||
License | ||
<Icon | ||
title="License detection is best effort. Please see the linked license file for details." | ||
path={info} | ||
className="size-4 text-gray-700 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export function LicenseSidebarBlock(props: BlockProps) { | ||
let content: ReactNode; | ||
|
||
if (props.license === undefined) { | ||
content = <span className="flex h-em w-24 animate-pulse bg-gray-500/25" />; | ||
} else if (props.license === null || props.license.length === 0) { | ||
content = "None detected"; | ||
} else { | ||
const sortedLicenses = [...props.license].sort( | ||
(a, b) => b.confidence - a.confidence, | ||
); | ||
|
||
const groupedLicenses = Object.groupBy( | ||
sortedLicenses, | ||
(license) => license.link, | ||
); | ||
|
||
const licenses = Object.entries(groupedLicenses).map(([link, license]) => ( | ||
<li className="flex flex-col items-start gap-2" key={link}> | ||
<a | ||
href={link} | ||
className="underline" | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
{license[0].file} | ||
</a> | ||
<span className="text-gray-800 dark:text-gray-300"> | ||
{license?.map((license, index, arr) => ( | ||
<Fragment key={license.spdx}> | ||
{license.spdx} | ||
{index < arr.length - 1 && ", "} | ||
</Fragment> | ||
))} | ||
</span> | ||
</li> | ||
)); | ||
|
||
content = <ul className="flex flex-col gap-4">{licenses}</ul>; | ||
} | ||
|
||
return ( | ||
<SidebarBlock title={<LicenseSidebarBlockTitle />}>{content}</SidebarBlock> | ||
); | ||
} | ||
|
||
export function LicenceSidebarBlockSkeleton() { | ||
return <LicenseSidebarBlock />; | ||
} |
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
frontend/src/components/RepoMetadataSidebarBlock/index.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SidebarBlock } from "../SidebarBlock"; | ||
|
||
function getLinkLabel(url: string) { | ||
const match = url.match(/github\.com\/([^/]+)\/([^/]+)/); | ||
|
||
if (!match) { | ||
return null; | ||
} | ||
|
||
return `${match[1]}/${match[2]}`; | ||
} | ||
|
||
interface BlockProps { | ||
link?: string | undefined; | ||
} | ||
|
||
export function RepoSidebarBlock(props: BlockProps) { | ||
return ( | ||
<SidebarBlock title="Repository"> | ||
{props.link ? ( | ||
<a | ||
href={props.link} | ||
className="underline" | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
{getLinkLabel(props.link)} | ||
</a> | ||
) : ( | ||
<span className="flex h-em w-32 animate-pulse bg-gray-500/25" /> | ||
)} | ||
</SidebarBlock> | ||
); | ||
} | ||
|
||
export function RepoSidebarBlockSkeleton() { | ||
return <RepoSidebarBlock />; | ||
} |
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