Skip to content

Commit

Permalink
Merge pull request #10749 from DestinyItemManager/migrate-reversed
Browse files Browse the repository at this point in the history
Fix migration of reversed sorts
  • Loading branch information
bhollis authored Oct 10, 2024
2 parents 28675a1 + f161b03 commit e9dbca7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/app/dim-api/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,23 +463,20 @@ function migrateSettings(state: DimApiState) {
}

// Replace 'element' sort with 'elementWeapon' and 'elementArmor'
const sortOrder = state.settings.itemSortOrderCustom || [];
const reversals = state.settings.itemSortReversals || [];
const sortOrder = [...new Set(state.settings.itemSortOrderCustom || [])];
const reversals = [...new Set(state.settings.itemSortReversals || [])];

if (sortOrder.includes('element')) {
state = changeSetting(
state,
'itemSortOrderCustom',
sortOrder.toSpliced(sortOrder.indexOf('element'), 1, 'elementWeapon', 'elementArmor'),
);
sortOrder.splice(sortOrder.indexOf('element'), 1, 'elementWeapon', 'elementArmor');
}
if (sortOrder.length !== (state.settings.itemSortOrderCustom?.length ?? 0)) {
state = changeSetting(state, 'itemSortOrderCustom', sortOrder);
}

if (reversals.includes('element')) {
state = changeSetting(
state,
'itemSortReversals',
reversals.toSpliced(sortOrder.indexOf('element'), 1, 'elementWeapon', 'elementArmor'),
);
reversals.splice(reversals.indexOf('element'), 1, 'elementWeapon', 'elementArmor');
}
if (reversals.length !== (state.settings.itemSortReversals?.length ?? 0)) {
state = changeSetting(state, 'itemSortReversals', reversals);
}

// converts any old custom stats stored in the old settings key, to the new format
Expand Down
10 changes: 10 additions & 0 deletions src/app/search/__snapshots__/query-parser.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parse | |: ast 1`] = `
{
"length": 0,
"op": "noop",
"startIndex": 0,
}
`;

exports[`parse | |: lexer 1`] = `[]`;

exports[`parse | (
(
(is:weapon -is:maxpower powerlimit:1060 or tag:junk or is:blue)
Expand Down
1 change: 1 addition & 0 deletions src/app/search/query-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const cases = [
[
'/* My cool search */ (/* armor */ is:armor and is:blue) or (/*weapons*/ is:weapon and perkname:"Kill Clip")',
],
[' '],
];

// Each of these asserts that the first query is the same as the second query once parsed
Expand Down
3 changes: 3 additions & 0 deletions src/app/search/search-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ export function parseAndValidateQuery<I, FilterCtx, SuggestionsCtx>(
if (ast.op === 'or' && ast.operands.every((op) => op.op === 'filter' && op.type === 'id')) {
saveInHistory = false;
}
if (ast.op === 'noop') {
saveable = false;
}
canonical = canonicalizeQuery(ast);
saveable = canonical.length <= 2048;
}
Expand Down

0 comments on commit e9dbca7

Please sign in to comment.