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

Feat: support download pod lods in velaux #739

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion packages/velaux-ui/src/locals/Zh/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,5 +622,6 @@
"Show Values File": "查看 Value 文件",
"Showing all projects you are permitted": "你拥有权限的所有项目",
"More": "显示更多",
"Hide": "收起"
"Hide": "收起",
basuotian marked this conversation as resolved.
Show resolved Hide resolved
"download": "下载"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Dialog, Grid, Checkbox, Dropdown, Menu } from '@alifd/next';
import { Dialog, Grid, Checkbox, Dropdown, Menu, Button, Icon } from '@alifd/next';
import React, { Component } from 'react';

import { If } from '../../../../components/If';
import Translation from '../../../../components/Translation';
import type { ContainerLogResponse, PodBase } from '../../../../interface/observation';
import { momentDate, momentShortDate } from '../../../../utils/common';
import { downloadStringFile } from '../../../../utils/utils';
import locale from '../../../../utils/locale';
import './index.less';
import { listContainerLog } from '../../../../api/observation';
Expand Down Expand Up @@ -115,6 +116,18 @@ class ContainerLog extends Component<Props, State> {
}
};

downloadLog = () => {
const { pod, containerName = '' } = this.props;
const { logs } = this.state;

let logContent: string[] = [];
logs.map((line) => {
logContent.push(line.content)
});

downloadStringFile(logContent.join("\n"), pod?.metadata.name + "-" + containerName);
};

render() {
const { logs, info, showTimestamps, autoRefresh, refreshInterval, previous } = this.state;
return (
Expand All @@ -126,7 +139,18 @@ class ContainerLog extends Component<Props, State> {
onClose={this.props.onClose}
overflowScroll
v2
title={<Translation>Container Log</Translation>}
title={
<Row style={{ width: '100%' }}>
<Col span={12}>
<Translation>Container Log</Translation>
</Col>
<Col span={12}>
<Button style={{float: "right"}} type="normal" size="small" onClick={this.downloadLog}>
<Icon type="download" />
</Button>
</Col>
</Row>
}
footer={
<Row style={{ width: '100%' }}>
<Col span={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
}
}

.next-btn {
margin-right: 8px !important;
}

.logBox {
display: flex;
flex: 1 1 0%;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Grid, Checkbox, Dropdown, Menu, Loading } from '@alifd/next';
import { Grid, Checkbox, Dropdown, Menu, Loading, Button, Icon } from '@alifd/next';
import Ansi from 'ansi-to-react';
import React, { Component, Fragment } from 'react';

import { listContainerLog } from '../../../../api/observation';
import Translation from '../../../../components/Translation';
import type { ContainerLogResponse, PodBase } from '../../../../interface/observation';
import { momentDate, momentShortDate } from '../../../../utils/common';
import { downloadStringFile } from '../../../../utils/utils';
import './index.less';
import { If } from '../../../../components/If';
import { FaEllipsisV } from 'react-icons/fa';
Expand Down Expand Up @@ -138,12 +139,27 @@ class ContainerLog extends Component<Props, State> {
}
};

downloadLog = () => {
basuotian marked this conversation as resolved.
Show resolved Hide resolved
const { pod, activeContainerName = '' } = this.props;
const { logs } = this.state;

let logContent: string[] = [];
logs.map((line) => {
logContent.push(line.content);
});

downloadStringFile(logContent.join("\n"), pod?.metadata.name + "-" + activeContainerName);
};

render() {
const { Row, Col } = Grid;
const { logs, info, showTimestamps, autoRefresh, refreshInterval, previous, loading } = this.state;
return (
<Fragment>
<div className="application-logs-actions">
<Button type="normal" size="small" onClick={this.downloadLog}>
<Icon type="download"/>
</Button>
<Checkbox checked={showTimestamps} onChange={(v) => this.setState({ showTimestamps: v })}>
<Translation className="font-bold font-size-14">Show timestamps</Translation>
</Checkbox>
Expand Down
9 changes: 9 additions & 0 deletions packages/velaux-ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,12 @@ export function getBrowserNameAndVersion() {
//return eg:ie9.0 firefox34.0 chrome37.0
return browserNV;
}

export function downloadStringFile(content: string, filename: string) {
const element = document.createElement("a");
const file = new Blob([content], {type: 'text/plain'});
element.href = URL.createObjectURL(file);
element.download = filename;
document.body.appendChild(element);
element.click();
}