mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move downloadAllLogs logic to injectable
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
5090c323fb
commit
298c8a1145
@ -13,7 +13,9 @@ import type { LogTabViewModel } from "./logs-view-model";
|
|||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import openSaveFileDialogInjectable from "../../../utils/save-file.injectable";
|
import openSaveFileDialogInjectable from "../../../utils/save-file.injectable";
|
||||||
import { DownloadLogsDropdown } from "./download-logs-dropdown";
|
import { DownloadLogsDropdown } from "./download-logs-dropdown";
|
||||||
import callForLogsInjectable, { CallForLogs } from "./call-for-logs.injectable";
|
import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api";
|
||||||
|
import downloadAllLogsInjectable from "./download-all-logs.injectable";
|
||||||
|
import type { PodLogsQuery } from "../../../../common/k8s-api/endpoints";
|
||||||
|
|
||||||
export interface LogControlsProps {
|
export interface LogControlsProps {
|
||||||
model: LogTabViewModel;
|
model: LogTabViewModel;
|
||||||
@ -21,10 +23,10 @@ export interface LogControlsProps {
|
|||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
openSaveFileDialog: (filename: string, contents: BlobPart | BlobPart[], type: string) => void;
|
openSaveFileDialog: (filename: string, contents: BlobPart | BlobPart[], type: string) => void;
|
||||||
callForLogs: CallForLogs;
|
downloadAllLogs: (params: ResourceDescriptor, query: PodLogsQuery) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NonInjectedLogControls = observer(({ openSaveFileDialog, model, callForLogs }: Dependencies & LogControlsProps) => {
|
const NonInjectedLogControls = observer(({ openSaveFileDialog, model, downloadAllLogs }: Dependencies & LogControlsProps) => {
|
||||||
const tabData = model.logTabData.get();
|
const tabData = model.logTabData.get();
|
||||||
const pod = model.pod.get();
|
const pod = model.pod.get();
|
||||||
|
|
||||||
@ -45,19 +47,6 @@ const NonInjectedLogControls = observer(({ openSaveFileDialog, model, callForLog
|
|||||||
model.reloadLogs();
|
model.reloadLogs();
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadAllLogs = async () => {
|
|
||||||
const pod = model.pod.get();
|
|
||||||
|
|
||||||
if (pod) {
|
|
||||||
const logs = await callForLogs(
|
|
||||||
{ name: pod.getName(), namespace: pod.getNs() },
|
|
||||||
{ timestamps: showTimestamps, previous }
|
|
||||||
)
|
|
||||||
|
|
||||||
openSaveFileDialog(`${pod.getName()}.log`, logs, "text/plain");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const downloadLogs = () => {
|
const downloadLogs = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const fileName = pod.getName();
|
const fileName = pod.getName();
|
||||||
@ -97,7 +86,10 @@ const NonInjectedLogControls = observer(({ openSaveFileDialog, model, callForLog
|
|||||||
|
|
||||||
<DownloadLogsDropdown
|
<DownloadLogsDropdown
|
||||||
downloadVisibleLogs={downloadLogs}
|
downloadVisibleLogs={downloadLogs}
|
||||||
downloadAllLogs={downloadAllLogs}
|
downloadAllLogs={() => downloadAllLogs(
|
||||||
|
{ name: pod.getName(), namespace: pod.getNs() },
|
||||||
|
{ timestamps: showTimestamps, previous }
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -107,7 +99,7 @@ const NonInjectedLogControls = observer(({ openSaveFileDialog, model, callForLog
|
|||||||
export const LogControls = withInjectables<Dependencies, LogControlsProps>(NonInjectedLogControls, {
|
export const LogControls = withInjectables<Dependencies, LogControlsProps>(NonInjectedLogControls, {
|
||||||
getProps: (di, props) => ({
|
getProps: (di, props) => ({
|
||||||
openSaveFileDialog: di.inject(openSaveFileDialogInjectable),
|
openSaveFileDialog: di.inject(openSaveFileDialogInjectable),
|
||||||
callForLogs: di.inject(callForLogsInjectable),
|
downloadAllLogs: di.inject(downloadAllLogsInjectable),
|
||||||
...props,
|
...props,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import type { PodContainer, Pod, PodLogsQuery } from "../../../../common/k8s-api/endpoints";
|
||||||
|
import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api";
|
||||||
|
import openSaveFileDialogInjectable from "../../../utils/save-file.injectable";
|
||||||
|
import callForLogsInjectable from "./call-for-logs.injectable";
|
||||||
|
|
||||||
|
export interface PodLogsTabData {
|
||||||
|
selectedPod: Pod;
|
||||||
|
selectedContainer: PodContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadAllLogsInjectable = getInjectable({
|
||||||
|
id: "download-all-logs",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const callForLogs = di.inject(callForLogsInjectable);
|
||||||
|
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable)
|
||||||
|
|
||||||
|
return async (params: ResourceDescriptor, query: PodLogsQuery) => {
|
||||||
|
const logs = await callForLogs(params, query)
|
||||||
|
|
||||||
|
openSaveFileDialog(`${params.name}.log`, logs, "text/plain");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default downloadAllLogsInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user