-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make getEdgeFilteringWarning a util, memoize derived state
- Loading branch information
Showing
5 changed files
with
64 additions
and
59 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Compare selected edges to edge filters to determine if a warning should be shown | ||
* @param {Array} filters - edge filters | ||
* @param {Array} edges - selected edges | ||
* There are four main cases to consider: | ||
* 1. Selected edge is in the filters with rule EXISTS -- no warning | ||
* 2. Selected edge is not in the filters with rule EXISTS -- show a warning | ||
* 3. Selected edge is in the filters with rule DOES_NOT_EXIST -- show a warning | ||
* 4. Selected edge is not in the filters with rule DOES_NOT_EXIST -- no warning | ||
*/ | ||
|
||
const getEdgeFilteringWarning = (filters, edges) => { | ||
const existFilters = filters.filter((rule) => rule.options.operator === 'EXISTS'); | ||
const doesNotExistFilters = filters.filter((rule) => rule.options.operator === 'NOT_EXISTS'); | ||
|
||
// if any edge should show a warning, return true | ||
return edges.some((edge) => { | ||
const isEdgeInExistFilters = existFilters.some((rule) => rule.options.type === edge); | ||
const isEdgeInDoesNotExistFilters = doesNotExistFilters.some( | ||
(rule) => rule.options.type === edge, | ||
); | ||
|
||
// case 1 | ||
if (isEdgeInExistFilters) { | ||
return false; | ||
} | ||
|
||
// case 2 | ||
if (!isEdgeInExistFilters && existFilters.length > 0) { | ||
return true; | ||
} | ||
|
||
// case 3 | ||
if (isEdgeInDoesNotExistFilters) { | ||
return true; | ||
} | ||
|
||
// No warning in other cases | ||
return false; | ||
}); | ||
}; | ||
|
||
export default getEdgeFilteringWarning; |