Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
wip
dominik-zeglen5edc0393404f
diff --git a/saleor/static/dashboard-next/components/TablePagination/TablePaginationActions.tsx b/saleor/static/dashboard-next/components/TablePagination/TablePaginationActions.tsxindex 103f9c9d6a..bc7acb6046 100644--- a/saleor/static/dashboard-next/components/TablePagination/TablePaginationActions.tsx+++ b/saleor/static/dashboard-next/components/TablePagination/TablePaginationActions.tsx@@ -19,19 +19,21 @@ const decorate = withStyles();interface TablePaginationActionsProps {- backIconButtonProps: any;+ backIconButtonProps?: any;classes: any;+ className: string;hasNextPage: boolean;hasPreviousPage: boolean;- nextIconButtonProps: any;+ nextIconButtonProps?: any;onNextPage(event);onPreviousPage(event);}-const TablePaginationActions = decorate<TablePaginationActionsProps>(+export const TablePaginationActions = decorate<TablePaginationActionsProps>(({backIconButtonProps,classes,+ className,hasNextPage,hasPreviousPage,nextIconButtonProps,@@ -40,7 +42,7 @@ const TablePaginationActions = decorate<TablePaginationActionsProps>(theme,...other}) => (- <div className={classes.root} {...other}>+ <div className={[classes.root, className].join(" ")} {...other}><IconButtononClick={onPreviousPage}disabled={!hasPreviousPage}diff --git a/saleor/static/dashboard-next/components/TablePagination/index.ts b/saleor/static/dashboard-next/components/TablePagination/index.tsindex 731a67cc7b..0d128c72d9 100644--- a/saleor/static/dashboard-next/components/TablePagination/index.ts+++ b/saleor/static/dashboard-next/components/TablePagination/index.ts@@ -1,2 +1,3 @@export { default } from "./TablePagination";export * from "./TablePagination";+export * from "./TablePaginationActions";diff --git a/saleor/static/dashboard-next/gql-types.ts b/saleor/static/dashboard-next/gql-types.tsindex 9cc046e414..6d3bdf770b 100644--- a/saleor/static/dashboard-next/gql-types.ts+++ b/saleor/static/dashboard-next/gql-types.ts@@ -1616,6 +1616,8 @@ export interface ProductVariantCreateDataQuery {export interface ProductImageQueryVariables {productId: string,imageId: string,+ imageAfter?: string | null,+ imageBefore?: string | null,};export interface ProductImageQuery {@@ -1634,6 +1636,29 @@ export interface ProductImageQuery {},} >,} | null,+ images: {+ edges: Array< {+ // A cursor for use in pagination+ cursor: string,+ // The item at the end of the edge+ node: {+ // The ID of the object.+ id: string,+ alt: string,+ url: string,+ },+ } >,+ pageInfo: {+ // When paginating backwards, are there more items?+ hasPreviousPage: boolean,+ // When paginating forwards, are there more items?+ hasNextPage: boolean,+ // When paginating backwards, the cursor to continue.+ startCursor: string | null,+ // When paginating forwards, the cursor to continue.+ endCursor: string | null,+ },+ } | null,} | null,};diff --git a/saleor/static/dashboard-next/products/components/ProductImageNavigation/ProductImageNavigation.tsx b/saleor/static/dashboard-next/products/components/ProductImageNavigation/ProductImageNavigation.tsxnew file mode 100644index 0000000000..c4d390c640--- /dev/null+++ b/saleor/static/dashboard-next/products/components/ProductImageNavigation/ProductImageNavigation.tsx@@ -0,0 +1,99 @@+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import { withStyles } from "@material-ui/core/styles";+import * as React from "react";++import { ListProps } from "../../../";+import CardTitle from "../../../components/CardTitle";+import Skeleton from "../../../components/Skeleton";+import { TablePaginationActions } from "../../../components/TablePagination";+import i18n from "../../../i18n";++interface ProductImageNavigationProps extends ListProps {+ images?: Array<{+ id: string;+ url: string;+ }>;+ highlighted?: string;+}++const decorate = withStyles(theme => ({+ card: {+ marginBottom: 2 * theme.spacing.unit+ },+ image: {+ height: "100%",+ objectFit: "contain" as "contain",+ userSelect: "none" as "none",+ width: "100%"+ },+ imageContainer: {+ "&.highlighted": {+ borderColor: theme.palette.primary.main+ },+ background: "#ffffff",+ border: "2px solid #eaeaea",+ borderRadius: theme.spacing.unit,+ cursor: "pointer" as "pointer",+ height: 48,+ overflow: "hidden" as "hidden",+ padding: theme.spacing.unit / 2,+ position: "relative" as "relative"+ },+ root: {+ display: "grid" as "grid",+ gridColumnGap: theme.spacing.unit * 2 + "px",+ gridRowGap: theme.spacing.unit + "px",+ gridTemplateColumns: "repeat(4, 1fr)"+ },+ toolbar: { marginTop: -theme.spacing.unit / 2 }+}));+const ProductImageNavigation = decorate<ProductImageNavigationProps>(+ ({+ classes,+ disabled,+ highlighted,+ images,+ onNextPage,+ onPreviousPage,+ onRowClick,+ pageInfo+ }) => (+ <Card className={classes.card}>+ <CardTitle+ title={i18n.t("All photos")}+ toolbar={+ <TablePaginationActions+ hasNextPage={!disabled && pageInfo.hasNextPage}+ hasPreviousPage={!disabled && pageInfo.hasPreviousPage}+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ className={classes.toolbar}+ />+ }+ />+ <CardContent>+ {images === undefined ? (+ <Skeleton />+ ) : (+ <div className={classes.root}>+ {images.map(image => (+ <div+ className={[+ classes.imageContainer,+ image.id === highlighted ? "highlighted" : undefined+ ].join(" ")}+ onClick={onRowClick(image.id)}+ key={image.id}+ >+ <img className={classes.image} src={image.url} />+ </div>+ ))}+ </div>+ )}+ </CardContent>+ </Card>+ )+);+ProductImageNavigation.displayName = "ProductImageNavigation";+export default ProductImageNavigation;diff --git a/saleor/static/dashboard-next/products/components/ProductImageNavigation/index.ts b/saleor/static/dashboard-next/products/components/ProductImageNavigation/index.tsnew file mode 100644index 0000000000..d4d8bf59ec--- /dev/null+++ b/saleor/static/dashboard-next/products/components/ProductImageNavigation/index.ts@@ -0,0 +1,2 @@+export { default } from "./ProductImageNavigation";+export * from "./ProductImageNavigation";diff --git a/saleor/static/dashboard-next/products/components/ProductImagePage/ProductImagePage.tsx b/saleor/static/dashboard-next/products/components/ProductImagePage/ProductImagePage.tsxindex 9da6aa38e5..c9cc669055 100644--- a/saleor/static/dashboard-next/products/components/ProductImagePage/ProductImagePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductImagePage/ProductImagePage.tsx@@ -4,6 +4,7 @@ import { withStyles } from "@material-ui/core/styles";import TextField from "@material-ui/core/TextField";import * as React from "react";+import { ListProps } from "../../..";import CardTitle from "../../../components/CardTitle";import Container from "../../../components/Container";import Form from "../../../components/Form";@@ -13,11 +14,18 @@ import SaveButtonBar, {} from "../../../components/SaveButtonBar";import Skeleton from "../../../components/Skeleton";import i18n from "../../../i18n";+import ProductImageNavigation from "../ProductImageNavigation";-interface ProductImagePageProps {- image?: string;+interface ProductImagePageProps extends ListProps {+ image?: {+ id: string;+ url: string;+ };+ images?: Array<{+ id: string;+ url: string;+ }>;description?: string;- disabled?: boolean;saveButtonBarState?: SaveButtonBarState;onBack: () => void;onDelete: () => void;@@ -47,12 +55,17 @@ const decorate = withStyles(theme => ({const ProductImagePage = decorate<ProductImagePageProps>(({classes,- image,description,disabled,+ image,+ images,+ pageInfo,saveButtonBarState,onBack,onDelete,+ onNextPage,+ onPreviousPage,+ onRowClick,onSubmit}) => (<Form@@ -66,6 +79,15 @@ const ProductImagePage = decorate<ProductImagePageProps>(<PageHeader title={i18n.t("Edit Photo")} onBack={onBack} /><div className={classes.root}><div>+ <ProductImageNavigation+ onNextPage={onNextPage}+ onPreviousPage={onPreviousPage}+ disabled={disabled}+ images={images}+ highlighted={image ? image.id : undefined}+ onRowClick={onRowClick}+ pageInfo={pageInfo}+ /><Card><CardTitle title={i18n.t("Photo Information")} /><CardContent>@@ -88,7 +110,7 @@ const ProductImagePage = decorate<ProductImagePageProps>(<CardContent>{!!image ? (<div className={classes.imageContainer}>- <img src={image} className={classes.image} />+ <img src={image.url} className={classes.image} /></div>) : (<Skeleton />diff --git a/saleor/static/dashboard-next/products/index.tsx b/saleor/static/dashboard-next/products/index.tsxindex 945f8f8348..c77720b12a 100644--- a/saleor/static/dashboard-next/products/index.tsx+++ b/saleor/static/dashboard-next/products/index.tsx@@ -40,9 +40,15 @@ const ProductVariant: React.StatelessComponent<RouteComponentProps<any>> = ({const ProductImage: React.StatelessComponent<RouteComponentProps<any>> = ({match}) => {+ const qs = parseQs(location.search.substr(1));+ const params = {+ after: qs.after,+ before: qs.before+ };return (<ProductImageComponentimageId={match.params.imageId}+ params={params}productId={match.params.productId}/>);diff --git a/saleor/static/dashboard-next/products/queries.ts b/saleor/static/dashboard-next/products/queries.tsindex e0abf35148..ee76b5e543 100644--- a/saleor/static/dashboard-next/products/queries.ts+++ b/saleor/static/dashboard-next/products/queries.ts@@ -397,7 +397,12 @@ export const TypedProductImageQuery = Query as React.ComponentType<QueryProps<ProductImageQuery, ProductImageQueryVariables>>;export const productImageQuery = gql`- query ProductImage($productId: ID!, $imageId: String!) {+ query ProductImage(+ $productId: ID!+ $imageId: String!+ $imageAfter: String+ $imageBefore: String+ ) {product(id: $productId) {image: images(after: $imageId, first: 1) {edges {@@ -409,6 +414,22 @@ export const productImageQuery = gql`}}}+ images(after: $imageAfter, before: $imageBefore, first: 8) {+ edges {+ cursor+ node {+ id+ alt+ url+ }+ }+ pageInfo {+ hasPreviousPage+ hasNextPage+ startCursor+ endCursor+ }+ }}}`;diff --git a/saleor/static/dashboard-next/products/views/ProductImage.tsx b/saleor/static/dashboard-next/products/views/ProductImage.tsxindex 6d12e4c75b..b1fcb6744c 100644--- a/saleor/static/dashboard-next/products/views/ProductImage.tsx+++ b/saleor/static/dashboard-next/products/views/ProductImage.tsx@@ -1,7 +1,8 @@import * as React from "react";-import { productUrl } from "..";+import { productImageUrl, productUrl } from "..";import Navigator from "../../components/Navigator";+import { createPaginationData, createPaginationState } from "../../misc";import ProductImagePage from "../components/ProductImagePage";import {productImageDeleteMutation,@@ -12,19 +13,33 @@ import { productImageQuery, TypedProductImageQuery } from "../queries";interface ProductImageProps {imageId: string;productId: string;+ params: {+ after?: string;+ before?: string;+ };}+const PAGINATE_BY = 8;+export const ProductImage: React.StatelessComponent<ProductImageProps> = ({imageId,+ params,productId}) => (<Navigator>{navigate => {const handleBack = () => navigate(productUrl(productId));+ const paginationState = createPaginationState(PAGINATE_BY, params);return (<TypedProductImageQueryquery={productImageQuery}- variables={{ imageId, productId }}+ variables={{+ imageAfter: paginationState.after,+ imageBefore: paginationState.before,+ imageId,+ productId+ }}+ fetchPolicy="cache-and-network">{({ data, loading }) => {return (@@ -35,6 +50,21 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({{mutate => {const handleDelete = () =>mutate({ variables: { id: imageId } });+ const {+ loadNextPage,+ loadPreviousPage,+ pageInfo+ } = createPaginationData(+ navigate,+ paginationState,+ productImageUrl(productId, imageId),+ data && data.product && data.product.images+ ? data.product.images.pageInfo+ : undefined,+ loading+ );+ const handleImageClick = (id: string) => () =>+ navigate(productImageUrl(productId, id));const image =data &&data.product &&@@ -49,9 +79,21 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({description={image ? image.alt : null}// TODO: unlock editing after API fixesdisabled={true}- image={image ? image.url : null}+ image={image || null}+ images={+ data &&+ data.product &&+ data.product.images &&+ data.product.images.edges+ ? data.product.images.edges.map(edge => edge.node)+ : undefined+ }+ pageInfo={pageInfo}onBack={handleBack}onDelete={handleDelete}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={handleImageClick}onSubmit={() => {}}/>);diff --git a/saleor/static/dashboard-next/products/views/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList.tsxindex 671f90b530..c8a6ac01c8 100644--- a/saleor/static/dashboard-next/products/views/ProductList.tsx+++ b/saleor/static/dashboard-next/products/views/ProductList.tsx@@ -22,7 +22,7 @@ const decorate = withStyles(theme => ({gridTemplateColumns: "100%",[theme.breakpoints.up("md")]: {gridGap: theme.spacing.unit * 2 + "px",- gridTemplateColumns: "3fr 1fr"+ gridTemplateColumns: "9fr 4fr"}}}));diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductImagePage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductImagePage.tsxindex 217277dc1c..29e608fb2b 100644--- a/saleor/static/dashboard-next/storybook/stories/products/ProductImagePage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductImagePage.tsx@@ -5,12 +5,17 @@ import * as placeholder from "../../../../images/placeholder1080x1080.png";import ProductImagePage from "../../../products/components/ProductImagePage";import Decorator from "../../Decorator";+const images = (Array(8) as any)+ .fill({ id: "img", url: placeholder })+ .map((image, imageIndex) => ({ ...image, id: image.id + imageIndex }));+storiesOf("Views / Products / Product image details", module).addDecorator(Decorator).add("when loaded data", () => (<ProductImagePageonSubmit={() => {}}- image={placeholder}+ image={{ id: "img1", url: placeholder }}+ images={images}onBack={() => {}}onDelete={() => {}}/>diff --git a/saleor/static/dashboard-next/storybook/webpack.config.js b/saleor/static/dashboard-next/storybook/webpack.config.jsindex 257171f9f7..d1f4e3b2a1 100644--- a/saleor/static/dashboard-next/storybook/webpack.config.js+++ b/saleor/static/dashboard-next/storybook/webpack.config.js@@ -1,11 +1,10 @@/* eslint-disable */-var path = require("path");-var webpack = require("webpack");+const path = require("path");-var resolve = path.resolve.bind(path, `${__dirname}/../../../../`);+const resolve = path.resolve.bind(path, `${__dirname}/../../../../`);-var reactPath;-var reactDomPath;+let reactPath;+let reactDomPath;if (process.env.NODE_ENV === "production") {reactPath = "node_modules/react/umd/react.production.min.js";@@ -14,14 +13,8 @@ if (process.env.NODE_ENV === "production") {reactPath = "node_modules/react/umd/react.development.js";reactDomPath = "node_modules/react-dom/umd/react-dom.development.js";}-var providePlugin = new webpack.ProvidePlugin({- "query-string": "query-string"-});-var config = {- entry: {- "dashboard-next": "./saleor/static/dashboard-next/index.tsx"- },+const config = {module: {rules: [{@@ -31,6 +24,7 @@ var config = {},{test: /\.tsx?$/,+ exclude: /node_modules/,loader: "ts-loader"},{@@ -42,7 +36,6 @@ var config = {}]},- plugins: [providePlugin],resolve: {alias: {react: resolve(reactPath),