Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Connect restyled components to API
dominik-zeglen4242c0b3646e
diff --git a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsxindex 2806ed5874..53d48b21a1 100644--- a/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryProductsCard/CategoryProductsCard.tsx@@ -6,23 +6,11 @@ import { PageListProps } from "../../..";import CardTitle from "../../../components/CardTitle";import ProductList from "../../../components/ProductList";import i18n from "../../../i18n";-import { MoneyType } from "../../../products";+import { CategoryDetails_category_products_edges_node } from "../../types/CategoryDetails";interface CategoryProductsCardProps extends PageListProps {- products: Array<{- id: string;- name: string;- productType: {- name: string;- };- thumbnailUrl: string;- availability: {- available: boolean;- };- price: MoneyType;- }>;+ products: CategoryDetails_category_products_edges_node[];categoryName: string;- onAddProduct?();}export const CategoryProductsCard: React.StatelessComponent<@@ -31,7 +19,7 @@ export const CategoryProductsCard: React.StatelessComponent<products,disabled,pageInfo,- onAddProduct,+ onAdd,onNextPage,onPreviousPage,onRowClick,@@ -41,7 +29,7 @@ export const CategoryProductsCard: React.StatelessComponent<<CardTitletitle={i18n.t("Products in {{ categoryName }}", { categoryName })}toolbar={- <Button color="secondary" variant="flat" onClick={onAddProduct}>+ <Button color="secondary" variant="flat" onClick={onAdd}>{i18n.t("Add product")}</Button>}diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsxindex 05199072c0..f6a6c38cb7 100644--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx@@ -13,10 +13,14 @@ import SeoForm from "../../../components/SeoForm";import Tabs, { Tab } from "../../../components/Tab";import i18n from "../../../i18n";import { maybe } from "../../../misc";-import { MoneyType } from "../../../products";import CategoryDetailsForm from "../../components/CategoryDetailsForm";import CategoryList from "../../components/CategoryList";-import CategoryBackground from "../CategoryBackground";+import {+ CategoryDetails_category,+ CategoryDetails_category_children_edges_node,+ CategoryDetails_category_products_edges_node+} from "../../types/CategoryDetails";+// import CategoryBackground from "../CategoryBackground";import CategoryProductsCard from "../CategoryProductsCard";interface FormData {@@ -30,46 +34,16 @@ export interface CategoryUpdatePageProps {errors: UserError[];disabled: boolean;placeholderImage: string;- category: {- SeoDescription: string;- SeoTitle: string;- backgroundImage: {- url: string;- };- id: string;- name: string;- description: string;- };- products: Array<{- id: string;- name: string;- productType: {- name: string;- };- thumbnailUrl: string;- availability: {- available: boolean;- };- price: MoneyType;- }>;- subcategories: Array<{- id: string;- name: string;- children: {- totalCount: number;- };- products: {- totalCount: number;- };- }>;+ category: CategoryDetails_category;+ products: CategoryDetails_category_products_edges_node[];+ subcategories: CategoryDetails_category_children_edges_node[];pageInfo: {hasNextPage: boolean;hasPreviousPage: boolean;};- loading: boolean;saveButtonBarState?: SaveButtonBarState;onImageDelete: () => void;- onSubmit(data: FormData);+ onSubmit: (data: FormData) => void;onImageUpload(event: React.ChangeEvent<any>);onNextPage();onPreviousPage();@@ -93,9 +67,7 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(classes,disabled,errors: userErrors,- loading,pageInfo,- placeholderImage,products,saveButtonBarState,subcategories,@@ -104,8 +76,6 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(onBack,onCategoryClick,onDelete,- onImageDelete,- onImageUpload,onNextPage,onPreviousPage,onProductClick,@@ -113,10 +83,10 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(}) => {const initialData = category? {- description: category.description,+ description: category.description || "",name: category.name,- seoDescription: category.SeoDescription,- seoTitle: category.SeoTitle+ seoDescription: category.seoDescription || "",+ seoTitle: category.seoTitle || ""}: {description: "",@@ -125,7 +95,12 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(seoTitle: ""};return (- <Form onSubmit={onSubmit} initial={initialData} errors={userErrors}>+ <Form+ onSubmit={onSubmit}+ initial={initialData}+ errors={userErrors}+ key={JSON.stringify(category)}+ >{({ data, change, errors, submit, hasChanged }) => (<Container width="md"><PageHeader@@ -139,12 +114,13 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(onChange={change}/><CardSpacer />- <CategoryBackground+ {/* TODO: Uncomment this section after API fixes */}+ {/* <CategoryBackgroundonImageUpload={onImageUpload}onImageDelete={onImageDelete}backgroundImage={maybe(() => category.backgroundImage)}placeholderImage={placeholderImage}- />+ /> */}<CardSpacer /><SeoFormhelperText={i18n.t(@@ -154,7 +130,7 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(titlePlaceholder={data.name}description={data.seoDescription}descriptionPlaceholder={data.description}- loading={loading}+ loading={!category}onChange={change}disabled={disabled}/>@@ -189,7 +165,7 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>()}{currentTab === 1 && (<CategoryProductsCard- categoryName={category.name}+ categoryName={maybe(() => category.name)}products={products}disabled={disabled}pageInfo={pageInfo}diff --git a/saleor/static/dashboard-next/categories/fixtures.ts b/saleor/static/dashboard-next/categories/fixtures.tsindex 7518560b27..74b879921b 100644--- a/saleor/static/dashboard-next/categories/fixtures.ts+++ b/saleor/static/dashboard-next/categories/fixtures.ts@@ -1,4 +1,4 @@-import * as block1 from "../../images/block1.jpg";+import { CategoryDetails_category } from "./types/CategoryDetails";export const categories = [{@@ -62,18 +62,277 @@ export const categories = [}}];-export const category = {- SeoDescription:- "Across pressure PM food discover recognize. Send letter reach listen. Quickly work plan rule.\nTell lose part purpose do when. Whatever drug contain particularly defense.",- SeoTitle: "Apparel",- backgroundImage: {- url: block1+export const category: (+ placeholderImage: string+) => CategoryDetails_category = (placeholderImage: string) => ({+ __typename: "Category",+ children: {+ __typename: "CategoryCountableConnection",+ edges: []},description:- "Across pressure PM food discover recognize. Send letter reach listen. Quickly work plan rule.\nTell lose part purpose do when. Whatever drug contain particularly defense.",- id: "c1",- name: "Apparel"-};+ "Difference direction to treat anything worker occur. Miss in thousand Democrat civil hope set.",+ id: "Q2F0ZWdvcnk6NA==",+ name: "Coffees",+ parent: {+ __typename: "Category",+ id: "Q2F0ZWdvcnk6Mw=="+ },+ products: {+ __typename: "ProductCountableConnection",+ edges: [+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjA=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyMQ==",+ name: "Gardner-Schultz",+ price: {+ __typename: "Money",+ amount: 83.3,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjE=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyMg==",+ name: "James, Martinez and Murray",+ price: {+ __typename: "Money",+ amount: 68.27,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjI=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyMw==",+ name: "Curtis, Joyce and Turner",+ price: {+ __typename: "Money",+ amount: 21.43,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjM=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyNA==",+ name: "Davis, Brown and Ray",+ price: {+ __typename: "Money",+ amount: 62.76,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjQ=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyNQ==",+ name: "Gallegos Ltd",+ price: {+ __typename: "Money",+ amount: 7.13,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjU=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyNg==",+ name: "Franklin Inc",+ price: {+ __typename: "Money",+ amount: 48.82,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjY=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyNw==",+ name: "Williams-Taylor",+ price: {+ __typename: "Money",+ amount: 27.34,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjc=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyOA==",+ name: "Riddle, Evans and Hicks",+ price: {+ __typename: "Money",+ amount: 75.42,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjg=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDoyOQ==",+ name: "Hebert-Sherman",+ price: {+ __typename: "Money",+ amount: 86.62,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ },+ {+ __typename: "ProductCountableEdge",+ cursor: "YXJyYXljb25uZWN0aW9uOjk=",+ node: {+ __typename: "Product",+ availability: {+ __typename: "ProductAvailability",+ available: true+ },+ id: "UHJvZHVjdDozMA==",+ name: "Carter and Sons",+ price: {+ __typename: "Money",+ amount: 48.66,+ currency: "USD"+ },+ productType: {+ __typename: "ProductType",+ id: "UHJvZHVjdFR5cGU6Mw==",+ name: "Coffee"+ },+ thumbnailUrl: placeholderImage+ }+ }+ ],+ pageInfo: {+ __typename: "PageInfo",+ endCursor: "YXJyYXljb25uZWN0aW9uOjk=",+ hasNextPage: false,+ hasPreviousPage: false,+ startCursor: "YXJyYXljb25uZWN0aW9uOjA="+ }+ },+ seoDescription: null,+ seoTitle: null+});export const errors = [{field: "name",diff --git a/saleor/static/dashboard-next/categories/index.tsx b/saleor/static/dashboard-next/categories/index.tsxindex 1fdabaf0d0..2e2155f776 100644--- a/saleor/static/dashboard-next/categories/index.tsx+++ b/saleor/static/dashboard-next/categories/index.tsx@@ -1,41 +1,33 @@-// import { parse as parseQs } from "qs";+import { parse as parseQs } from "qs";import * as React from "react";import { Route, RouteComponentProps, Switch } from "react-router-dom";import { CategoryCreateView } from "./views/CategoryCreate";+import CategoryDetailsView from "./views/CategoryDetails";import CategoryList from "./views/CategoryList";-// import { CategoryCreateForm } from "./views/CategoryCreate";-// import CategoryDetails from "./views/CategoryDetails";-// import { CategoryUpdateForm } from "./views/CategoryUpdate";--// const CategoryPaginator: React.StatelessComponent<RouteComponentProps<any>> = ({-// location,-// match-// }) => {-// const qs = parseQs(location.search.substr(1));-// const params = {-// after: qs.after,-// before: qs.before-// };-// return <CategoryDetails id={match.params.id} params={params} />;-// };+const CategoryDetails: React.StatelessComponent<RouteComponentProps<any>> = ({+ location,+ match+}) => {+ const qs = parseQs(location.search.substr(1));+ const params = {+ after: qs.after,+ before: qs.before+ };+ return <CategoryDetailsView id={match.params.id} params={params} />;+};const CategoryCreate: React.StatelessComponent<RouteComponentProps<any>> = ({match}) => {return <CategoryCreateView parentId={match.params.id} />;};-// const SubcategoryUpdateForm: React.StatelessComponent<-// RouteComponentProps<any>-// > = ({ match }) => {-// return <CategoryUpdateForm id={match.params.id} />;-// };const Component = ({ match }) => (<Switch><Route exact path={match.url} component={CategoryList} /><Route exact path={`${match.url}/add/`} component={CategoryCreate} />- <Route exact path={`${match.url}/:id/add/`} component={null} />- <Route exact path={`${match.url}/:id/`} component={null} />+ <Route exact path={`${match.url}/:id/add/`} component={CategoryCreate} />+ <Route path={`${match.url}/:id/`} component={CategoryDetails} /></Switch>);diff --git a/saleor/static/dashboard-next/categories/mutations.ts b/saleor/static/dashboard-next/categories/mutations.tsindex 8b24d822b0..244be96d08 100644--- a/saleor/static/dashboard-next/categories/mutations.ts+++ b/saleor/static/dashboard-next/categories/mutations.ts@@ -1,6 +1,7 @@import gql from "graphql-tag";import { TypedMutation } from "../mutations";+import { categoryDetailsFragment } from "./queries";import {CategoryCreate,CategoryCreateVariables@@ -30,6 +31,7 @@ export const TypedCategoryDeleteMutation = TypedMutation<>(categoryDeleteMutation);export const categoryCreateMutation = gql`+ ${categoryDetailsFragment}mutation CategoryCreate($input: CategoryInput!) {categoryCreate(input: $input) {errors {@@ -37,14 +39,7 @@ export const categoryCreateMutation = gql`message}category {- id- name- description- parent {- id- }- seoDescription- seoTitle+ ...CategoryDetailsFragment}}}@@ -55,19 +50,15 @@ export const TypedCategoryCreateMutation = TypedMutation<>(categoryCreateMutation);export const categoryUpdateMutation = gql`- mutation CategoryUpdate($id: ID!, $name: String, $description: String) {- categoryUpdate(id: $id, input: { name: $name, description: $description }) {+ ${categoryDetailsFragment}+ mutation CategoryUpdate($id: ID!, $input: CategoryInput!) {+ categoryUpdate(id: $id, input: $input) {errors {fieldmessage}category {- id- name- description- parent {- id- }+ ...CategoryDetailsFragment}}}diff --git a/saleor/static/dashboard-next/categories/queries.ts b/saleor/static/dashboard-next/categories/queries.tsindex 6ba1b2cb65..1350950eed 100644--- a/saleor/static/dashboard-next/categories/queries.ts+++ b/saleor/static/dashboard-next/categories/queries.ts@@ -7,6 +7,19 @@ import {} from "./types/CategoryDetails";import { RootCategories } from "./types/RootCategories";+export const categoryDetailsFragment = gql`+ fragment CategoryDetailsFragment on Category {+ id+ name+ description+ seoDescription+ seoTitle+ parent {+ id+ }+ }+`;+export const rootCategories = gql`query RootCategories {categories(level: 0) {@@ -30,6 +43,7 @@ export const TypedRootCategoriesQuery = TypedQuery<RootCategories, {}>();export const categoryDetails = gql`+ ${categoryDetailsFragment}query CategoryDetails($id: ID!$first: Int@@ -38,12 +52,7 @@ export const categoryDetails = gql`$before: String) {category(id: $id) {- id- name- description- parent {- id- }+ ...CategoryDetailsFragmentchildren {edges {node {@@ -70,7 +79,14 @@ export const categoryDetails = gql`node {idname+ availability {+ available+ }thumbnailUrl+ price {+ amount+ currency+ }productType {idnamediff --git a/saleor/static/dashboard-next/categories/types/CategoryCreate.ts b/saleor/static/dashboard-next/categories/types/CategoryCreate.tsindex dcc5bd8b6e..e517628fda 100644--- a/saleor/static/dashboard-next/categories/types/CategoryCreate.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryCreate.ts@@ -23,9 +23,9 @@ export interface CategoryCreate_categoryCreate_category {id: string;name: string;description: string;- parent: CategoryCreate_categoryCreate_category_parent | null;seoDescription: string | null;seoTitle: string | null;+ parent: CategoryCreate_categoryCreate_category_parent | null;}export interface CategoryCreate_categoryCreate {diff --git a/saleor/static/dashboard-next/categories/types/CategoryDetails.ts b/saleor/static/dashboard-next/categories/types/CategoryDetails.tsindex d2caba5a54..3d516421c0 100644--- a/saleor/static/dashboard-next/categories/types/CategoryDetails.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryDetails.ts@@ -46,6 +46,17 @@ export interface CategoryDetails_category_products_pageInfo {startCursor: string | null;}+export interface CategoryDetails_category_products_edges_node_availability {+ __typename: "ProductAvailability";+ available: boolean | null;+}++export interface CategoryDetails_category_products_edges_node_price {+ __typename: "Money";+ amount: number;+ currency: string;+}+export interface CategoryDetails_category_products_edges_node_productType {__typename: "ProductType";id: string;@@ -56,7 +67,9 @@ export interface CategoryDetails_category_products_edges_node {__typename: "Product";id: string;name: string;+ availability: CategoryDetails_category_products_edges_node_availability | null;thumbnailUrl: string | null;+ price: CategoryDetails_category_products_edges_node_price | null;productType: CategoryDetails_category_products_edges_node_productType;}@@ -77,6 +90,8 @@ export interface CategoryDetails_category {id: string;name: string;description: string;+ seoDescription: string | null;+ seoTitle: string | null;parent: CategoryDetails_category_parent | null;children: CategoryDetails_category_children | null;products: CategoryDetails_category_products | null;diff --git a/saleor/static/dashboard-next/categories/types/CategoryDetailsFragment.ts b/saleor/static/dashboard-next/categories/types/CategoryDetailsFragment.tsnew file mode 100644index 0000000000..18ce0d538c--- /dev/null+++ b/saleor/static/dashboard-next/categories/types/CategoryDetailsFragment.ts@@ -0,0 +1,21 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL fragment: CategoryDetailsFragment+// ====================================================++export interface CategoryDetailsFragment_parent {+ __typename: "Category";+ id: string;+}++export interface CategoryDetailsFragment {+ __typename: "Category";+ id: string;+ name: string;+ description: string;+ seoDescription: string | null;+ seoTitle: string | null;+ parent: CategoryDetailsFragment_parent | null;+}diff --git a/saleor/static/dashboard-next/categories/types/CategoryUpdate.ts b/saleor/static/dashboard-next/categories/types/CategoryUpdate.tsindex 54f081afa7..0c81b619b0 100644--- a/saleor/static/dashboard-next/categories/types/CategoryUpdate.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryUpdate.ts@@ -1,6 +1,8 @@/* tslint:disable */// This file was automatically generated and should not be edited.+import { CategoryInput } from "./../../types/globalTypes";+// ====================================================// GraphQL mutation operation: CategoryUpdate// ====================================================@@ -21,6 +23,8 @@ export interface CategoryUpdate_categoryUpdate_category {id: string;name: string;description: string;+ seoDescription: string | null;+ seoTitle: string | null;parent: CategoryUpdate_categoryUpdate_category_parent | null;}@@ -36,6 +40,5 @@ export interface CategoryUpdate {export interface CategoryUpdateVariables {id: string;- name?: string | null;- description?: string | null;+ input: CategoryInput;}diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails.tsxdeleted file mode 100644index b1f788aca0..0000000000--- a/saleor/static/dashboard-next/categories/views/CategoryDetails.tsx+++ /dev/null@@ -1,241 +0,0 @@-import * as React from "react";-import { Redirect } from "react-router-dom";--import CategoryDetailsPage from "../../categories/components/CategoryDetailsPage";-import ErrorMessageCard from "../../components/ErrorMessageCard";-import Navigator from "../../components/Navigator";-import i18n from "../../i18n";-import {- createPaginationData,- createPaginationState,- PageInfo-} from "../../misc";-import { productAddUrl, productUrl } from "../../products";-import { categoryAddUrl, categoryEditUrl, categoryShowUrl } from "../index";-import { TypedCategoryDeleteMutation } from "../mutations";-import {- categoryPropertiesQuery,- rootCategoryChildrenQuery,- TypedCategoryPropertiesQuery,- TypedRootCategoryChildrenQuery-} from "../queries";-import {- CategoryProperties,- CategoryProperties_category-} from "../types/CategoryProperties";--interface CategoryDeleteProviderProps {- category?: CategoryProperties_category;- children:- | ((deleteCategory: () => void) => React.ReactElement<any>)- | React.ReactNode;-}--interface QueryParams {- after?: string;- before?: string;-}--const PAGINATE_BY = 20;--const CategoryDeleteProvider: React.StatelessComponent<- CategoryDeleteProviderProps-> = ({ category, children }) => (- <TypedCategoryDeleteMutation- variables={{- id: (category && category.id) || ""- }}- >- {(deleteCategory, { called, loading, error: deleteError }) => {- if (called && !loading) {- return (- <Redirect- to={categoryShowUrl(category.parent ? category.parent.id : null)}- push={false}- />- );- }- if (deleteError) {- return <ErrorMessageCard message={deleteError.message} />;- }-- if (typeof children === "function") {- return children(deleteCategory);- }- if (React.Children.count(children) > 0) {- return React.Children.only(children);- }- return null;- }}- </TypedCategoryDeleteMutation>-);--interface CategoryPaginationProviderProps {- children:- | ((- props: {- data: CategoryProperties;- loading: boolean;- pageInfo: PageInfo;- loadNextPage: () => void;- loadPreviousPage: () => void;- }- ) => React.ReactElement<any>)- | React.ReactNode;- id?: string;- navigate: (url: string, push: boolean) => void;- params: QueryParams;-}--const CategoryPaginationProvider: React.StatelessComponent<- CategoryPaginationProviderProps-> = ({ children, id, navigate, params }) => {- const paginationState = createPaginationState(PAGINATE_BY, params);- return (- <TypedCategoryPropertiesQuery- query={categoryPropertiesQuery}- variables={{ id, ...paginationState }}- fetchPolicy="network-only"- >- {({ loading, error, data }) => {- if (error) {- return (- <ErrorMessageCard- message={i18n.t("Unable to find a matching category.")}- />- );- }- const {- loadNextPage,- loadPreviousPage,- pageInfo- } = createPaginationData(- navigate,- paginationState,- categoryShowUrl(id),- data && data.category && data.category.products- ? data.category.products.pageInfo- : undefined,- loading- );-- if (typeof children === "function") {- return children({- data,- loadNextPage,- loadPreviousPage,- loading,- pageInfo- });- }- if (React.Children.count(children) > 0) {- return React.Children.only(children);- }- return null;- }}- </TypedCategoryPropertiesQuery>- );-};--interface CategoryDetailsProps {- params: QueryParams;- id: string;-}--const CategoryDetails: React.StatelessComponent<CategoryDetailsProps> = ({- params,- id-}) => {- if (id) {- return (- <Navigator>- {navigate => {- return (- <CategoryPaginationProvider- id={id}- params={params}- navigate={navigate}- >- {({- data,- loading,- loadNextPage,- loadPreviousPage,- pageInfo- }) => {- return (- <CategoryDeleteProvider category={data.category}>- {deleteCategory => (- <CategoryDetailsPage- category={data ? data.category : undefined}- products={- data && data.category && data.category.products- ? data.category.products.edges.map(- edge => edge.node- )- : undefined- }- subcategories={- data && data.category && data.category.children- ? data.category.children.edges.map(- edge => edge.node- )- : undefined- }- loading={loading}- onAddCategory={() => navigate(categoryAddUrl(id))}- onAddProduct={() => navigate(productAddUrl)}- onBack={() => window.history.back()}- onCategoryClick={id => () =>- navigate(categoryShowUrl(id))}- onDelete={deleteCategory}- onEdit={() => navigate(categoryEditUrl(id))}- onProductClick={id => () => navigate(productUrl(id))}- pageInfo={pageInfo}- onNextPage={loadNextPage}- onPreviousPage={loadPreviousPage}- />- )}- </CategoryDeleteProvider>- );- }}- </CategoryPaginationProvider>- );- }}- </Navigator>- );- }- return (- <TypedRootCategoryChildrenQuery- query={rootCategoryChildrenQuery}- fetchPolicy="network-only"- >- {({ error, loading, data }) => {- if (error) {- return <ErrorMessageCard message={error.message} />;- }- return (- <Navigator>- {navigate => (- <CategoryDetailsPage- subcategories={- data && data.categories- ? data.categories.edges.map(edge => edge.node)- : undefined- }- loading={loading}- onAddCategory={() => navigate(categoryAddUrl())}- onAddProduct={() => navigate(productAddUrl)}- onBack={() => window.history.back()}- onCategoryClick={id => () => navigate(categoryShowUrl(id))}- onProductClick={id => () => navigate(productUrl(id))}- />- )}- </Navigator>- );- }}- </TypedRootCategoryChildrenQuery>- );-};--export default CategoryDetails;diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsxnew file mode 100644index 0000000000..65141fd1c6--- /dev/null+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx@@ -0,0 +1,197 @@+import DialogContentText from "@material-ui/core/DialogContentText";+import * as React from "react";+import { Route } from "react-router-dom";++import { categoryListUrl, categoryUrl, categoryAddUrl } from "../..";+import ActionDialog from "../../../components/ActionDialog";+import Messages from "../../../components/messages";+import Navigator from "../../../components/Navigator";+import i18n from "../../../i18n";+import {+ createPaginationData,+ createPaginationState,+ maybe+} from "../../../misc";+import { productUrl, productAddUrl } from "../../../products";+import { CategoryUpdatePage } from "../../components/CategoryUpdatePage/CategoryUpdatePage";+import {+ TypedCategoryDeleteMutation,+ TypedCategoryUpdateMutation+} from "../../mutations";+import { TypedCategoryDetailsQuery } from "../../queries";+import { CategoryDelete } from "../../types/CategoryDelete";+import { CategoryUpdate } from "../../types/CategoryUpdate";+import { categoryDeleteUrl } from "./urls";++export interface QueryParams {+ after?: string;+ before?: string;+}+export interface CategoryDetailsProps {+ params: QueryParams;+ id: string;+}++const PAGINATE_BY = 20;++export const CategoryDetails: React.StatelessComponent<+ CategoryDetailsProps+> = ({ id, params }) => (+ <Navigator>+ {navigate => (+ <Messages>+ {pushMessage => {+ const onCategoryUpdate = (data: CategoryUpdate) => {+ if (+ data.categoryUpdate.errors === null ||+ data.categoryUpdate.errors.length === 0+ ) {+ pushMessage({+ text: i18n.t("Category updated", {+ context: "notification"+ })+ });+ }+ };+ const onCategoryDelete = (data: CategoryDelete) => {+ if (+ data.categoryDelete.errors === null ||+ data.categoryDelete.errors.length === 0+ ) {+ pushMessage({+ text: i18n.t("Category deleted", {+ context: "notification"+ })+ });+ navigate(categoryListUrl);+ }+ };++ return (+ <TypedCategoryDeleteMutation onCompleted={onCategoryDelete}>+ {deleteCategory => (+ <TypedCategoryUpdateMutation onCompleted={onCategoryUpdate}>+ {(updateCategory, updateResult) => {+ const paginationState = createPaginationState(+ PAGINATE_BY,+ params+ );+ return (+ <TypedCategoryDetailsQuery+ variables={{ ...paginationState, id }}+ >+ {({ data, loading }) => {+ const paginationData = createPaginationData(+ navigate,+ paginationState,+ categoryUrl(id),+ maybe(() => data.category.products.pageInfo),+ loading+ );+ return (+ <>+ <CategoryUpdatePage+ category={maybe(() => data.category)}+ disabled={loading}+ errors={maybe(+ () => updateResult.data.categoryUpdate.errors+ )}+ placeholderImage={""}+ onAddCategory={() =>+ navigate(categoryAddUrl(id))+ }+ onAddProduct={() => navigate(productAddUrl)}+ onBack={() =>+ navigate(+ categoryUrl(+ maybe(() => data.category.parent.id)+ )+ )+ }+ onCategoryClick={id => () =>+ navigate(categoryUrl(id))}+ onDelete={() => navigate(categoryDeleteUrl(id))}+ onImageDelete={() => undefined}+ onImageUpload={() => undefined}+ onNextPage={paginationData.loadNextPage}+ onPreviousPage={paginationData.loadPreviousPage}+ pageInfo={paginationData.pageInfo}+ onProductClick={id => () =>+ navigate(productUrl(id))}+ onSubmit={formData =>+ updateCategory({+ variables: {+ id,+ input: {+ description: formData.description,+ name: formData.name,+ seo: {+ description: formData.seoDescription,+ title: formData.seoTitle+ }+ }+ }+ })+ }+ products={maybe(() =>+ data.category.products.edges.map(+ edge => edge.node+ )+ )}+ saveButtonBarState={+ loading ? "loading" : "default"+ }+ subcategories={maybe(() =>+ data.category.children.edges.map(+ edge => edge.node+ )+ )}+ />+ <Route+ path={categoryDeleteUrl(id)}+ render={({ match }) => (+ <ActionDialog+ onClose={() =>+ navigate(categoryUrl(id), true)+ }+ onConfirm={() =>+ deleteCategory({ variables: { id } })+ }+ open={!!match}+ title={i18n.t("Delete category", {+ context: "modal title"+ })}+ variant="delete"+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ categoryName }}</strong>?",+ {+ categoryName: maybe(+ () => data.category.name+ ),+ context: "modal message"+ }+ )+ }}+ />+ </ActionDialog>+ )}+ />+ </>+ );+ }}+ </TypedCategoryDetailsQuery>+ );+ }}+ </TypedCategoryUpdateMutation>+ )}+ </TypedCategoryDeleteMutation>+ );+ }}+ </Messages>+ )}+ </Navigator>+);+export default CategoryDetails;diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts b/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.tsnew file mode 100644index 0000000000..f3ea8d8f09--- /dev/null+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/urls.ts@@ -0,0 +1,3 @@+import { categoryUrl } from "../..";++export const categoryDeleteUrl = (id: string) => categoryUrl(id) + "delete";diff --git a/saleor/static/dashboard-next/categories/views/CategoryUpdate.tsx b/saleor/static/dashboard-next/categories/views/CategoryUpdate.tsxdeleted file mode 100644index b4875d772a..0000000000--- a/saleor/static/dashboard-next/categories/views/CategoryUpdate.tsx+++ /dev/null@@ -1,75 +0,0 @@-import * as React from "react";--import ErrorMessageCard from "../../components/ErrorMessageCard";-import Messages from "../../components/messages";-import Navigator, { NavigatorLink } from "../../components/Navigator";-import i18n from "../../i18n";-import CategoryEditPage from "../components/CategoryEditPage";-import { categoryShowUrl } from "../index";-import { TypedCategoryUpdateMutation } from "../mutations";-import { categoryDetailsQuery, TypedCategoryDetailsQuery } from "../queries";-import { CategoryUpdate } from "../types/CategoryUpdate";--interface CategoryUpdateFormProps {- id: string;-}--export const CategoryUpdateForm: React.StatelessComponent<- CategoryUpdateFormProps-> = ({ id }) => (- <Messages>- {pushMessage => (- <Navigator>- {navigate => (- <TypedCategoryDetailsQuery- query={categoryDetailsQuery}- variables={{ id }}- >- {({ data, loading, error }) => {- if (error) {- return <ErrorMessageCard message={error.message} />;- }- const handleUpdateSuccess = (data: CategoryUpdate) => {- if (data.categoryUpdate.errors.length === 0) {- pushMessage({ text: i18n.t("Category updated") });- navigate(categoryShowUrl(data.categoryUpdate.category.id));- }- };- return (- <TypedCategoryUpdateMutation onCompleted={handleUpdateSuccess}>- {(- updateCategory,- { called, data: updateResult, loading: updateInProgress }- ) => {- const errors =- called && !updateInProgress && updateResult- ? updateResult.categoryUpdate.errors- : [];- return (- <NavigatorLink to={categoryShowUrl(id)}>- {handleCancel => (- <CategoryEditPage- category={data ? data.category : undefined}- errors={errors}- disabled={updateInProgress || loading}- variant="edit"- onBack={handleCancel}- onSubmit={data =>- updateCategory({- variables: { ...data, id }- })- }- />- )}- </NavigatorLink>- );- }}- </TypedCategoryUpdateMutation>- );- }}- </TypedCategoryDetailsQuery>- )}- </Navigator>- )}- </Messages>-);diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsxindex 5468673ec7..5858d67604 100644--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx@@ -8,10 +8,10 @@ import TableRow from "@material-ui/core/TableRow";import * as React from "react";import { ListProps } from "../..";+import { CategoryDetails_category_products_edges_node } from "../../categories/types/CategoryDetails";import TableCellAvatar from "../../components/TableCellAvatar";import i18n from "../../i18n";import { renderCollection } from "../../misc";-import { MoneyType } from "../../products";import Money from "../Money";import Skeleton from "../Skeleton";import StatusLabel from "../StatusLabel";@@ -35,18 +35,7 @@ const decorate = withStyles(theme => ({}));interface ProductListProps extends ListProps {- products?: Array<{- id: string;- name: string;- productType: {- name: string;- };- thumbnailUrl: string;- availability: {- available: boolean;- };- price: MoneyType;- }>;+ products: CategoryDetails_category_products_edges_node[];}export const ProductList = decorate<ProductListProps>(diff --git a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsxindex 6251bead93..c2861fa74a 100644--- a/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx+++ b/saleor/static/dashboard-next/products/components/ProductListCard/ProductListCard.tsx@@ -3,26 +3,15 @@ import Card from "@material-ui/core/Card";import AddIcon from "@material-ui/icons/Add";import * as React from "react";-import { MoneyType } from "../..";import { PageListProps } from "../../..";+import { CategoryDetails_category_products_edges_node } from "../../../categories/types/CategoryDetails";import Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import ProductList from "../../../components/ProductList";import i18n from "../../../i18n";interface ProductListCardProps extends PageListProps {- products?: Array<{- id: string;- name: string;- productType: {- name: string;- };- thumbnailUrl: string;- availability: {- available: boolean;- };- price: MoneyType;- }>;+ products: CategoryDetails_category_products_edges_node[];}export const ProductListCard: React.StatelessComponent<diff --git a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsxindex e0e78006c3..82ec147fe1 100644--- a/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx+++ b/saleor/static/dashboard-next/storybook/stories/categories/CategoryUpdatePage.tsx@@ -2,21 +2,19 @@ import { storiesOf } from "@storybook/react";import * as React from "react";import * as placeholderImage from "../../../../images/placeholder255x255.png";-import { categories, category } from "../../../categories/fixtures";-import { products as productsFixture } from "../../../products/fixtures";+import { category as categoryFixture } from "../../../categories/fixtures";import CategoryUpdatePage, {CategoryUpdatePageProps} from "../../../categories/components/CategoryUpdatePage";import Decorator from "../../Decorator";-const products = productsFixture(placeholderImage);+const category = categoryFixture(placeholderImage);const updateProps: CategoryUpdatePageProps = {category,disabled: false,errors: [],- loading: false,onAddCategory: undefined,onAddProduct: undefined,onBack: () => undefined,@@ -33,18 +31,15 @@ const updateProps: CategoryUpdatePageProps = {hasPreviousPage: true},placeholderImage,- products,- subcategories: categories+ products: category.products.edges.map(edge => edge.node),+ subcategories: category.children.edges.map(edge => edge.node)};storiesOf("Views / Categories / Update category", module).addDecorator(Decorator).add("default", () => <CategoryUpdatePage {...updateProps} />).add("no background", () => (- <CategoryUpdatePage- {...updateProps}- category={{ ...category, backgroundImage: null }}- />+ <CategoryUpdatePage {...updateProps} category={category} />)).add("no subcategories", () => (<CategoryUpdatePage {...updateProps} subcategories={[]} />@@ -58,7 +53,6 @@ storiesOf("Views / Categories / Update category", module)subcategories={undefined}disabled={true}products={undefined}- loading={true}category={undefined}/>));diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsxindex 3febf86ee3..91fc954336 100644--- a/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductListCard.tsx@@ -2,19 +2,14 @@ import { storiesOf } from "@storybook/react";import * as React from "react";import * as placeholderImage from "../../../../images/placeholder255x255.png";+import { category as categoryFixture } from "../../../categories/fixtures";import { pageListProps } from "../../../fixtures";import ProductListCard from "../../../products/components/ProductListCard";-import { products as productFixture } from "../../../products/fixtures";import Decorator from "../../Decorator";-const products = productFixture(placeholderImage);--// disabled: false,-// onAdd: undefined,-// onNextPage: undefined,-// onPreviousPage: undefined,-// onRowClick: () => undefined,-// pageInfo+const products = categoryFixture(placeholderImage).products.edges.map(+ edge => edge.node+);storiesOf("Views / Products / Product list", module).addDecorator(Decorator)