Merge pull request #3055 from appsmithorg/fix/rte-newline
Added defaultText and defaultHTML properties in RTE
This commit is contained in:
commit
3b2072eeb9
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable cypress/no-unnecessary-waiting */
|
||||||
const commonlocators = require("../../../../locators/commonlocators.json");
|
const commonlocators = require("../../../../locators/commonlocators.json");
|
||||||
const queryLocators = require("../../../../locators/QueryEditor.json");
|
const queryLocators = require("../../../../locators/QueryEditor.json");
|
||||||
const dsl = require("../../../../fixtures/MultipleWidgetDsl.json");
|
const dsl = require("../../../../fixtures/MultipleWidgetDsl.json");
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
const dsl = require("../../../fixtures/ModalWidgetDsl.json");
|
const dsl = require("../../../fixtures/ModalWidgetDsl.json");
|
||||||
|
|
||||||
describe("Modal Functionality ", function() {
|
describe("Modal Functionality ", function() {
|
||||||
|
it("Collapse the tabs of Property pane", function() {
|
||||||
it("Collapse the tabs of Property pane", function()
|
|
||||||
{
|
|
||||||
// Add a modal widget from teh entity explorer
|
// Add a modal widget from teh entity explorer
|
||||||
// Click on the property Pane
|
// Click on the property Pane
|
||||||
// Select Form Type as Modal Type
|
// Select Form Type as Modal Type
|
||||||
|
|
@ -18,21 +16,17 @@ it("Collapse the tabs of Property pane", function()
|
||||||
// Close the modal
|
// Close the modal
|
||||||
// Click on the Table Action button
|
// Click on the Table Action button
|
||||||
// Ensure the modal pop up
|
// Ensure the modal pop up
|
||||||
}
|
});
|
||||||
)
|
|
||||||
|
|
||||||
it("Rename a modal", function()
|
it("Rename a modal", function() {
|
||||||
{
|
|
||||||
// Click on the entity explore
|
// Click on the entity explore
|
||||||
// Ensure modal is dispalyed to user
|
// Ensure modal is dispalyed to user
|
||||||
// Rename the modal
|
// Rename the modal
|
||||||
// Ensure the modal name is replaced in the table
|
// Ensure the modal name is replaced in the table
|
||||||
// Click on the action button
|
// Click on the action button
|
||||||
// Ensure the modal pop up
|
// Ensure the modal pop up
|
||||||
}
|
});
|
||||||
)
|
it("Convert Modal to ", function() {
|
||||||
it("Convert Modal to ", function()
|
|
||||||
{
|
|
||||||
// Click on the entity explore
|
// Click on the entity explore
|
||||||
// Ensure modal is dispalyed to user
|
// Ensure modal is dispalyed to user
|
||||||
// Add a button widget
|
// Add a button widget
|
||||||
|
|
@ -43,8 +37,5 @@ it("Convert Modal to ", function()
|
||||||
// Convert the Modal from "Alert" to "Form"
|
// Convert the Modal from "Alert" to "Form"
|
||||||
// Click on the button
|
// Click on the button
|
||||||
// Ensure a form modal is dispalyed to user
|
// Ensure a form modal is dispalyed to user
|
||||||
}
|
});
|
||||||
)
|
});
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
const dsl = require("../../../fixtures/tableWidgetDsl.json");
|
const dsl = require("../../../fixtures/tableWidgetDsl.json");
|
||||||
|
|
||||||
describe("Table functionality ", function() {
|
describe("Table functionality ", function() {
|
||||||
it("Adding background Colour to table", function()
|
it("Adding background Colour to table", function() {
|
||||||
{
|
|
||||||
// Add a table
|
// Add a table
|
||||||
// Click on the property pane
|
// Click on the property pane
|
||||||
// Scroll Styles
|
// Scroll Styles
|
||||||
|
|
@ -12,17 +11,13 @@ describe("Table functionality ", function() {
|
||||||
// Click on the setting/ Control pane of the column
|
// Click on the setting/ Control pane of the column
|
||||||
// Navigate to add background colour and Text colour
|
// Navigate to add background colour and Text colour
|
||||||
// Ensure the row colour gets overlapped on table colour
|
// Ensure the row colour gets overlapped on table colour
|
||||||
}
|
});
|
||||||
)
|
it("Collapse the tabs of Property pane", function() {
|
||||||
it("Collapse the tabs of Property pane", function()
|
|
||||||
{
|
|
||||||
// Add a table
|
// Add a table
|
||||||
// Click on the property pane
|
// Click on the property pane
|
||||||
// Collapse the General ,Action and Tab option
|
// Collapse the General ,Action and Tab option
|
||||||
}
|
});
|
||||||
)
|
it("Bind the column with same name", function() {
|
||||||
it("Bind the column with same name", function()
|
|
||||||
{
|
|
||||||
// Add a table
|
// Add a table
|
||||||
// Click on the property pane
|
// Click on the property pane
|
||||||
// Click on the Add new column
|
// Click on the Add new column
|
||||||
|
|
@ -31,11 +26,9 @@ describe("Table functionality ", function() {
|
||||||
// Add an input widget
|
// Add an input widget
|
||||||
// Bind the column with new column name
|
// Bind the column with new column name
|
||||||
// Select the row from the binded table
|
// Select the row from the binded table
|
||||||
}
|
});
|
||||||
)
|
|
||||||
|
|
||||||
it("Hide and created custom column ", function()
|
it("Hide and created custom column ", function() {
|
||||||
{
|
|
||||||
// Add a table
|
// Add a table
|
||||||
// Click on the property pane
|
// Click on the property pane
|
||||||
// Click on the Add new column
|
// Click on the Add new column
|
||||||
|
|
@ -46,8 +39,5 @@ describe("Table functionality ", function() {
|
||||||
// and observe on edit mode the table column is dispalyed
|
// and observe on edit mode the table column is dispalyed
|
||||||
// Click on deploy
|
// Click on deploy
|
||||||
// Ensure the hidden column is not displayed and custom column is disaplyed to user
|
// Ensure the hidden column is not displayed and custom column is disaplyed to user
|
||||||
}
|
});
|
||||||
)
|
});
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@
|
||||||
"reselect": "^4.0.0",
|
"reselect": "^4.0.0",
|
||||||
"scroll-into-view-if-needed": "^2.2.26",
|
"scroll-into-view-if-needed": "^2.2.26",
|
||||||
"shallowequal": "^1.1.0",
|
"shallowequal": "^1.1.0",
|
||||||
|
"showdown": "^1.9.1",
|
||||||
"smartlook-client": "^4.5.1",
|
"smartlook-client": "^4.5.1",
|
||||||
"styled-components": "^5.2.0",
|
"styled-components": "^5.2.0",
|
||||||
"styled-system": "^5.1.5",
|
"styled-system": "^5.1.5",
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import { debounce } from "lodash";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { useScript, ScriptStatus } from "utils/hooks/useScript";
|
import { useScript, ScriptStatus } from "utils/hooks/useScript";
|
||||||
|
|
||||||
import { isString } from "utils/helpers";
|
|
||||||
|
|
||||||
const StyledRTEditor = styled.div`
|
const StyledRTEditor = styled.div`
|
||||||
&& {
|
&& {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
@ -50,7 +48,7 @@ export const RichtextEditorComponent = (
|
||||||
(editorContent.current.length === 0 ||
|
(editorContent.current.length === 0 ||
|
||||||
editorContent.current !== props.defaultValue)
|
editorContent.current !== props.defaultValue)
|
||||||
) {
|
) {
|
||||||
const content = getContent();
|
const content = props.defaultValue;
|
||||||
|
|
||||||
editorInstance.setContent(content, {
|
editorInstance.setContent(content, {
|
||||||
format: "html",
|
format: "html",
|
||||||
|
|
@ -73,20 +71,20 @@ export const RichtextEditorComponent = (
|
||||||
resize: false,
|
resize: false,
|
||||||
setup: (editor: any) => {
|
setup: (editor: any) => {
|
||||||
editor.mode.set(props.isDisabled === true ? "readonly" : "design");
|
editor.mode.set(props.isDisabled === true ? "readonly" : "design");
|
||||||
const content = getContent();
|
const content = props.defaultValue;
|
||||||
editor.setContent(content, { format: "html" });
|
editor.setContent(content, { format: "html" });
|
||||||
editor
|
editor
|
||||||
.on("Change", () => {
|
.on("Change", () => {
|
||||||
onChange(editor.getContent());
|
onChange(editor.getContent({ format: "html" }));
|
||||||
})
|
})
|
||||||
.on("Undo", () => {
|
.on("Undo", () => {
|
||||||
onChange(editor.getContent());
|
onChange(editor.getContent({ format: "html" }));
|
||||||
})
|
})
|
||||||
.on("Redo", () => {
|
.on("Redo", () => {
|
||||||
onChange(editor.getContent());
|
onChange(editor.getContent({ format: "html" }));
|
||||||
})
|
})
|
||||||
.on("KeyUp", () => {
|
.on("KeyUp", () => {
|
||||||
onChange(editor.getContent());
|
onChange(editor.getContent({ format: "html" }));
|
||||||
});
|
});
|
||||||
setEditorInstance(editor);
|
setEditorInstance(editor);
|
||||||
editor.on("init", () => {
|
editor.on("init", () => {
|
||||||
|
|
@ -108,15 +106,6 @@ export const RichtextEditorComponent = (
|
||||||
};
|
};
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
/**
|
|
||||||
* get content for rich text editor
|
|
||||||
*/
|
|
||||||
const getContent = () => {
|
|
||||||
return props.defaultValue && isString(props.defaultValue)
|
|
||||||
? props.defaultValue.replace(/\n/g, "<br/>")
|
|
||||||
: props.defaultValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (status !== ScriptStatus.READY) return null;
|
if (status !== ScriptStatus.READY) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ const WidgetConfigResponse: WidgetConfigReducerState = {
|
||||||
isVisible: true,
|
isVisible: true,
|
||||||
widgetName: "RichTextEditor",
|
widgetName: "RichTextEditor",
|
||||||
isDefaultClickDisabled: true,
|
isDefaultClickDisabled: true,
|
||||||
|
inputType: "html",
|
||||||
version: 1,
|
version: 1,
|
||||||
},
|
},
|
||||||
IMAGE_WIDGET: {
|
IMAGE_WIDGET: {
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,20 @@ const renamedCanvasNameConflictMigration = (
|
||||||
return currentDSL;
|
return currentDSL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rteDefaultValueMigration = (
|
||||||
|
currentDSL: ContainerWidgetProps<WidgetProps>,
|
||||||
|
): ContainerWidgetProps<WidgetProps> => {
|
||||||
|
if (currentDSL.type === WidgetTypes.RICH_TEXT_EDITOR_WIDGET) {
|
||||||
|
currentDSL.inputType = "html";
|
||||||
|
}
|
||||||
|
currentDSL.children?.forEach((children) =>
|
||||||
|
rteDefaultValueMigration(children),
|
||||||
|
);
|
||||||
|
|
||||||
|
return currentDSL;
|
||||||
|
};
|
||||||
|
|
||||||
|
// A rudimentary transform function which updates the DSL based on its version.
|
||||||
function migrateOldChartData(currentDSL: ContainerWidgetProps<WidgetProps>) {
|
function migrateOldChartData(currentDSL: ContainerWidgetProps<WidgetProps>) {
|
||||||
if (currentDSL.type === WidgetTypes.CHART_WIDGET) {
|
if (currentDSL.type === WidgetTypes.CHART_WIDGET) {
|
||||||
if (isString(currentDSL.chartData)) {
|
if (isString(currentDSL.chartData)) {
|
||||||
|
|
@ -423,6 +437,11 @@ const transformDSL = (currentDSL: ContainerWidgetProps<WidgetProps>) => {
|
||||||
currentDSL.version = 14;
|
currentDSL.version = 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentDSL.version === 14) {
|
||||||
|
currentDSL = rteDefaultValueMigration(currentDSL);
|
||||||
|
currentDSL.version = 15;
|
||||||
|
}
|
||||||
|
|
||||||
return currentDSL;
|
return currentDSL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ import Skeleton from "components/utils/Skeleton";
|
||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
import { retryPromise } from "utils/AppsmithUtils";
|
import { retryPromise } from "utils/AppsmithUtils";
|
||||||
import withMeta, { WithMeta } from "./MetaHOC";
|
import withMeta, { WithMeta } from "./MetaHOC";
|
||||||
|
const showdown = require("showdown");
|
||||||
|
|
||||||
|
export enum RTEFormats {
|
||||||
|
MARKDOWN = "markdown",
|
||||||
|
HTML = "html",
|
||||||
|
}
|
||||||
const RichTextEditorComponent = lazy(() =>
|
const RichTextEditorComponent = lazy(() =>
|
||||||
retryPromise(() =>
|
retryPromise(() =>
|
||||||
import(
|
import(
|
||||||
|
|
@ -27,6 +32,25 @@ class RichTextEditorWidget extends BaseWidget<
|
||||||
{
|
{
|
||||||
sectionName: "General",
|
sectionName: "General",
|
||||||
children: [
|
children: [
|
||||||
|
{
|
||||||
|
propertyName: "inputType",
|
||||||
|
helpText:
|
||||||
|
"Sets the input type of the default text property in widget.",
|
||||||
|
label: "Input Type",
|
||||||
|
controlType: "DROP_DOWN",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: "Markdown",
|
||||||
|
value: "markdown",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "HTML",
|
||||||
|
value: "html",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
isBindProperty: false,
|
||||||
|
isTriggerProperty: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
propertyName: "defaultText",
|
propertyName: "defaultText",
|
||||||
helpText:
|
helpText:
|
||||||
|
|
@ -110,11 +134,16 @@ class RichTextEditorWidget extends BaseWidget<
|
||||||
};
|
};
|
||||||
|
|
||||||
getPageView() {
|
getPageView() {
|
||||||
|
let defaultValue = this.props.text || "";
|
||||||
|
if (this.props.inputType === RTEFormats.MARKDOWN) {
|
||||||
|
const converter = new showdown.Converter();
|
||||||
|
defaultValue = converter.makeHtml(defaultValue);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<Skeleton />}>
|
<Suspense fallback={<Skeleton />}>
|
||||||
<RichTextEditorComponent
|
<RichTextEditorComponent
|
||||||
onValueChange={this.onValueChange}
|
onValueChange={this.onValueChange}
|
||||||
defaultValue={this.props.text || ""}
|
defaultValue={defaultValue}
|
||||||
widgetId={this.props.widgetId}
|
widgetId={this.props.widgetId}
|
||||||
placeholder={this.props.placeholder}
|
placeholder={this.props.placeholder}
|
||||||
key={this.props.widgetId}
|
key={this.props.widgetId}
|
||||||
|
|
@ -132,7 +161,8 @@ class RichTextEditorWidget extends BaseWidget<
|
||||||
|
|
||||||
export interface RichTextEditorWidgetProps extends WidgetProps, WithMeta {
|
export interface RichTextEditorWidgetProps extends WidgetProps, WithMeta {
|
||||||
defaultText?: string;
|
defaultText?: string;
|
||||||
text?: string;
|
text: string;
|
||||||
|
inputType: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
onTextChange?: string;
|
onTextChange?: string;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
|
|
|
||||||
2560
app/client/yarn.lock
2560
app/client/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user