-
-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10451 from DestinyItemManager/search-stuff
Loadout search tweaks
- Loading branch information
Showing
9 changed files
with
106 additions
and
9 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
18 changes: 18 additions & 0 deletions
18
src/app/search/loadouts/__snapshots__/loadout-search-filter.test.ts.snap
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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`buildSearchConfig generates a reasonable filter map: is filters 1`] = ` | ||
[ | ||
"fashiononly", | ||
"modsonly", | ||
] | ||
`; | ||
|
||
exports[`buildSearchConfig generates a reasonable filter map: key-value filters 1`] = ` | ||
[ | ||
"exactname", | ||
"keyword", | ||
"name", | ||
"notes", | ||
"season", | ||
] | ||
`; |
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,40 @@ | ||
import { canonicalFilterFormats } from '../filter-types'; | ||
import { buildFiltersMap } from '../search-config'; | ||
import { allLoadoutFilters } from './loadout-search-filter'; | ||
|
||
describe('buildSearchConfig', () => { | ||
const searchConfig = buildFiltersMap(2, allLoadoutFilters); | ||
|
||
test('generates a reasonable filter map', () => { | ||
expect(Object.keys(searchConfig.isFilters).sort()).toMatchSnapshot('is filters'); | ||
expect(Object.keys(searchConfig.kvFilters).sort()).toMatchSnapshot('key-value filters'); | ||
}); | ||
|
||
test('filter formats specify unambiguous formats ', () => { | ||
/* | ||
* We have a bunch of filter formats for which `keyword:value` | ||
* with purely alphabetic values can be valid syntax. Filters should | ||
* avoid specifying more than one of these. | ||
* query and freeform filters are sort of the same thing, | ||
* except queries are exhaustive and freeform aren't. Overloaded | ||
* range filters can also accept single words as filter value, | ||
* because `season:worthy` is actually `season:10` and we don't | ||
* want these to be mistaken for queries or freeforms. | ||
*/ | ||
|
||
for (const filter of searchConfig.allFilters) { | ||
let formats = canonicalFilterFormats(filter.format); | ||
|
||
if (formats.length < 1) { | ||
throw new Error(`filter ${filter.keywords} has no formats`); | ||
} | ||
|
||
formats = formats.filter( | ||
(f) => f === 'query' || f === 'freeform' || (f === 'range' && filter.overload), | ||
); | ||
if (formats.length > 1) { | ||
throw new Error(`filter ${filter.keywords} specifies ambiguous formats ${formats}`); | ||
} | ||
} | ||
}); | ||
}); |
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,30 @@ | ||
import { tl } from 'app/i18next-t'; | ||
import { Loadout } from 'app/loadout-drawer/loadout-types'; | ||
import { isArmorModsOnly, isFashionOnly } from 'app/loadout-drawer/loadout-utils'; | ||
import { FilterDefinition } from 'app/search/filter-types'; | ||
import { LoadoutFilterContext, LoadoutSuggestionsContext } from '../loadout-filter-types'; | ||
|
||
// simple checks against check an attribute found on DimItem | ||
const simpleFilters: FilterDefinition<Loadout, LoadoutFilterContext, LoadoutSuggestionsContext>[] = | ||
[ | ||
{ | ||
keywords: 'fashiononly', | ||
description: tl('LoadoutFilter.FashionOnly'), | ||
destinyVersion: 2, | ||
filter: | ||
({ d2Definitions }) => | ||
(loadout) => | ||
isFashionOnly(d2Definitions!, loadout), | ||
}, | ||
{ | ||
keywords: 'modsonly', | ||
description: tl('LoadoutFilter.ModsOnly'), | ||
destinyVersion: 2, | ||
filter: | ||
({ d2Definitions }) => | ||
(loadout) => | ||
isArmorModsOnly(d2Definitions!, loadout), | ||
}, | ||
]; | ||
|
||
export default simpleFilters; |
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