Skip to content

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

Add collection details

dominik-zeglen926a963dd4ff
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index 3573289e02..01d2accd07 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -62,6 +62,7 @@ const CollectionDetailsPage = decorate<CollectionDetailsPageProps>(
seoTitle: maybe(() => collection.seoTitle)
}}
onSubmit={onSubmit}
+ key={JSON.stringify(collection) + isFeatured}
>
{({ change, data, errors: formErrors, hasChanged, submit }) => (
<Container width="md">
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
index 5c945e7408..6980e91351 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
@@ -83,9 +83,9 @@ const CollectionProducts = decorate<CollectionProductsProps>(
<TableRow>
<TablePagination
colSpan={4}
- hasNextPage={pageInfo.hasNextPage}
+ hasNextPage={maybe(() => pageInfo.hasNextPage)}
onNextPage={onNextPage}
- hasPreviousPage={pageInfo.hasPreviousPage}
+ hasPreviousPage={maybe(() => pageInfo.hasPreviousPage)}
onPreviousPage={onPreviousPage}
/>
</TableRow>
diff --git a/saleor/static/dashboard-next/collections/index.tsx b/saleor/static/dashboard-next/collections/index.tsx
index 961a8e41a4..10d6495825 100644
--- a/saleor/static/dashboard-next/collections/index.tsx
+++ b/saleor/static/dashboard-next/collections/index.tsx
@@ -2,7 +2,8 @@ import { parse as parseQs } from "qs";
import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
-import { collectionListUrl } from "./urls";
+import { collectionListUrl, collectionUrl } from "./urls";
+import CollectionDetailsView from "./views/CollectionDetails";
import CollectionListView from "./views/CollectionList";
const CollectionList: React.StatelessComponent<RouteComponentProps<{}>> = ({
@@ -16,12 +17,30 @@ const CollectionList: React.StatelessComponent<RouteComponentProps<{}>> = ({
return <CollectionListView params={params} />;
};
+interface CollectionDetailsRouteProps {
+ id: string;
+}
+const CollectionDetails: React.StatelessComponent<
+ RouteComponentProps<CollectionDetailsRouteProps>
+> = ({ location, match }) => {
+ const qs = parseQs(location.search.substr(1));
+ const params = {
+ after: qs.after,
+ before: qs.before
+ };
+ return (
+ <CollectionDetailsView
+ id={decodeURIComponent(match.params.id)}
+ 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} /> */}
+ {/* <Route exact path={`${match.url}/add/`} component={CategoryCreate} /> */}
+ <Route path={collectionUrl(":id")} component={CollectionDetails} />
</Switch>
);
export default Component;
diff --git a/saleor/static/dashboard-next/collections/queries.ts b/saleor/static/dashboard-next/collections/queries.ts
index 9239b60520..bce1fe69bb 100644
--- a/saleor/static/dashboard-next/collections/queries.ts
+++ b/saleor/static/dashboard-next/collections/queries.ts
@@ -95,6 +95,11 @@ export const collectionDetails = gql`
}
}
}
+ shop {
+ homepageCollection {
+ id
+ }
+ }
}
`;
export const TypedCollectionDetailsQuery = TypedQuery<
diff --git a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts b/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
index 0bce2d4b60..1dc1b60f18 100644
--- a/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
+++ b/saleor/static/dashboard-next/collections/types/CollectionDetails.ts
@@ -56,8 +56,19 @@ export interface CollectionDetails_collection {
products: CollectionDetails_collection_products | null;
}
+export interface CollectionDetails_shop_homepageCollection {
+ __typename: "Collection";
+ id: string;
+}
+
+export interface CollectionDetails_shop {
+ __typename: "Shop";
+ homepageCollection: CollectionDetails_shop_homepageCollection | null;
+}
+
export interface CollectionDetails {
collection: CollectionDetails_collection | null;
+ shop: CollectionDetails_shop | null;
}
export interface CollectionDetailsVariables {
diff --git a/saleor/static/dashboard-next/collections/urls.ts b/saleor/static/dashboard-next/collections/urls.ts
index bf611ff075..e54654d5a9 100644
--- a/saleor/static/dashboard-next/collections/urls.ts
+++ b/saleor/static/dashboard-next/collections/urls.ts
@@ -1,3 +1,7 @@
export const collectionListUrl = "/collections/";
export const collectionUrl = (id: string) => "/collections/" + id + "/";
export const collectionAddUrl = "/collections/add/";
+export const collectionRemoveUrl = (id: string) =>
+ collectionUrl(id) + "remove/";
+export const collectionImageRemoveUrl = (id: string) =>
+ collectionUrl(id) + "removeImage/";
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
new file mode 100644
index 0000000000..a1b81f3109
--- /dev/null
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -0,0 +1,76 @@
+import * as React from "react";
+
+import Navigator from "../../components/Navigator";
+import { createPaginationData, createPaginationState, maybe } from "../../misc";
+import CollectionDetailsPage from "../components/CollectionDetailsPage/CollectionDetailsPage";
+import { TypedCollectionDetailsQuery } from "../queries";
+import {
+ collectionAddUrl,
+ collectionImageRemoveUrl,
+ collectionListUrl,
+ collectionRemoveUrl,
+ collectionUrl
+} from "../urls";
+
+interface CollectionListProps {
+ id: string;
+ params: {
+ after?: string;
+ before?: string;
+ };
+}
+
+const PAGINATE_BY = 20;
+
+export const CollectionDetails: React.StatelessComponent<
+ CollectionListProps
+> = ({ id, params }) => (
+ <Navigator>
+ {navigate => {
+ const paginationState = createPaginationState(PAGINATE_BY, params);
+ return (
+ <TypedCollectionDetailsQuery variables={{ id, ...paginationState }}>
+ {({ data, loading }) => {
+ const {
+ loadNextPage,
+ loadPreviousPage,
+ pageInfo
+ } = createPaginationData(
+ navigate,
+ paginationState,
+ collectionUrl(encodeURIComponent(id)),
+ maybe(() => data.collection.products.pageInfo),
+ loading
+ );
+ return (
+ <CollectionDetailsPage
+ onAdd={() => navigate(collectionAddUrl)}
+ onBack={() => navigate(collectionListUrl)}
+ disabled={loading}
+ collection={maybe(() => data.collection)}
+ isFeatured={maybe(
+ () => data.shop.homepageCollection.id === data.collection.id,
+ false
+ )}
+ onCollectionRemove={() =>
+ navigate(collectionRemoveUrl(encodeURIComponent(id)))
+ }
+ onImageDelete={() =>
+ navigate(collectionImageRemoveUrl(encodeURIComponent(id)))
+ }
+ onImageUpload={() => undefined}
+ onSubmit={() => undefined}
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ onRowClick={id => () =>
+ navigate(collectionUrl(encodeURIComponent(id)))}
+ />
+ );
+ }}
+ </TypedCollectionDetailsQuery>
+ );
+ }}
+ </Navigator>
+);
+export default CollectionDetails;