-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Filter Feature #6684
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
Merged
+1,562
−8
Merged
Filter Feature #6684
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5a287a
feat: filterSearch initial version
sujithvn d59ee6f
fix: graphql linter errors and reversal sampledata
sujithvn 566714e
fix: review comment fixes
sujithvn 21c62f1
fix: review comment fixes 2
sujithvn 315bb97
fix: add changeset and unit test
sujithvn cde07fd
fix: update README of plugins - utils & products
sujithvn 9dc4fe9
fix: more review comment fixes
sujithvn 8c72369
fix: fixed 1 missed entry in test case
sujithvn 0bc6279
fix: upgrade version of api-util and simp-schema
sujithvn 0e4b0dc
Merge branch 'trunk' into feat-filter-search
sujithvn f16ad92
fix: update api-util and pnpm-lock
sujithvn 5c86ead
fix: revert simpl-schema version to 1.12
sujithvn 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 hidden or 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,9 @@ | ||
--- | ||
"@reactioncommerce/api-core": minor | ||
"@reactioncommerce/api-plugin-accounts": minor | ||
"@reactioncommerce/api-plugin-orders": minor | ||
"@reactioncommerce/api-plugin-products": minor | ||
"@reactioncommerce/api-utils": minor | ||
--- | ||
|
||
Filter feature. This new feature provides a common function that can be used in a new query endpoint to get filtered results from any collection. |
This file contains hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
packages/api-plugin-accounts/src/queries/filterAccounts.js
This file contains hidden or 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,24 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterAccounts | ||
* @method | ||
* @memberof GraphQL/Accounts | ||
* @summary Query the Accounts collection for a list of customers/accounts | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Accounts object Promise | ||
*/ | ||
export default async function filterAccounts(context, conditions, shopId) { | ||
const { collections: { Accounts } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Account", conditions, shopId); | ||
|
||
return Accounts.find(filterQuery); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/api-plugin-accounts/src/queries/filterCustomers.js
This file contains hidden or 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,25 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterCustomers | ||
* @method | ||
* @memberof GraphQL/Customers | ||
* @summary Query the Accounts collection for a list of customers/accounts | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Accounts object Promise | ||
*/ | ||
export default async function filterCustomers(context, conditions, shopId) { | ||
const { collections: { Accounts } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Account", conditions, shopId); | ||
|
||
filterQuery.groups = { $in: [null, []] }; // filter out non-customer accounts | ||
return Accounts.find(filterQuery); | ||
} |
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
packages/api-plugin-accounts/src/resolvers/Query/filterAccounts.js
This file contains hidden or 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 getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; | ||
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; | ||
|
||
/** | ||
* @name Query/accounts | ||
* @method | ||
* @memberof Accounts/Query | ||
* @summary Query for a list of accounts | ||
* @param {Object} _ - unused | ||
* @param {Object} args - an object of all arguments that were sent by the client | ||
* @param {String} args.shopId - id of shop to query | ||
* @param {Object} args.conditions - object containing the filter conditions | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} info Info about the GraphQL request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing - in JSDoc |
||
* @returns {Promise<Object>} Accounts | ||
*/ | ||
export default async function filterAccounts(_, args, context, info) { | ||
const { | ||
shopId, | ||
conditions, | ||
...connectionArgs | ||
} = args; | ||
|
||
const query = await context.queries.filterAccounts(context, conditions, shopId); | ||
|
||
return getPaginatedResponse(query, connectionArgs, { | ||
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info), | ||
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info), | ||
includeTotalCount: wasFieldRequested("totalCount", info) | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/api-plugin-accounts/src/resolvers/Query/filterCustomers.js
This file contains hidden or 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 getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; | ||
import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; | ||
|
||
/** | ||
* @name Query/accounts | ||
* @method | ||
* @memberof Customers/Query | ||
* @summary Query for a list of customers | ||
* @param {Object} _ - unused | ||
* @param {Object} args - an object of all arguments that were sent by the client | ||
* @param {String} args.shopId - id of shop to query | ||
* @param {Object} args.conditions - object containing the filter conditions | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} info Info about the GraphQL request | ||
* @returns {Promise<Object>} Accounts | ||
*/ | ||
export default async function filterCustomers(_, args, context, info) { | ||
const { | ||
shopId, | ||
conditions, | ||
...connectionArgs | ||
} = args; | ||
|
||
const query = await context.queries.filterCustomers(context, conditions, shopId); | ||
|
||
return getPaginatedResponse(query, connectionArgs, { | ||
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info), | ||
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info), | ||
includeTotalCount: wasFieldRequested("totalCount", info) | ||
}); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,25 @@ | ||
import generateFilterQuery from "@reactioncommerce/api-utils/generateFilterQuery.js"; | ||
|
||
/** | ||
* @name filterOrders | ||
* @method | ||
* @memberof GraphQL/Orders | ||
* @summary Query the Orders collection for a list of orders | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} conditions - object containing the filter conditions | ||
* @param {String} shopId - shopID to filter by | ||
* @returns {Promise<Object>} Orders object Promise | ||
*/ | ||
export default async function filterOrders(context, conditions, shopId) { | ||
const { collections: { Orders } } = context; | ||
|
||
if (!shopId) { | ||
throw new Error("shopId is required"); | ||
} | ||
|
||
await context.validatePermissions("reaction:legacy:orders", "read", { shopId }); | ||
|
||
const { filterQuery } = generateFilterQuery(context, "Order", conditions, shopId); | ||
|
||
return Orders.find(filterQuery); | ||
} |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.