-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(next-queries): add next query preview logic #611
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f4547fd
chore: WIP add next query preview request
ajperezbau 877f657
feat: add next query preview request and save it on the store
ajperezbau 08d20b1
feat: reset results when a user accepts a query
ajperezbau 542397f
feat: add NextQueryPreviewMounted event to wiring
ajperezbau 3745b80
feat: create mutation to reset the next queries results
ajperezbau 8d8f5b2
test: add tests to fetchNextQueryPreview action
ajperezbau 35fa95d
feat: change fetch and save action to avoid cancelling the previous p…
ajperezbau 012e571
docs: add doc
ajperezbau 0e9b587
fix: PR Fixes
ajperezbau d8b84cf
refactor: remove unneeded type and change setResultsPreview action to…
ajperezbau 2330e3f
fix: add catch to fetchAndSave action
ajperezbau 92b593f
feat: add next-query-preview-results type to x-types
ajperezbau 8af670d
refactor: change NextQueryPreviewResults type import
ajperezbau cf82627
fix: PR fix
ajperezbau 9caed35
fix: PR Fixes
ajperezbau 9f62b86
Merge branch 'main' into feature/EX-6119-add-next-query-preview-logic
ajperezbau e82cd16
fix: PR Fixes
ajperezbau 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
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,13 @@ | ||
import { Result } from './result/result.model'; | ||
|
||
/** | ||
* Interface to type the query preview objects. | ||
*/ | ||
export interface PreviewResults { | ||
/** The searched query. */ | ||
query: string; | ||
/** The results to preview the search request. */ | ||
items: Result[]; | ||
/** The number of results of the query. */ | ||
totalResults: number; | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...ents/src/x-modules/next-queries/store/actions/fetch-and-save-next-query-preview.action.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,22 @@ | ||
import { NextQueriesXStoreModule } from '../types'; | ||
|
||
// eslint-disable-next-line max-len | ||
export const fetchAndSaveNextQueryPreview: NextQueriesXStoreModule['actions']['fetchAndSaveNextQueryPreview'] = | ||
({ dispatch, commit }, query): Promise<void> => { | ||
return dispatch('fetchNextQueryPreview', query) | ||
.then(response => { | ||
if (response) { | ||
commit('setResultsPreview', { | ||
[query]: { | ||
query, | ||
totalResults: response.totalResults, | ||
items: response.results | ||
} | ||
}); | ||
} | ||
}) | ||
.catch(error => { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
}); | ||
}; |
30 changes: 30 additions & 0 deletions
30
.../x-components/src/x-modules/next-queries/store/actions/fetch-next-query-preview.action.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,30 @@ | ||
import { NextQueriesXStoreModule } from '../types'; | ||
import { XPlugin } from '../../../../plugins/x-plugin'; | ||
|
||
/** | ||
* Default implementation for the {@link NextQueriesActions.fetchNextQueryPreview}. | ||
* | ||
* @param state - The state of the store, used to retrieve the rows and the extraParams to be sent | ||
* in the request. | ||
* @param query - The next query to send in the request. | ||
* @returns A Promise of a SearchResponse when it fetches the results, `null` if the request was | ||
* not made. | ||
*/ | ||
export const fetchNextQueryPreview: NextQueriesXStoreModule['actions']['fetchNextQueryPreview'] = ( | ||
{ state }, | ||
query | ||
) => { | ||
if (!query) { | ||
return null; | ||
} | ||
return XPlugin.adapter.search( | ||
{ | ||
query, | ||
rows: state.config.maxPreviewItemsToRequest, | ||
extraParams: state.params | ||
}, | ||
{ | ||
id: `fetchNextQueryPreview-${query}` | ||
} | ||
); | ||
}; |
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
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.
The query is a required parameter for this action, so no checks should be needed. We can trust TypeScript. With this I believe we can simplify the return type and just set a
SearchResponse
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.
Even if the query is a required parameter, nothing avoids calling the function with an empty string, although that would not be a legit use of this function 🤔
Should I remove that comprobation anyway?
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 think Abraham is right, and I would leave the empty string check. Specially thinking of reusing the wire with custom wiring config in setups. Better prevent an error request to API