文件操作 - TextPanel.tsx
返回文件管理
返回主菜单
删除本文件
文件: /usr/share/grafana/public/app/plugins/panel/text/TextPanel.tsx
编辑文件内容
// Libraries import React, { PureComponent } from 'react'; import { debounce } from 'lodash'; import { PanelProps, renderMarkdown, textUtil } from '@grafana/data'; // Utils import config from 'app/core/config'; // Types import { TextOptions } from './types'; import { stylesFactory } from '@grafana/ui'; import { css, cx } from 'emotion'; import DangerouslySetHtmlContent from 'dangerously-set-html-content'; interface Props extends PanelProps<TextOptions> {} interface State { html: string; } export class TextPanel extends PureComponent<Props, State> { constructor(props: Props) { super(props); this.state = { html: this.processContent(props.options), }; } updateHTML = debounce(() => { const html = this.processContent(this.props.options); if (html !== this.state.html) { this.setState({ html }); } }, 150); componentDidUpdate(prevProps: Props) { // Since any change could be referenced in a template variable, // This needs to process everytime (with debounce) this.updateHTML(); } prepareHTML(html: string): string { const { replaceVariables } = this.props; html = replaceVariables(html, {}, 'html'); return config.disableSanitizeHtml ? html : textUtil.sanitize(html); } prepareText(content: string): string { return this.prepareHTML( content .replace(/&/g, '&') .replace(/>/g, '>') .replace(/</g, '<') .replace(/\n/g, '<br/>') ); } prepareMarkdown(content: string): string { return this.prepareHTML(renderMarkdown(content)); } processContent(options: TextOptions): string { const { mode, content } = options; if (!content) { return ''; } if (mode === 'markdown') { return this.prepareMarkdown(content); } if (mode === 'html') { return this.prepareHTML(content); } return this.prepareText(content); } render() { const { html } = this.state; const styles = getStyles(); return <DangerouslySetHtmlContent html={html} className={cx('markdown-html', styles.content)} />; } } const getStyles = stylesFactory(() => { return { content: css` height: 100%; `, }; });
修改文件时间
将文件时间修改为当前时间的前一年
删除文件