Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor link editing wip
dominik-zeglen896cffe8338e
diff --git a/saleor/static/dashboard-next/collections/fixtures.ts b/saleor/static/dashboard-next/collections/fixtures.tsindex 5225803cd7..764de3ffdf 100644--- a/saleor/static/dashboard-next/collections/fixtures.ts+++ b/saleor/static/dashboard-next/collections/fixtures.ts@@ -1,3 +1,4 @@+import { content } from "../storybook/stories/components/RichTextEditor";import { CollectionDetails_collection } from "./types/CollectionDetails";import { CollectionList_collections_edges_node } from "./types/CollectionList";@@ -36,7 +37,7 @@ export const collection: (alt: "Alt text",url: placeholderCollectionImage},- description: "Lorem ipsum dolor sit amet",+ description: JSON.stringify(content),id: "Q29sbGVjdGlvbjox",isPublished: true,name: "Summer collection",diff --git a/saleor/static/dashboard-next/components/Anchor/Anchor.tsx b/saleor/static/dashboard-next/components/Anchor/Anchor.tsxnew file mode 100644index 0000000000..39c65d3714--- /dev/null+++ b/saleor/static/dashboard-next/components/Anchor/Anchor.tsx@@ -0,0 +1,18 @@+import * as React from "react";++export interface AnchorProps extends React.HTMLAttributes<HTMLDivElement> {+ children: (anchor: React.RefObject<HTMLDivElement>) => React.ReactNode;+}++class Anchor extends React.Component<AnchorProps> {+ anchor = React.createRef<HTMLDivElement>();++ render() {+ return (+ <div ref={this.anchor} {...this.props}>+ {this.props.children(this.anchor)}+ </div>+ );+ }+}+export default Anchor;diff --git a/saleor/static/dashboard-next/components/Anchor/index.ts b/saleor/static/dashboard-next/components/Anchor/index.tsnew file mode 100644index 0000000000..63f537245e--- /dev/null+++ b/saleor/static/dashboard-next/components/Anchor/index.ts@@ -0,0 +1,2 @@+export { default } from './Anchor';+export * from './Anchor';\ No newline at end of filediff --git a/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx b/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsxindex 47e2aef8a7..16d031e803 100644--- a/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx+++ b/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx@@ -1,20 +1,180 @@+import Button from "@material-ui/core/Button";+import ClickAwayListener from "@material-ui/core/ClickAwayListener";+import Grow from "@material-ui/core/Grow";+import IconButton from "@material-ui/core/IconButton";+import Paper from "@material-ui/core/Paper";+import Popper from "@material-ui/core/Popper";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import TextField from "@material-ui/core/TextField";+import Typography from "@material-ui/core/Typography";+import DeleteIcon from "@material-ui/icons/Delete";import { ContentState } from "draft-js";import * as React from "react";++import i18n from "../../i18n";+import Anchor from "../Anchor";+import Form from "../Form";import Link from "../Link";+import Toggle from "../Toggle";interface LinkEntityProps {children: React.ReactNode;contentState: ContentState;entityKey: string;+ onEdit: (entityKey: string) => void;+ onRemove: (entityKey: string) => void;}-const LinkEntity: React.StatelessComponent<LinkEntityProps> = ({- children,- contentState,- entityKey-}) => (- <Link href={contentState.getEntity(entityKey).getData().href}>- {children}- </Link>+const styles = (theme: Theme) =>+ createStyles({+ anchor: {+ display: "inline-block"+ },+ container: {+ alignItems: "center",+ display: "flex"+ },+ inline: {+ display: "inline-block"+ },+ root: {+ alignItems: "center",+ display: "flex",+ minHeight: 72,+ padding: `${theme.spacing.unit * 1.5}px ${theme.spacing.unit *+ 1.5}px ${theme.spacing.unit * 1.5}px ${theme.spacing.unit * 3}px`+ },+ separator: {+ backgroundColor: theme.palette.grey[300],+ display: "inline-block",+ height: 30,+ marginLeft: theme.spacing.unit * 2,+ marginRight: theme.spacing.unit,+ width: 1+ }+ });++const LinkEntity = withStyles(styles, {+ name: "LinkEntity"+})(+ ({+ classes,+ children,+ contentState,+ entityKey,+ onEdit,+ onRemove+ }: LinkEntityProps & WithStyles<typeof styles>) => (+ <Toggle>+ {(isOpened, { disable, toggle }) => (+ <>+ <Anchor className={classes.anchor}>+ {anchor => (+ <Popper+ open={isOpened}+ anchorEl={anchor.current}+ transition+ placement="bottom"+ >+ {({ TransitionProps, placement }) => (+ <Grow+ {...TransitionProps}+ style={{+ transformOrigin: placement+ }}+ >+ <Paper className={classes.root}>+ <ClickAwayListener+ onClickAway={disable}+ mouseEvent="onClick"+ >+ <Form+ initial={{+ value: contentState.getEntity(entityKey).getData()+ .href+ }}+ onSubmit={formData => onEdit(formData.value)}+ >+ {({ change, data, submit }) => (+ <Toggle>+ {(editMode, { toggle: toggleEditMode }) => (+ <div className={classes.container}>+ {editMode ? (+ <TextField+ value={data.value}+ onChange={change}+ />+ ) : (+ <Typography+ className={classes.inline}+ variant="body1"+ >+ {+ contentState+ .getEntity(entityKey)+ .getData().href+ }+ </Typography>+ )}+ <span className={classes.separator} />+ {editMode ? (+ <>+ <Button+ onClick={toggleEditMode}+ variant="flat"+ >+ {i18n.t("Cancel")}+ </Button>+ <Button+ onClick={() => onEdit(entityKey)}+ color="secondary"+ variant="flat"+ >+ {i18n.t("Save")}+ </Button>+ </>+ ) : (+ <>+ <Button+ onClick={toggleEditMode}+ color="secondary"+ variant="flat"+ >+ {i18n.t("Edit")}+ </Button>+ <IconButton+ onClick={() => onRemove(entityKey)}+ >+ <DeleteIcon color="secondary" />+ </IconButton>+ </>+ )}+ </div>+ )}+ </Toggle>+ )}+ </Form>+ </ClickAwayListener>+ </Paper>+ </Grow>+ )}+ </Popper>+ )}+ </Anchor>+ <Link+ href={contentState.getEntity(entityKey).getData().href}+ onClick={toggle}+ >+ {children}+ </Link>+ </>+ )}+ </Toggle>+ ));export default LinkEntity;diff --git a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsxindex c294822878..536abdd27c 100644--- a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx+++ b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx@@ -130,6 +130,13 @@ const styles = (theme: Theme) =>border: `1px ${theme.palette.grey[300]} solid`,display: "inline-flex",marginBottom: theme.spacing.unit+ },+ "&-block": {+ "&--blockquote": {+ borderLeft: `2px solid ${theme.palette.grey[300]}`,+ margin: 0,+ padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`+ }}}}@@ -167,6 +174,7 @@ const RichTextEditor = withStyles(styles, { name: "RichTextEditor" })({ icon: <BoldIcon />, type: INLINE_STYLE.BOLD },{ icon: <ItalicIcon />, type: INLINE_STYLE.ITALIC }]}+ enableLineBreakentityTypes={[{attributes: ["href"],diff --git a/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsxindex d4571ce591..6f2c790254 100644--- a/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx+++ b/saleor/static/dashboard-next/pages/components/PageInfo/PageInfo.tsx@@ -1,5 +1,6 @@import Card from "@material-ui/core/Card";import CardContent from "@material-ui/core/CardContent";+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";import TextField from "@material-ui/core/TextField";import * as React from "react";@@ -16,35 +17,46 @@ export interface PageInfoProps {onChange: (event: React.ChangeEvent<any>) => void;}-const PageInfo: React.StatelessComponent<PageInfoProps> = ({- data,- disabled,- errors,- onChange-}) => (- <Card>- <CardTitle title={i18n.t("General Informations")} />- <CardContent>- <TextField- disabled={disabled}- error={!!errors.title}- fullWidth- helperText={errors.title}- label={i18n.t("Title")}- name={"title" as keyof FormData}- value={data.title}- onChange={onChange}- />- <FormSpacer />- <RichTextEditor- disabled={disabled}- initial={data.content}- label={i18n.t("Content")}- name={"content" as keyof FormData}- onChange={onChange}- />- </CardContent>- </Card>+const styles = createStyles({+ root: {+ overflow: "visible"+ }+});++const PageInfo = withStyles(styles, {+ name: "PageInfo"+})(+ ({+ classes,+ data,+ disabled,+ errors,+ onChange+ }: PageInfoProps & WithStyles<typeof styles>) => (+ <Card className={classes.root}>+ <CardTitle title={i18n.t("General Informations")} />+ <CardContent>+ <TextField+ disabled={disabled}+ error={!!errors.title}+ fullWidth+ helperText={errors.title}+ label={i18n.t("Title")}+ name={"title" as keyof FormData}+ value={data.title}+ onChange={onChange}+ />+ <FormSpacer />+ <RichTextEditor+ disabled={disabled}+ initial={data.content}+ label={i18n.t("Content")}+ name={"content" as keyof FormData}+ onChange={onChange}+ />+ </CardContent>+ </Card>+ ));PageInfo.displayName = "PageInfo";export default PageInfo;