diff --git a/plugins/home/src/api/config.test.ts b/plugins/home/src/api/config.test.ts index 178287bb3d..c21d856038 100644 --- a/plugins/home/src/api/config.test.ts +++ b/plugins/home/src/api/config.test.ts @@ -23,13 +23,13 @@ describe('config', () => { const mockConfig = new MockConfigApi({ field: 'pathname', operator: '==', - value: '3', + value: '/home', }); const res = readFilterConfig(mockConfig); expect(res).toEqual({ field: 'pathname', operator: '==', - value: '3', + value: '/home', }); }); @@ -66,11 +66,11 @@ describe('config', () => { ]); }); - it('returns only invalid filters', async () => { + it('returns only valid filters', async () => { const mockValidConfig = new MockConfigApi({ field: 'id', operator: '==', - value: '3', + value: 3, }); const mockInvalidConfig = new MockConfigApi({ myField: 'pathname', @@ -81,7 +81,7 @@ describe('config', () => { mockValidConfig, mockInvalidConfig, ]); - expect(res).toEqual([{ field: 'id', operator: '==', value: '3' }]); + expect(res).toEqual([{ field: 'id', operator: '==', value: 3 }]); }); }); }); diff --git a/plugins/home/src/api/config.ts b/plugins/home/src/api/config.ts index 359026958f..65833c13d5 100644 --- a/plugins/home/src/api/config.ts +++ b/plugins/home/src/api/config.ts @@ -40,9 +40,8 @@ export function readFilterConfig(config: Config): try { const field = config.getString('field') as keyof Visit; const operator = config.getString('operator'); - const value = - config.getOptionalNumber('value') ?? config.getString('value'); - if (isOperator(operator)) { + const value = getValue(config); + if (isOperator(operator) && value !== undefined) { return { field, operator, value }; } return undefined; @@ -52,6 +51,20 @@ export function readFilterConfig(config: Config): } } +function getValue(config: Config) { + let value = undefined; + try { + value = config.getString('value'); + } catch (error) { + try { + value = config.getNumber('value'); + } catch { + // value is not string or number - ignore filter + } + } + return value; +} + /** * Reads a set of filter by configs. *