mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow to navigate to created resource details from notification (#4422)
navigate to created resource details from notification
This commit is contained in:
parent
44f1f38a75
commit
4f33dfdfd5
@ -95,10 +95,10 @@ export class ApiManager {
|
|||||||
return this.stores.get(this.resolveApi(api)?.apiBase) as S;
|
return this.stores.get(this.resolveApi(api)?.apiBase) as S;
|
||||||
}
|
}
|
||||||
|
|
||||||
lookupApiLink(ref: IKubeObjectRef, parentObject: KubeObject): string {
|
lookupApiLink(ref: IKubeObjectRef, parentObject?: KubeObject): string {
|
||||||
const {
|
const {
|
||||||
kind, apiVersion, name,
|
kind, apiVersion, name,
|
||||||
namespace = parentObject.getNs(),
|
namespace = parentObject?.getNs(),
|
||||||
} = ref;
|
} = ref;
|
||||||
|
|
||||||
if (!kind) return "";
|
if (!kind) return "";
|
||||||
|
|||||||
@ -370,7 +370,7 @@ async function attemptInstall(request: InstallRequest, d?: ExtendableDisposer):
|
|||||||
if (curState !== ExtensionInstallationState.IDLE) {
|
if (curState !== ExtensionInstallationState.IDLE) {
|
||||||
dispose();
|
dispose();
|
||||||
|
|
||||||
return Notifications.error(
|
return void Notifications.error(
|
||||||
<div className="flex column gaps">
|
<div className="flex column gaps">
|
||||||
<b>Extension Install Collision:</b>
|
<b>Extension Install Collision:</b>
|
||||||
<p>The <em>{name}</em> extension is currently {curState.toLowerCase()}.</p>
|
<p>The <em>{name}</em> extension is currently {curState.toLowerCase()}.</p>
|
||||||
|
|||||||
@ -35,6 +35,11 @@ import { InfoPanel } from "./info-panel";
|
|||||||
import * as resourceApplierApi from "../../../common/k8s-api/endpoints/resource-applier.api";
|
import * as resourceApplierApi from "../../../common/k8s-api/endpoints/resource-applier.api";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import logger from "../../../common/logger";
|
import logger from "../../../common/logger";
|
||||||
|
import type { KubeJsonApiData, KubeJsonApiError } from "../../../common/k8s-api/kube-json-api";
|
||||||
|
import { getDetailsUrl } from "../kube-detail-params";
|
||||||
|
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||||
|
import { prevDefault } from "../../utils";
|
||||||
|
import { navigate } from "../../navigation";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tab: DockTab;
|
tab: DockTab;
|
||||||
@ -103,28 +108,35 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
|
|
||||||
// skip empty documents
|
// skip empty documents
|
||||||
const resources = yaml.loadAll(this.data).filter(Boolean);
|
const resources = yaml.loadAll(this.data).filter(Boolean);
|
||||||
const createdResources: string[] = [];
|
|
||||||
|
|
||||||
if (resources.length === 0) {
|
if (resources.length === 0) {
|
||||||
return void logger.info("Nothing to create");
|
return void logger.info("Nothing to create");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const result of await Promise.allSettled(resources.map(resourceApplierApi.update))) {
|
const creatingResources = resources.map(async (resource: string) => {
|
||||||
if (result.status === "fulfilled") {
|
try {
|
||||||
createdResources.push(result.value.metadata.name);
|
const data: KubeJsonApiData = await resourceApplierApi.update(resource);
|
||||||
} else {
|
const { kind, apiVersion, metadata: { name, namespace }} = data;
|
||||||
Notifications.error(result.reason.toString());
|
const resourceLink = apiManager.lookupApiLink({ kind, apiVersion, name, namespace });
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createdResources.length > 0) {
|
const showDetails = () => {
|
||||||
Notifications.ok((
|
navigate(getDetailsUrl(resourceLink));
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = Notifications.ok(
|
||||||
<p>
|
<p>
|
||||||
{createdResources.length === 1 ? "Resource" : "Resources"}{" "}
|
{kind} <a onClick={prevDefault(showDetails)}>{name}</a> successfully created.
|
||||||
<b>{createdResources.join(", ")}</b> successfully created
|
</p>,
|
||||||
</p>
|
);
|
||||||
));
|
} catch (error) {
|
||||||
|
const failureReason = (error as KubeJsonApiError).reason.toString();
|
||||||
|
|
||||||
|
Notifications.error(failureReason);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.allSettled(creatingResources);
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export class Notifications extends React.Component {
|
|||||||
public elem: HTMLElement;
|
public elem: HTMLElement;
|
||||||
|
|
||||||
static ok(message: NotificationMessage) {
|
static ok(message: NotificationMessage) {
|
||||||
notificationsStore.add({
|
return notificationsStore.add({
|
||||||
message,
|
message,
|
||||||
timeout: 2_500,
|
timeout: 2_500,
|
||||||
status: NotificationStatus.OK,
|
status: NotificationStatus.OK,
|
||||||
@ -43,7 +43,7 @@ export class Notifications extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static error(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
static error(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
||||||
notificationsStore.add({
|
return notificationsStore.add({
|
||||||
message,
|
message,
|
||||||
timeout: 10_000,
|
timeout: 10_000,
|
||||||
status: NotificationStatus.ERROR,
|
status: NotificationStatus.ERROR,
|
||||||
@ -52,7 +52,7 @@ export class Notifications extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static shortInfo(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
static shortInfo(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
||||||
this.info(message, {
|
return this.info(message, {
|
||||||
timeout: 5_000,
|
timeout: 5_000,
|
||||||
...customOpts,
|
...customOpts,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user