Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay home queries to be non-blocking for the UI #4405

Merged
merged 17 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-badgers-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Delay home queries to be non-blocking for the UI
4 changes: 2 additions & 2 deletions cypress/support/customCommands/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Cypress.Commands.add("loginInShop", () => {
});

Cypress.Commands.add("visitHomePageLoggedViaApi", user => {
cy.addAliasToGraphRequest("Home")
cy.addAliasToGraphRequest("UserDetails")
.loginUserViaRequest("auth", user)
.visit(urlList.homePage)
.waitForRequestAndCheckIfNoErrors("@Home");
.waitForRequestAndCheckIfNoErrors("@UserDetails");
});

Cypress.Commands.add(
Expand Down
18 changes: 8 additions & 10 deletions cypress/support/pages/homePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { HOMEPAGE_SELECTORS } from "../../elements/homePage/homePage-selectors";
export function changeChannel(channelName) {
cy.get(HEADER_SELECTORS.channelSelect)
.click()
.addAliasToGraphRequest("Home")
.get(HEADER_SELECTORS.channelSelectList)
.contains(channelName)
.click()
.wait("@Home");
.click();
}

export function expectWelcomeMessageIncludes(name) {
Expand All @@ -21,37 +19,37 @@ export function expectWelcomeMessageIncludes(name) {

export function getOrdersReadyToFulfillRegex(
ordersReadyToFulfillBefore,
quantityOfNewOrders
quantityOfNewOrders,
) {
const allOrdersReadyToFulfill =
ordersReadyToFulfillBefore + quantityOfNewOrders;
const notANumberRegex = "\\D*";
return new RegExp(
`${notANumberRegex}${allOrdersReadyToFulfill}${notANumberRegex}`
`${notANumberRegex}${allOrdersReadyToFulfill}${notANumberRegex}`,
);
}

export function getOrdersReadyForCaptureRegex(
ordersReadyForCaptureBefore,
quantityOfNewOrders
quantityOfNewOrders,
) {
const allOrdersReadyForCapture =
ordersReadyForCaptureBefore + quantityOfNewOrders;
const notANumberRegex = "\\D*";
return new RegExp(
`${notANumberRegex}${allOrdersReadyForCapture}${notANumberRegex}`
`${notANumberRegex}${allOrdersReadyForCapture}${notANumberRegex}`,
);
}

export function getProductsOutOfStockRegex(
productsOutOfStockBefore,
quantityOfNewProducts
quantityOfNewProducts,
) {
const allProductsOutOfStock =
productsOutOfStockBefore + quantityOfNewProducts;
const notANumberRegex = "\\D*";
return new RegExp(
`${notANumberRegex}${allProductsOutOfStock}${notANumberRegex}`
`${notANumberRegex}${allProductsOutOfStock}${notANumberRegex}`,
);
}

Expand All @@ -67,7 +65,7 @@ export function getSalesAmountRegex(salesAmountBefore, addedAmount) {
const totalAmountWithSeparators = `${totalAmountIntegerWithThousandsSeparator}${decimalSeparator}${totalAmountDecimalValue}`;
const notANumberRegex = "\\D*";
return new RegExp(
`${notANumberRegex}${totalAmountWithSeparators}${notANumberRegex}`
`${notANumberRegex}${totalAmountWithSeparators}${notANumberRegex}`,
);
}

Expand Down
6 changes: 6 additions & 0 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
"context": "section description",
"string": "Strategy defines the preference of warehouses for stock allocations and reservations."
},
"/Fa+RP": {
"string": "Couldn't load top products"
},
"/ILyIf": {
"context": "tax classes menu header",
"string": "Tax class label"
Expand Down Expand Up @@ -241,6 +244,9 @@
"context": "page label",
"string": "Hidden"
},
"/U8FUp": {
"string": "Couldn't load activities"
},
"/V7UOC": {
"context": "unassign category from sale and save, button",
"string": "Unassign and save"
Expand Down
187 changes: 142 additions & 45 deletions src/graphql/hooks.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8843,8 +8843,8 @@ export function useCustomerGiftCardListLazyQuery(baseOptions?: ApolloReactHooks.
export type CustomerGiftCardListQueryHookResult = ReturnType<typeof useCustomerGiftCardListQuery>;
export type CustomerGiftCardListLazyQueryHookResult = ReturnType<typeof useCustomerGiftCardListLazyQuery>;
export type CustomerGiftCardListQueryResult = Apollo.QueryResult<Types.CustomerGiftCardListQuery, Types.CustomerGiftCardListQueryVariables>;
export const HomeDocument = gql`
query Home($channel: String!, $datePeriod: DateRangeInput!, $hasPermissionToManageProducts: Boolean!, $hasPermissionToManageOrders: Boolean!) {
export const HomeAnaliticsDocument = gql`
query HomeAnalitics($channel: String!, $datePeriod: DateRangeInput!, $hasPermissionToManageOrders: Boolean!) {
salesToday: ordersTotal(period: TODAY, channel: $channel) @include(if: $hasPermissionToManageOrders) {
gross {
amount
Expand All @@ -8854,18 +8854,93 @@ export const HomeDocument = gql`
ordersToday: orders(filter: {created: $datePeriod}, channel: $channel) @include(if: $hasPermissionToManageOrders) {
totalCount
}
ordersToFulfill: orders(filter: {status: READY_TO_FULFILL}, channel: $channel) @include(if: $hasPermissionToManageOrders) {
totalCount
}
ordersToCapture: orders(filter: {status: READY_TO_CAPTURE}, channel: $channel) @include(if: $hasPermissionToManageOrders) {
totalCount
}
productsOutOfStock: products(
filter: {stockAvailability: OUT_OF_STOCK}
channel: $channel
) {
totalCount
}
`;

/**
* __useHomeAnaliticsQuery__
*
* To run a query within a React component, call `useHomeAnaliticsQuery` and pass it any options that fit your needs.
* When your component renders, `useHomeAnaliticsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useHomeAnaliticsQuery({
* variables: {
* channel: // value for 'channel'
* datePeriod: // value for 'datePeriod'
* hasPermissionToManageOrders: // value for 'hasPermissionToManageOrders'
* },
* });
*/
export function useHomeAnaliticsQuery(baseOptions: ApolloReactHooks.QueryHookOptions<Types.HomeAnaliticsQuery, Types.HomeAnaliticsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useQuery<Types.HomeAnaliticsQuery, Types.HomeAnaliticsQueryVariables>(HomeAnaliticsDocument, options);
}
export function useHomeAnaliticsLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<Types.HomeAnaliticsQuery, Types.HomeAnaliticsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useLazyQuery<Types.HomeAnaliticsQuery, Types.HomeAnaliticsQueryVariables>(HomeAnaliticsDocument, options);
}
export type HomeAnaliticsQueryHookResult = ReturnType<typeof useHomeAnaliticsQuery>;
export type HomeAnaliticsLazyQueryHookResult = ReturnType<typeof useHomeAnaliticsLazyQuery>;
export type HomeAnaliticsQueryResult = Apollo.QueryResult<Types.HomeAnaliticsQuery, Types.HomeAnaliticsQueryVariables>;
export const HomeActivitiesDocument = gql`
query HomeActivities($hasPermissionToManageOrders: Boolean!) {
activities: homepageEvents(last: 10) @include(if: $hasPermissionToManageOrders) {
edges {
node {
amount
composedId
date
email
emailType
id
message
orderNumber
oversoldItems
quantity
type
user {
id
email
}
}
}
}
}
`;

/**
* __useHomeActivitiesQuery__
*
* To run a query within a React component, call `useHomeActivitiesQuery` and pass it any options that fit your needs.
* When your component renders, `useHomeActivitiesQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useHomeActivitiesQuery({
* variables: {
* hasPermissionToManageOrders: // value for 'hasPermissionToManageOrders'
* },
* });
*/
export function useHomeActivitiesQuery(baseOptions: ApolloReactHooks.QueryHookOptions<Types.HomeActivitiesQuery, Types.HomeActivitiesQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useQuery<Types.HomeActivitiesQuery, Types.HomeActivitiesQueryVariables>(HomeActivitiesDocument, options);
}
export function useHomeActivitiesLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<Types.HomeActivitiesQuery, Types.HomeActivitiesQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useLazyQuery<Types.HomeActivitiesQuery, Types.HomeActivitiesQueryVariables>(HomeActivitiesDocument, options);
}
export type HomeActivitiesQueryHookResult = ReturnType<typeof useHomeActivitiesQuery>;
export type HomeActivitiesLazyQueryHookResult = ReturnType<typeof useHomeActivitiesLazyQuery>;
export type HomeActivitiesQueryResult = Apollo.QueryResult<Types.HomeActivitiesQuery, Types.HomeActivitiesQueryVariables>;
export const HomeTopProductsDocument = gql`
query HomeTopProducts($channel: String!, $hasPermissionToManageProducts: Boolean!) {
productTopToday: reportProductSales(period: TODAY, first: 5, channel: $channel) @include(if: $hasPermissionToManageProducts) {
edges {
node {
Expand Down Expand Up @@ -8893,60 +8968,82 @@ export const HomeDocument = gql`
}
}
}
activities: homepageEvents(last: 10) @include(if: $hasPermissionToManageOrders) {
edges {
node {
amount
composedId
date
email
emailType
id
message
orderNumber
oversoldItems
quantity
type
user {
id
email
}
}
`;

/**
* __useHomeTopProductsQuery__
*
* To run a query within a React component, call `useHomeTopProductsQuery` and pass it any options that fit your needs.
* When your component renders, `useHomeTopProductsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useHomeTopProductsQuery({
* variables: {
* channel: // value for 'channel'
* hasPermissionToManageProducts: // value for 'hasPermissionToManageProducts'
* },
* });
*/
export function useHomeTopProductsQuery(baseOptions: ApolloReactHooks.QueryHookOptions<Types.HomeTopProductsQuery, Types.HomeTopProductsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useQuery<Types.HomeTopProductsQuery, Types.HomeTopProductsQueryVariables>(HomeTopProductsDocument, options);
}
}
export function useHomeTopProductsLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<Types.HomeTopProductsQuery, Types.HomeTopProductsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useLazyQuery<Types.HomeTopProductsQuery, Types.HomeTopProductsQueryVariables>(HomeTopProductsDocument, options);
}
export type HomeTopProductsQueryHookResult = ReturnType<typeof useHomeTopProductsQuery>;
export type HomeTopProductsLazyQueryHookResult = ReturnType<typeof useHomeTopProductsLazyQuery>;
export type HomeTopProductsQueryResult = Apollo.QueryResult<Types.HomeTopProductsQuery, Types.HomeTopProductsQueryVariables>;
export const HomeNotificationsDocument = gql`
query homeNotifications($channel: String!, $hasPermissionToManageOrders: Boolean!) {
ordersToFulfill: orders(filter: {status: READY_TO_FULFILL}, channel: $channel) @include(if: $hasPermissionToManageOrders) {
totalCount
}
ordersToCapture: orders(filter: {status: READY_TO_CAPTURE}, channel: $channel) @include(if: $hasPermissionToManageOrders) {
totalCount
}
productsOutOfStock: products(
filter: {stockAvailability: OUT_OF_STOCK}
channel: $channel
) {
totalCount
}
}
`;

/**
* __useHomeQuery__
* __useHomeNotificationsQuery__
*
* To run a query within a React component, call `useHomeQuery` and pass it any options that fit your needs.
* When your component renders, `useHomeQuery` returns an object from Apollo Client that contains loading, error, and data properties
* To run a query within a React component, call `useHomeNotificationsQuery` and pass it any options that fit your needs.
* When your component renders, `useHomeNotificationsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useHomeQuery({
* const { data, loading, error } = useHomeNotificationsQuery({
* variables: {
* channel: // value for 'channel'
* datePeriod: // value for 'datePeriod'
* hasPermissionToManageProducts: // value for 'hasPermissionToManageProducts'
* hasPermissionToManageOrders: // value for 'hasPermissionToManageOrders'
* },
* });
*/
export function useHomeQuery(baseOptions: ApolloReactHooks.QueryHookOptions<Types.HomeQuery, Types.HomeQueryVariables>) {
export function useHomeNotificationsQuery(baseOptions: ApolloReactHooks.QueryHookOptions<Types.HomeNotificationsQuery, Types.HomeNotificationsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useQuery<Types.HomeQuery, Types.HomeQueryVariables>(HomeDocument, options);
return ApolloReactHooks.useQuery<Types.HomeNotificationsQuery, Types.HomeNotificationsQueryVariables>(HomeNotificationsDocument, options);
}
export function useHomeLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<Types.HomeQuery, Types.HomeQueryVariables>) {
export function useHomeNotificationsLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<Types.HomeNotificationsQuery, Types.HomeNotificationsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return ApolloReactHooks.useLazyQuery<Types.HomeQuery, Types.HomeQueryVariables>(HomeDocument, options);
return ApolloReactHooks.useLazyQuery<Types.HomeNotificationsQuery, Types.HomeNotificationsQueryVariables>(HomeNotificationsDocument, options);
}
export type HomeQueryHookResult = ReturnType<typeof useHomeQuery>;
export type HomeLazyQueryHookResult = ReturnType<typeof useHomeLazyQuery>;
export type HomeQueryResult = Apollo.QueryResult<Types.HomeQuery, Types.HomeQueryVariables>;
export type HomeNotificationsQueryHookResult = ReturnType<typeof useHomeNotificationsQuery>;
export type HomeNotificationsLazyQueryHookResult = ReturnType<typeof useHomeNotificationsLazyQuery>;
export type HomeNotificationsQueryResult = Apollo.QueryResult<Types.HomeNotificationsQuery, Types.HomeNotificationsQueryVariables>;
export const MenuCreateDocument = gql`
mutation MenuCreate($input: MenuCreateInput!) {
menuCreate(input: $input) {
Expand Down
26 changes: 24 additions & 2 deletions src/graphql/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10277,15 +10277,37 @@ export type CustomerGiftCardListQueryVariables = Exact<{

export type CustomerGiftCardListQuery = { __typename: 'Query', giftCards: { __typename: 'GiftCardCountableConnection', edges: Array<{ __typename: 'GiftCardCountableEdge', node: { __typename: 'GiftCard', id: string, last4CodeChars: string, expiryDate: any | null, isActive: boolean, currentBalance: { __typename: 'Money', amount: number, currency: string } } }> } | null };

export type HomeQueryVariables = Exact<{
export type HomeAnaliticsQueryVariables = Exact<{
channel: Scalars['String'];
datePeriod: DateRangeInput;
hasPermissionToManageOrders: Scalars['Boolean'];
}>;


export type HomeAnaliticsQuery = { __typename: 'Query', salesToday: { __typename: 'TaxedMoney', gross: { __typename: 'Money', amount: number, currency: string } } | null, ordersToday: { __typename: 'OrderCountableConnection', totalCount: number | null } | null };

export type HomeActivitiesQueryVariables = Exact<{
hasPermissionToManageOrders: Scalars['Boolean'];
}>;


export type HomeActivitiesQuery = { __typename: 'Query', activities: { __typename: 'OrderEventCountableConnection', edges: Array<{ __typename: 'OrderEventCountableEdge', node: { __typename: 'OrderEvent', amount: number | null, composedId: string | null, date: any | null, email: string | null, emailType: OrderEventsEmailsEnum | null, id: string, message: string | null, orderNumber: string | null, oversoldItems: Array<string> | null, quantity: number | null, type: OrderEventsEnum | null, user: { __typename: 'User', id: string, email: string } | null } }> } | null };

export type HomeTopProductsQueryVariables = Exact<{
channel: Scalars['String'];
hasPermissionToManageProducts: Scalars['Boolean'];
}>;


export type HomeTopProductsQuery = { __typename: 'Query', productTopToday: { __typename: 'ProductVariantCountableConnection', edges: Array<{ __typename: 'ProductVariantCountableEdge', node: { __typename: 'ProductVariant', id: string, quantityOrdered: number | null, revenue: { __typename: 'TaxedMoney', gross: { __typename: 'Money', amount: number, currency: string } } | null, attributes: Array<{ __typename: 'SelectedAttribute', values: Array<{ __typename: 'AttributeValue', id: string, name: string | null }> }>, product: { __typename: 'Product', id: string, name: string, thumbnail: { __typename: 'Image', url: string } | null } } }> } | null };

export type HomeNotificationsQueryVariables = Exact<{
channel: Scalars['String'];
hasPermissionToManageOrders: Scalars['Boolean'];
}>;


export type HomeQuery = { __typename: 'Query', salesToday: { __typename: 'TaxedMoney', gross: { __typename: 'Money', amount: number, currency: string } } | null, ordersToday: { __typename: 'OrderCountableConnection', totalCount: number | null } | null, ordersToFulfill: { __typename: 'OrderCountableConnection', totalCount: number | null } | null, ordersToCapture: { __typename: 'OrderCountableConnection', totalCount: number | null } | null, productsOutOfStock: { __typename: 'ProductCountableConnection', totalCount: number | null } | null, productTopToday: { __typename: 'ProductVariantCountableConnection', edges: Array<{ __typename: 'ProductVariantCountableEdge', node: { __typename: 'ProductVariant', id: string, quantityOrdered: number | null, revenue: { __typename: 'TaxedMoney', gross: { __typename: 'Money', amount: number, currency: string } } | null, attributes: Array<{ __typename: 'SelectedAttribute', values: Array<{ __typename: 'AttributeValue', id: string, name: string | null }> }>, product: { __typename: 'Product', id: string, name: string, thumbnail: { __typename: 'Image', url: string } | null } } }> } | null, activities: { __typename: 'OrderEventCountableConnection', edges: Array<{ __typename: 'OrderEventCountableEdge', node: { __typename: 'OrderEvent', amount: number | null, composedId: string | null, date: any | null, email: string | null, emailType: OrderEventsEmailsEnum | null, id: string, message: string | null, orderNumber: string | null, oversoldItems: Array<string> | null, quantity: number | null, type: OrderEventsEnum | null, user: { __typename: 'User', id: string, email: string } | null } }> } | null };
export type HomeNotificationsQuery = { __typename: 'Query', ordersToFulfill: { __typename: 'OrderCountableConnection', totalCount: number | null } | null, ordersToCapture: { __typename: 'OrderCountableConnection', totalCount: number | null } | null, productsOutOfStock: { __typename: 'ProductCountableConnection', totalCount: number | null } | null };

export type MenuCreateMutationVariables = Exact<{
input: MenuCreateInput;
Expand Down
Loading
Loading