mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Adding LogTabStore Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding Pod selector in logs tab Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refresh containers on pod change Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding <LogResourceSelector /> tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Adding LogTabStore tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Clearn getPodsByOwnerId method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Extracting dummy pods into mock file Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Eliminating containers and initContainers from store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Refreshing tab pods if pod amount is changed in store Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * A bit of cleaning up, fixing tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix lint newline errors Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Return getPodsByOwner() method Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Rename log tab when pod changes Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import "./log-controls.scss";
|
|
|
|
import React from "react";
|
|
import { observer } from "mobx-react";
|
|
|
|
import { Pod } from "../../api/endpoints";
|
|
import { cssNames, saveFileDialog } from "../../utils";
|
|
import { logStore } from "./log.store";
|
|
import { Checkbox } from "../checkbox";
|
|
import { Icon } from "../icon";
|
|
import { LogTabData } from "./log-tab.store";
|
|
|
|
interface Props {
|
|
tabData: LogTabData
|
|
logs: string[]
|
|
save: (data: Partial<LogTabData>) => void
|
|
reload: () => void
|
|
}
|
|
|
|
export const LogControls = observer((props: Props) => {
|
|
const { tabData, save, reload, logs } = props;
|
|
const { showTimestamps, previous } = tabData;
|
|
const since = logs.length ? logStore.getTimestamps(logs[0]) : null;
|
|
const pod = new Pod(tabData.selectedPod);
|
|
|
|
const toggleTimestamps = () => {
|
|
save({ showTimestamps: !showTimestamps });
|
|
};
|
|
|
|
const togglePrevious = () => {
|
|
save({ previous: !previous });
|
|
reload();
|
|
};
|
|
|
|
const downloadLogs = () => {
|
|
const fileName = pod.getName();
|
|
const logsToDownload = showTimestamps ? logs : logStore.logsWithoutTimestamps;
|
|
|
|
saveFileDialog(`${fileName}.log`, logsToDownload.join("\n"), "text/plain");
|
|
};
|
|
|
|
return (
|
|
<div className={cssNames("LogControls flex gaps align-center justify-space-between wrap")}>
|
|
<div className="time-range">
|
|
{since && (
|
|
<span>
|
|
Logs from{" "}
|
|
<b>{new Date(since[0]).toLocaleString()}</b>
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="flex gaps align-center">
|
|
<Checkbox
|
|
label="Show timestamps"
|
|
value={showTimestamps}
|
|
onChange={toggleTimestamps}
|
|
className="show-timestamps"
|
|
/>
|
|
<Checkbox
|
|
label="Show previous terminated container"
|
|
value={previous}
|
|
onChange={togglePrevious}
|
|
className="show-previous"
|
|
/>
|
|
<Icon
|
|
material="get_app"
|
|
onClick={downloadLogs}
|
|
tooltip="Download"
|
|
className="download-icon"
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
});
|