-
Notifications
You must be signed in to change notification settings - Fork 706
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
Check cluster/ns in views + refactor + ui improvements #3623
Changes from 13 commits
0be7f0b
8fda9d7
08b3ced
145d152
66482be
570c9a9
fdc2458
fcd3aa1
a44869e
5403428
22c503c
0094428
5441292
026945c
c56660b
7a30d5c
f11d2ba
4eaaf26
14028b0
c014f1e
e853742
d26db2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
import { useSelector } from "react-redux"; | ||
import { IRepo, IStoreState } from "shared/types"; | ||
import { IStoreState } from "shared/types"; | ||
import * as url from "shared/url"; | ||
import { getPluginIcon, trimDescription } from "shared/utils"; | ||
import { getPluginIcon, PluginNames, trimDescription } from "shared/utils"; | ||
import placeholder from "../../placeholder.png"; | ||
import InfoCard from "../InfoCard/InfoCard"; | ||
import { IPackageCatalogItem } from "./CatalogItem"; | ||
|
||
export default function PackageCatalogItem(props: IPackageCatalogItem) { | ||
const { icon, name, repo, version, description, namespace, id } = props; | ||
const { | ||
config: { kubeappsNamespace }, | ||
} = useSelector((state: IStoreState) => state); | ||
const iconSrc = icon || placeholder; | ||
const cluster = useSelector((state: IStoreState) => state.clusters.currentCluster); | ||
const link = url.app.packages.get( | ||
const { cluster, namespace, availablePackageSummary } = props; | ||
const { config } = useSelector((state: IStoreState) => state); | ||
|
||
// A package is "global" if its cluster and namespace are the ones in which Kubeapps is installed on | ||
const isGlobal = | ||
availablePackageSummary.availablePackageRef?.context?.namespace === config.kubeappsNamespace && | ||
availablePackageSummary.availablePackageRef?.context?.cluster === config.kubeappsCluster; | ||
|
||
// Use the current cluster/namespace in the URL (passed as props here), | ||
// but, if it is global a "global" segement will be included in the generated URL. | ||
const packageViewLink = url.app.packages.get( | ||
cluster, | ||
namespace, | ||
name, | ||
repo || ({} as IRepo), | ||
kubeappsNamespace, | ||
props.plugin, | ||
availablePackageSummary.availablePackageRef!, | ||
isGlobal, | ||
); | ||
const bgIcon = getPluginIcon(props.plugin); | ||
|
||
// Historically, this tag is used to show the repository a given package is from, | ||
// but each plugin as its own way to describe the repository right now. | ||
let repositoryName; | ||
switch (availablePackageSummary.availablePackageRef?.plugin?.name) { | ||
case PluginNames.PACKAGES_HELM: | ||
repositoryName = availablePackageSummary.availablePackageRef?.identifier.split("/")[0]; | ||
break; | ||
// TODO: consider the fluxv2 plugin | ||
default: | ||
// Fallback to the plugin name | ||
repositoryName = availablePackageSummary.availablePackageRef?.plugin?.name; | ||
break; | ||
} | ||
|
||
return ( | ||
<InfoCard | ||
key={id} | ||
title={decodeURIComponent(name)} | ||
link={link} | ||
info={version || ""} | ||
icon={iconSrc} | ||
description={trimDescription(description)} | ||
tag1Content={<span>{repo.name}</span>} | ||
bgIcon={bgIcon} | ||
key={availablePackageSummary.availablePackageRef?.identifier} | ||
title={decodeURIComponent(availablePackageSummary.displayName)} | ||
link={packageViewLink} | ||
info={availablePackageSummary?.latestVersion?.pkgVersion || ""} | ||
icon={availablePackageSummary.iconUrl || placeholder} | ||
description={trimDescription(availablePackageSummary.shortDescription)} | ||
tag1Content={<span>{repositoryName}</span>} | ||
bgIcon={getPluginIcon(availablePackageSummary.availablePackageRef?.plugin)} | ||
/> | ||
); | ||
} | ||
Comment on lines
+26
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here are the changes indeed. I've used this way to extract the repo name; not sure if we would want to include it as part of the API, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me from context how all this data can be removed (or replaced with availablePackageSummary) - unless you've updated elsewhere to populate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have the chance to write some comments to ease the review, but, yep, of course, I had to update it elsewhere. Particulary, this info is being used in the
<InfoCard>
that is rendered atPackageCatalogItem.tsx
.Ideally, these components would get simplified to just an
AvailablePackageSummaryItem
, but currently we sill to differentiate between a package and an operator.Wherefore I just simply extracted the operator things (namespace, description, etc) back to the
OperatorCatalogItem
and simplify as much as I could the package item. However, I had to leave some fields (like thename: c.displayName
as they were being used in theCatalogItem
.But, at least, we are converging, step by step, in simplifying the UI logic in favor of the new package data model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. Thanks for the explanation :)