Skip to content
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

Revert syntax range color back to black #56869

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6216,7 +6216,6 @@ const CONST = {
LOWER_THAN: 'lt',
LOWER_THAN_OR_EQUAL_TO: 'lte',
},
SYNTAX_RANGE_NAME: 'syntax',
SYNTAX_ROOT_KEYS: {
TYPE: 'type',
STATUS: 'status',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function buildSubstitutionsMap(
): SubstitutionMap {
const parsedQuery = parse(query) as {ranges: SearchAutocompleteQueryRange[]};

const searchAutocompleteQueryRanges = parsedQuery.ranges.filter((range) => range.key !== CONST.SEARCH.SYNTAX_RANGE_NAME);

const searchAutocompleteQueryRanges = parsedQuery.ranges;
if (searchAutocompleteQueryRanges.length === 0) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type {SearchAutocompleteQueryRange, SearchAutocompleteQueryRangeKey} from '@components/Search/types';
import type {SearchAutocompleteQueryRange, SearchFilterKey} from '@components/Search/types';
import {parse} from '@libs/SearchParser/autocompleteParser';
import {sanitizeSearchValue} from '@libs/SearchQueryUtils';
import CONST from '@src/CONST';

type SubstitutionMap = Record<string, string>;

const getSubstitutionMapKey = (filterKey: SearchAutocompleteQueryRangeKey, value: string) => `${filterKey}:${value}`;
const getSubstitutionMapKey = (filterKey: SearchFilterKey, value: string) => `${filterKey}:${value}`;

/**
* Given a plaintext query and a SubstitutionMap object, this function will return a transformed query where:
Expand All @@ -22,7 +21,7 @@ const getSubstitutionMapKey = (filterKey: SearchAutocompleteQueryRangeKey, value
function getQueryWithSubstitutions(changedQuery: string, substitutions: SubstitutionMap) {
const parsed = parse(changedQuery) as {ranges: SearchAutocompleteQueryRange[]};

const searchAutocompleteQueryRanges = parsed.ranges.filter((range) => range.key !== CONST.SEARCH.SYNTAX_RANGE_NAME);
const searchAutocompleteQueryRanges = parsed.ranges;

if (searchAutocompleteQueryRanges.length === 0) {
return changedQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {SearchAutocompleteQueryRange, SearchAutocompleteQueryRangeKey} from '@components/Search/types';
import type {SearchAutocompleteQueryRange, SearchFilterKey} from '@components/Search/types';
import {parse} from '@libs/SearchParser/autocompleteParser';
import CONST from '@src/CONST';
import type {SubstitutionMap} from './getQueryWithSubstitutions';

const getSubstitutionsKey = (filterKey: SearchAutocompleteQueryRangeKey, value: string) => `${filterKey}:${value}`;
const getSubstitutionsKey = (filterKey: SearchFilterKey, value: string) => `${filterKey}:${value}`;

/**
* Given a plaintext query and a SubstitutionMap object,
Expand All @@ -19,7 +18,7 @@ const getSubstitutionsKey = (filterKey: SearchAutocompleteQueryRangeKey, value:
function getUpdatedSubstitutionsMap(query: string, substitutions: SubstitutionMap): SubstitutionMap {
const parsedQuery = parse(query) as {ranges: SearchAutocompleteQueryRange[]};

const searchAutocompleteQueryRanges = parsedQuery.ranges.filter((range) => range.key !== CONST.SEARCH.SYNTAX_RANGE_NAME);
const searchAutocompleteQueryRanges = parsedQuery.ranges;

if (searchAutocompleteQueryRanges.length === 0) {
return {};
Expand Down
5 changes: 1 addition & 4 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ type SearchFilterKey =
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID;

type SearchAutocompleteQueryRangeKey = SearchFilterKey | typeof CONST.SEARCH.SYNTAX_RANGE_NAME;

type UserFriendlyKey = ValueOf<typeof CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS>;

type QueryFilters = Array<{
Expand Down Expand Up @@ -132,7 +130,7 @@ type SearchAutocompleteResult = {
};

type SearchAutocompleteQueryRange = {
key: SearchAutocompleteQueryRangeKey;
key: SearchFilterKey;
length: number;
start: number;
value: string;
Expand Down Expand Up @@ -161,5 +159,4 @@ export type {
SearchAutocompleteResult,
PaymentData,
SearchAutocompleteQueryRange,
SearchAutocompleteQueryRangeKey,
};
6 changes: 1 addition & 5 deletions src/libs/SearchAutocompleteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function filterOutRangesWithCorrectValue(
case CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG:
return tagList.get().includes(range.value);
default:
return true;
return false;
}
}

Expand All @@ -200,10 +200,6 @@ function parseForLiveMarkdown(
.map((range) => {
let type = 'mention-user';

if (range.key === CONST.SEARCH.SYNTAX_RANGE_NAME) {
type = CONST.SEARCH.SYNTAX_RANGE_NAME;
}

if ((range.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO || CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM) && (userLogins.get().includes(range.value) || range.value === userDisplayName)) {
type = 'mention-here';
}
Expand Down
19 changes: 2 additions & 17 deletions src/libs/SearchParser/autocompleteParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,34 +287,19 @@ function peg$parse(input, options) {
start: location().end.offset,
length: 0,
};
return {
key: "syntax",
value: key,
start: location().start.offset,
length: location().end.offset - location().start.offset,
};
return;
}

autocomplete = {
key,
...value[value.length - 1],
};
const result = value
return value
.filter((filter) => filter.length > 0)
.map((filter) => ({
key,
...filter,
}));

return [
{
key: "syntax",
value: key,
start: location().start.offset,
length: result[0].start - location().start.offset,
},
...result,
];
};
var peg$f3 = function() { autocomplete = null; };
var peg$f4 = function(parts, empty) {
Expand Down
19 changes: 2 additions & 17 deletions src/libs/SearchParser/autocompleteParser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,19 @@ defaultFilter
start: location().end.offset,
length: 0,
};
return {
key: "syntax",
value: key,
start: location().start.offset,
length: location().end.offset - location().start.offset,
};
return;
}

autocomplete = {
key,
...value[value.length - 1],
};
const result = value
return value
.filter((filter) => filter.length > 0)
.map((filter) => ({
key,
...filter,
}));

return [
{
key: "syntax",
value: key,
start: location().start.offset,
length: result[0].start - location().start.offset,
},
...result,
];
}

freeTextFilter = _ (identifier / ",") _ { autocomplete = null; }
Expand Down
42 changes: 4 additions & 38 deletions tests/unit/SearchAutocompleteParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const tests = [
length: 3,
},
ranges: [
{key: 'syntax', value: 'type', start: 0, length: 5},
{key: 'type', value: 'expense', start: 5, length: 7},
{key: 'syntax', value: 'status', start: 13, length: 7},
{key: 'status', value: 'all', start: 20, length: 3},
],
},
Expand All @@ -25,11 +23,8 @@ const tests = [
expected: {
autocomplete: null,
ranges: [
{key: 'syntax', value: 'taxRate', start: 0, length: 9},
{key: 'taxRate', value: 'rate1', start: 9, length: 5},
{key: 'syntax', value: 'expenseType', start: 15, length: 13},
{key: 'expenseType', value: 'card', start: 28, length: 4},
{key: 'syntax', value: 'cardID', start: 33, length: 5},
{key: 'cardID', value: 'Big Bank', start: 38, length: 10},
],
},
Expand All @@ -39,11 +34,8 @@ const tests = [
expected: {
autocomplete: null,
ranges: [
{key: 'syntax', value: 'taxRate', start: 0, length: 8},
{key: 'taxRate', value: 'rate1', start: 8, length: 5},
{key: 'syntax', value: 'expenseType', start: 14, length: 12},
{key: 'expenseType', value: 'card', start: 26, length: 4},
{key: 'syntax', value: 'cardID', start: 31, length: 7},
{key: 'cardID', value: 'Big Bank', start: 38, length: 10},
],
},
Expand All @@ -58,10 +50,8 @@ const tests = [
value: 'meal & entertainment',
},
ranges: [
{key: 'syntax', value: 'expenseType', start: 11, length: 13},
{key: 'expenseType', length: 4, start: 24, value: 'cash'},
{key: 'expenseType', length: 4, start: 29, value: 'card'},
{key: 'syntax', value: 'category', start: 80, length: 9},
{key: 'category', length: 6, start: 89, value: 'travel'},
{key: 'category', length: 5, start: 96, value: 'hotel'},
{key: 'category', length: 22, start: 102, value: 'meal & entertainment'},
Expand All @@ -78,11 +68,8 @@ const tests = [
value: 'a b',
},
ranges: [
{key: 'syntax', value: 'type', start: 0, length: 5},
{key: 'type', value: 'expense', start: 5, length: 7},
{key: 'syntax', value: 'status', start: 13, length: 7},
{key: 'status', value: 'all', start: 20, length: 3},
{key: 'syntax', value: 'category', start: 24, length: 9},
{key: 'category', value: 'a b', start: 33, length: 5},
],
},
Expand All @@ -105,7 +92,7 @@ const tests = [
query: 'tag:,,',
expected: {
autocomplete: null,
ranges: [{key: 'syntax', value: 'tag', start: 0, length: 4}],
ranges: [],
},
},
{
Expand All @@ -118,9 +105,7 @@ const tests = [
length: 3,
},
ranges: [
{key: 'syntax', value: 'in', start: 0, length: 3},
{key: 'in', value: '123456', start: 3, length: 6},
{key: 'syntax', value: 'currency', start: 10, length: 9},
{key: 'currency', value: 'USD', start: 19, length: 3},
],
},
Expand All @@ -135,7 +120,6 @@ const tests = [
length: 4,
},
ranges: [
{key: 'syntax', value: 'tag', start: 0, length: 4},
{key: 'tag', value: 'aa', start: 4, length: 2},
{key: 'tag', value: 'bbb', start: 7, length: 3},
{key: 'tag', value: 'cccc', start: 11, length: 4},
Expand All @@ -151,7 +135,7 @@ const tests = [
start: 9,
length: 0,
},
ranges: [{key: 'syntax', value: 'category', start: 0, length: 9}],
ranges: [],
},
},
{
Expand All @@ -163,10 +147,7 @@ const tests = [
start: 21,
length: 0,
},
ranges: [
{key: 'syntax', value: 'category', start: 0, length: 9},
{key: 'category', value: 'Advertising', start: 9, length: 11},
],
ranges: [{key: 'category', value: 'Advertising', start: 9, length: 11}],
},
},
{
Expand All @@ -179,7 +160,6 @@ const tests = [
length: 12,
},
ranges: [
{key: 'syntax', value: 'in', start: 0, length: 3},
{key: 'in', value: 'Big Room', start: 3, length: 10},
{key: 'in', value: 'small room', start: 14, length: 12},
],
Expand All @@ -194,20 +174,15 @@ const tests = [
start: 12,
length: 3,
},
ranges: [
{key: 'syntax', value: 'category', start: 0, length: 12},
{key: 'category', value: 'Car', start: 12, length: 3},
],
ranges: [{key: 'category', value: 'Car', start: 12, length: 3}],
},
},
{
query: 'type:expense status:all word',
expected: {
autocomplete: null,
ranges: [
{key: 'syntax', value: 'type', start: 0, length: 5},
{key: 'type', value: 'expense', start: 5, length: 7},
{key: 'syntax', value: 'status', start: 13, length: 7},
{key: 'status', value: 'all', start: 20, length: 3},
],
},
Expand All @@ -222,16 +197,11 @@ const tests = [
length: 4,
},
ranges: [
{key: 'syntax', value: 'in', start: 0, length: 3},
{key: 'in', value: 'Big Room', start: 3, length: 10},
{key: 'syntax', value: 'from', start: 14, length: 5},
{key: 'from', value: 'Friend', start: 19, length: 6},
{key: 'syntax', value: 'category', start: 26, length: 9},
{key: 'category', value: 'Car', start: 35, length: 3},
{key: 'category', value: 'Cell Phone', start: 39, length: 12},
{key: 'syntax', value: 'status', start: 52, length: 7},
{key: 'status', value: 'all', start: 59, length: 3},
{key: 'syntax', value: 'expenseType', start: 63, length: 13},
{key: 'expenseType', value: 'card', start: 76, length: 4},
{key: 'expenseType', value: 'cash', start: 81, length: 4},
],
Expand All @@ -247,15 +217,11 @@ const tests = [
length: 8,
},
ranges: [
{key: 'syntax', value: 'currency', start: 0, length: 9},
{key: 'currency', value: 'PLN', start: 9, length: 3},
{key: 'currency', value: 'USD', start: 13, length: 3},
{key: 'syntax', value: 'taxRate', start: 25, length: 9},
{key: 'taxRate', value: 'tax', start: 34, length: 3},
{key: 'syntax', value: 'tag', start: 66, length: 4},
{key: 'tag', value: 'General Overhead', start: 70, length: 18},
{key: 'tag', value: 'IT', start: 89, length: 2},
{key: 'syntax', value: 'expenseType', start: 92, length: 13},
{key: 'expenseType', value: 'card', start: 105, length: 4},
{key: 'expenseType', value: 'distance', start: 110, length: 8},
],
Expand Down
Loading