Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add category list and creating
dominik-zeglen7997998a3e61
diff --git a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsxindex 569a80b7c4..20f4d7d524 100644--- a/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx+++ b/saleor/static/dashboard-next/categories/components/CategoryListPage/CategoryListPage.tsx@@ -24,7 +24,7 @@ export interface CategoryTableProps {const decorate = withStyles({});-export const CategoryTable = decorate<CategoryTableProps>(+export const CategoryListPage = decorate<CategoryTableProps>(({ categories, onAddCategory, onCategoryClick }) => {return (<>@@ -49,4 +49,4 @@ export const CategoryTable = decorate<CategoryTableProps>();});-export default CategoryTable;+export default CategoryListPage;diff --git a/saleor/static/dashboard-next/categories/index.tsx b/saleor/static/dashboard-next/categories/index.tsxindex f358c2f2bb..1fdabaf0d0 100644--- a/saleor/static/dashboard-next/categories/index.tsx+++ b/saleor/static/dashboard-next/categories/index.tsx@@ -1,6 +1,8 @@// import { parse as parseQs } from "qs";import * as React from "react";-import { Route, Switch } from "react-router-dom";+import { Route, RouteComponentProps, Switch } from "react-router-dom";+import { CategoryCreateView } from "./views/CategoryCreate";+import CategoryList from "./views/CategoryList";// import { CategoryCreateForm } from "./views/CategoryCreate";// import CategoryDetails from "./views/CategoryDetails";@@ -17,11 +19,11 @@ import { Route, Switch } from "react-router-dom";// };// return <CategoryDetails id={match.params.id} params={params} />;// };-// const SubcategoryCreateForm: React.StatelessComponent<-// RouteComponentProps<any>-// > = ({ match }) => {-// return <CategoryCreateForm parentId={match.params.id} />;-// };+const CategoryCreate: React.StatelessComponent<RouteComponentProps<any>> = ({+ match+}) => {+ return <CategoryCreateView parentId={match.params.id} />;+};// const SubcategoryUpdateForm: React.StatelessComponent<// RouteComponentProps<any>// > = ({ match }) => {@@ -30,9 +32,8 @@ import { Route, Switch } from "react-router-dom";const Component = ({ match }) => (<Switch>- <Route exact path={match.url} component={null} />- <Route exact path={`${match.url}/add/`} component={null} />- <Route exact path={`${match.url}/:id/edit/`} component={null} />+ <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} /></Switch>@@ -45,10 +46,7 @@ export const categoryAddUrl = (parentId?: string) => {}return `/categories/add/`;};-export const categoryEditUrl = (id: string) => {- return `/categories/${id}/edit/`;-};-export const categoryShowUrl = (id?: string) => {+export const categoryUrl = (id?: string) => {return `/categories/${id ? `${id}/` : ""}`;};export default Component;diff --git a/saleor/static/dashboard-next/categories/mutations.ts b/saleor/static/dashboard-next/categories/mutations.tsindex d18d499691..8b24d822b0 100644--- a/saleor/static/dashboard-next/categories/mutations.ts+++ b/saleor/static/dashboard-next/categories/mutations.ts@@ -30,10 +30,8 @@ export const TypedCategoryDeleteMutation = TypedMutation<>(categoryDeleteMutation);export const categoryCreateMutation = gql`- mutation CategoryCreate($name: String, $description: String, $parent: ID) {- categoryCreate(- input: { name: $name, description: $description, parent: $parent }- ) {+ mutation CategoryCreate($input: CategoryInput!) {+ categoryCreate(input: $input) {errors {fieldmessage@@ -45,6 +43,8 @@ export const categoryCreateMutation = gql`parent {id}+ seoDescription+ seoTitle}}}diff --git a/saleor/static/dashboard-next/categories/queries.ts b/saleor/static/dashboard-next/categories/queries.tsindex 223a29fe57..6ba1b2cb65 100644--- a/saleor/static/dashboard-next/categories/queries.ts+++ b/saleor/static/dashboard-next/categories/queries.ts@@ -1,41 +1,16 @@import gql from "graphql-tag";-import * as React from "react";-import { Query, QueryProps } from "react-apollo";+import { TypedQuery } from "../queries";import {CategoryDetails,CategoryDetailsVariables} from "./types/CategoryDetails";-import {- CategoryProperties,- CategoryPropertiesVariables-} from "./types/CategoryProperties";-import { RootCategoryChildren } from "./types/RootCategoryChildren";--export const TypedCategoryDetailsQuery = Query as React.ComponentType<- QueryProps<CategoryDetails, CategoryDetailsVariables>->;-export const categoryDetailsQuery = gql`- query CategoryDetails($id: ID!) {- category(id: $id) {- id- name- description- parent {- id- }- }- }-`;+import { RootCategories } from "./types/RootCategories";-export const TypedRootCategoryChildrenQuery = Query as React.ComponentType<- QueryProps<RootCategoryChildren>->;-export const rootCategoryChildrenQuery = gql`- query RootCategoryChildren {+export const rootCategories = gql`+ query RootCategories {categories(level: 0) {edges {- cursornode {idname@@ -50,12 +25,12 @@ export const rootCategoryChildrenQuery = gql`}}`;+export const TypedRootCategoriesQuery = TypedQuery<RootCategories, {}>(+ rootCategories+);-export const TypedCategoryPropertiesQuery = Query as React.ComponentType<- QueryProps<CategoryProperties, CategoryPropertiesVariables>->;-export const categoryPropertiesQuery = gql`- query CategoryProperties(+export const categoryDetails = gql`+ query CategoryDetails($id: ID!$first: Int$after: String@@ -84,7 +59,6 @@ export const categoryPropertiesQuery = gql`}}products(first: $first, after: $after, last: $last, before: $before) {- totalCountpageInfo {endCursorhasNextPage@@ -107,3 +81,7 @@ export const categoryPropertiesQuery = gql`}}`;+export const TypedCategoryDetailsQuery = TypedQuery<+ CategoryDetails,+ CategoryDetailsVariables+>(categoryDetails);diff --git a/saleor/static/dashboard-next/categories/types/CategoryCreate.ts b/saleor/static/dashboard-next/categories/types/CategoryCreate.tsindex 0dd17c9cd5..dcc5bd8b6e 100644--- a/saleor/static/dashboard-next/categories/types/CategoryCreate.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryCreate.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: CategoryCreate// ====================================================@@ -22,6 +24,8 @@ export interface CategoryCreate_categoryCreate_category {name: string;description: string;parent: CategoryCreate_categoryCreate_category_parent | null;+ seoDescription: string | null;+ seoTitle: string | null;}export interface CategoryCreate_categoryCreate {@@ -35,7 +39,5 @@ export interface CategoryCreate {}export interface CategoryCreateVariables {- name?: string | null;- description?: string | null;- parent?: string | null;+ input: CategoryInput;}diff --git a/saleor/static/dashboard-next/categories/types/CategoryDetails.ts b/saleor/static/dashboard-next/categories/types/CategoryDetails.tsindex 321e692d17..d2caba5a54 100644--- a/saleor/static/dashboard-next/categories/types/CategoryDetails.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryDetails.ts@@ -10,12 +10,76 @@ export interface CategoryDetails_category_parent {id: string;}+export interface CategoryDetails_category_children_edges_node_children {+ __typename: "CategoryCountableConnection";+ totalCount: number | null;+}++export interface CategoryDetails_category_children_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface CategoryDetails_category_children_edges_node {+ __typename: "Category";+ id: string;+ name: string;+ children: CategoryDetails_category_children_edges_node_children | null;+ products: CategoryDetails_category_children_edges_node_products | null;+}++export interface CategoryDetails_category_children_edges {+ __typename: "CategoryCountableEdge";+ node: CategoryDetails_category_children_edges_node;+}++export interface CategoryDetails_category_children {+ __typename: "CategoryCountableConnection";+ edges: CategoryDetails_category_children_edges[];+}++export interface CategoryDetails_category_products_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}++export interface CategoryDetails_category_products_edges_node_productType {+ __typename: "ProductType";+ id: string;+ name: string;+}++export interface CategoryDetails_category_products_edges_node {+ __typename: "Product";+ id: string;+ name: string;+ thumbnailUrl: string | null;+ productType: CategoryDetails_category_products_edges_node_productType;+}++export interface CategoryDetails_category_products_edges {+ __typename: "ProductCountableEdge";+ cursor: string;+ node: CategoryDetails_category_products_edges_node;+}++export interface CategoryDetails_category_products {+ __typename: "ProductCountableConnection";+ pageInfo: CategoryDetails_category_products_pageInfo;+ edges: CategoryDetails_category_products_edges[];+}+export interface CategoryDetails_category {__typename: "Category";id: string;name: string;description: string;parent: CategoryDetails_category_parent | null;+ children: CategoryDetails_category_children | null;+ products: CategoryDetails_category_products | null;}export interface CategoryDetails {@@ -24,4 +88,8 @@ export interface CategoryDetails {export interface CategoryDetailsVariables {id: string;+ first?: number | null;+ after?: string | null;+ last?: number | null;+ before?: string | null;}diff --git a/saleor/static/dashboard-next/categories/types/CategoryProperties.ts b/saleor/static/dashboard-next/categories/types/CategoryProperties.tsindex 4aa3375a09..3ff2be8c53 100644--- a/saleor/static/dashboard-next/categories/types/CategoryProperties.ts+++ b/saleor/static/dashboard-next/categories/types/CategoryProperties.ts@@ -68,7 +68,6 @@ export interface CategoryProperties_category_products_edges {export interface CategoryProperties_category_products {__typename: "ProductCountableConnection";- totalCount: number | null;pageInfo: CategoryProperties_category_products_pageInfo;edges: CategoryProperties_category_products_edges[];}diff --git a/saleor/static/dashboard-next/categories/types/RootCategories.ts b/saleor/static/dashboard-next/categories/types/RootCategories.tsnew file mode 100644index 0000000000..c44f498e53--- /dev/null+++ b/saleor/static/dashboard-next/categories/types/RootCategories.ts@@ -0,0 +1,38 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL query operation: RootCategories+// ====================================================++export interface RootCategories_categories_edges_node_children {+ __typename: "CategoryCountableConnection";+ totalCount: number | null;+}++export interface RootCategories_categories_edges_node_products {+ __typename: "ProductCountableConnection";+ totalCount: number | null;+}++export interface RootCategories_categories_edges_node {+ __typename: "Category";+ id: string;+ name: string;+ children: RootCategories_categories_edges_node_children | null;+ products: RootCategories_categories_edges_node_products | null;+}++export interface RootCategories_categories_edges {+ __typename: "CategoryCountableEdge";+ node: RootCategories_categories_edges_node;+}++export interface RootCategories_categories {+ __typename: "CategoryCountableConnection";+ edges: RootCategories_categories_edges[];+}++export interface RootCategories {+ categories: RootCategories_categories | null;+}diff --git a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsxindex 342228ae23..af72fd30d2 100644--- a/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx+++ b/saleor/static/dashboard-next/categories/views/CategoryCreate.tsx@@ -1,19 +1,20 @@import * as React from "react";+import { categoryUrl } from "../";import Messages from "../../components/messages";-import Navigator, { NavigatorLink } from "../../components/Navigator";+import Navigator from "../../components/Navigator";import i18n from "../../i18n";-import CategoryEditPage from "../components/CategoryEditPage";-import { categoryShowUrl } from "../index";+import { maybe } from "../../misc";+import CategoryCreatePage from "../components/CategoryCreatePage";import { TypedCategoryCreateMutation } from "../mutations";import { CategoryCreate } from "../types/CategoryCreate";-interface CategoryCreateFormProps {+interface CategoryCreateViewProps {parentId: string;}-export const CategoryCreateForm: React.StatelessComponent<- CategoryCreateFormProps+export const CategoryCreateView: React.StatelessComponent<+ CategoryCreateViewProps> = ({ parentId }) => (<Messages>{pushMessage => (@@ -22,36 +23,33 @@ export const CategoryCreateForm: React.StatelessComponent<const handleSuccess = (data: CategoryCreate) => {if (data.categoryCreate.errors.length === 0) {pushMessage({ text: i18n.t("Category created") });- navigate(categoryShowUrl(data.categoryCreate.category.id));+ navigate(categoryUrl(data.categoryCreate.category.id));}};return (<TypedCategoryCreateMutation onCompleted={handleSuccess}>- {(- mutate,- { called, data: createResult, loading: createInProgress }- ) => {- const errors =- called && !createInProgress && createResult- ? createResult.categoryCreate.errors- : [];- return (- <NavigatorLink to={categoryShowUrl(parentId)}>- {handleCancel => (- <CategoryEditPage- category={{ description: "", name: "" }}- errors={errors}- disabled={createInProgress}- variant="add"- onBack={handleCancel}- onSubmit={data =>- mutate({ variables: { ...data, parent: parentId } })+ {(mutate, { data, loading }) => (+ <CategoryCreatePage+ errors={maybe(() => data.categoryCreate.errors, [])}+ disabled={loading}+ onBack={() => navigate(categoryUrl(parentId))}+ onSubmit={formData =>+ mutate({+ variables: {+ input: {+ description: formData.description,+ name: formData.name,+ parent: parentId,+ seo: {+ description: formData.seoDescription,+ title: formData.seoTitle+ }}- />- )}- </NavigatorLink>- );- }}+ }+ })+ }+ />+ )}</TypedCategoryCreateMutation>);}}@@ -59,3 +57,4 @@ export const CategoryCreateForm: React.StatelessComponent<)}</Messages>);+export default CategoryCreateView;diff --git a/saleor/static/dashboard-next/categories/views/CategoryList.tsx b/saleor/static/dashboard-next/categories/views/CategoryList.tsxnew file mode 100644index 0000000000..4f22a6172f--- /dev/null+++ b/saleor/static/dashboard-next/categories/views/CategoryList.tsx@@ -0,0 +1,27 @@+import * as React from "react";++import { categoryAddUrl, categoryUrl } from "..";+import Navigator from "../../components/Navigator";+import { maybe } from "../../misc";+import { CategoryListPage } from "../components/CategoryListPage/CategoryListPage";+import { TypedRootCategoriesQuery } from "../queries";++export const CategoryList: React.StatelessComponent = () => (+ <Navigator>+ {navigate => (+ <TypedRootCategoriesQuery>+ {({ data }) => (+ <CategoryListPage+ categories={maybe(+ () => data.categories.edges.map(edge => edge.node),+ []+ )}+ onAddCategory={() => navigate(categoryAddUrl())}+ onCategoryClick={id => () => navigate(categoryUrl(id))}+ />+ )}+ </TypedRootCategoriesQuery>+ )}+ </Navigator>+);+export default CategoryList;diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex 4fdb0f40e0..e63b52a630 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -131,17 +131,17 @@ export interface AttributeCreateInput {values?: (AttributeValueCreateInput | null)[] | null;}+export interface AttributeUpdateInput {+ name?: string | null;+ removeValues?: (string | null)[] | null;+ addValues?: (AttributeValueCreateInput | null)[] | null;+}+export interface AttributeValueCreateInput {name: string;value?: string | null;}-export interface AttributeUpdateInput {- name?: string | null;- removeValues: (string | null)[];- addValues: (AttributeValueCreateInput | null)[];-}-export interface AttributeValueInput {slug: string;value: string;@@ -152,6 +152,14 @@ export interface AuthorizationKeyInput {password: string;}+export interface CategoryInput {+ description?: string | null;+ name?: string | null;+ parent?: string | null;+ slug?: string | null;+ seo?: SeoInput | null;+}+export interface DraftOrderInput {billingAddress?: AddressInput | null;user?: string | null;@@ -215,6 +223,11 @@ export interface ProductTypeInput {taxRate?: TaxRateType | null;}+export interface SeoInput {+ title?: string | null;+ description?: string | null;+}+export interface ShopSettingsInput {headerText?: string | null;description?: string | null;