Skip to content
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

Format license block differently #177

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions frontend/src/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export interface paths {

export interface definitions {
/**
* @description Addr represents a full provider address (NAMESPACE/NAME). It currently translates to
* github.com/NAMESPACE/terraform-provider-NAME .
* @description Addr describes a module address combination of NAMESPACE-NAME-TARGETSYSTEM. This will translate to
* github.com/NAMESPACE/terraform-TARGETSYSTEM-NAME for now.
*/
Addr: { [key: string]: unknown };
/** BaseDetails is an embedded struct describing a module or a submodule. */
Expand Down Expand Up @@ -102,21 +102,25 @@ export interface definitions {
deleted_at: string;
id: definitions["IndexID"];
};
/** License describes a license found in a repository. */
/**
* @description License describes a license found in a repository. Note: the license detection is best effort. When displaying the
* license to the user, always show a link to the actual license and warn users that they have to inspect the license
* themselves.
*/
License: {
/**
* Format: float
* @description Confidence indicates how accurate the license detection is.
*/
confidence?: number;
confidence: number;
/** @description File holds the file in the repository where the license was detected. */
file?: string;
file: string;
/** @description IsCompatible signals if the license is compatible with the OpenTofu project. */
is_compatible?: boolean;
is_compatible: boolean;
/** @description Link may contain a link to the license file for humans to view. This may be empty. */
link?: string;
/** @description SPDX is the SPDX identifier for the license. */
spdx?: string;
spdx: string;
};
/** List is a list of licenses found in a repository. */
LicenseList: definitions["License"][];
Expand Down Expand Up @@ -274,9 +278,15 @@ export interface definitions {
Provider: {
addr: definitions["ProviderAddr"];
blocked_reason?: string;
canonical_addr?: definitions["ProviderAddr"];
/** @description Description is the extracted description for the provider. This may be empty. */
description: string;
is_blocked: boolean;
/**
* @description ReverseAliases contains a list of providers that are aliases of the current one. This field is the inverse of
* CanonicalAddr.
*/
reverse_aliases?: definitions["ProviderAddr"][];
/** @description Versions holds the list of versions this provider supports. */
versions: definitions["ProviderVersionDescriptor"][];
};
Expand Down
51 changes: 33 additions & 18 deletions frontend/src/components/LicenseSidebarBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ function LicenseSidebarBlockTitle() {
);
}

function getSeparator(index: number, length: number) {
let separator = "";

if (index < length - 2) {
separator = ", ";
} else if (index === length - 2) {
separator = " and ";
}

return separator;
}

export function LicenseSidebarBlock(props: BlockProps) {
let content: ReactNode;

Expand All @@ -35,27 +47,30 @@ export function LicenseSidebarBlock(props: BlockProps) {

const groupedLicenses = Object.groupBy(
sortedLicenses,
(license) => license.link,
(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 key={link} className="text-gray-800 dark:text-gray-300">
{license?.map((license, index, arr) => (
<Fragment key={license.spdx}>
{license.spdx}
{getSeparator(index, arr.length)}
</Fragment>
))}{" "}
in{" "}
{link ? (
<a
href={link}
className="text-gray-900 underline dark:text-white"
target="_blank"
rel="noreferrer noopener"
>
{license[0].file}
</a>
) : (
license[0].file
)}
</li>
));

Expand Down
Loading