mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 04:00:09 -04:00
* Add visualizations project settings * Move visualizations to redash-visualizations * Delete shared components * Remove antd from deps * Remove p-r-5 from table utils * Remove visualization deps from package.json * Rename package and change its version * Test preinstall script * Update Dockerfile build for frontend * Test adding dockerignore * Update jest tests * Add step for jest tests * Include viz-lib on dev commands * User prettier v1 for now * Delete unused libs on the app * Add readme draft (to be finished) * Add getOptions to Editor * Add required libraries and finish basic example * Bump version
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import React, { useState } from "react";
|
|
import PropTypes from "prop-types";
|
|
import { markdown } from "markdown";
|
|
import Menu from "antd/lib/menu";
|
|
import HtmlContent from "@redash/viz/lib/components/HtmlContent";
|
|
import TextboxDialog from "@/components/dashboards/TextboxDialog";
|
|
import Widget from "./Widget";
|
|
|
|
function TextboxWidget(props) {
|
|
const { widget, canEdit } = props;
|
|
const [text, setText] = useState(widget.text);
|
|
|
|
const editTextBox = () => {
|
|
TextboxDialog.showModal({
|
|
text: widget.text,
|
|
}).onClose(newText => {
|
|
widget.text = newText;
|
|
setText(newText);
|
|
return widget.save();
|
|
});
|
|
};
|
|
|
|
const TextboxMenuOptions = [
|
|
<Menu.Item key="edit" onClick={editTextBox}>
|
|
Edit
|
|
</Menu.Item>,
|
|
];
|
|
|
|
if (!widget.width) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Widget {...props} menuOptions={canEdit ? TextboxMenuOptions : null} className="widget-text">
|
|
<HtmlContent className="body-row-auto scrollbox t-body p-15 markdown">{markdown.toHTML(text || "")}</HtmlContent>
|
|
</Widget>
|
|
);
|
|
}
|
|
|
|
TextboxWidget.propTypes = {
|
|
widget: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
|
canEdit: PropTypes.bool,
|
|
};
|
|
|
|
TextboxWidget.defaultProps = {
|
|
canEdit: false,
|
|
};
|
|
|
|
export default TextboxWidget;
|