Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add links
dominik-zeglenfb3fd3375d60
diff --git a/saleor/static/dashboard-next/components/RichTextEditor/Link.tsx b/saleor/static/dashboard-next/components/RichTextEditor/Link.tsxindex 5ff258481f..e5ae59ea3d 100644--- a/saleor/static/dashboard-next/components/RichTextEditor/Link.tsx+++ b/saleor/static/dashboard-next/components/RichTextEditor/Link.tsx@@ -1,10 +1,15 @@+import { ContentState } from "draft-js";import * as React from "react";interface LinkProps {children: React.ReactNode;+ contentState: ContentState;+ entityKey: string;}-const Link: React.StatelessComponent<LinkProps> = ({ children }) => (- <a>{children}</a>-);+const Link: React.StatelessComponent<LinkProps> = ({+ children,+ contentState,+ entityKey+}) => <a href={contentState.getEntity(entityKey).getData().href}>{children}</a>;export default Link;diff --git a/saleor/static/dashboard-next/components/RichTextEditor/LinkSource.tsx b/saleor/static/dashboard-next/components/RichTextEditor/LinkSource.tsxindex 9eb5887e58..70b0a9f3cc 100644--- a/saleor/static/dashboard-next/components/RichTextEditor/LinkSource.tsx+++ b/saleor/static/dashboard-next/components/RichTextEditor/LinkSource.tsx@@ -1,33 +1,41 @@-import { AtomicBlockUtils } from "draft-js";+import { EditorState, RichUtils } from "draft-js";import * as React from "react";interface LinkSourceProps {- editorState: any;+ editorState: EditorState;entityType: {type: string;};- onComplete: (updateState: any) => void;+ onComplete: (updateState: EditorState) => void;}class LinkSource extends React.Component<LinkSourceProps> {componentDidMount() {const { editorState, entityType, onComplete } = this.props;- const src = window.prompt("Link URL");+ const href = window.prompt("Link URL");- if (src) {+ if (href) {const content = editorState.getCurrentContent();const contentWithEntity = content.createEntity(entityType.type,- "IMMUTABLE",- { src }+ "MUTABLE",+ { href });const entityKey = contentWithEntity.getLastCreatedEntityKey();- const nextState = AtomicBlockUtils.insertAtomicBlock(- editorState,- entityKey,- " "+ const newEditorState = EditorState.set(editorState, {+ currentContent: contentWithEntity+ });+ const nextState = RichUtils.toggleLink(+ newEditorState,+ newEditorState.getSelection(),+ entityKey);+ // const nextState = AtomicBlockUtils.insertAtomicBlock(+ // editorState,+ // entityKey,+ // " "+ // );onComplete(nextState);} else {diff --git a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsxindex 5f66d70d3b..66530f7b28 100644--- a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx+++ b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx@@ -141,7 +141,7 @@ const RichTextEditor = withStyles(styles, { name: "RichTextEditor" })(]}entityTypes={[{- attributes: ["url"],+ attributes: ["href"],decorator: Link,source: LinkSource,type: ENTITY_TYPE.LINK