-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix search by order number in Navigator #5063
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1a2159
use search by order number
Cloud11PL 7e692d2
fixes
Cloud11PL 0819685
Update src/components/NavigatorSearch/modes/orders.ts
Cloud11PL 2193cff
lint
Cloud11PL 3129ee2
add test for making search query
Cloud11PL 4f0cd4c
improve test
Cloud11PL 7f345a1
Merge branch 'main' into MERX-637-search-bar-order
Cloud11PL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
You can now search by order number in Navigator search. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// @ts-strict-ignore | ||
import { | ||
CheckIfOrderExistsQuery, | ||
SearchCatalogQuery, | ||
SearchCustomersQuery, | ||
} from "@dashboard/graphql"; | ||
import { SearchCatalogQuery, SearchCustomersQuery } from "@dashboard/graphql"; | ||
import { RelayToFlat } from "@dashboard/types"; | ||
|
||
import { QuickOrderSearchResult } from "../queries/useQuickOrderSearch"; | ||
|
||
export interface ActionQueries { | ||
catalog: SearchCatalogQuery; | ||
customers: RelayToFlat<SearchCustomersQuery["search"]>; | ||
order: CheckIfOrderExistsQuery["order"]; | ||
orders: QuickOrderSearchResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/components/NavigatorSearch/queries/useCheckIfOrderExists.ts
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/components/NavigatorSearch/queries/useQuickOrderSearch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { act, renderHook } from "@testing-library/react-hooks"; | ||
|
||
import { useQuickOrderSearch } from "./useQuickOrderSearch"; | ||
|
||
const useSearchOrdersByNumberQuery = jest.fn(); | ||
|
||
jest.mock("@dashboard/graphql", () => ({ | ||
SearchOrdersByNumberQuery: {}, | ||
useSearchOrdersByNumberQuery: (props: any) => useSearchOrdersByNumberQuery(props), | ||
})); | ||
jest.mock("@dashboard/hooks/useDebounce", () => (fn: any) => fn); | ||
|
||
describe("useQuickOrderSearch", () => { | ||
it("invokes search query", () => { | ||
// Arrange | ||
const { result } = renderHook(() => useQuickOrderSearch()); | ||
const [, setQueryDebounced] = result.current; | ||
|
||
// Act | ||
act(() => setQueryDebounced("1234")); | ||
|
||
// Assert | ||
expect(useSearchOrdersByNumberQuery).toHaveBeenCalledWith({ | ||
skip: false, | ||
variables: { | ||
first: 1, | ||
query: "1234", | ||
}, | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/components/NavigatorSearch/queries/useQuickOrderSearch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
SearchOrdersByNumberQuery, | ||
SearchOrdersByNumberQueryHookResult, | ||
useSearchOrdersByNumberQuery, | ||
} from "@dashboard/graphql"; | ||
import useDebounce from "@dashboard/hooks/useDebounce"; | ||
import { useState } from "react"; | ||
|
||
type OrderNode = NonNullable<SearchOrdersByNumberQuery["orders"]>["edges"][0]["node"]; | ||
export type QuickOrderSearchResult = OrderNode[]; | ||
|
||
export function useQuickOrderSearch(): [ | ||
SearchOrdersByNumberQueryHookResult, | ||
(query: string) => void, | ||
] { | ||
const [query, setQuery] = useState<string>(""); | ||
const setQueryDebounced = useDebounce(setQuery); | ||
|
||
const result = useSearchOrdersByNumberQuery({ | ||
skip: query === "", | ||
variables: { | ||
first: 1, | ||
query, | ||
}, | ||
}); | ||
|
||
return [result, setQueryDebounced]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't entries be a links? navigation based on onClick are hacky a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can improve it in the scope of the general Navigator improvements ticket (it's in backlog)