Skip to content
Open
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
92 changes: 19 additions & 73 deletions front/src/views/Boxes/BoxesView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ const boxesQuery = ({
boxes: {
__typename: "BoxPage",
elements:
state === "InStock" && state2 === "Scrap"
? [instockBox1, instockBox2, scrapBox]
: state === "InStock"
? [instockBox1, instockBox2]
: state === "Scrap"
? [scrapBox]
: state === "Donated"
? []
: [],
state === "ALL"
? [instockBox1, instockBox2]
: state === "InStock" && state2 === "Scrap"
? [instockBox1, instockBox2, scrapBox]
: state === "InStock"
? [instockBox1, instockBox2]
: state === "Scrap"
? [scrapBox]
: state === "Donated"
? []
: [],
pageInfo: {
__typename: "PageInfo",
hasNextPage: false,
Expand Down Expand Up @@ -307,13 +309,7 @@ describe("4.8.1 - Initial load of Page", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", paginationInput: 50 }),
boxesQuery({ state: "InStock" }),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -326,23 +322,11 @@ describe("4.8.1 - Initial load of Page", () => {
const failedInitialFetching = [
{
name: "4.8.1.2.2 - Failed to Fetch Initial Data",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
initialQueryGraphQLError({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [initialQueryGraphQLError({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
},
{
name: "4.8.1.2.6 - Failed to Fetch Initial Data",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
initialQueryNetworkError({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [initialQueryNetworkError({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
},
];

Expand Down Expand Up @@ -396,13 +380,7 @@ describe("4.8.1 - Initial load of Page", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand All @@ -428,7 +406,6 @@ describe("4.8.1 - Initial load of Page", () => {
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1,6",
mocks: [
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Scrap" }),
actionsQuery,
Expand Down Expand Up @@ -519,13 +496,7 @@ describe("4.8.1 - Initial load of Page", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -648,8 +619,6 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
Expand Down Expand Up @@ -747,13 +716,7 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -820,13 +783,7 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -861,9 +818,6 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
mocks: [
boxesQuery({ state: "ALL", paginationInput: 50 }),
boxesQuery({ state: "ALL" }),
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
actionsQuery,
],
cache,
Expand Down Expand Up @@ -891,13 +845,7 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
{
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?product_ids=267&state_ids=1",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ paginationInput: 50 }),
boxesQuery({}),
actionsQuery,
],
mocks: [boxesQuery({ paginationInput: 50 }), boxesQuery({}), actionsQuery],
cache,
addTypename: true,
jotaiAtoms,
Expand Down Expand Up @@ -932,8 +880,6 @@ describe("4.8.3 - URL Parameter Sync for Filters", () => {
routePath: "/bases/:baseId/boxes",
initialUrl: "/bases/2/boxes?product_ids=267,350&state_ids=1,5",
mocks: [
boxesQuery({ state: "Scrap", paginationInput: 50 }),
boxesQuery({ state: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Donated", paginationInput: 50 }),
boxesQuery({ state: "InStock", state2: "Donated" }),
actionsQuery,
Expand Down
35 changes: 0 additions & 35 deletions front/src/views/Boxes/BoxesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import { FaInfoCircle } from "react-icons/fa";
import { useAtomValue } from "jotai";
import { selectedBaseIdAtom } from "stores/globalPreferenceStore";
import { DateCell, ProductWithSPCheckmarkCell } from "components/Table/Cells";
import { BoxState } from "queries/types";
import BoxesTable, { PAGE_SIZE } from "./components/BoxesTable";
import { boxStateIds } from "utils/constants"; // added import to map state names -> ids
import { useSearchParams } from "react-router-dom";

export const BOXES_QUERY_ELEMENT_FIELD_FRAGMENT = graphql(
Expand Down Expand Up @@ -202,8 +200,6 @@ function Boxes({
},
});

// The first 50 boxes to be shown are preloaded causing the suspense on the initial mount.
// The rest of the boxes are fetched in the background in the following useEffect.
const [boxesQueryRef, { refetch: refetchBoxes }] = useBackgroundQuery(BOXES_FOR_BOXESVIEW_QUERY, {
variables: prepareBoxesForBoxesViewQueryVariables(
baseId,
Expand All @@ -219,37 +215,6 @@ function Boxes({
return;
}

// Only on very initial mount, query 50 boxes of the most used states to preload the data into
// Apollo cache.
// But skip preloading a state if the current table config already requests it via filters.
// e.g. if tableConfig.getColumnFilters() already contains the id for "Donated" (boxStateIds.Donated),
// do not query Donated here.
const states = ["InStock", "Donated", "Scrap"] satisfies Partial<BoxState>[];

// Read the current state filter values (these are state IDs like "5", "6" etc.)
const stateFilterValues: string[] =
(tableConfig.getColumnFilters().find((f) => f.id === "state")?.value as string[]) ?? [];

for (const state of states) {
const stateId = boxStateIds[state];
// If the table is already filtered to this state ID, skip preloading it.
if (stateId && stateFilterValues.includes(stateId)) {
continue;
}

apolloClient.query({
query: BOXES_FOR_BOXESVIEW_QUERY,
variables: {
baseId,
filterInput: {
states: [state],
},
paginationInput: PAGE_SIZE,
},
fetchPolicy: "network-only",
});
}

apolloClient
Comment thread
pylipp marked this conversation as resolved.
.query({
query: BOXES_FOR_BOXESVIEW_QUERY,
Expand Down
Loading
Loading