Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add collection list view
dominik-zeglend9a22e73ec47
diff --git a/saleor/static/dashboard-next/collections/index.tsx b/saleor/static/dashboard-next/collections/index.tsxnew file mode 100644index 0000000000..961a8e41a4--- /dev/null+++ b/saleor/static/dashboard-next/collections/index.tsx@@ -0,0 +1,27 @@+import { parse as parseQs } from "qs";+import * as React from "react";+import { Route, RouteComponentProps, Switch } from "react-router-dom";++import { collectionListUrl } from "./urls";+import CollectionListView from "./views/CollectionList";++const CollectionList: React.StatelessComponent<RouteComponentProps<{}>> = ({+ location+}) => {+ const qs = parseQs(location.search.substr(1));+ const params = {+ after: qs.after,+ before: qs.before+ };+ return <CollectionListView params={params} />;+};++const Component = () => (+ <Switch>+ <Route exact path={collectionListUrl} component={CollectionList} />+ {/* <Route exact path={`${match.url}/add/`} component={CategoryCreate} />+ <Route exact path={`${match.url}/:id/add/`} component={CategoryCreate} />+ <Route path={`${match.url}/:id/`} component={CategoryDetails} /> */}+ </Switch>+);+export default Component;diff --git a/saleor/static/dashboard-next/collections/queries.ts b/saleor/static/dashboard-next/collections/queries.tsindex 7538d4ed75..9239b60520 100644--- a/saleor/static/dashboard-next/collections/queries.ts+++ b/saleor/static/dashboard-next/collections/queries.ts@@ -48,6 +48,12 @@ export const collectionList = gql`}}}+ pageInfo {+ endCursor+ hasNextPage+ hasPreviousPage+ startCursor+ }}}`;@@ -81,6 +87,12 @@ export const collectionDetails = gql`thumbnailUrl}}+ pageInfo {+ endCursor+ hasNextPage+ hasPreviousPage+ startCursor+ }}}}diff --git a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts b/saleor/static/dashboard-next/collections/types/CollectionDetails.tsindex 4c753652b6..0bce2d4b60 100644--- a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts+++ b/saleor/static/dashboard-next/collections/types/CollectionDetails.ts@@ -31,9 +31,18 @@ export interface CollectionDetails_collection_products_edges {node: CollectionDetails_collection_products_edges_node;}+export interface CollectionDetails_collection_products_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}+export interface CollectionDetails_collection_products {__typename: "ProductCountableConnection";edges: CollectionDetails_collection_products_edges[];+ pageInfo: CollectionDetails_collection_products_pageInfo;}export interface CollectionDetails_collection {diff --git a/saleor/static/dashboard-next/collections/types/CollectionList.ts b/saleor/static/dashboard-next/collections/types/CollectionList.tsindex 6556851aea..2dc9c2bceb 100644--- a/saleor/static/dashboard-next/collections/types/CollectionList.ts+++ b/saleor/static/dashboard-next/collections/types/CollectionList.ts@@ -23,9 +23,18 @@ export interface CollectionList_collections_edges {node: CollectionList_collections_edges_node;}+export interface CollectionList_collections_pageInfo {+ __typename: "PageInfo";+ endCursor: string | null;+ hasNextPage: boolean;+ hasPreviousPage: boolean;+ startCursor: string | null;+}+export interface CollectionList_collections {__typename: "CollectionCountableConnection";edges: CollectionList_collections_edges[];+ pageInfo: CollectionList_collections_pageInfo;}export interface CollectionList {diff --git a/saleor/static/dashboard-next/collections/urls.ts b/saleor/static/dashboard-next/collections/urls.tsnew file mode 100644index 0000000000..bf611ff075--- /dev/null+++ b/saleor/static/dashboard-next/collections/urls.ts@@ -0,0 +1,3 @@+export const collectionListUrl = "/collections/";+export const collectionUrl = (id: string) => "/collections/" + id + "/";+export const collectionAddUrl = "/collections/add/";diff --git a/saleor/static/dashboard-next/collections/views/CollectionList.tsx b/saleor/static/dashboard-next/collections/views/CollectionList.tsxnew file mode 100644index 0000000000..52f5ba4452--- /dev/null+++ b/saleor/static/dashboard-next/collections/views/CollectionList.tsx@@ -0,0 +1,58 @@+import * as React from "react";++import Navigator from "../../components/Navigator";+import { createPaginationData, createPaginationState, maybe } from "../../misc";+import CollectionListPage from "../components/CollectionListPage/CollectionListPage";+import { TypedCollectionListQuery } from "../queries";+import { collectionAddUrl, collectionListUrl, collectionUrl } from "../urls";++interface CollectionListProps {+ params: {+ after?: string;+ before?: string;+ };+}++const PAGINATE_BY = 20;++export const CollectionList: React.StatelessComponent<CollectionListProps> = ({+ params+}) => (+ <Navigator>+ {navigate => {+ const paginationState = createPaginationState(PAGINATE_BY, params);+ return (+ <TypedCollectionListQuery variables={paginationState}>+ {({ data, loading }) => {+ const {+ loadNextPage,+ loadPreviousPage,+ pageInfo+ } = createPaginationData(+ navigate,+ paginationState,+ collectionListUrl,+ maybe(() => data.collections.pageInfo),+ loading+ );+ return (+ <CollectionListPage+ onAdd={() => navigate(collectionAddUrl)}+ disabled={loading}+ collections={maybe(() =>+ data.collections.edges.map(edge => edge.node)+ )}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ pageInfo={pageInfo}+ onRowClick={id => () =>+ navigate(collectionUrl(encodeURIComponent(id)))}+ />+ );+ }}+ </TypedCollectionListQuery>+ );+ }}+ </Navigator>+);+export default CollectionList;diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsxindex 42142e5785..521472ab37 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -17,6 +17,7 @@ import LoginLoading from "./auth/components/LoginLoading/LoginLoading";import SectionRoute from "./auth/components/SectionRoute";import { hasPermission } from "./auth/misc";import CategorySection from "./categories";+import CollectionSection from "./collections";import { DateProvider } from "./components/DateFormatter";import { LocaleProvider } from "./components/Locale";import { MessageManager } from "./components/messages";@@ -109,6 +110,11 @@ render(path="/categories"component={CategorySection}/>+ <SectionRoute+ permissions={[PermissionEnum.MANAGE_PRODUCTS]}+ path="/collections"+ component={CollectionSection}+ /><SectionRoutepermissions={[PermissionEnum.MANAGE_PAGES]}path="/pages"diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsxindex b20b2e5e97..357b7c62b3 100644--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx@@ -293,7 +293,6 @@ export const ProductUpdate = decorate<ProductUpdateProps>(titlePlaceholder={data.name}description={data.seoDescription}descriptionPlaceholder={data.description}- storefrontUrl={product ? product.url : undefined}loading={disabled}onClick={onSeoClick}onChange={change}