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

Enable viewing AvailablePackageDetail with flux. #3628

Merged
merged 2 commits into from
Oct 24, 2021
Merged
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
9 changes: 0 additions & 9 deletions dashboard/src/components/Catalog/PackageCatalogItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useSelector } from "react-redux";
import { IStoreState } from "shared/types";
import * as url from "shared/url";
import { getPluginIcon, PluginNames, trimDescription } from "shared/utils";
import placeholder from "../../placeholder.png";
Expand All @@ -8,20 +6,13 @@ import { IPackageCatalogItem } from "./CatalogItem";

export default function PackageCatalogItem(props: IPackageCatalogItem) {
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,
availablePackageSummary.availablePackageRef!,
isGlobal,
);

// Historically, this tag is used to show the repository a given package is from,
Expand Down
5 changes: 3 additions & 2 deletions dashboard/src/components/PackageHeader/PackageView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ afterEach(() => {
spyOnUseDispatch.mockRestore();
});

const routePathParam = `/c/${defaultProps.cluster}/ns/${defaultProps.packageNamespace}/packages/${defaultProps.plugin.name}/${defaultProps.plugin.version}/${defaultProps.id}`;
const routePath = "/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageId";
const routePathParam = `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/packages/${defaultProps.plugin.name}/${defaultProps.plugin.version}/${defaultProps.cluster}/${defaultProps.packageNamespace}/${defaultProps.id}`;
const routePath =
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId";
const history = createMemoryHistory({ initialEntries: [routePathParam] });

it("triggers the fetchAvailablePackageVersions when mounting", () => {
Expand Down
14 changes: 6 additions & 8 deletions dashboard/src/components/PackageHeader/PackageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import PackageReadme from "./PackageReadme";
interface IRouteParams {
cluster: string;
namespace: string;
global: string;
pluginName: string;
pluginVersion: string;
packageCluster: string;
packageNamespace: string;
packageId: string;
packageVersion?: string;
}
Expand All @@ -36,10 +37,11 @@ export default function PackageView() {
const {
cluster: targetCluster,
namespace: targetNamespace,
global,
packageId,
pluginName,
pluginVersion,
packageCluster,
packageNamespace,
packageVersion,
} = ReactRouter.useParams() as IRouteParams;
const {
Expand All @@ -49,12 +51,8 @@ export default function PackageView() {

const [pluginObj] = useState({ name: pluginName, version: pluginVersion } as Plugin);

const isGlobal = global === "global";

// Use the cluster/namespace from the URL unless it comes from a "global" repository.
// In that case, use the cluster/namespace from where kubeapps has been installed on
const packageCluster = isGlobal ? config.kubeappsCluster : targetCluster;
const packageNamespace = isGlobal ? config.kubeappsNamespace : targetNamespace;
const isGlobal =
packageCluster === config.kubeappsCluster && packageNamespace === config.kubeappsNamespace;

// Fetch the selected/latest version on the initial load
useEffect(() => {
Expand Down
7 changes: 2 additions & 5 deletions dashboard/src/containers/RoutesContainer/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ const privateRoutes = {
"/c/:cluster/ns/:namespace/apps/new-from-:global(global)/:pluginName/:pluginVersion/:packageId/versions/:packageVersion":
DeploymentForm,
"/c/:cluster/ns/:namespace/catalog": Catalog,
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageId": PackageView,
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageId/versions/:packageVersion":
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId":
PackageView,
"/c/:cluster/ns/:namespace/:global(global)-packages/:pluginName/:pluginVersion/:packageId":
PackageView,
"/c/:cluster/ns/:namespace/:global(global)-packages/:pluginName/:pluginVersion/:packageId/versions/:packageVersion":
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId/versions/:packageVersion":
PackageView,
"/c/:cluster/ns/:namespace/operators": OperatorsListContainer,
"/c/:cluster/ns/:namespace/operators/:operator": OperatorViewContainer,
Expand Down
9 changes: 6 additions & 3 deletions dashboard/src/shared/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ export const app = {
cluster: string,
namespace: string,
availablePackageReference: AvailablePackageReference,
isGlobal: boolean,
) => {
const pkgPluginName = availablePackageReference?.plugin?.name;
const pkgPluginVersion = availablePackageReference?.plugin?.version;
const pkgId = availablePackageReference?.identifier || "";
const globalSegment = isGlobal ? "global-packages" : "packages";
return `/c/${cluster}/ns/${namespace}/${globalSegment}/${pkgPluginName}/${pkgPluginVersion}/${encodeURIComponent(
// Some plugins may not be cluster-aware nor support multi-cluster, so
// if the returned available package ref doesn't set cluster, use the current
// one.
const pkgCluster = availablePackageReference?.context?.cluster || cluster;
const pkgNamespace = availablePackageReference?.context?.namespace;
return `/c/${cluster}/ns/${namespace}/packages/${pkgPluginName}/${pkgPluginVersion}/${pkgCluster}/${pkgNamespace}/${encodeURIComponent(
pkgId,
)}`;
},
Expand Down