Skip to content

Saleor Core: the high performance, composable, headless commerce API.

wip add category details

dominik-zeglen06b582efcc92
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx
new file mode 100644
index 0000000000..216dbbf3ae
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetails/CollectionDetails.tsx
@@ -0,0 +1,46 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import { withStyles } from "@material-ui/core/styles";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import i18n from "../../../i18n";
+
+export interface CollectionDetailsProps {
+ data: {
+ name: string;
+ };
+ disabled: boolean;
+ errors: {
+ name?: string;
+ };
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const decorate = withStyles({
+ name: {
+ width: "80%"
+ }
+});
+const CollectionDetails = decorate<CollectionDetailsProps>(
+ ({ classes, disabled, data, onChange, errors }) => (
+ <Card>
+ <CardTitle title={i18n.t("General information")} />
+ <CardContent>
+ <TextField
+ classes={{ root: classes.name }}
+ label={i18n.t("Name")}
+ name="name"
+ disabled={disabled}
+ value={data.name}
+ onChange={onChange}
+ error={!!errors.name}
+ helperText={errors.name}
+ />
+ </CardContent>
+ </Card>
+ )
+);
+CollectionDetails.displayName = "CollectionDetails";
+export default CollectionDetails;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetails/index.ts b/saleor/static/dashboard-next/collections/components/CollectionDetails/index.ts
new file mode 100644
index 0000000000..5f4e124e70
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetails/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CollectionDetails";
+export * from "./CollectionDetails";
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
new file mode 100644
index 0000000000..aa50f4f3af
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -0,0 +1,78 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+import { CardSpacer } from "../../../components/CardSpacer";
+import { Container } from "../../../components/Container";
+import Form from "../../../components/Form";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar";
+import { maybe } from "../../../misc";
+import { CollectionDetails_collection } from "../../types/CollectionDetails";
+import CollectionDetails from "../CollectionDetails/CollectionDetails";
+
+export interface CollectionDetailsPageFormData {
+ name: string;
+ seoDescription: string;
+ seoTitle: string;
+ isPublished: boolean;
+}
+
+export interface CollectionDetailsPageProps {
+ collection: CollectionDetails_collection;
+ disabled: boolean;
+ onBack: () => void;
+ onCollectionRemove: () => void;
+ onImageUpload: () => void;
+ onSubmit: (data: CollectionDetailsPageFormData) => void;
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "9fr 4fr"
+ }
+}));
+const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
+ ({ classes, collection, disabled, onBack, onCollectionRemove, onSubmit }) => (
+ <Form
+ initial={{
+ isPublished: maybe(() => collection.isPublished),
+ name: maybe(() => collection.name),
+ seoDescription: maybe(() => collection.seoDescription),
+ seoTitle: maybe(() => collection.seoTitle)
+ }}
+ onSubmit={onSubmit}
+ >
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={maybe(() => collection.name)} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <CollectionDetails
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <CollectionProducts
+ products={maybe(() =>
+ collection.products.edges.map(edge => edge.node)
+ )}
+ />
+ </div>
+ <div />
+ </div>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onCancel={onBack}
+ onDelete={onCollectionRemove}
+ onSave={submit}
+ />
+ </Container>
+ )}
+ </Form>
+ )
+);
+CollectionDetailsPage.displayName = "CollectionDetailsPage";
+export default CollectionDetailsPage;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/index.ts b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/index.ts
new file mode 100644
index 0000000000..641c72a745
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CollectionDetailsPage";
+export * from "./CollectionDetailsPage";
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
new file mode 100644
index 0000000000..6402ffd655
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
@@ -0,0 +1,9 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+export interface CollectionProductsProps {}
+
+const decorate = withStyles(theme => ({ root: {} }));
+const CollectionProducts = decorate<CollectionProductsProps>(({ classes }) => <div />);
+CollectionProducts.displayName = "CollectionProducts";
+export default CollectionProducts;
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/index.ts b/saleor/static/dashboard-next/collections/components/CollectionProducts/index.ts
new file mode 100644
index 0000000000..3f37d0ff8b
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CollectionProducts";
+export * from "./CollectionProducts";
diff --git a/saleor/static/dashboard-next/collections/fixtures.ts b/saleor/static/dashboard-next/collections/fixtures.ts
index 62fab4ae59..6237c7849c 100644
--- a/saleor/static/dashboard-next/collections/fixtures.ts
+++ b/saleor/static/dashboard-next/collections/fixtures.ts
@@ -1,3 +1,4 @@
+import { CollectionDetails_collection } from "./types/CollectionDetails";
import { CollectionList_collections_edges_node } from "./types/CollectionList";
export const collections: CollectionList_collections_edges_node[] = [
@@ -22,3 +23,87 @@ export const collections: CollectionList_collections_edges_node[] = [
}
}
];
+export const collection: (
+ placeholderImage: string
+) => CollectionDetails_collection = placeholderImage => ({
+ __typename: "Collection",
+ backgroundImage: {
+ __typename: "Image",
+ url:
+ "/media/collection-backgrounds/saleor/static/placeholders/products-list/summer_drbDitj.jpg"
+ },
+ id: "Q29sbGVjdGlvbjox",
+ isPublished: true,
+ name: "Summer collection",
+ products: {
+ __typename: "ProductCountableConnection",
+ edges: [
+ {
+ __typename: "ProductCountableEdge",
+ cursor: "YXJyYXljb25uZWN0aW9uOjA=",
+ node: {
+ __typename: "Product",
+ id: "UHJvZHVjdDoxNw==",
+ isPublished: true,
+ name: "Murray Inc",
+ productType: {
+ __typename: "ProductType",
+ id: "UHJvZHVjdFR5cGU6Mg==",
+ name: "Mugs"
+ },
+ thumbnailUrl: placeholderImage
+ }
+ },
+ {
+ __typename: "ProductCountableEdge",
+ cursor: "YXJyYXljb25uZWN0aW9uOjE=",
+ node: {
+ __typename: "Product",
+ id: "UHJvZHVjdDoyNw==",
+ isPublished: true,
+ name: "Williams-Taylor",
+ productType: {
+ __typename: "ProductType",
+ id: "UHJvZHVjdFR5cGU6Mw==",
+ name: "Coffee"
+ },
+ thumbnailUrl: placeholderImage
+ }
+ },
+ {
+ __typename: "ProductCountableEdge",
+ cursor: "YXJyYXljb25uZWN0aW9uOjI=",
+ node: {
+ __typename: "Product",
+ id: "UHJvZHVjdDoyOQ==",
+ isPublished: true,
+ name: "Hebert-Sherman",
+ productType: {
+ __typename: "ProductType",
+ id: "UHJvZHVjdFR5cGU6Mw==",
+ name: "Coffee"
+ },
+ thumbnailUrl: placeholderImage
+ }
+ },
+ {
+ __typename: "ProductCountableEdge",
+ cursor: "YXJyYXljb25uZWN0aW9uOjM=",
+ node: {
+ __typename: "Product",
+ id: "UHJvZHVjdDo1Mw==",
+ isPublished: true,
+ name: "Estes, Johnson and Graham",
+ productType: {
+ __typename: "ProductType",
+ id: "UHJvZHVjdFR5cGU6Ng==",
+ name: "Books"
+ },
+ thumbnailUrl: placeholderImage
+ }
+ }
+ ]
+ },
+ seoDescription: "",
+ seoTitle: ""
+});
diff --git a/saleor/static/dashboard-next/collections/queries.ts b/saleor/static/dashboard-next/collections/queries.ts
index 6fced27fbf..7538d4ed75 100644
--- a/saleor/static/dashboard-next/collections/queries.ts
+++ b/saleor/static/dashboard-next/collections/queries.ts
@@ -15,15 +15,13 @@ export const collectionFragment = gql`
id
isPublished
name
- products {
- totalCount
- }
}
`;
export const collectionDetailsFragment = gql`
${collectionFragment}
fragment CollectionDetailsFragment on Collection {
+ ...CollectionFragment
backgroundImage {
url
}
@@ -45,6 +43,9 @@ export const collectionList = gql`
edges {
node {
...CollectionFragment
+ products {
+ totalCount
+ }
}
}
}
diff --git a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts b/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
index a515fbb84b..4c753652b6 100644
--- a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
+++ b/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
@@ -38,10 +38,12 @@ export interface CollectionDetails_collection_products {
export interface CollectionDetails_collection {
__typename: "Collection";
+ id: string;
+ isPublished: boolean;
+ name: string;
backgroundImage: CollectionDetails_collection_backgroundImage | null;
seoDescription: string | null;
seoTitle: string | null;
- isPublished: boolean;
products: CollectionDetails_collection_products | null;
}
diff --git a/saleor/static/dashboard-next/collections/types/CollectionDetailsFragment.ts b/saleor/static/dashboard-next/collections/types/CollectionDetailsFragment.ts
index 3f8b8b4b74..6f7fbc50ed 100644
--- a/saleor/static/dashboard-next/collections/types/CollectionDetailsFragment.ts
+++ b/saleor/static/dashboard-next/collections/types/CollectionDetailsFragment.ts
@@ -12,8 +12,10 @@ export interface CollectionDetailsFragment_backgroundImage {
export interface CollectionDetailsFragment {
__typename: "Collection";
+ id: string;
+ isPublished: boolean;
+ name: string;
backgroundImage: CollectionDetailsFragment_backgroundImage | null;
seoDescription: string | null;
seoTitle: string | null;
- isPublished: boolean;
}
diff --git a/saleor/static/dashboard-next/collections/types/CollectionFragment.ts b/saleor/static/dashboard-next/collections/types/CollectionFragment.ts
index 3f9814ad4e..6179a23f46 100644
--- a/saleor/static/dashboard-next/collections/types/CollectionFragment.ts
+++ b/saleor/static/dashboard-next/collections/types/CollectionFragment.ts
@@ -5,15 +5,9 @@
// GraphQL fragment: CollectionFragment
// ====================================================
-export interface CollectionFragment_products {
- __typename: "ProductCountableConnection";
- totalCount: number | null;
-}
-
export interface CollectionFragment {
__typename: "Collection";
id: string;
isPublished: boolean;
name: string;
- products: CollectionFragment_products | null;
}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 08a5a3eba7..68aaa6cdcb 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -39,7 +39,7 @@ function loadStories() {
require("./stories/categories/CategoryListPage");
// Collections
- // require("./stories/collections/CollectionDetailsPage");
+ require("./stories/collections/CollectionDetailsPage");
require("./stories/collections/CollectionListPage");
// Configuration
diff --git a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
index d0c92be33b..0094d4eec6 100644
--- a/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/collections/CollectionDetailsPage.tsx
@@ -1,37 +1,26 @@
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import * as placeholderImage from "../../../../placeholders/products-list/summer.jpg";
-import { storefrontUrl } from "../../../collections";
-import CollectionDetailsPage from "../../../collections/components/CollectionDetailsPage";
-import { collections as collectionsFixture } from "../../../collections/fixtures";
+import * as placeholderImage from "../../../../images/placeholder60x60.png";
+import CollectionDetailsPage, {
+ CollectionDetailsPageProps
+} from "../../../collections/components/CollectionDetailsPage";
+import { collection as collectionFixture } from "../../../collections/fixtures";
import Decorator from "../../Decorator";
-const collection = collectionsFixture(placeholderImage)[0];
-const callbacks = {
- onBack: undefined,
- onDelete: undefined,
- onImageRemove: undefined,
- onNextPage: undefined,
- onPreviousPage: undefined,
- onProductAdd: undefined,
- onProductClick: () => undefined,
- onProductRemove: () => undefined,
- onShow: undefined,
- onSubmit: () => undefined,
- storefrontUrl
+const collection = collectionFixture(placeholderImage);
+
+const props: CollectionDetailsPageProps = {
+ collection,
+ onBack: () => undefined,
+ onCollectionRemove: () => undefined,
+ onImageUpload: () => undefined,
+ onSubmit: () => undefined
};
storiesOf("Views / Collections / Collection details", module)
.addDecorator(Decorator)
- .add("default", () => (
- <CollectionDetailsPage
- disabled={false}
- collection={collection}
- products={collection.products.edges.map(edge => edge.node)}
- {...callbacks}
- />
- ))
- .add("when loading", () => (
- <CollectionDetailsPage disabled={true} {...callbacks} />
+ .add("default", () => <CollectionDetailsPage {...props} />)
+ .add("other", () => (
+ <CollectionDetailsPage {...props} collection={undefined} />
));