Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Restyle timeline widget
dominik-zeglen4ec2166961d2
diff --git a/saleor/static/dashboard-next/components/Debounce.tsx b/saleor/static/dashboard-next/components/Debounce.tsxindex 43675d5b19..228a2e3c6e 100644--- a/saleor/static/dashboard-next/components/Debounce.tsx+++ b/saleor/static/dashboard-next/components/Debounce.tsx@@ -8,6 +8,7 @@ export interface DebounceProps {) => React.ReactElement<any>)| React.ReactNode;submit: (event: React.FormEvent<any>) => void;+ time?: number;}export interface DebounceState {timer: any | null;@@ -24,7 +25,7 @@ export class Debounce extends React.Component<DebounceProps, DebounceState> {clearTimeout(timer);}this.setState({- timer: setTimeout(this.props.submit, 200)+ timer: setTimeout(this.props.submit, this.props.time || 200)});this.props.change(event);};diff --git a/saleor/static/dashboard-next/components/Hr.tsx b/saleor/static/dashboard-next/components/Hr.tsxnew file mode 100644index 0000000000..e3b53ac959--- /dev/null+++ b/saleor/static/dashboard-next/components/Hr.tsx@@ -0,0 +1,16 @@+import { withStyles } from "@material-ui/core/styles";+import * as React from "react";++const decorate = withStyles({+ root: {+ backgroundColor: "#eeeeee",+ border: "none",+ display: "block" as "block",+ height: 1,+ margin: 0,+ width: "100%"+ }+});+export const Hr = decorate(({ classes }) => <hr className={classes.root} />);+Hr.displayName = "Hr";+export default Hr;diff --git a/saleor/static/dashboard-next/components/Timeline/Timeline.tsx b/saleor/static/dashboard-next/components/Timeline/Timeline.tsxindex ac0f2984b3..da6a3be23f 100644--- a/saleor/static/dashboard-next/components/Timeline/Timeline.tsx+++ b/saleor/static/dashboard-next/components/Timeline/Timeline.tsx@@ -1,41 +1,17 @@import Avatar from "@material-ui/core/Avatar";import Button from "@material-ui/core/Button";-import Card from "@material-ui/core/Card";import CardActions from "@material-ui/core/CardActions";import CardContent from "@material-ui/core/CardContent";-import * as colors from "@material-ui/core/colors";+import deepPurple from "@material-ui/core/colors/deepPurple";import grey from "@material-ui/core/colors/grey";-import ExpansionPanel from "@material-ui/core/ExpansionPanel";-import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";-import ExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";import { withStyles } from "@material-ui/core/styles";import TextField from "@material-ui/core/TextField";-import Typography from "@material-ui/core/Typography";-import ExpandMoreIcon from "@material-ui/icons/ExpandMore";import PersonIcon from "@material-ui/icons/Person";import * as classNames from "classnames";-import * as CRC from "crc-32";import * as React from "react";import i18n from "../../i18n";-import DateFormatter from "../DateFormatter";-interface TimelineNodeProps {- date: string;- title: string;- amount: number | null;- email: string | null;- emailType: string | null;- type: string;- quantity: number | null;-}-interface TimelineNoteProps {- date: string;- message: string | null;- user: {- email: string;- };-}interface TimelineAddNoteProps {message: string;onChange(event: React.ChangeEvent<any>);@@ -57,52 +33,6 @@ const decorate = withStyles(theme => ({cardActionsExpanded: {maxHeight: theme.spacing.unit * 6},- noExpander: {- marginLeft: theme.spacing.unit * 3- },- noExpanderNodeDate: {- position: "absolute" as "absolute",- right: theme.spacing.unit * 7- },- nodeDate: {- position: "absolute" as "absolute",- right: theme.spacing.unit * 3- },- nodeDot: {- backgroundColor: theme.palette.secondary.main,- borderColor: grey[300],- borderRadius: "100%",- borderStyle: "solid",- borderWidth: 2,- height: theme.spacing.unit * 2,- left: -theme.spacing.unit * 4 - 1,- position: "relative" as "relative",- width: theme.spacing.unit * 2- },- nodeRoot: {- "&:last-child:after": {- background: theme.palette.background.default,- content: "''",- height: `calc(50% - ${theme.spacing.unit}px)`,- left: `${-theme.spacing.unit * 3 - 2}px`,- position: "absolute" as "absolute",- top: `calc(50% + ${theme.spacing.unit}px)`,- width: "2px"- },- alignItems: "center",- display: "flex",- marginBottom: theme.spacing.unit * 3,- minHeight: theme.spacing.unit * 8,- position: "relative" as "relative",- width: "100%"- },- noteContent: {- paddingLeft: theme.spacing.unit * 10.5- },- noteDate: {- position: "absolute" as "absolute",- right: theme.spacing.unit * 7- },noteRoot: {left: -theme.spacing.unit * 8.5 - 1,marginBottom: theme.spacing.unit * 3,@@ -113,17 +43,6 @@ const decorate = withStyles(theme => ({alignItems: "center" as "center",display: "flex" as "flex"},- noteUser: {- marginLeft: theme.spacing.unit * 5.5- },- panel: {- "&:before": {- display: "none"- },- background: "none",- width: "100%"- },-root: {borderColor: grey[300],borderStyle: "solid",@@ -132,80 +51,18 @@ const decorate = withStyles(theme => ({paddingLeft: theme.spacing.unit * 3}}));-const palette = [- colors.amber,- colors.blue,- colors.cyan,- colors.deepOrange,- colors.deepPurple,- colors.green,- colors.indigo,- colors.lightBlue,- colors.lightGreen,- colors.lime,- colors.orange,- colors.pink,- colors.purple,- colors.red,- colors.teal,- colors.yellow-].map(color => color[500]);export const Timeline = decorate(({ classes, children }) => (<div className={classes.root}>{children}</div>));-export const TimelineNode = decorate<TimelineNodeProps>(- ({ classes, date, children, title }) => (- <div className={classes.nodeRoot}>- <span className={classes.nodeDot} />- {children ? (- <ExpansionPanel className={classes.panel} elevation={0}>- <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>- <Typography>{title}</Typography>- <Typography className={classes.nodeDate}>- <DateFormatter date={date} />- </Typography>- </ExpansionPanelSummary>- <ExpansionPanelDetails>- <Typography>{children}</Typography>- </ExpansionPanelDetails>- </ExpansionPanel>- ) : (- <>- <Typography className={classes.noExpander}>{title}</Typography>- <Typography className={classes.noExpanderNodeDate}>- <DateFormatter date={date} />- </Typography>- </>- )}- </div>- )-);-export const TimelineNote = decorate<TimelineNoteProps>(- ({ classes, date, user, message }) => (- <Card className={classes.noteRoot}>- <CardContent className={classes.noteTitle}>- <Avatar- style={{ background: palette[CRC.str(user.email) % palette.length] }}- >- <PersonIcon />- </Avatar>- <Typography className={classes.noteUser}>{user.email}</Typography>- <Typography className={classes.noteDate}>- <DateFormatter date={date} />- </Typography>- </CardContent>- <CardContent>- <Typography className={classes.noteContent}>{message}</Typography>- </CardContent>- </Card>- )-);export const TimelineAddNote = decorate<TimelineAddNoteProps>(({ classes, message, onChange, onSubmit }) => (<div className={classes.noteRoot}><CardContent className={classes.noteTitle}>- <Avatar style={{ background: palette[0] }} className={classes.avatar}>+ <Avatar+ style={{ background: deepPurple[500] }}+ className={classes.avatar}+ ><PersonIcon /></Avatar><TextFielddiff --git a/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx b/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsxnew file mode 100644index 0000000000..d6e7b8989c--- /dev/null+++ b/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx@@ -0,0 +1,94 @@+import grey from "@material-ui/core/colors/grey";+import ExpansionPanel from "@material-ui/core/ExpansionPanel";+import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";+import ExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";+import { withStyles } from "@material-ui/core/styles";+import Typography from "@material-ui/core/Typography";+import ExpandMoreIcon from "@material-ui/icons/ExpandMore";+import * as React from "react";++import DateFormatter from "../DateFormatter";++interface TimelineEventProps {+ date: string;+ title: string;+}++const decorate = withStyles(theme => ({+ date: {+ position: "absolute" as "absolute",+ right: theme.spacing.unit * 3+ },+ dot: {+ backgroundColor: theme.palette.primary.main,+ borderColor: grey[300],+ borderRadius: "100%",+ borderStyle: "solid",+ borderWidth: 2,+ height: 16,+ left: -33,+ position: "absolute" as "absolute",+ top: 19,+ width: 16+ },+ noExpander: {+ alignItems: "center" as "center",+ display: "flex" as "flex",+ justifyContent: "space-between" as "space-between",+ marginBottom: theme.spacing.unit,+ marginLeft: theme.spacing.unit,+ width: "100%"+ },+ panel: {+ "&:before": {+ display: "none"+ },+ background: "none",+ width: "100%"+ },+ root: {+ "&:last-child:after": {+ background: theme.palette.background.default,+ content: "''",+ height: `calc(50% - ${theme.spacing.unit}px)`,+ left: `${-theme.spacing.unit * 3 - 2}px`,+ position: "absolute" as "absolute",+ top: `calc(50% + ${theme.spacing.unit}px)`,+ width: "2px"+ },+ alignItems: "center",+ display: "flex",+ marginBottom: theme.spacing.unit * 3,+ minHeight: theme.spacing.unit * 8,+ position: "relative" as "relative",+ width: "100%"+ }+}));++export const TimelineEvent = decorate<TimelineEventProps>(+ ({ classes, children, date, title }) => (+ <div className={classes.root}>+ <span className={classes.dot} />+ {children ? (+ <ExpansionPanel className={classes.panel} elevation={0}>+ <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>+ <Typography>{title}</Typography>+ <div className={classes.date}>+ <DateFormatter date={date} />+ </div>+ </ExpansionPanelSummary>+ <ExpansionPanelDetails>+ <Typography>{children}</Typography>+ </ExpansionPanelDetails>+ </ExpansionPanel>+ ) : (+ <div className={classes.noExpander}>+ <Typography>{title}</Typography>+ <DateFormatter date={date} />+ </div>+ )}+ </div>+ )+);+TimelineEvent.displayName = "TimelineEvent";+export default TimelineEvent;diff --git a/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx b/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsxnew file mode 100644index 0000000000..446b608972--- /dev/null+++ b/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx@@ -0,0 +1,98 @@+import Avatar from "@material-ui/core/Avatar";+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import * as colors from "@material-ui/core/colors";+import { withStyles } from "@material-ui/core/styles";+import Typography from "@material-ui/core/Typography";+import PersonIcon from "@material-ui/icons/Person";+import * as CRC from "crc-32";+import * as React from "react";++import DateFormatter from "../DateFormatter";+import Hr from "../Hr";++interface TimelineNoteProps {+ date: string;+ message: string | null;+ user: {+ email: string;+ };+}++const palette = [+ colors.amber,+ colors.blue,+ colors.cyan,+ colors.deepOrange,+ colors.deepPurple,+ colors.green,+ colors.indigo,+ colors.lightBlue,+ colors.lightGreen,+ colors.lime,+ colors.orange,+ colors.pink,+ colors.purple,+ colors.red,+ colors.teal,+ colors.yellow+].map(color => color[500]);++const decorate = withStyles(theme => ({+ avatar: {+ left: -45,+ position: "absolute" as "absolute",+ top: 0+ },+ card: {+ marginBottom: theme.spacing.unit * 3,+ marginLeft: theme.spacing.unit * 3,+ position: "relative" as "relative"+ },+ cardContent: {+ "&:last-child": {+ paddingBottom: 16+ }+ },+ content: {+ marginTop: theme.spacing.unit * 2+ },+ root: {+ position: "relative" as "relative"+ },+ title: {+ alignItems: "center" as "center",+ display: "flex" as "flex",+ justifyContent: "space-between" as "space-between",+ marginBottom: theme.spacing.unit+ }+}));+export const TimelineNote = decorate<TimelineNoteProps>(+ ({ classes, date, user, message }) => (+ <div className={classes.root}>+ <Avatar+ className={classes.avatar}+ style={{ background: palette[CRC.str(user.email) % palette.length] }}+ >+ <PersonIcon />+ </Avatar>+ <Card className={classes.card}>+ <CardContent className={classes.cardContent}>+ <div className={classes.title}>+ <Typography>{user.email}</Typography>+ <DateFormatter date={date} />+ </div>+ <Hr />+ <Typography+ className={classes.content}+ dangerouslySetInnerHTML={{+ __html: message.replace("\n", "<br />")+ }}+ />+ </CardContent>+ </Card>+ </div>+ )+);+TimelineNote.displayName = "TimelineNote";+export default TimelineNote;diff --git a/saleor/static/dashboard-next/components/Timeline/index.ts b/saleor/static/dashboard-next/components/Timeline/index.tsindex a468f26d94..8c38072058 100644--- a/saleor/static/dashboard-next/components/Timeline/index.ts+++ b/saleor/static/dashboard-next/components/Timeline/index.ts@@ -1,2 +1,4 @@export { default } from "./Timeline";export * from "./Timeline";+export * from "./TimelineEvent";+export * from "./TimelineNote";diff --git a/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx b/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsxindex 3490cfcff7..63aff0a69f 100644--- a/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx@@ -8,30 +8,89 @@ import Skeleton from "../../../components/Skeleton";import {Timeline,TimelineAddNote,- TimelineNode,+ TimelineEvent,TimelineNote-} from "../../../components/Timeline/Timeline";+} from "../../../components/Timeline";import i18n from "../../../i18n";import { OrderEvents } from "../../../types/globalTypes";+import { OrderDetails_order_events } from "../../types/OrderDetails";export interface FormData {message: string;}+const getEventMessage = (event: OrderDetails_order_events) => {+ switch (event.type) {+ case OrderEvents.CANCELED:+ return i18n.t("Order has been cancelled", {+ context: "order history message"+ });+ case OrderEvents.EMAIL_SENT:+ return i18n.t("An e-mail has been sent to customer", {+ context: "order history message"+ });+ case OrderEvents.FULFILLMENT_CANCELED:+ return i18n.t("Fulfillment had been cancelled", {+ context: "order history message"+ });+ case OrderEvents.FULFILLMENT_FULFILLED_ITEMS:+ return i18n.t("Filfilled {{ quantity }} items", {+ context: "order history message",+ quantity: event.quantity+ });+ case OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:+ return i18n.t("Restocked {{ quantity }} items", {+ context: "order history message",+ quantity: event.quantity+ });+ case OrderEvents.ORDER_FULLY_PAID:+ return i18n.t("Order has been fully paid", {+ context: "order history message"+ });+ case OrderEvents.ORDER_MARKED_AS_PAID:+ return i18n.t("Marked order as paid", {+ context: "order history message"+ });+ case OrderEvents.OTHER:+ return event.message;+ case OrderEvents.OVERSOLD_ITEMS:+ return i18n.t("Oversold {{ quantity }} items", {+ context: "order history message",+ quantity: event.quantity+ });+ case OrderEvents.PAYMENT_CAPTURED:+ return i18n.t("Payment has been captured", {+ context: "order history message"+ });+ case OrderEvents.PAYMENT_REFUNDED:+ return i18n.t("Payment has been refunded", {+ context: "order history message"+ });+ case OrderEvents.PAYMENT_RELEASED:+ return i18n.t("Payment has been released", {+ context: "order history message"+ });+ case OrderEvents.PLACED:+ return i18n.t("Order has been placed", {+ context: "order history message"+ });+ case OrderEvents.PLACED_FROM_DRAFT:+ return i18n.t("Order has been created from draft", {+ context: "order history message"+ });+ case OrderEvents.TRACKING_UPDATED:+ return i18n.t("Updated fulfillment group's tracking number", {+ context: "order history message"+ });+ case OrderEvents.UPDATED:+ return i18n.t("Order has been updated", {+ context: "order history message"+ });+ }+};+interface OrderHistoryProps {- history?: Array<{- amount?: number;- date: string;- email?: string;- emailType?: string;- id: string;- message?: string;- quantity?: number;- type: OrderEvents;- user: {- email: string;- };- }>;+ history: OrderDetails_order_events[];onNoteAdd: (data: FormData) => void;}@@ -74,20 +133,19 @@ const OrderHistory = decorate<OrderHistoryProps>();}return (- <TimelineNode- amount={event.amount}- email={event.email}- emailType={event.emailType}- quantity={event.quantity}- type={event.type}+ <TimelineEventdate={event.date}- title={event.message}+ title={getEventMessage(event)}key={event.id}>- <Typography variant="caption">- {i18n.t("by {{ user }}", { user: event.user.email })}- </Typography>- </TimelineNode>+ {event.user && (+ <Typography variant="caption">+ {i18n.t("by {{ user }}", {+ user: event.user.email+ })}+ </Typography>+ )}+ </TimelineEvent>);})}</Timeline>diff --git a/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx b/saleor/static/dashboard-next/orders/containers/OrderOperations.tsxindex 976d6eed84..ec343e7ef8 100644--- a/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx+++ b/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx@@ -208,13 +208,14 @@ const OrderOperations: React.StatelessComponent<OrderOperationsProps> = ({.orderRefund.errors,[]),- ...maybe(+ ...(maybe(() =>addNote.data- .orderAddNote- .errors,- []- ),+ .orderAddNote.errors+ )+ ? addNote.data+ .orderAddNote.errors+ : []),...maybe(() =>update.datadiff --git a/saleor/static/dashboard-next/storybook/stories/components/Timeline.tsx b/saleor/static/dashboard-next/storybook/stories/components/Timeline.tsxindex 097801a934..de1f05f257 100644--- a/saleor/static/dashboard-next/storybook/stories/components/Timeline.tsx+++ b/saleor/static/dashboard-next/storybook/stories/components/Timeline.tsx@@ -2,7 +2,7 @@ import { storiesOf } from "@storybook/react";import * as React from "react";import Timeline, {- TimelineNode,+ TimelineEvent,TimelineNote} from "../../../components/Timeline";import Decorator from "../../Decorator";@@ -11,30 +11,15 @@ storiesOf("Generics / Timeline", module).addDecorator(Decorator).add("default", () => (<Timeline>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}+ <TimelineEventdate="2018-05-07T16:58:02+00:00"title="Expansion panel 1"/>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}+ <TimelineEventdate="2018-05-07T16:48:02+00:00"title="Expansion panel 2"/>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}+ <TimelineEventdate="2018-05-06T16:58:02+00:00"title="Expansion panel 3"/>@@ -42,58 +27,26 @@ storiesOf("Generics / Timeline", module))).add("with expansion panels", () => (<Timeline>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}- date="2018-05-07T16:58:02+00:00"- title="Expansion panel 1"- >+ <TimelineEvent date="2018-05-07T16:58:02+00:00" title="Expansion panel 1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget.- </TimelineNode>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}- date="2018-05-07T16:48:02+00:00"- title="Expansion panel 2"- >+ </TimelineEvent>+ <TimelineEvent date="2018-05-07T16:48:02+00:00" title="Expansion panel 2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget.- </TimelineNode>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}- date="2018-05-06T16:58:02+00:00"- title="Expansion panel 3"- >+ </TimelineEvent>+ <TimelineEvent date="2018-05-06T16:58:02+00:00" title="Expansion panel 3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget.- </TimelineNode>+ </TimelineEvent></Timeline>)).add("with order notes", () => (<Timeline>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}- date="2018-05-07T16:58:02+00:00"- title="Expansion panel 1"- >+ <TimelineEvent date="2018-05-07T16:58:02+00:00" title="Expansion panel 1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget.- </TimelineNode>+ </TimelineEvent><TimelineNotedate="2018-05-07T16:58:02+00:00"user={{ email: "[email protected]" }}@@ -106,17 +59,9 @@ storiesOf("Generics / Timeline", module)message="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget."/>- <TimelineNode- amount={null}- email={null}- emailType={null}- quantity={null}- type={null}- date="2018-05-06T16:58:02+00:00"- title="Expansion panel 3"- >+ <TimelineEvent date="2018-05-06T16:58:02+00:00" title="Expansion panel 3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendissemalesuada lacus ex, sit amet blandit leo lobortis eget.- </TimelineNode>+ </TimelineEvent></Timeline>));