Merge pull request #249 from mirumee/fix/subcategories-pagination

Fix subcategories pagination
This commit is contained in:
Marcin Gębala 2019-11-12 16:37:37 +01:00 committed by GitHub
commit 09295a5d16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 14 deletions

View file

@ -6,6 +6,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix minor bugs - #244 by @dominik-zeglen - Fix minor bugs - #244 by @dominik-zeglen
- Fix tax settings updating - #243 by @dominik-zeglen - Fix tax settings updating - #243 by @dominik-zeglen
- Fix subcategories pagination - #249 by @dominik-zeglen
## 2.0.0 ## 2.0.0

View file

@ -93,7 +93,14 @@ export const category: (
}, },
children: { children: {
__typename: "CategoryCountableConnection", __typename: "CategoryCountableConnection",
edges: [] edges: [],
pageInfo: {
__typename: "PageInfo",
endCursor: "YXJyYXljb25uZWN0aW9uOjk=",
hasNextPage: false,
hasPreviousPage: false,
startCursor: "YXJyYXljb25uZWN0aW9uOjA="
}
}, },
descriptionJson: JSON.stringify(content), descriptionJson: JSON.stringify(content),
id: "Q2F0ZWdvcnk6NA==", id: "Q2F0ZWdvcnk6NA==",

View file

@ -1,6 +1,6 @@
import gql from "graphql-tag"; import gql from "graphql-tag";
import { TypedQuery } from "../queries"; import { pageInfoFragment, TypedQuery } from "../queries";
import { import {
CategoryDetails, CategoryDetails,
CategoryDetailsVariables CategoryDetailsVariables
@ -38,6 +38,7 @@ export const categoryDetailsFragment = gql`
export const rootCategories = gql` export const rootCategories = gql`
${categoryFragment} ${categoryFragment}
${pageInfoFragment}
query RootCategories( query RootCategories(
$first: Int $first: Int
$after: String $after: String
@ -59,10 +60,7 @@ export const rootCategories = gql`
} }
} }
pageInfo { pageInfo {
endCursor ...PageInfoFragment
hasNextPage
hasPreviousPage
startCursor
} }
} }
} }
@ -74,6 +72,7 @@ export const TypedRootCategoriesQuery = TypedQuery<RootCategories, {}>(
export const categoryDetails = gql` export const categoryDetails = gql`
${categoryFragment} ${categoryFragment}
${categoryDetailsFragment} ${categoryDetailsFragment}
${pageInfoFragment}
query CategoryDetails( query CategoryDetails(
$id: ID! $id: ID!
$first: Int $first: Int
@ -83,19 +82,19 @@ export const categoryDetails = gql`
) { ) {
category(id: $id) { category(id: $id) {
...CategoryDetailsFragment ...CategoryDetailsFragment
children(first: 20) { children(first: $first, after: $after, last: $last, before: $before) {
edges { edges {
node { node {
...CategoryFragment ...CategoryFragment
} }
} }
pageInfo {
...PageInfoFragment
}
} }
products(first: $first, after: $after, last: $last, before: $before) { products(first: $first, after: $after, last: $last, before: $before) {
pageInfo { pageInfo {
endCursor ...PageInfoFragment
hasNextPage
hasPreviousPage
startCursor
} }
edges { edges {
cursor cursor

View file

@ -40,9 +40,18 @@ export interface CategoryDetails_category_children_edges {
node: CategoryDetails_category_children_edges_node; node: CategoryDetails_category_children_edges_node;
} }
export interface CategoryDetails_category_children_pageInfo {
__typename: "PageInfo";
endCursor: string | null;
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: string | null;
}
export interface CategoryDetails_category_children { export interface CategoryDetails_category_children {
__typename: "CategoryCountableConnection"; __typename: "CategoryCountableConnection";
edges: CategoryDetails_category_children_edges[]; edges: CategoryDetails_category_children_edges[];
pageInfo: CategoryDetails_category_children_pageInfo;
} }
export interface CategoryDetails_category_products_pageInfo { export interface CategoryDetails_category_products_pageInfo {

View file

@ -162,7 +162,9 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
}; };
const { loadNextPage, loadPreviousPage, pageInfo } = paginate( const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
maybe(() => data.category.products.pageInfo), params.activeTab === CategoryPageTab.categories
? maybe(() => data.category.children.pageInfo)
: maybe(() => data.category.products.pageInfo),
paginationState, paginationState,
params params
); );

View file

@ -2,7 +2,12 @@
/* eslint-disable */ /* eslint-disable */
// This file was automatically generated and should not be edited. // This file was automatically generated and should not be edited.
import { SiteDomainInput, ShopSettingsInput, AddressInput, AuthorizationKeyType } from "./../../types/globalTypes"; import {
SiteDomainInput,
ShopSettingsInput,
AddressInput,
AuthorizationKeyType
} from "./../../types/globalTypes";
// ==================================================== // ====================================================
// GraphQL mutation operation: ShopSettingsUpdate // GraphQL mutation operation: ShopSettingsUpdate
@ -143,5 +148,5 @@ export interface ShopSettingsUpdate {
export interface ShopSettingsUpdateVariables { export interface ShopSettingsUpdateVariables {
shopDomainInput: SiteDomainInput; shopDomainInput: SiteDomainInput;
shopSettingsInput: ShopSettingsInput; shopSettingsInput: ShopSettingsInput;
addressInput: AddressInput; addressInput?: AddressInput | null;
} }