Skip to content
Draft
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
3 changes: 1 addition & 2 deletions src/hooks/makeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { QueryResult } from "@apollo/client";
import { DocumentNode } from "graphql";
import { useState } from "react";
Expand Down Expand Up @@ -41,7 +40,7 @@ function makeSearch<TData, TVariables extends SearchVariables>(
variables: {
...opts.variables,
query: searchQuery,
},
} as TVariables,
});

return {
Expand Down
11 changes: 7 additions & 4 deletions src/hooks/makeTopLevelSearch/makeTopLevelSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { PageInfoFragment } from "@dashboard/graphql";
import { DocumentNode } from "graphql";

Expand All @@ -10,7 +9,7 @@ export interface SearchData {
node: any;
}>;
pageInfo: PageInfoFragment;
};
} | null;
}

export interface ResultSearchData {
Expand All @@ -28,19 +27,23 @@ function makeTopLevelSearch<TData extends SearchData, TVariables extends SearchV
return prev;
}

if (!next.search) {
return prev;
}

return {
...prev,
search: {
...prev.search,
edges: [...(prev.search?.edges ?? []), ...(next.search?.edges ?? [])],
edges: [...(prev.search?.edges ?? []), ...(next.search.edges ?? [])],
pageInfo: next.search.pageInfo,
},
};
Comment on lines 34 to 41
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: prev.search could be null here, which would cause issues when spreading it on line 37. The null check on line 30 only validates that next.search exists, but doesn't check prev.search. Consider adding a check like if (!next.search || !prev.search) on line 30 to ensure both are non-null before attempting to merge them.

Copilot uses AI. Check for mistakes.
},
{
...result.variables,
after: result.data.search.pageInfo.endCursor,
},
} as Partial<TVariables>,
);
}
});
Expand Down
1 change: 0 additions & 1 deletion src/searches/useAttributeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchAttributesDocument,
Expand Down
24 changes: 14 additions & 10 deletions src/searches/useAttributeValueSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql, useApolloClient } from "@apollo/client";
import {
SearchAttributeValuesDocument,
Expand Down Expand Up @@ -39,18 +38,19 @@ export function useSearchAttributeValuesSuggestions() {
query,
},
})
.then(({ data }) =>
mapEdgesToItems(data.attribute.choices).map(({ name, slug }) => ({
label: name,
value: slug,
})),
.then(
({ data }) =>
mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ?? undefined is redundant here. The mapEdgesToItems function already accepts undefined | null as per its signature: function mapEdgesToItems<T>(data?: Connection<T> | undefined | null). You can simplify this to mapEdgesToItems(data.attribute?.choices)?.map(...).

Suggested change
mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({
mapEdgesToItems(data.attribute?.choices)?.map(({ name, slug }) => ({

Copilot uses AI. Check for mistakes.
label: name,
value: slug,
})) ?? [],
);
}

export default makeSearch<SearchAttributeValuesQuery, SearchAttributeValuesQueryVariables>(
SearchAttributeValuesDocument,
result => {
if (result.data?.attribute.choices.pageInfo.hasNextPage) {
if (result.data?.attribute?.choices?.pageInfo?.hasNextPage) {
result.loadMore(
(prev, next) => {
if (
Expand All @@ -60,15 +60,19 @@ export default makeSearch<SearchAttributeValuesQuery, SearchAttributeValuesQuery
return prev;
}

if (!next.attribute || !next.attribute.choices || !prev.attribute) {
return prev;
}

return {
...prev,
attribute: {
...prev.attribute,
choices: {
...prev?.attribute.choices,
...(prev.attribute.choices ?? next.attribute.choices),
edges: [
...(prev.attribute.choices?.edges ?? []),
...(next.attribute.choices?.edges ?? []),
...(next.attribute.choices.edges ?? []),
],
pageInfo: next.attribute.choices.pageInfo,
},
Expand All @@ -78,7 +82,7 @@ export default makeSearch<SearchAttributeValuesQuery, SearchAttributeValuesQuery
{
...result.variables,
after: result.data.attribute.choices.pageInfo.endCursor,
},
} as Partial<SearchAttributeValuesQueryVariables>,
);
}
},
Expand Down
15 changes: 10 additions & 5 deletions src/searches/useAvailableInGridAttributesSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchAvailableInGridAttributesDocument,
Expand Down Expand Up @@ -32,26 +31,32 @@ export default makeSearch<
SearchAvailableInGridAttributesQuery,
SearchAvailableInGridAttributesQueryVariables
>(SearchAvailableInGridAttributesDocument, result => {
if (result.data?.availableInGrid.pageInfo.hasNextPage) {
if (result.data?.availableInGrid?.pageInfo?.hasNextPage) {
result.loadMore(
(prev, next) => {
if (prev.availableInGrid.pageInfo.endCursor === next.availableInGrid.pageInfo.endCursor) {
if (
prev.availableInGrid?.pageInfo?.endCursor === next.availableInGrid?.pageInfo?.endCursor
) {
return prev;
}

if (!next.availableInGrid || !prev.availableInGrid) {
return prev;
}

return {
...prev,
availableInGrid: {
...prev.availableInGrid,
edges: [...prev.availableInGrid.edges, ...next.availableInGrid.edges],
edges: [...(prev.availableInGrid.edges ?? []), ...(next.availableInGrid.edges ?? [])],
pageInfo: next.availableInGrid.pageInfo,
},
} as SearchAvailableInGridAttributesQuery;
},
{
...result.variables,
after: result.data.availableInGrid.pageInfo.endCursor,
},
} as Partial<SearchAvailableInGridAttributesQueryVariables>,
);
}
});
64 changes: 35 additions & 29 deletions src/searches/useAvailablePageAttributesSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchAvailablePageAttributesDocument,
Expand Down Expand Up @@ -28,33 +27,40 @@ export const searchPageAttributes = gql`
export default makeSearch<
SearchAvailablePageAttributesQuery,
SearchAvailablePageAttributesQueryVariables
>(SearchAvailablePageAttributesDocument, result =>
result.loadMore(
(prev, next) => {
if (
prev.pageType.availableAttributes.pageInfo.endCursor ===
next.pageType.availableAttributes.pageInfo.endCursor
) {
return prev;
}
>(SearchAvailablePageAttributesDocument, result => {
if (result.data?.pageType?.availableAttributes?.pageInfo?.hasNextPage) {
result.loadMore(
(prev, next) => {
if (
prev.pageType?.availableAttributes?.pageInfo?.endCursor ===
next.pageType?.availableAttributes?.pageInfo?.endCursor
) {
return prev;
}

return {
...prev,
pageType: {
...prev.pageType,
availableAttributes: {
...prev.pageType.availableAttributes,
edges: [
...prev.pageType.availableAttributes.edges,
...next.pageType.availableAttributes.edges,
],
pageInfo: next.pageType.availableAttributes.pageInfo,
if (!next.pageType || !next.pageType.availableAttributes || !prev.pageType) {
return prev;
}

return {
...prev,
pageType: {
...prev.pageType,
availableAttributes: {
...(prev.pageType.availableAttributes ?? next.pageType.availableAttributes),
edges: [
...(prev.pageType.availableAttributes?.edges ?? []),
...(next.pageType.availableAttributes.edges ?? []),
],
pageInfo: next.pageType.availableAttributes.pageInfo,
},
},
},
};
},
{
after: result.data.pageType.availableAttributes.pageInfo.endCursor,
},
),
);
};
},
{
...result.variables,
after: result.data.pageType.availableAttributes.pageInfo.endCursor,
} as Partial<SearchAvailablePageAttributesQueryVariables>,
);
}
});
64 changes: 35 additions & 29 deletions src/searches/useAvailableProductAttributeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchAvailableProductAttributesDocument,
Expand Down Expand Up @@ -28,33 +27,40 @@ export const searchProductAttributes = gql`
export default makeSearch<
SearchAvailableProductAttributesQuery,
SearchAvailableProductAttributesQueryVariables
>(SearchAvailableProductAttributesDocument, result =>
result.loadMore(
(prev, next) => {
if (
prev.productType.availableAttributes.pageInfo.endCursor ===
next.productType.availableAttributes.pageInfo.endCursor
) {
return prev;
}
>(SearchAvailableProductAttributesDocument, result => {
if (result.data?.productType?.availableAttributes?.pageInfo?.hasNextPage) {
result.loadMore(
(prev, next) => {
if (
prev.productType?.availableAttributes?.pageInfo?.endCursor ===
next.productType?.availableAttributes?.pageInfo?.endCursor
) {
return prev;
}

return {
...prev,
productType: {
...prev.productType,
availableAttributes: {
...prev.productType.availableAttributes,
edges: [
...prev.productType.availableAttributes.edges,
...next.productType.availableAttributes.edges,
],
pageInfo: next.productType.availableAttributes.pageInfo,
if (!next.productType || !next.productType.availableAttributes || !prev.productType) {
return prev;
}

return {
...prev,
productType: {
...prev.productType,
availableAttributes: {
...(prev.productType.availableAttributes ?? next.productType.availableAttributes),
edges: [
...(prev.productType.availableAttributes?.edges ?? []),
...(next.productType.availableAttributes.edges ?? []),
],
pageInfo: next.productType.availableAttributes.pageInfo,
},
},
},
};
},
{
after: result.data.productType.availableAttributes.pageInfo.endCursor,
},
),
);
};
},
{
...result.variables,
after: result.data.productType.availableAttributes.pageInfo.endCursor,
} as Partial<SearchAvailableProductAttributesQueryVariables>,
);
}
});
1 change: 0 additions & 1 deletion src/searches/useCategorySearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchCategoriesDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useCollectionSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchCollectionsDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useCustomerSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchCustomersDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useGiftCardTagsSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchGiftCardTagsDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useOrderVariantSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchOrderVariantDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/usePageSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchPagesDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/usePageTypeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchPageTypesDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/usePermissionGroupSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchPermissionGroupsDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useProductSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchProductsDocument,
Expand Down
12 changes: 6 additions & 6 deletions src/searches/useProductTypeSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql, useApolloClient } from "@apollo/client";
import {
SearchProductTypesDocument,
Expand Down Expand Up @@ -36,11 +35,12 @@ export function useSearchProductTypes() {
query,
},
})
.then(({ data }) =>
mapEdgesToItems(data.search).map(({ name, id }) => ({
label: name,
value: id,
})),
.then(
({ data }) =>
mapEdgesToItems(data.search ?? undefined)?.map(({ name, id }) => ({
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ?? undefined is redundant here. The mapEdgesToItems function already accepts undefined | null as per its signature: function mapEdgesToItems<T>(data?: Connection<T> | undefined | null). You can simplify this to mapEdgesToItems(data.search)?.map(...).

Suggested change
mapEdgesToItems(data.search ?? undefined)?.map(({ name, id }) => ({
mapEdgesToItems(data.search)?.map(({ name, id }) => ({

Copilot uses AI. Check for mistakes.
label: name,
value: id,
})) ?? [],
);
}

Expand Down
1 change: 0 additions & 1 deletion src/searches/useShippingZonesSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchShippingZonesDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useStaffMemberSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchStaffMembersDocument,
Expand Down
1 change: 0 additions & 1 deletion src/searches/useWarehouseSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { gql } from "@apollo/client";
import {
SearchWarehousesDocument,
Expand Down
Loading